objc2_web_kit/generated/WebScriptObject.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#[cfg(feature = "objc2-javascript-core")]
8use objc2_javascript_core::*;
9
10use crate::*;
11
12mod private_NSObjectWebScripting {
13 pub trait Sealed {}
14}
15
16/// Category "WebScripting" on [`NSObject`].
17#[doc(alias = "WebScripting")]
18pub unsafe trait NSObjectWebScripting:
19 ClassType + Sized + private_NSObjectWebScripting::Sealed
20{
21 extern_methods!(
22 /// Parameter `selector`: The selector that will be exposed to the script environment.
23 ///
24 /// Use the returned string as the exported name for the selector
25 /// in the script environment. It is the responsibility of the class to ensure
26 /// uniqueness of the returned name. If nil is returned or this
27 /// method is not implemented the default name for the selector will
28 /// be used. The default name concatenates the components of the
29 /// Objective-C selector name and replaces ':' with '_'. '_' characters
30 /// are escaped with an additional '$', i.e. '_' becomes "$_". '$' are
31 /// also escaped, i.e.
32 /// Objective-C name Default script name
33 /// moveTo:: move__
34 /// moveTo_ moveTo$_
35 /// moveTo$_ moveTo$$$_
36 ///
37 /// Returns: Returns the name to be used to represent the specified selector in the
38 /// scripting environment.
39 ///
40 /// # Safety
41 ///
42 /// `selector` must be a valid selector.
43 #[unsafe(method(webScriptNameForSelector:))]
44 #[unsafe(method_family = none)]
45 unsafe fn webScriptNameForSelector(selector: Option<Sel>) -> Option<Retained<NSString>>;
46
47 /// Parameter `selector`: The selector the will be exposed to the script environment.
48 ///
49 /// Return NO to export the selector to the script environment.
50 /// Return YES to prevent the selector from being exported to the script environment.
51 /// If this method is not implemented on the class no selectors will be exported.
52 ///
53 /// Returns: Returns YES to hide the selector, NO to export the selector.
54 ///
55 /// # Safety
56 ///
57 /// `selector` must be a valid selector.
58 #[unsafe(method(isSelectorExcludedFromWebScript:))]
59 #[unsafe(method_family = none)]
60 unsafe fn isSelectorExcludedFromWebScript(selector: Option<Sel>) -> bool;
61
62 /// Parameter `name`: The name of the instance variable that will be exposed to the
63 /// script environment. Only instance variables that meet the export criteria will
64 /// be exposed.
65 ///
66 /// Provide an alternate name for a property.
67 ///
68 /// Returns: Returns the name to be used to represent the specified property in the
69 /// scripting environment.
70 ///
71 /// # Safety
72 ///
73 /// `name` must be a valid pointer.
74 #[unsafe(method(webScriptNameForKey:))]
75 #[unsafe(method_family = none)]
76 unsafe fn webScriptNameForKey(name: *const c_char) -> Option<Retained<NSString>>;
77
78 /// Parameter `name`: The name of the instance variable that will be exposed to the
79 /// script environment.
80 ///
81 /// Return NO to export the property to the script environment.
82 /// Return YES to prevent the property from being exported to the script environment.
83 ///
84 /// Returns: Returns YES to hide the property, NO to export the property.
85 ///
86 /// # Safety
87 ///
88 /// `name` must be a valid pointer.
89 #[unsafe(method(isKeyExcludedFromWebScript:))]
90 #[unsafe(method_family = none)]
91 unsafe fn isKeyExcludedFromWebScript(name: *const c_char) -> bool;
92
93 /// Parameter `name`: The name of the method to invoke.
94 ///
95 /// Parameter `arguments`: The arguments to pass the method.
96 ///
97 /// If a script attempts to invoke a method that is not exported,
98 /// invokeUndefinedMethodFromWebScript:withArguments: will be called.
99 ///
100 /// Returns: The return value of the invocation. The value will be converted as appropriate
101 /// for the script environment.
102 ///
103 /// # Safety
104 ///
105 /// - `name` might not allow `None`.
106 /// - `arguments` generic should be of the correct type.
107 /// - `arguments` might not allow `None`.
108 #[unsafe(method(invokeUndefinedMethodFromWebScript:withArguments:))]
109 #[unsafe(method_family = none)]
110 unsafe fn invokeUndefinedMethodFromWebScript_withArguments(
111 &self,
112 name: Option<&NSString>,
113 arguments: Option<&NSArray>,
114 ) -> Option<Retained<AnyObject>>;
115
116 /// Parameter `arguments`: The arguments to pass the method.
117 ///
118 /// If a script attempts to call an exposed object as a function,
119 /// this method will be called.
120 ///
121 /// Returns: The return value of the call. The value will be converted as appropriate
122 /// for the script environment.
123 ///
124 /// # Safety
125 ///
126 /// - `arguments` generic should be of the correct type.
127 /// - `arguments` might not allow `None`.
128 #[unsafe(method(invokeDefaultMethodWithArguments:))]
129 #[unsafe(method_family = none)]
130 unsafe fn invokeDefaultMethodWithArguments(
131 &self,
132 arguments: Option<&NSArray>,
133 ) -> Option<Retained<AnyObject>>;
134
135 /// finalizeForScript is called on objects exposed to the script
136 /// environment just before the script environment garbage collects the object.
137 /// Subsequently, any references to WebScriptObjects made by the exposed object will
138 /// be invalid and have undefined consequences.
139 #[unsafe(method(finalizeForWebScript))]
140 #[unsafe(method_family = none)]
141 unsafe fn finalizeForWebScript(&self);
142 );
143}
144
145impl private_NSObjectWebScripting::Sealed for NSObject {}
146unsafe impl NSObjectWebScripting for NSObject {}
147
148extern_class!(
149 /// WebScriptObjects are used to wrap script objects passed from
150 /// script environments to Objective-C. WebScriptObjects cannot be created
151 /// directly. In normal uses of WebKit, you gain access to the script
152 /// environment using the "windowScriptObject" method on WebView.
153 ///
154 /// The following KVC methods are commonly used to access properties of the
155 /// WebScriptObject:
156 ///
157 /// - (void)setValue:(id)value forKey:(NSString *)key
158 /// - (id)valueForKey:(NSString *)key
159 ///
160 /// As it possible to remove attributes from web script objects, the following
161 /// additional method augments the basic KVC methods:
162 ///
163 /// - (void)removeWebScriptKey:(NSString *)name;
164 ///
165 /// Also, since the sparse array access allowed in script objects doesn't map well
166 /// to NSArray, the following methods can be used to access index based properties:
167 ///
168 /// - (id)webScriptValueAtIndex:(unsigned)index;
169 /// - (void)setWebScriptValueAtIndex:(unsigned)index value:(id)value;
170 ///
171 /// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/webscriptobject?language=objc)
172 #[unsafe(super(NSObject))]
173 #[derive(Debug, PartialEq, Eq, Hash)]
174 #[deprecated]
175 pub struct WebScriptObject;
176);
177
178extern_conformance!(
179 unsafe impl NSObjectProtocol for WebScriptObject {}
180);
181
182impl WebScriptObject {
183 extern_methods!(
184 /// Throws an exception in the current script execution context.
185 ///
186 /// Returns: Either NO if an exception could not be raised, YES otherwise.
187 ///
188 /// # Safety
189 ///
190 /// `exception_message` might not allow `None`.
191 #[deprecated]
192 #[unsafe(method(throwException:))]
193 #[unsafe(method_family = none)]
194 pub unsafe fn throwException(exception_message: Option<&NSString>) -> bool;
195
196 #[cfg(feature = "objc2-javascript-core")]
197 /// Returns: The equivalent JSObjectRef for this WebScriptObject.
198 ///
199 /// Use this method to bridge between the WebScriptObject and
200 /// JavaScriptCore APIs.
201 #[unsafe(method(JSObject))]
202 #[unsafe(method_family = none)]
203 pub unsafe fn JSObject(&self) -> JSObjectRef;
204
205 /// Parameter `name`: The name of the method to call in the script environment.
206 ///
207 /// Parameter `arguments`: The arguments to pass to the script environment.
208 ///
209 /// Calls the specified method in the script environment using the
210 /// specified arguments.
211 ///
212 /// Returns: Returns the result of calling the script method.
213 /// Returns WebUndefined when an exception is thrown in the script environment.
214 ///
215 /// # Safety
216 ///
217 /// - `name` might not allow `None`.
218 /// - `arguments` generic should be of the correct type.
219 /// - `arguments` might not allow `None`.
220 #[deprecated]
221 #[unsafe(method(callWebScriptMethod:withArguments:))]
222 #[unsafe(method_family = none)]
223 pub unsafe fn callWebScriptMethod_withArguments(
224 &self,
225 name: Option<&NSString>,
226 arguments: Option<&NSArray>,
227 ) -> Option<Retained<AnyObject>>;
228
229 /// Parameter `script`: The script to execute in the target script environment.
230 ///
231 /// The script will be executed in the target script environment. The format
232 /// of the script is dependent of the target script environment.
233 ///
234 /// Returns: Returns the result of evaluating the script in the script environment.
235 /// Returns WebUndefined when an exception is thrown in the script environment.
236 ///
237 /// # Safety
238 ///
239 /// `script` might not allow `None`.
240 #[deprecated]
241 #[unsafe(method(evaluateWebScript:))]
242 #[unsafe(method_family = none)]
243 pub unsafe fn evaluateWebScript(
244 &self,
245 script: Option<&NSString>,
246 ) -> Option<Retained<AnyObject>>;
247
248 /// Parameter `name`: The name of the property to remove.
249 ///
250 /// Removes the property from the object in the script environment.
251 ///
252 /// # Safety
253 ///
254 /// `name` might not allow `None`.
255 #[deprecated]
256 #[unsafe(method(removeWebScriptKey:))]
257 #[unsafe(method_family = none)]
258 pub unsafe fn removeWebScriptKey(&self, name: Option<&NSString>);
259
260 /// Converts the target object to a string representation. The coercion
261 /// of non string objects type is dependent on the script environment.
262 ///
263 /// Returns: Returns the string representation of the object.
264 #[deprecated]
265 #[unsafe(method(stringRepresentation))]
266 #[unsafe(method_family = none)]
267 pub unsafe fn stringRepresentation(&self) -> Option<Retained<NSString>>;
268
269 /// Parameter `index`: The index of the property to return.
270 ///
271 /// Gets the value of the property at the specified index.
272 ///
273 /// Returns: The value of the property. Returns WebUndefined when an exception is
274 /// thrown in the script environment.
275 #[deprecated]
276 #[unsafe(method(webScriptValueAtIndex:))]
277 #[unsafe(method_family = none)]
278 pub unsafe fn webScriptValueAtIndex(&self, index: c_uint) -> Option<Retained<AnyObject>>;
279
280 /// Parameter `index`: The index of the property to set.
281 ///
282 /// Parameter `value`: The value of the property to set.
283 ///
284 /// Sets the property value at the specified index.
285 ///
286 /// # Safety
287 ///
288 /// - `value` should be of the correct type.
289 /// - `value` might not allow `None`.
290 #[deprecated]
291 #[unsafe(method(setWebScriptValueAtIndex:value:))]
292 #[unsafe(method_family = none)]
293 pub unsafe fn setWebScriptValueAtIndex_value(
294 &self,
295 index: c_uint,
296 value: Option<&AnyObject>,
297 );
298
299 /// Parameter `description`: The description of the exception.
300 ///
301 /// Raises an exception in the script environment in the context of the
302 /// current object.
303 ///
304 /// # Safety
305 ///
306 /// `description` might not allow `None`.
307 #[deprecated]
308 #[unsafe(method(setException:))]
309 #[unsafe(method_family = none)]
310 pub unsafe fn setException(&self, description: Option<&NSString>);
311
312 #[cfg(feature = "objc2-javascript-core")]
313 /// Returns: The equivalent Objective-C JSValue for this WebScriptObject.
314 ///
315 /// Use this method to bridge between the WebScriptObject and
316 /// JavaScriptCore Objective-C APIs.
317 #[deprecated]
318 #[unsafe(method(JSValue))]
319 #[unsafe(method_family = none)]
320 pub unsafe fn JSValue(&self) -> Option<Retained<JSValue>>;
321 );
322}
323
324/// Methods declared on superclass `NSObject`.
325impl WebScriptObject {
326 extern_methods!(
327 #[unsafe(method(init))]
328 #[unsafe(method_family = init)]
329 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
330
331 #[unsafe(method(new))]
332 #[unsafe(method_family = new)]
333 pub unsafe fn new() -> Retained<Self>;
334 );
335}
336
337extern_class!(
338 /// [Apple's documentation](https://developer.apple.com/documentation/webkit/webundefined?language=objc)
339 #[unsafe(super(NSObject))]
340 #[derive(Debug, PartialEq, Eq, Hash)]
341 #[deprecated]
342 pub struct WebUndefined;
343);
344
345extern_conformance!(
346 unsafe impl NSCoding for WebUndefined {}
347);
348
349extern_conformance!(
350 unsafe impl NSCopying for WebUndefined {}
351);
352
353unsafe impl CopyingHelper for WebUndefined {
354 type Result = Self;
355}
356
357extern_conformance!(
358 unsafe impl NSObjectProtocol for WebUndefined {}
359);
360
361impl WebUndefined {
362 extern_methods!(
363 /// Returns: The WebUndefined shared instance.
364 #[deprecated]
365 #[unsafe(method(undefined))]
366 #[unsafe(method_family = none)]
367 pub unsafe fn undefined() -> Option<Retained<WebUndefined>>;
368 );
369}
370
371/// Methods declared on superclass `NSObject`.
372impl WebUndefined {
373 extern_methods!(
374 #[unsafe(method(init))]
375 #[unsafe(method_family = init)]
376 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
377
378 #[unsafe(method(new))]
379 #[unsafe(method_family = new)]
380 pub unsafe fn new() -> Retained<Self>;
381 );
382}