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
47extern_conformance!(
48    unsafe impl NSCopying for WKUserScript {}
49);
50
51unsafe impl CopyingHelper for WKUserScript {
52    type Result = Self;
53}
54
55extern_conformance!(
56    unsafe impl NSObjectProtocol for WKUserScript {}
57);
58
59impl WKUserScript {
60    extern_methods!(
61        #[unsafe(method(source))]
62        #[unsafe(method_family = none)]
63        pub unsafe fn source(&self) -> Retained<NSString>;
64
65        #[unsafe(method(injectionTime))]
66        #[unsafe(method_family = none)]
67        pub unsafe fn injectionTime(&self) -> WKUserScriptInjectionTime;
68
69        #[unsafe(method(isForMainFrameOnly))]
70        #[unsafe(method_family = none)]
71        pub unsafe fn isForMainFrameOnly(&self) -> bool;
72
73        /// Returns an initialized user script that can be added to a
74        ///
75        /// ```text
76        ///  WKUserContentController
77        /// ```
78        ///
79        /// .
80        ///
81        /// Parameter `source`: The script source.
82        ///
83        /// Parameter `injectionTime`: When the script should be injected.
84        ///
85        /// Parameter `forMainFrameOnly`: Whether the script should be injected into all frames or just the main frame.
86        ///
87        /// Calling this method is the same as calling `initWithSource:injectionTime:forMainFrameOnly:inContentWorld:` with a `contentWorld` value of `WKContentWorld.pageWorld`
88        #[unsafe(method(initWithSource:injectionTime:forMainFrameOnly:))]
89        #[unsafe(method_family = init)]
90        pub unsafe fn initWithSource_injectionTime_forMainFrameOnly(
91            this: Allocated<Self>,
92            source: &NSString,
93            injection_time: WKUserScriptInjectionTime,
94            for_main_frame_only: bool,
95        ) -> Retained<Self>;
96
97        #[cfg(feature = "WKContentWorld")]
98        /// Returns an initialized user script that can be added to a
99        ///
100        /// ```text
101        ///  WKUserContentController
102        /// ```
103        ///
104        /// .
105        ///
106        /// Parameter `source`: The script source.
107        ///
108        /// Parameter `injectionTime`: When the script should be injected.
109        ///
110        /// Parameter `forMainFrameOnly`: Whether the script should be injected into all frames or just the main frame.
111        ///
112        /// Parameter `contentWorld`: The WKContentWorld in which to inject the script.
113        #[unsafe(method(initWithSource:injectionTime:forMainFrameOnly:inContentWorld:))]
114        #[unsafe(method_family = init)]
115        pub unsafe fn initWithSource_injectionTime_forMainFrameOnly_inContentWorld(
116            this: Allocated<Self>,
117            source: &NSString,
118            injection_time: WKUserScriptInjectionTime,
119            for_main_frame_only: bool,
120            content_world: &WKContentWorld,
121        ) -> Retained<Self>;
122    );
123}
124
125/// Methods declared on superclass `NSObject`.
126impl WKUserScript {
127    extern_methods!(
128        #[unsafe(method(init))]
129        #[unsafe(method_family = init)]
130        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
131
132        #[unsafe(method(new))]
133        #[unsafe(method_family = new)]
134        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
135    );
136}