Skip to content

Commit c27b4ff

Browse files
authoredJan 26, 2025··
chore(deps): Use objc2 v0.6 (#1468)
1 parent a92baaa commit c27b4ff

14 files changed

+360
-412
lines changed
 

‎.changes/objc2-v6.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
wry: patch
3+
---
4+
5+
Update to `objc2` v0.6.
6+
7+
This bumps MSRV on macOS/iOS to 1.71.

‎Cargo.toml

+22-9
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ features = [
9292
"Win32_UI_Input_KeyboardAndMouse",
9393
]
9494

95-
[target."cfg(any(target_os = \"ios\", target_os = \"macos\"))".dependencies]
95+
[target.'cfg(target_vendor = "apple")'.dependencies]
9696
url = "2.5"
97-
block2 = "0.5"
98-
objc2 = { version = "0.5", features = ["exception"] }
99-
objc2-web-kit = { version = "0.2.0", features = [
97+
block2 = "0.6"
98+
objc2 = { version = "0.6", features = ["exception"] }
99+
objc2-web-kit = { version = "0.3.0", default-features = false, features = [
100+
"std",
101+
"objc2-core-foundation",
100102
"objc2-app-kit",
101103
"block2",
102104
"WKWebView",
@@ -122,7 +124,13 @@ objc2-web-kit = { version = "0.2.0", features = [
122124
"WKUserScript",
123125
"WKHTTPCookieStore",
124126
] }
125-
objc2-foundation = { version = "0.2.0", features = [
127+
objc2-core-foundation = { version = "0.3.0", default-features = false, features = [
128+
"std",
129+
"CFCGTypes",
130+
] }
131+
objc2-foundation = { version = "0.3.0", default-features = false, features = [
132+
"std",
133+
"objc2-core-foundation",
126134
"NSURLRequest",
127135
"NSURL",
128136
"NSString",
@@ -131,6 +139,7 @@ objc2-foundation = { version = "0.2.0", features = [
131139
"NSDictionary",
132140
"NSObject",
133141
"NSData",
142+
"NSEnumerator",
134143
"NSKeyValueObserving",
135144
"NSThread",
136145
"NSJSONSerialization",
@@ -142,8 +151,10 @@ objc2-foundation = { version = "0.2.0", features = [
142151
"NSRunLoop",
143152
] }
144153

145-
[target."cfg(target_os = \"ios\")".dependencies]
146-
objc2-ui-kit = { version = "0.2.2", features = [
154+
[target.'cfg(target_os = "ios")'.dependencies]
155+
objc2-ui-kit = { version = "0.3.0", default-features = false, features = [
156+
"std",
157+
"objc2-core-foundation",
147158
"UIResponder",
148159
"UIScrollView",
149160
"UIView",
@@ -152,8 +163,10 @@ objc2-ui-kit = { version = "0.2.2", features = [
152163
"UIEvent",
153164
] }
154165

155-
[target."cfg(target_os = \"macos\")".dependencies]
156-
objc2-app-kit = { version = "0.2.0", features = [
166+
[target.'cfg(target_os = "macos")'.dependencies]
167+
objc2-app-kit = { version = "0.3.0", default-features = false, features = [
168+
"std",
169+
"objc2-core-foundation",
157170
"NSApplication",
158171
"NSButton",
159172
"NSControl",

‎src/wkwebview/class/document_title_changed_observer.rs

+13-20
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
use std::{ffi::c_void, ptr::null_mut};
66

77
use objc2::{
8-
declare_class, msg_send, msg_send_id,
9-
mutability::InteriorMutable,
8+
define_class, msg_send,
109
rc::Retained,
1110
runtime::{AnyObject, NSObject},
12-
ClassType, DeclaredClass,
11+
AllocAnyThread, DefinedClass,
1312
};
1413
use objc2_foundation::{
1514
NSDictionary, NSKeyValueChangeKey, NSKeyValueObservingOptions,
@@ -22,21 +21,15 @@ pub struct DocumentTitleChangedObserverIvars {
2221
pub handler: Box<dyn Fn(String)>,
2322
}
2423

25-
declare_class!(
24+
define_class!(
25+
#[unsafe(super(NSObject))]
26+
#[name = "DocumentTitleChangedObserver"]
27+
#[ivars = DocumentTitleChangedObserverIvars]
2628
pub struct DocumentTitleChangedObserver;
2729

28-
unsafe impl ClassType for DocumentTitleChangedObserver {
29-
type Super = NSObject;
30-
type Mutability = InteriorMutable;
31-
const NAME: &'static str = "DocumentTitleChangedObserver";
32-
}
33-
34-
impl DeclaredClass for DocumentTitleChangedObserver {
35-
type Ivars = DocumentTitleChangedObserverIvars;
36-
}
37-
38-
unsafe impl DocumentTitleChangedObserver {
39-
#[method(observeValueForKeyPath:ofObject:change:context:)]
30+
/// NSKeyValueObserving.
31+
impl DocumentTitleChangedObserver {
32+
#[unsafe(method(observeValueForKeyPath:ofObject:change:context:))]
4033
fn observe_value_for_key_path(
4134
&self,
4235
key_path: Option<&NSString>,
@@ -49,8 +42,8 @@ declare_class!(
4942
unsafe {
5043
let handler = &self.ivars().handler;
5144
// if !handler.is_null() {
52-
let title: *const NSString = msg_send![object, title];
53-
handler((*title).to_string());
45+
let title: *const NSString = msg_send![object, title];
46+
handler((*title).to_string());
5447
// }
5548
}
5649
}
@@ -68,7 +61,7 @@ impl DocumentTitleChangedObserver {
6861
handler,
6962
});
7063

71-
let observer: Retained<Self> = unsafe { msg_send_id![super(observer), init] };
64+
let observer: Retained<Self> = unsafe { msg_send![super(observer), init] };
7265

7366
unsafe {
7467
observer
@@ -77,7 +70,7 @@ impl DocumentTitleChangedObserver {
7770
.addObserver_forKeyPath_options_context(
7871
&observer,
7972
&NSString::from_str("title"),
80-
NSKeyValueObservingOptions::NSKeyValueObservingOptionNew,
73+
NSKeyValueObservingOptions::New,
8174
null_mut(),
8275
);
8376
}

‎src/wkwebview/class/url_scheme_handler.rs

+28-24
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::{
77
ffi::{c_char, c_void, CStr},
88
panic::AssertUnwindSafe,
99
ptr::NonNull,
10-
slice,
1110
};
1211

1312
use http::{
@@ -17,7 +16,7 @@ use http::{
1716
use objc2::{
1817
rc::Retained,
1918
runtime::{AnyClass, AnyObject, ClassBuilder, ProtocolObject},
20-
ClassType,
19+
AllocAnyThread, ClassType,
2120
};
2221
use objc2_foundation::{
2322
NSData, NSHTTPURLResponse, NSMutableDictionary, NSObject, NSObjectProtocol, NSString, NSURL,
@@ -29,12 +28,13 @@ use crate::{wkwebview::WEBVIEW_IDS, RequestAsyncResponder, WryWebView};
2928

3029
pub fn create(name: &str) -> &AnyClass {
3130
unsafe {
32-
let scheme_name = format!("{}URLSchemeHandler", name);
31+
let scheme_name = format!("{}URLSchemeHandler\0", name);
32+
let scheme_name = CStr::from_bytes_with_nul(scheme_name.as_bytes()).unwrap();
3333
let cls = ClassBuilder::new(&scheme_name, NSObject::class());
3434
match cls {
3535
Some(mut cls) => {
36-
cls.add_ivar::<*mut c_void>("function");
37-
cls.add_ivar::<*mut c_char>("webview_id");
36+
cls.add_ivar::<*mut c_void>(CStr::from_bytes_with_nul(b"function\0").unwrap());
37+
cls.add_ivar::<*mut c_char>(CStr::from_bytes_with_nul(b"webview_id\0").unwrap());
3838
cls.add_method(
3939
objc2::sel!(webView:startURLSchemeTask:),
4040
start_task as extern "C" fn(_, _, _, _),
@@ -54,7 +54,7 @@ pub fn create(name: &str) -> &AnyClass {
5454
extern "C" fn start_task(
5555
this: &AnyObject,
5656
_sel: objc2::runtime::Sel,
57-
webview: &'static mut WryWebView,
57+
webview: &'static WryWebView,
5858
task: &'static ProtocolObject<dyn WKURLSchemeTask>,
5959
) {
6060
unsafe {
@@ -65,14 +65,20 @@ extern "C" fn start_task(
6565
let task_key = task.hash(); // hash by task object address
6666
let task_uuid = webview.add_custom_task_key(task_key);
6767

68-
let ivar = this.class().instance_variable("webview_id").unwrap();
68+
let ivar = this
69+
.class()
70+
.instance_variable(CStr::from_bytes_with_nul(b"webview_id\0").unwrap())
71+
.unwrap();
6972
let webview_id_ptr: *mut c_char = *ivar.load(this);
7073
let webview_id = CStr::from_ptr(webview_id_ptr)
7174
.to_str()
7275
.ok()
7376
.unwrap_or_default();
7477

75-
let ivar = this.class().instance_variable("function").unwrap();
78+
let ivar = this
79+
.class()
80+
.instance_variable(CStr::from_bytes_with_nul(b"function\0").unwrap())
81+
.unwrap();
7682
let function: &*mut c_void = ivar.load(this);
7783
if !function.is_null() {
7884
let function = &mut *(*function
@@ -98,9 +104,7 @@ extern "C" fn start_task(
98104
let body = request.HTTPBody();
99105
let body_stream = request.HTTPBodyStream();
100106
if let Some(body) = body {
101-
let length = body.length();
102-
let data_bytes = body.bytes();
103-
sent_form_body = slice::from_raw_parts(data_bytes.as_ptr(), length).to_vec();
107+
sent_form_body = body.to_vec();
104108
} else if let Some(body_stream) = body_stream {
105109
body_stream.open();
106110

@@ -121,7 +125,7 @@ extern "C" fn start_task(
121125
// get all our headers values and inject them in our request
122126
if let Some(all_headers) = all_headers {
123127
for current_header in all_headers.allKeys().to_vec() {
124-
let header_value = all_headers.valueForKey(current_header).unwrap();
128+
let header_value = all_headers.valueForKey(&current_header).unwrap();
125129
// inject the header into the request
126130
http_request = http_request.header(current_header.to_string(), header_value.to_string());
127131
}
@@ -196,7 +200,7 @@ extern "C" fn start_task(
196200
// FIXME: though we give it a static lifetime, it's not guaranteed to be valid.
197201
task: &'static ProtocolObject<dyn WKURLSchemeTask>,
198202
// FIXME: though we give it a static lifetime, it's not guaranteed to be valid.
199-
webview: &'static mut WryWebView,
203+
webview: &'static WryWebView,
200204
task_key: usize,
201205
task_uuid: Retained<NSUUID>,
202206
webview_id: &str,
@@ -215,24 +219,24 @@ extern "C" fn start_task(
215219
// default to HTTP/1.1
216220
let wanted_version = format!("{:#?}", sent_response.version());
217221

218-
let mut headers = NSMutableDictionary::new();
222+
let headers = NSMutableDictionary::new();
219223
if let Some(mime) = wanted_mime {
220-
headers.insert_id(
221-
NSString::from_str(CONTENT_TYPE.as_str()).as_ref(),
222-
NSString::from_str(mime.to_str().unwrap()),
224+
headers.insert(
225+
&*NSString::from_str(CONTENT_TYPE.as_str()),
226+
&*NSString::from_str(mime.to_str().unwrap()),
223227
);
224228
}
225-
headers.insert_id(
226-
NSString::from_str(CONTENT_LENGTH.as_str()).as_ref(),
227-
NSString::from_str(&content.len().to_string()),
229+
headers.insert(
230+
&*NSString::from_str(CONTENT_LENGTH.as_str()),
231+
&*NSString::from_str(&content.len().to_string()),
228232
);
229233

230234
// add headers
231235
for (name, value) in sent_response.headers().iter() {
232236
if let Ok(value) = value.to_str() {
233-
headers.insert_id(
234-
NSString::from_str(name.as_str()).as_ref(),
235-
NSString::from_str(value),
237+
headers.insert(
238+
&*NSString::from_str(name.as_str()),
239+
&*NSString::from_str(value),
236240
);
237241
}
238242
}
@@ -334,7 +338,7 @@ extern "C" fn start_task(
334338
extern "C" fn stop_task(
335339
_this: &ProtocolObject<dyn WKURLSchemeHandler>,
336340
_sel: objc2::runtime::Sel,
337-
webview: &mut WryWebView,
341+
webview: &WryWebView,
338342
task: &ProtocolObject<dyn WKURLSchemeTask>,
339343
) {
340344
webview.remove_custom_task_key(task.hash());

‎src/wkwebview/class/wry_download_delegate.rs

+11-25
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
use std::{cell::RefCell, path::PathBuf, rc::Rc};
66

7-
use objc2::{
8-
declare_class, msg_send_id, mutability::MainThreadOnly, rc::Retained, runtime::NSObject,
9-
ClassType, DeclaredClass,
10-
};
7+
use objc2::{define_class, msg_send, rc::Retained, runtime::NSObject, MainThreadOnly};
118
use objc2_foundation::{
129
MainThreadMarker, NSData, NSError, NSObjectProtocol, NSString, NSURLResponse, NSURL,
1310
};
@@ -20,23 +17,17 @@ pub struct WryDownloadDelegateIvars {
2017
pub completed: Option<Rc<dyn Fn(String, Option<PathBuf>, bool) + 'static>>,
2118
}
2219

23-
declare_class!(
20+
define_class!(
21+
#[unsafe(super(NSObject))]
22+
#[name = "WryDownloadDelegate"]
23+
#[thread_kind = MainThreadOnly]
24+
#[ivars = WryDownloadDelegateIvars]
2425
pub struct WryDownloadDelegate;
2526

26-
unsafe impl ClassType for WryDownloadDelegate {
27-
type Super = NSObject;
28-
type Mutability = MainThreadOnly;
29-
const NAME: &'static str = "WryDownloadDelegate";
30-
}
31-
32-
impl DeclaredClass for WryDownloadDelegate {
33-
type Ivars = WryDownloadDelegateIvars;
34-
}
35-
3627
unsafe impl NSObjectProtocol for WryDownloadDelegate {}
3728

3829
unsafe impl WKDownloadDelegate for WryDownloadDelegate {
39-
#[method(download:decideDestinationUsingResponse:suggestedFilename:completionHandler:)]
30+
#[unsafe(method(download:decideDestinationUsingResponse:suggestedFilename:completionHandler:))]
4031
fn download_policy(
4132
&self,
4233
download: &WKDownload,
@@ -47,18 +38,13 @@ declare_class!(
4738
download_policy(self, download, response, suggested_path, handler);
4839
}
4940

50-
#[method(downloadDidFinish:)]
41+
#[unsafe(method(downloadDidFinish:))]
5142
fn download_did_finish(&self, download: &WKDownload) {
5243
download_did_finish(self, download);
5344
}
5445

55-
#[method(download:didFailWithError:resumeData:)]
56-
fn download_did_fail(
57-
&self,
58-
download: &WKDownload,
59-
error: &NSError,
60-
resume_data: &NSData,
61-
) {
46+
#[unsafe(method(download:didFailWithError:resumeData:))]
47+
fn download_did_fail(&self, download: &WKDownload, error: &NSError, resume_data: &NSData) {
6248
download_did_fail(self, download, error, resume_data);
6349
}
6450
}
@@ -77,6 +63,6 @@ impl WryDownloadDelegate {
7763
completed: download_completed_handler,
7864
});
7965

80-
unsafe { msg_send_id![super(delegate), init] }
66+
unsafe { msg_send![super(delegate), init] }
8167
}
8268
}

‎src/wkwebview/class/wry_navigation_delegate.rs

+15-32
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
use std::sync::{Arc, Mutex};
66

7-
use objc2::{
8-
declare_class, msg_send_id, mutability::MainThreadOnly, rc::Retained, runtime::NSObject,
9-
ClassType, DeclaredClass,
10-
};
7+
use objc2::{define_class, msg_send, rc::Retained, runtime::NSObject, MainThreadOnly};
118
use objc2_foundation::{MainThreadMarker, NSObjectProtocol};
129
use objc2_web_kit::{
1310
WKDownload, WKNavigation, WKNavigationAction, WKNavigationActionPolicy, WKNavigationDelegate,
@@ -40,23 +37,17 @@ pub struct WryNavigationDelegateIvars {
4037
pub on_page_load_handler: Option<Box<dyn Fn(PageLoadEvent)>>,
4138
}
4239

43-
declare_class!(
40+
define_class!(
41+
#[unsafe(super(NSObject))]
42+
#[name = "WryNavigationDelegate"]
43+
#[thread_kind = MainThreadOnly]
44+
#[ivars = WryNavigationDelegateIvars]
4445
pub struct WryNavigationDelegate;
4546

46-
unsafe impl ClassType for WryNavigationDelegate {
47-
type Super = NSObject;
48-
type Mutability = MainThreadOnly;
49-
const NAME: &'static str = "WryNavigationDelegate";
50-
}
51-
52-
impl DeclaredClass for WryNavigationDelegate {
53-
type Ivars = WryNavigationDelegateIvars;
54-
}
55-
5647
unsafe impl NSObjectProtocol for WryNavigationDelegate {}
5748

5849
unsafe impl WKNavigationDelegate for WryNavigationDelegate {
59-
#[method(webView:decidePolicyForNavigationAction:decisionHandler:)]
50+
#[unsafe(method(webView:decidePolicyForNavigationAction:decisionHandler:))]
6051
fn navigation_policy(
6152
&self,
6253
webview: &WKWebView,
@@ -66,7 +57,7 @@ declare_class!(
6657
navigation_policy(self, webview, action, handler);
6758
}
6859

69-
#[method(webView:decidePolicyForNavigationResponse:decisionHandler:)]
60+
#[unsafe(method(webView:decidePolicyForNavigationResponse:decisionHandler:))]
7061
fn navigation_policy_response(
7162
&self,
7263
webview: &WKWebView,
@@ -76,25 +67,17 @@ declare_class!(
7667
navigation_policy_response(self, webview, response, handler);
7768
}
7869

79-
#[method(webView:didFinishNavigation:)]
80-
fn did_finish_navigation(
81-
&self,
82-
webview: &WKWebView,
83-
navigation: &WKNavigation,
84-
) {
70+
#[unsafe(method(webView:didFinishNavigation:))]
71+
fn did_finish_navigation(&self, webview: &WKWebView, navigation: &WKNavigation) {
8572
did_finish_navigation(self, webview, navigation);
8673
}
8774

88-
#[method(webView:didCommitNavigation:)]
89-
fn did_commit_navigation(
90-
&self,
91-
webview: &WKWebView,
92-
navigation: &WKNavigation,
93-
) {
75+
#[unsafe(method(webView:didCommitNavigation:))]
76+
fn did_commit_navigation(&self, webview: &WKWebView, navigation: &WKNavigation) {
9477
did_commit_navigation(self, webview, navigation);
9578
}
9679

97-
#[method(webView:navigationAction:didBecomeDownload:)]
80+
#[unsafe(method(webView:navigationAction:didBecomeDownload:))]
9881
fn navigation_download_action(
9982
&self,
10083
webview: &WKWebView,
@@ -104,7 +87,7 @@ declare_class!(
10487
navigation_download_action(self, webview, action, download);
10588
}
10689

107-
#[method(webView:navigationResponse:didBecomeDownload:)]
90+
#[unsafe(method(webView:navigationResponse:didBecomeDownload:))]
10891
fn navigation_download_response(
10992
&self,
11093
webview: &WKWebView,
@@ -159,6 +142,6 @@ impl WryNavigationDelegate {
159142
on_page_load_handler,
160143
});
161144

162-
unsafe { msg_send_id![super(delegate), init] }
145+
unsafe { msg_send![super(delegate), init] }
163146
}
164147
}

‎src/wkwebview/class/wry_web_view.rs

+40-55
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
use std::collections::HashMap;
5+
use std::{cell::RefCell, collections::HashMap};
66

77
#[cfg(target_os = "macos")]
88
use objc2::runtime::ProtocolObject;
9-
use objc2::{
10-
declare_class, mutability::MainThreadOnly, rc::Retained, runtime::Bool, ClassType, DeclaredClass,
11-
};
9+
use objc2::{define_class, rc::Retained, runtime::Bool, DeclaredClass};
1210
#[cfg(target_os = "macos")]
1311
use objc2_app_kit::{NSDraggingDestination, NSEvent};
1412
use objc2_foundation::{NSObjectProtocol, NSUUID};
@@ -31,28 +29,19 @@ pub struct WryWebViewIvars {
3129
pub(crate) drag_drop_handler: Box<dyn Fn(DragDropEvent) -> bool>,
3230
#[cfg(target_os = "macos")]
3331
pub(crate) accept_first_mouse: objc2::runtime::Bool,
34-
pub(crate) custom_protocol_task_ids: HashMap<usize, Retained<NSUUID>>,
32+
pub(crate) custom_protocol_task_ids: RefCell<HashMap<usize, Retained<NSUUID>>>,
3533
}
3634

37-
declare_class!(
35+
define_class!(
36+
#[unsafe(super(WKWebView))]
37+
#[name = "WryWebView"]
38+
#[ivars = WryWebViewIvars]
3839
pub struct WryWebView;
3940

40-
unsafe impl ClassType for WryWebView {
41-
type Super = WKWebView;
42-
type Mutability = MainThreadOnly;
43-
const NAME: &'static str = "WryWebView";
44-
}
45-
46-
impl DeclaredClass for WryWebView {
47-
type Ivars = WryWebViewIvars;
48-
}
49-
50-
unsafe impl WryWebView {
51-
#[method(performKeyEquivalent:)]
52-
fn perform_key_equivalent(
53-
&self,
54-
event: &NSEvent,
55-
) -> Bool {
41+
/// Overridden NSView methods.
42+
impl WryWebView {
43+
#[unsafe(method(performKeyEquivalent:))]
44+
fn perform_key_equivalent(&self, event: &NSEvent) -> Bool {
5645
// This is a temporary workaround for https://github.com/tauri-apps/tauri/issues/9426
5746
// FIXME: When the webview is a child webview, performKeyEquivalent always return YES
5847
// and stop propagating the event to the window, hence the menu shortcut won't be
@@ -61,94 +50,90 @@ declare_class!(
6150
if self.ivars().is_child {
6251
Bool::NO
6352
} else {
64-
unsafe {
65-
objc2::msg_send![super(self), performKeyEquivalent: event]
66-
}
53+
unsafe { objc2::msg_send![super(self), performKeyEquivalent: event] }
6754
}
6855
}
6956

7057
#[cfg(target_os = "macos")]
71-
#[method(acceptsFirstMouse:)]
72-
fn accept_first_mouse(
73-
&self,
74-
_event: &NSEvent,
75-
) -> Bool {
76-
self.ivars().accept_first_mouse
58+
#[unsafe(method(acceptsFirstMouse:))]
59+
fn accept_first_mouse(&self, _event: &NSEvent) -> Bool {
60+
self.ivars().accept_first_mouse
7761
}
7862
}
7963
unsafe impl NSObjectProtocol for WryWebView {}
8064

8165
// Drag & Drop
8266
#[cfg(target_os = "macos")]
8367
unsafe impl NSDraggingDestination for WryWebView {
84-
#[method(draggingEntered:)]
68+
#[unsafe(method(draggingEntered:))]
8569
fn dragging_entered(
8670
&self,
8771
drag_info: &ProtocolObject<dyn objc2_app_kit::NSDraggingInfo>,
8872
) -> objc2_app_kit::NSDragOperation {
8973
drag_drop::dragging_entered(self, drag_info)
9074
}
9175

92-
#[method(draggingUpdated:)]
76+
#[unsafe(method(draggingUpdated:))]
9377
fn dragging_updated(
9478
&self,
9579
drag_info: &ProtocolObject<dyn objc2_app_kit::NSDraggingInfo>,
9680
) -> objc2_app_kit::NSDragOperation {
9781
drag_drop::dragging_updated(self, drag_info)
9882
}
9983

100-
#[method(performDragOperation:)]
84+
#[unsafe(method(performDragOperation:))]
10185
fn perform_drag_operation(
10286
&self,
10387
drag_info: &ProtocolObject<dyn objc2_app_kit::NSDraggingInfo>,
10488
) -> Bool {
10589
drag_drop::perform_drag_operation(self, drag_info)
10690
}
10791

108-
#[method(draggingExited:)]
109-
fn dragging_exited(
110-
&self,
111-
drag_info: &ProtocolObject<dyn objc2_app_kit::NSDraggingInfo>,
112-
) {
92+
#[unsafe(method(draggingExited:))]
93+
fn dragging_exited(&self, drag_info: &ProtocolObject<dyn objc2_app_kit::NSDraggingInfo>) {
11394
drag_drop::dragging_exited(self, drag_info)
11495
}
11596
}
11697

11798
// Synthetic mouse events
11899
#[cfg(target_os = "macos")]
119-
unsafe impl WryWebView {
120-
#[method(otherMouseDown:)]
121-
fn other_mouse_down(
122-
&self,
123-
event: &NSEvent,
124-
) {
100+
impl WryWebView {
101+
#[unsafe(method(otherMouseDown:))]
102+
fn other_mouse_down(&self, event: &NSEvent) {
125103
synthetic_mouse_events::other_mouse_down(self, event)
126104
}
127105

128-
#[method(otherMouseUp:)]
129-
fn other_mouse_up(
130-
&self,
131-
event: &NSEvent,
132-
) {
106+
#[unsafe(method(otherMouseUp:))]
107+
fn other_mouse_up(&self, event: &NSEvent) {
133108
synthetic_mouse_events::other_mouse_up(self, event)
134109
}
135110
}
136111
);
137112

138113
// Custom Protocol Task Checker
139114
impl WryWebView {
140-
pub(crate) fn add_custom_task_key(&mut self, task_id: usize) -> Retained<NSUUID> {
115+
pub(crate) fn add_custom_task_key(&self, task_id: usize) -> Retained<NSUUID> {
141116
let task_uuid = NSUUID::new();
142117
self
143-
.ivars_mut()
118+
.ivars()
144119
.custom_protocol_task_ids
120+
.borrow_mut()
145121
.insert(task_id, task_uuid.clone());
146122
task_uuid
147123
}
148-
pub(crate) fn remove_custom_task_key(&mut self, task_id: usize) {
149-
self.ivars_mut().custom_protocol_task_ids.remove(&task_id);
124+
pub(crate) fn remove_custom_task_key(&self, task_id: usize) {
125+
self
126+
.ivars()
127+
.custom_protocol_task_ids
128+
.borrow_mut()
129+
.remove(&task_id);
150130
}
151131
pub(crate) fn get_custom_task_uuid(&self, task_id: usize) -> Option<Retained<NSUUID>> {
152-
self.ivars().custom_protocol_task_ids.get(&task_id).cloned()
132+
self
133+
.ivars()
134+
.custom_protocol_task_ids
135+
.borrow()
136+
.get(&task_id)
137+
.cloned()
153138
}
154139
}

‎src/wkwebview/class/wry_web_view_delegate.rs

+11-20
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ use std::ffi::CStr;
66

77
use http::Request;
88
use objc2::{
9-
declare_class, msg_send_id,
10-
mutability::MainThreadOnly,
9+
define_class, msg_send,
1110
rc::Retained,
1211
runtime::{NSObject, ProtocolObject},
13-
ClassType, DeclaredClass,
12+
DeclaredClass, MainThreadOnly,
1413
};
1514
use objc2_foundation::{MainThreadMarker, NSObjectProtocol, NSString};
1615
use objc2_web_kit::{WKScriptMessage, WKScriptMessageHandler, WKUserContentController};
@@ -22,24 +21,18 @@ pub struct WryWebViewDelegateIvars {
2221
pub ipc_handler: Box<dyn Fn(Request<String>)>,
2322
}
2423

25-
declare_class!(
24+
define_class!(
25+
#[unsafe(super(NSObject))]
26+
#[name = "WryWebViewDelegate"]
27+
#[thread_kind = MainThreadOnly]
28+
#[ivars = WryWebViewDelegateIvars]
2629
pub struct WryWebViewDelegate;
2730

28-
unsafe impl ClassType for WryWebViewDelegate {
29-
type Super = NSObject;
30-
type Mutability = MainThreadOnly;
31-
const NAME: &'static str = "WryWebViewDelegate";
32-
}
33-
34-
impl DeclaredClass for WryWebViewDelegate {
35-
type Ivars = WryWebViewDelegateIvars;
36-
}
37-
3831
unsafe impl NSObjectProtocol for WryWebViewDelegate {}
3932

4033
unsafe impl WKScriptMessageHandler for WryWebViewDelegate {
4134
// Function for ipc handler
42-
#[method(userContentController:didReceiveScriptMessage:)]
35+
#[unsafe(method(userContentController:didReceiveScriptMessage:))]
4336
fn did_receive(
4437
this: &WryWebViewDelegate,
4538
_controller: &WKUserContentController,
@@ -52,9 +45,7 @@ declare_class!(
5245

5346
let ipc_handler = &this.ivars().ipc_handler;
5447
let body = msg.body();
55-
let is_string = Retained::cast::<NSObject>(body.clone()).isKindOfClass(NSString::class());
56-
if is_string {
57-
let body = Retained::cast::<NSString>(body);
48+
if let Ok(body) = body.downcast::<NSString>() {
5849
let js_utf8 = body.UTF8String();
5950

6051
let frame_info = msg.frameInfo();
@@ -92,9 +83,9 @@ impl WryWebViewDelegate {
9283
controller,
9384
});
9485

95-
let delegate: Retained<Self> = unsafe { msg_send_id![super(delegate), init] };
86+
let delegate: Retained<Self> = unsafe { msg_send![super(delegate), init] };
9687

97-
let proto_delegate = ProtocolObject::from_ref(delegate.as_ref());
88+
let proto_delegate = ProtocolObject::from_ref(&*delegate);
9889
unsafe {
9990
// this will increate the retain count of the delegate
10091
delegate.ivars().controller.addScriptMessageHandler_name(

‎src/wkwebview/class/wry_web_view_parent.rs

+19-32
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
use std::cell::Cell;
66

7-
use objc2::{
8-
declare_class, msg_send_id, mutability::MainThreadOnly, rc::Retained, ClassType, DeclaredClass,
9-
};
7+
use objc2::{define_class, msg_send, rc::Retained, DefinedClass, MainThreadOnly};
108
#[cfg(target_os = "macos")]
119
use objc2_app_kit::{NSApplication, NSEvent, NSView, NSWindow, NSWindowButton};
1210
use objc2_foundation::MainThreadMarker;
@@ -20,26 +18,17 @@ pub struct WryWebViewParentIvars {
2018
traffic_light_inset: Cell<Option<(f64, f64)>>,
2119
}
2220

23-
declare_class!(
21+
define_class!(
22+
#[unsafe(super(NSView))]
23+
#[name = "WryWebViewParent"]
24+
#[ivars = WryWebViewParentIvars]
2425
pub struct WryWebViewParent;
2526

26-
unsafe impl ClassType for WryWebViewParent {
27-
type Super = NSView;
28-
type Mutability = MainThreadOnly;
29-
const NAME: &'static str = "WryWebViewParent";
30-
}
31-
32-
impl DeclaredClass for WryWebViewParent {
33-
type Ivars = WryWebViewParentIvars;
34-
}
35-
36-
unsafe impl WryWebViewParent {
27+
/// Overridden NSView methods.
28+
impl WryWebViewParent {
3729
#[cfg(target_os = "macos")]
38-
#[method(keyDown:)]
39-
fn key_down(
40-
&self,
41-
event: &NSEvent,
42-
) {
30+
#[unsafe(method(keyDown:))]
31+
fn key_down(&self, event: &NSEvent) {
4332
let mtm = MainThreadMarker::new().unwrap();
4433
let app = NSApplication::sharedApplication(mtm);
4534
unsafe {
@@ -50,10 +39,10 @@ declare_class!(
5039
}
5140

5241
#[cfg(target_os = "macos")]
53-
#[method(drawRect:)]
42+
#[unsafe(method(drawRect:))]
5443
fn draw(&self, _dirty_rect: NSRect) {
5544
if let Some((x, y)) = self.ivars().traffic_light_inset.get() {
56-
unsafe {inset_traffic_lights(&self.window().unwrap(), x, y)};
45+
unsafe { inset_traffic_lights(&self.window().unwrap(), x, y) };
5746
}
5847
}
5948
}
@@ -62,13 +51,11 @@ declare_class!(
6251
impl WryWebViewParent {
6352
#[allow(dead_code)]
6453
pub fn new(mtm: MainThreadMarker) -> Retained<Self> {
65-
let delegate = mtm
66-
.alloc::<WryWebViewParent>()
67-
.set_ivars(WryWebViewParentIvars {
68-
#[cfg(target_os = "macos")]
69-
traffic_light_inset: Default::default(),
70-
});
71-
unsafe { msg_send_id![super(delegate), init] }
54+
let delegate = WryWebViewParent::alloc(mtm).set_ivars(WryWebViewParentIvars {
55+
#[cfg(target_os = "macos")]
56+
traffic_light_inset: Default::default(),
57+
});
58+
unsafe { msg_send![super(delegate), init] }
7259
}
7360

7461
#[cfg(target_os = "macos")]
@@ -89,13 +76,13 @@ impl WryWebViewParent {
8976
#[cfg(target_os = "macos")]
9077
pub unsafe fn inset_traffic_lights(window: &NSWindow, x: f64, y: f64) {
9178
let close = window
92-
.standardWindowButton(NSWindowButton::NSWindowCloseButton)
79+
.standardWindowButton(NSWindowButton::CloseButton)
9380
.unwrap();
9481
let miniaturize = window
95-
.standardWindowButton(NSWindowButton::NSWindowMiniaturizeButton)
82+
.standardWindowButton(NSWindowButton::MiniaturizeButton)
9683
.unwrap();
9784
let zoom = window
98-
.standardWindowButton(NSWindowButton::NSWindowZoomButton)
85+
.standardWindowButton(NSWindowButton::ZoomButton)
9986
.unwrap();
10087

10188
let title_bar_container_view = close.superview().unwrap().superview().unwrap();

‎src/wkwebview/class/wry_web_view_ui_delegate.rs

+11-20
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
use std::ptr::null_mut;
77

88
use block2::Block;
9-
use objc2::{
10-
declare_class, msg_send_id, mutability::MainThreadOnly, rc::Retained, runtime::NSObject,
11-
ClassType, DeclaredClass,
12-
};
9+
use objc2::{define_class, msg_send, rc::Retained, runtime::NSObject, MainThreadOnly};
1310
#[cfg(target_os = "macos")]
1411
use objc2_app_kit::{NSModalResponse, NSModalResponseOK, NSOpenPanel};
1512
use objc2_foundation::{MainThreadMarker, NSObjectProtocol};
@@ -26,30 +23,24 @@ use crate::WryWebView;
2623

2724
pub struct WryWebViewUIDelegateIvars {}
2825

29-
declare_class!(
26+
define_class!(
27+
#[unsafe(super(NSObject))]
28+
#[name = "WryWebViewUIDelegate"]
29+
#[thread_kind = MainThreadOnly]
30+
#[ivars = WryWebViewUIDelegateIvars]
3031
pub struct WryWebViewUIDelegate;
3132

32-
unsafe impl ClassType for WryWebViewUIDelegate {
33-
type Super = NSObject;
34-
type Mutability = MainThreadOnly;
35-
const NAME: &'static str = "WryWebViewUIDelegate";
36-
}
37-
38-
impl DeclaredClass for WryWebViewUIDelegate {
39-
type Ivars = WryWebViewUIDelegateIvars;
40-
}
41-
4233
unsafe impl NSObjectProtocol for WryWebViewUIDelegate {}
4334

4435
unsafe impl WKUIDelegate for WryWebViewUIDelegate {
4536
#[cfg(target_os = "macos")]
46-
#[method(webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:)]
37+
#[unsafe(method(webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:))]
4738
fn run_file_upload_panel(
4839
&self,
4940
_webview: &WryWebView,
5041
open_panel_params: &WKOpenPanelParameters,
5142
_frame: &WKFrameInfo,
52-
handler: &block2::Block<dyn Fn(*const NSArray<NSURL>)>
43+
handler: &block2::Block<dyn Fn(*const NSArray<NSURL>)>,
5344
) {
5445
unsafe {
5546
if let Some(mtm) = MainThreadMarker::new() {
@@ -70,14 +61,14 @@ declare_class!(
7061
}
7162
}
7263

73-
#[method(webView:requestMediaCapturePermissionForOrigin:initiatedByFrame:type:decisionHandler:)]
64+
#[unsafe(method(webView:requestMediaCapturePermissionForOrigin:initiatedByFrame:type:decisionHandler:))]
7465
fn request_media_capture_permission(
7566
&self,
7667
_webview: &WryWebView,
7768
_origin: &WKSecurityOrigin,
7869
_frame: &WKFrameInfo,
7970
_capture_type: WKMediaCaptureType,
80-
decision_handler: &Block<dyn Fn(WKPermissionDecision)>
71+
decision_handler: &Block<dyn Fn(WKPermissionDecision)>,
8172
) {
8273
//https://developer.apple.com/documentation/webkit/wkpermissiondecision?language=objc
8374
(*decision_handler).call((WKPermissionDecision::Grant,));
@@ -90,6 +81,6 @@ impl WryWebViewUIDelegate {
9081
let delegate = mtm
9182
.alloc::<WryWebViewUIDelegate>()
9283
.set_ivars(WryWebViewUIDelegateIvars {});
93-
unsafe { msg_send_id![super(delegate), init] }
84+
unsafe { msg_send![super(delegate), init] }
9485
}
9586
}

‎src/wkwebview/download.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(crate) fn navigation_download_action(
2222
) {
2323
unsafe {
2424
if let Some(delegate) = &this.ivars().download_delegate {
25-
let proto_delegate = ProtocolObject::from_ref(delegate.as_ref());
25+
let proto_delegate = ProtocolObject::from_ref(&**delegate);
2626
download.setDelegate(Some(proto_delegate));
2727
}
2828
}
@@ -37,7 +37,7 @@ pub(crate) fn navigation_download_response(
3737
) {
3838
unsafe {
3939
if let Some(delegate) = &this.ivars().download_delegate {
40-
let proto_delegate = ProtocolObject::from_ref(delegate.as_ref());
40+
let proto_delegate = ProtocolObject::from_ref(&**delegate);
4141
download.setDelegate(Some(proto_delegate));
4242
}
4343
}

‎src/wkwebview/drag_drop.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
use std::{ffi::CStr, path::PathBuf};
66

77
use objc2::{
8-
rc::Id,
9-
runtime::{AnyObject, Bool, ProtocolObject},
8+
runtime::{Bool, ProtocolObject},
109
DeclaredClass,
1110
};
1211
use objc2_app_kit::{NSDragOperation, NSDraggingInfo, NSFilenamesPboardType};
@@ -23,8 +22,9 @@ pub(crate) unsafe fn collect_paths(drag_info: &ProtocolObject<dyn NSDraggingInfo
2322

2423
if pb.availableTypeFromArray(&types).is_some() {
2524
let paths = pb.propertyListForType(NSFilenamesPboardType).unwrap();
26-
let paths: Id<NSArray<NSString>> = Id::<AnyObject>::cast(paths.clone());
27-
for path in paths.to_vec() {
25+
let paths = paths.downcast::<NSArray>().unwrap();
26+
for path in paths {
27+
let path = path.downcast::<NSString>().unwrap();
2828
let path = CStr::from_ptr(path.UTF8String()).to_string_lossy();
2929
drag_drop_paths.push(PathBuf::from(path.into_owned()));
3030
}

‎src/wkwebview/ios/WKWebView.rs

+133-131
Large diffs are not rendered by default.

‎src/wkwebview/mod.rs

+44-38
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ use objc2::runtime::Bool;
3535
use objc2::{
3636
rc::Retained,
3737
runtime::{AnyObject, NSObject, ProtocolObject},
38-
ClassType, DeclaredClass,
38+
AllocAnyThread, DeclaredClass, MainThreadOnly, Message,
3939
};
4040
#[cfg(target_os = "macos")]
4141
use objc2_app_kit::{NSApplication, NSAutoresizingMaskOptions, NSTitlebarSeparatorStyle, NSView};
4242
#[cfg(target_os = "macos")]
43-
use objc2_foundation::CGSize;
43+
use objc2_core_foundation::CGSize;
44+
use objc2_core_foundation::{CGPoint, CGRect};
4445
use objc2_foundation::{
45-
ns_string, CGPoint, CGRect, MainThreadMarker, NSArray, NSBundle, NSDate, NSError, NSHTTPCookie,
46+
ns_string, MainThreadMarker, NSArray, NSBundle, NSDate, NSError, NSHTTPCookie,
4647
NSHTTPCookieSameSiteLax, NSHTTPCookieSameSiteStrict, NSJSONSerialization, NSMutableURLRequest,
4748
NSNumber, NSObjectNSKeyValueCoding, NSObjectProtocol, NSString, NSUTF8StringEncoding, NSURL,
4849
NSUUID,
@@ -70,8 +71,8 @@ use once_cell::sync::Lazy;
7071
use raw_window_handle::{HasWindowHandle, RawWindowHandle};
7172

7273
use std::{
73-
collections::{HashMap, HashSet},
74-
ffi::{c_void, CString},
74+
collections::HashSet,
75+
ffi::{c_void, CStr, CString},
7576
net::Ipv4Addr,
7677
os::raw::c_char,
7778
panic::AssertUnwindSafe,
@@ -114,6 +115,7 @@ pub struct PrintOptions {
114115

115116
pub(crate) struct InnerWebView {
116117
id: String,
118+
mtm: MainThreadMarker,
117119
pub webview: Retained<WryWebView>,
118120
pub manager: Retained<WKUserContentController>,
119121
data_store: Retained<WKWebsiteDataStore>,
@@ -194,7 +196,7 @@ impl InnerWebView {
194196

195197
// Safety: objc runtime calls are unsafe
196198
unsafe {
197-
let config = WKWebViewConfiguration::new();
199+
let config = WKWebViewConfiguration::new(mtm);
198200

199201
// Incognito mode
200202
let (os_major_version, _, _) = util::operating_system_version();
@@ -208,14 +210,14 @@ impl InnerWebView {
208210
custom_data_store_available,
209211
pl_attrs.data_store_identifier,
210212
) {
211-
(true, _, _) => WKWebsiteDataStore::nonPersistentDataStore(),
213+
(true, _, _) => WKWebsiteDataStore::nonPersistentDataStore(mtm),
212214
// if data_store_identifier is given and custom data stores are available, use custom store
213215
(false, true, Some(data_store)) => {
214216
let identifier = NSUUID::from_bytes(data_store);
215-
WKWebsiteDataStore::dataStoreForIdentifier(&identifier)
217+
WKWebsiteDataStore::dataStoreForIdentifier(&identifier, mtm)
216218
}
217219
// default data store
218-
_ => WKWebsiteDataStore::defaultDataStore(),
220+
_ => WKWebsiteDataStore::defaultDataStore(mtm),
219221
};
220222

221223
// Register Custom Protocols
@@ -226,11 +228,17 @@ impl InnerWebView {
226228
let function = Box::into_raw(Box::new(function));
227229
protocol_ptrs.push(function);
228230

229-
let ivar = (*handler).class().instance_variable("function").unwrap();
231+
let ivar = (*handler)
232+
.class()
233+
.instance_variable(CStr::from_bytes_with_nul(b"function\0").unwrap())
234+
.unwrap();
230235
let ivar_delegate = ivar.load_mut(&mut *handler);
231236
*ivar_delegate = function as *mut _ as *mut c_void;
232237

233-
let ivar = (*handler).class().instance_variable("webview_id").unwrap();
238+
let ivar = (*handler)
239+
.class()
240+
.instance_variable(CStr::from_bytes_with_nul(b"webview_id\0").unwrap())
241+
.unwrap();
234242
let ivar_delegate: &mut *mut c_char = ivar.load_mut(&mut *handler);
235243
*ivar_delegate = CString::new(webview_id.as_bytes()).unwrap().into_raw();
236244

@@ -247,7 +255,7 @@ impl InnerWebView {
247255

248256
// WebView and manager
249257
let manager = config.userContentController();
250-
let webview = mtm.alloc::<WryWebView>().set_ivars(WryWebViewIvars {
258+
let webview = WryWebView::alloc(mtm).set_ivars(WryWebViewIvars {
251259
is_child,
252260
#[cfg(target_os = "macos")]
253261
drag_drop_handler: match attributes.drag_drop_handler {
@@ -256,7 +264,7 @@ impl InnerWebView {
256264
},
257265
#[cfg(target_os = "macos")]
258266
accept_first_mouse: Bool::new(attributes.accept_first_mouse),
259-
custom_protocol_task_ids: HashMap::new(),
267+
custom_protocol_task_ids: Default::default(),
260268
});
261269

262270
config.setWebsiteDataStore(&data_store);
@@ -289,9 +297,7 @@ impl InnerWebView {
289297
config.setValue_forKey(Some(&_yes), ns_string!("allowsInlineMediaPlayback"));
290298

291299
if attributes.autoplay {
292-
config.setMediaTypesRequiringUserActionForPlayback(
293-
WKAudiovisualMediaTypes::WKAudiovisualMediaTypeNone,
294-
);
300+
config.setMediaTypesRequiringUserActionForPlayback(WKAudiovisualMediaTypes::None);
295301
}
296302

297303
#[cfg(feature = "transparent")]
@@ -341,14 +347,14 @@ impl InnerWebView {
341347
size: CGSize::new(w as f64, h as f64),
342348
};
343349
let webview: Retained<WryWebView> =
344-
objc2::msg_send_id![super(webview), initWithFrame:frame configuration:&**config];
350+
objc2::msg_send![super(webview), initWithFrame: frame, configuration: &**config];
345351
webview
346352
};
347353
#[cfg(target_os = "ios")]
348354
let webview = {
349355
let frame = ns_view.frame();
350356
let webview: Retained<WryWebView> =
351-
objc2::msg_send_id![super(webview), initWithFrame:frame configuration:&**config];
357+
objc2::msg_send![super(webview), initWithFrame: frame, configuration: &**config];
352358
webview
353359
};
354360

@@ -382,12 +388,12 @@ impl InnerWebView {
382388
{
383389
if is_child {
384390
// fixed element
385-
webview.setAutoresizingMask(NSAutoresizingMaskOptions::NSViewMinYMargin);
391+
webview.setAutoresizingMask(NSAutoresizingMaskOptions::ViewMinYMargin);
386392
} else {
387393
// Auto-resize
388394
webview.setAutoresizingMask(
389-
NSAutoresizingMaskOptions::NSViewHeightSizable
390-
| NSAutoresizingMaskOptions::NSViewWidthSizable,
395+
NSAutoresizingMaskOptions::ViewHeightSizable
396+
| NSAutoresizingMaskOptions::ViewWidthSizable,
391397
);
392398
}
393399

@@ -406,7 +412,7 @@ impl InnerWebView {
406412
// disable scroll bounce by default
407413
// https://developer.apple.com/documentation/webkit/wkwebview/1614784-scrollview?language=objc
408414
// But not exist in objc2-web-kit
409-
let scroll_view: Retained<UIScrollView> = objc2::msg_send_id![&webview, scrollView];
415+
let scroll_view: Retained<UIScrollView> = objc2::msg_send![&webview, scrollView];
410416
// let scroll_view: Retained<UIScrollView> = webview.ivars().scrollView; // FIXME: not test yet
411417
scroll_view.setBounces(false)
412418
}
@@ -471,12 +477,11 @@ impl InnerWebView {
471477
mtm,
472478
);
473479

474-
let proto_navigation_policy_delegate =
475-
ProtocolObject::from_ref(navigation_policy_delegate.as_ref());
480+
let proto_navigation_policy_delegate = ProtocolObject::from_ref(&*navigation_policy_delegate);
476481
webview.setNavigationDelegate(Some(proto_navigation_policy_delegate));
477482

478483
let ui_delegate: Retained<WryWebViewUIDelegate> = WryWebViewUIDelegate::new(mtm);
479-
let proto_ui_delegate = ProtocolObject::from_ref(ui_delegate.as_ref());
484+
let proto_ui_delegate = ProtocolObject::from_ref(&*ui_delegate);
480485
webview.setUIDelegate(Some(proto_ui_delegate));
481486

482487
// ns window is required for the print operation
@@ -492,6 +497,7 @@ impl InnerWebView {
492497

493498
let mut w = Self {
494499
id: webview_id,
500+
mtm,
495501
webview: webview.clone(),
496502
manager: manager.clone(),
497503
ns_view: ns_view.retain(),
@@ -547,8 +553,8 @@ r#"Object.defineProperty(window, 'ipc', {
547553
}
548554

549555
parent_view.setAutoresizingMask(
550-
NSAutoresizingMaskOptions::NSViewHeightSizable
551-
| NSAutoresizingMaskOptions::NSViewWidthSizable,
556+
NSAutoresizingMaskOptions::ViewHeightSizable
557+
| NSAutoresizingMaskOptions::ViewWidthSizable,
552558
);
553559
parent_view.addSubview(&webview.clone());
554560

@@ -607,7 +613,7 @@ r#"Object.defineProperty(window, 'ipc', {
607613
if !val.is_null() {
608614
let json_ns_data = NSJSONSerialization::dataWithJSONObject_options_error(
609615
&*val,
610-
objc2_foundation::NSJSONWritingOptions::NSJSONWritingFragmentsAllowed,
616+
objc2_foundation::NSJSONWritingOptions::FragmentsAllowed,
611617
)
612618
.unwrap();
613619
let json_string = NSString::alloc();
@@ -647,7 +653,7 @@ r#"Object.defineProperty(window, 'ipc', {
647653
fn init(&self, js: &str, for_main_only: bool) {
648654
// Safety: objc runtime calls are unsafe
649655
unsafe {
650-
let userscript = WKUserScript::alloc();
656+
let userscript = WKUserScript::alloc(self.mtm);
651657
let script = WKUserScript::initWithSource_injectionTime_forMainFrameOnly(
652658
userscript,
653659
&NSString::from_str(js),
@@ -675,7 +681,7 @@ r#"Object.defineProperty(window, 'ipc', {
675681
unsafe {
676682
let config = self.webview.configuration();
677683
let store = config.websiteDataStore();
678-
let all_data_types = WKWebsiteDataStore::allWebsiteDataTypes();
684+
let all_data_types = WKWebsiteDataStore::allWebsiteDataTypes(self.mtm);
679685
let date = NSDate::dateWithTimeIntervalSince1970(0.0);
680686
let handler = block2::RcBlock::new(|| {});
681687
store.removeDataOfTypes_modifiedSince_completionHandler(&all_data_types, &date, &handler);
@@ -687,7 +693,7 @@ r#"Object.defineProperty(window, 'ipc', {
687693
// Safety: objc runtime calls are unsafe
688694
unsafe {
689695
let url = NSURL::URLWithString(&NSString::from_str(url)).unwrap();
690-
let mut request = NSMutableURLRequest::requestWithURL(&url);
696+
let request = NSMutableURLRequest::requestWithURL(&url);
691697
if let Some(headers) = headers {
692698
for (name, value) in headers.iter() {
693699
let key = NSString::from_str(name.as_str());
@@ -763,7 +769,7 @@ r#"Object.defineProperty(window, 'ipc', {
763769
#[cfg(target_os = "macos")]
764770
unsafe {
765771
// taken from <https://github.com/WebKit/WebKit/blob/784f93cb80a386c29186c510bba910b67ce3adc1/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm#L1939>
766-
let tool: Retained<AnyObject> = objc2::msg_send_id![&self.webview, _inspector];
772+
let tool: Retained<AnyObject> = objc2::msg_send![&self.webview, _inspector];
767773
let () = objc2::msg_send![&tool, show];
768774
}
769775
}
@@ -773,7 +779,7 @@ r#"Object.defineProperty(window, 'ipc', {
773779
#[cfg(target_os = "macos")]
774780
unsafe {
775781
// taken from <https://github.com/WebKit/WebKit/blob/784f93cb80a386c29186c510bba910b67ce3adc1/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm#L1939>
776-
let tool: Retained<AnyObject> = objc2::msg_send_id![&self.webview, _inspector];
782+
let tool: Retained<AnyObject> = objc2::msg_send![&self.webview, _inspector];
777783
let () = objc2::msg_send![&tool, close];
778784
}
779785
}
@@ -783,7 +789,7 @@ r#"Object.defineProperty(window, 'ipc', {
783789
#[cfg(target_os = "macos")]
784790
unsafe {
785791
// taken from <https://github.com/WebKit/WebKit/blob/784f93cb80a386c29186c510bba910b67ce3adc1/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm#L1939>
786-
let tool: Retained<AnyObject> = objc2::msg_send_id![&self.webview, _inspector];
792+
let tool: Retained<AnyObject> = objc2::msg_send![&self.webview, _inspector];
787793
let is_visible: bool = objc2::msg_send![&tool, isVisible];
788794
is_visible
789795
}
@@ -889,8 +895,8 @@ r#"Object.defineProperty(window, 'ipc', {
889895

890896
let same_site = cookie.sameSitePolicy();
891897
let same_site = match same_site {
892-
Some(policy) if policy.as_ref() == NSHTTPCookieSameSiteLax => cookie::SameSite::Lax,
893-
Some(policy) if policy.as_ref() == NSHTTPCookieSameSiteStrict => cookie::SameSite::Strict,
898+
Some(policy) if &*policy == NSHTTPCookieSameSiteLax => cookie::SameSite::Lax,
899+
Some(policy) if &*policy == NSHTTPCookieSameSiteStrict => cookie::SameSite::Strict,
894900
_ => cookie::SameSite::None,
895901
};
896902
cookie_builder = cookie_builder.same_site(same_site);
@@ -948,7 +954,7 @@ r#"Object.defineProperty(window, 'ipc', {
948954
let cookies = cookies
949955
.to_vec()
950956
.into_iter()
951-
.map(|cookie| Self::cookie_from_wkwebview(cookie))
957+
.map(|cookie| Self::cookie_from_wkwebview(&cookie))
952958
.collect();
953959
let _ = tx.send(cookies);
954960
},
@@ -1003,7 +1009,7 @@ pub fn platform_webview_version() -> Result<String> {
10031009
let webkit_version = dict
10041010
.objectForKey(&NSString::from_str("CFBundleVersion"))
10051011
.unwrap();
1006-
let webkit_version = Retained::cast::<NSString>(webkit_version);
1012+
let webkit_version = webkit_version.downcast::<NSString>().unwrap();
10071013

10081014
bundle.unload();
10091015
Ok(webkit_version.to_string())

0 commit comments

Comments
 (0)
Please sign in to comment.