objc2_web_kit/generated/
WKUserScript.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ptr::NonNull;
4use objc2::__framework_prelude::*;
5use objc2_foundation::*;
6
7use crate::*;
8
9/// when a user script should be injected into a webpage.
10///
11/// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wkuserscriptinjectiontime?language=objc)
12// NS_ENUM
13#[repr(transparent)]
14#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
15pub struct WKUserScriptInjectionTime(pub NSInteger);
16impl WKUserScriptInjectionTime {
17    #[doc(alias = "WKUserScriptInjectionTimeAtDocumentStart")]
18    pub const AtDocumentStart: Self = Self(0);
19    #[doc(alias = "WKUserScriptInjectionTimeAtDocumentEnd")]
20    pub const AtDocumentEnd: Self = Self(1);
21}
22
23unsafe impl Encode for WKUserScriptInjectionTime {
24    const ENCODING: Encoding = NSInteger::ENCODING;
25}
26
27unsafe impl RefEncode for WKUserScriptInjectionTime {
28    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
29}
30
31extern_class!(
32    /// A
33    ///
34    /// ```text
35    ///  WKUserScript
36    /// ```
37    ///
38    /// object represents a script that can be injected into webpages.
39    ///
40    /// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wkuserscript?language=objc)
41    #[unsafe(super(NSObject))]
42    #[thread_kind = MainThreadOnly]
43    #[derive(Debug, PartialEq, Eq, Hash)]
44    pub struct WKUserScript;
45);
46
47unsafe impl NSCopying for WKUserScript {}
48
49unsafe impl CopyingHelper for WKUserScript {
50    type Result = Self;
51}
52
53unsafe impl NSObjectProtocol for WKUserScript {}
54
55impl WKUserScript {
56    extern_methods!(
57        #[unsafe(method(source))]
58        #[unsafe(method_family = none)]
59        pub unsafe fn source(&self) -> Retained<NSString>;
60
61        #[unsafe(method(injectionTime))]
62        #[unsafe(method_family = none)]
63        pub unsafe fn injectionTime(&self) -> WKUserScriptInjectionTime;
64
65        #[unsafe(method(isForMainFrameOnly))]
66        #[unsafe(method_family = none)]
67        pub unsafe fn isForMainFrameOnly(&self) -> bool;
68
69        /// Returns an initialized user script that can be added to a
70        ///
71        /// ```text
72        ///  WKUserContentController
73        /// ```
74        ///
75        /// .
76        ///
77        /// Parameter `source`: The script source.
78        ///
79        /// Parameter `injectionTime`: When the script should be injected.
80        ///
81        /// Parameter `forMainFrameOnly`: Whether the script should be injected into all frames or just the main frame.
82        ///
83        /// Calling this method is the same as calling `initWithSource:injectionTime:forMainFrameOnly:inContentWorld:` with a `contentWorld` value of `WKContentWorld.pageWorld`
84        #[unsafe(method(initWithSource:injectionTime:forMainFrameOnly:))]
85        #[unsafe(method_family = init)]
86        pub unsafe fn initWithSource_injectionTime_forMainFrameOnly(
87            this: Allocated<Self>,
88            source: &NSString,
89            injection_time: WKUserScriptInjectionTime,
90            for_main_frame_only: bool,
91        ) -> Retained<Self>;
92
93        #[cfg(feature = "WKContentWorld")]
94        /// Returns an initialized user script that can be added to a
95        ///
96        /// ```text
97        ///  WKUserContentController
98        /// ```
99        ///
100        /// .
101        ///
102        /// Parameter `source`: The script source.
103        ///
104        /// Parameter `injectionTime`: When the script should be injected.
105        ///
106        /// Parameter `forMainFrameOnly`: Whether the script should be injected into all frames or just the main frame.
107        ///
108        /// Parameter `contentWorld`: The WKContentWorld in which to inject the script.
109        #[unsafe(method(initWithSource:injectionTime:forMainFrameOnly:inContentWorld:))]
110        #[unsafe(method_family = init)]
111        pub unsafe fn initWithSource_injectionTime_forMainFrameOnly_inContentWorld(
112            this: Allocated<Self>,
113            source: &NSString,
114            injection_time: WKUserScriptInjectionTime,
115            for_main_frame_only: bool,
116            content_world: &WKContentWorld,
117        ) -> Retained<Self>;
118    );
119}
120
121/// Methods declared on superclass `NSObject`.
122impl WKUserScript {
123    extern_methods!(
124        #[unsafe(method(init))]
125        #[unsafe(method_family = init)]
126        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
127
128        #[unsafe(method(new))]
129        #[unsafe(method_family = new)]
130        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
131    );
132}