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