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