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