objc2_web_kit/generated/WKUserContentController.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_class!(
11 /// A WKUserContentController object provides a way for JavaScript to post
12 /// messages to a web view.
13 /// The user content controller associated with a web view is specified by its
14 /// web view configuration.
15 ///
16 /// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/wkusercontentcontroller?language=objc)
17 #[unsafe(super(NSObject))]
18 #[thread_kind = MainThreadOnly]
19 #[derive(Debug, PartialEq, Eq, Hash)]
20 pub struct WKUserContentController;
21);
22
23extern_conformance!(
24 unsafe impl NSCoding for WKUserContentController {}
25);
26
27extern_conformance!(
28 unsafe impl NSObjectProtocol for WKUserContentController {}
29);
30
31extern_conformance!(
32 unsafe impl NSSecureCoding for WKUserContentController {}
33);
34
35impl WKUserContentController {
36 extern_methods!(
37 #[cfg(feature = "WKUserScript")]
38 /// The user scripts associated with this user content
39 /// controller.
40 #[unsafe(method(userScripts))]
41 #[unsafe(method_family = none)]
42 pub unsafe fn userScripts(&self) -> Retained<NSArray<WKUserScript>>;
43
44 #[cfg(feature = "WKUserScript")]
45 /// Adds a user script.
46 ///
47 /// Parameter `userScript`: The user script to add.
48 #[unsafe(method(addUserScript:))]
49 #[unsafe(method_family = none)]
50 pub unsafe fn addUserScript(&self, user_script: &WKUserScript);
51
52 /// Removes all associated user scripts.
53 #[unsafe(method(removeAllUserScripts))]
54 #[unsafe(method_family = none)]
55 pub unsafe fn removeAllUserScripts(&self);
56
57 #[cfg(all(feature = "WKContentWorld", feature = "WKScriptMessageHandler"))]
58 /// Adds a script message handler.
59 ///
60 /// Parameter `scriptMessageHandler`: The script message handler to add.
61 ///
62 /// Parameter `contentWorld`: The WKContentWorld in which to add the script message handler.
63 ///
64 /// Parameter `name`: The name of the message handler.
65 ///
66 /// Adding a script message handler adds a function
67 /// window.webkit.messageHandlers.
68 /// <name
69 /// >.postMessage(
70 /// <messageBody
71 /// >) to all frames, available in the given WKContentWorld.
72 ///
73 /// The name argument must be a non-empty string.
74 ///
75 /// Each WKContentWorld can have any number of script message handlers, but only one per unique name.
76 ///
77 /// Once any script message handler has been added to a WKContentWorld for a given name, it is an error to add another
78 /// script message handler to that WKContentWorld for that same name without first removing the previous script message handler.
79 ///
80 /// The above restriction applies to any type of script message handler - WKScriptMessageHandler and WKScriptMessageHandlerWithReply
81 /// objects will conflict with each other if you try to add them to the same WKContentWorld with the same name.
82 #[unsafe(method(addScriptMessageHandler:contentWorld:name:))]
83 #[unsafe(method_family = none)]
84 pub unsafe fn addScriptMessageHandler_contentWorld_name(
85 &self,
86 script_message_handler: &ProtocolObject<dyn WKScriptMessageHandler>,
87 world: &WKContentWorld,
88 name: &NSString,
89 );
90
91 #[cfg(all(
92 feature = "WKContentWorld",
93 feature = "WKScriptMessageHandlerWithReply"
94 ))]
95 /// Adds a script message handler.
96 ///
97 /// Parameter `scriptMessageHandlerWithReply`: The script message handler to add.
98 ///
99 /// Parameter `contentWorld`: The WKContentWorld in which to add the script message handler.
100 ///
101 /// Parameter `name`: The name of the message handler.
102 ///
103 /// Adding a script message handler adds a function
104 /// window.webkit.messageHandlers.
105 /// <name
106 /// >.postMessage(
107 /// <messageBody
108 /// >) to all frames, available in the given WKContentWorld.
109 ///
110 /// The name argument must be a non-empty string.
111 ///
112 /// Each WKContentWorld can have any number of script message handlers, but only one per unique name.
113 ///
114 /// Once any script message handler has been added to a WKContentWorld for a given name, it is an error to add another
115 /// script message handler to that WKContentWorld for that same name without first removing the previous script message handler.
116 ///
117 /// The above restriction applies to any type of script message handler - WKScriptMessageHandlerWithReply and WKScriptMessageHandler
118 /// objects will conflict with each other if you try to add them to the same WKContentWorld with the same name.
119 ///
120 /// Refer to the WKScriptMessageHandlerWithReply documentation for examples of how it is more flexible than WKScriptMessageHandler.
121 #[unsafe(method(addScriptMessageHandlerWithReply:contentWorld:name:))]
122 #[unsafe(method_family = none)]
123 pub unsafe fn addScriptMessageHandlerWithReply_contentWorld_name(
124 &self,
125 script_message_handler_with_reply: &ProtocolObject<dyn WKScriptMessageHandlerWithReply>,
126 content_world: &WKContentWorld,
127 name: &NSString,
128 );
129
130 #[cfg(feature = "WKScriptMessageHandler")]
131 /// Adds a script message handler to the main world used by page content itself.
132 ///
133 /// Parameter `scriptMessageHandler`: The script message handler to add.
134 ///
135 /// Parameter `name`: The name of the message handler.
136 ///
137 /// Calling this method is equivalent to calling addScriptMessageHandler:contentWorld:name:
138 /// with [WKContentWorld pageWorld] as the contentWorld argument.
139 #[unsafe(method(addScriptMessageHandler:name:))]
140 #[unsafe(method_family = none)]
141 pub unsafe fn addScriptMessageHandler_name(
142 &self,
143 script_message_handler: &ProtocolObject<dyn WKScriptMessageHandler>,
144 name: &NSString,
145 );
146
147 #[cfg(feature = "WKContentWorld")]
148 /// Removes a script message handler.
149 ///
150 /// Parameter `name`: The name of the message handler to remove.
151 ///
152 /// Parameter `contentWorld`: The WKContentWorld from which to remove the script message handler.
153 #[unsafe(method(removeScriptMessageHandlerForName:contentWorld:))]
154 #[unsafe(method_family = none)]
155 pub unsafe fn removeScriptMessageHandlerForName_contentWorld(
156 &self,
157 name: &NSString,
158 content_world: &WKContentWorld,
159 );
160
161 /// Removes a script message handler.
162 ///
163 /// Parameter `name`: The name of the message handler to remove.
164 ///
165 /// Calling this method is equivalent to calling removeScriptMessageHandlerForName:contentWorld:
166 /// with [WKContentWorld pageWorld] as the contentWorld argument.
167 #[unsafe(method(removeScriptMessageHandlerForName:))]
168 #[unsafe(method_family = none)]
169 pub unsafe fn removeScriptMessageHandlerForName(&self, name: &NSString);
170
171 #[cfg(feature = "WKContentWorld")]
172 /// Removes all script message handlers from a given WKContentWorld.
173 ///
174 /// Parameter `contentWorld`: The WKContentWorld from which to remove all script message handlers.
175 #[unsafe(method(removeAllScriptMessageHandlersFromContentWorld:))]
176 #[unsafe(method_family = none)]
177 pub unsafe fn removeAllScriptMessageHandlersFromContentWorld(
178 &self,
179 content_world: &WKContentWorld,
180 );
181
182 /// Removes all associated script message handlers.
183 #[unsafe(method(removeAllScriptMessageHandlers))]
184 #[unsafe(method_family = none)]
185 pub unsafe fn removeAllScriptMessageHandlers(&self);
186
187 #[cfg(feature = "WKContentRuleList")]
188 /// Adds a content rule list.
189 ///
190 /// Parameter `contentRuleList`: The content rule list to add.
191 #[unsafe(method(addContentRuleList:))]
192 #[unsafe(method_family = none)]
193 pub unsafe fn addContentRuleList(&self, content_rule_list: &WKContentRuleList);
194
195 #[cfg(feature = "WKContentRuleList")]
196 /// Removes a content rule list.
197 ///
198 /// Parameter `contentRuleList`: The content rule list to remove.
199 #[unsafe(method(removeContentRuleList:))]
200 #[unsafe(method_family = none)]
201 pub unsafe fn removeContentRuleList(&self, content_rule_list: &WKContentRuleList);
202
203 /// Removes all associated content rule lists.
204 #[unsafe(method(removeAllContentRuleLists))]
205 #[unsafe(method_family = none)]
206 pub unsafe fn removeAllContentRuleLists(&self);
207 );
208}
209
210/// Methods declared on superclass `NSObject`.
211impl WKUserContentController {
212 extern_methods!(
213 #[unsafe(method(init))]
214 #[unsafe(method_family = init)]
215 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
216
217 #[unsafe(method(new))]
218 #[unsafe(method_family = new)]
219 pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
220 );
221}