Skip to content

Commit

Permalink
Remove webcontext implementation on wkwebview (#922)
Browse files Browse the repository at this point in the history
  • Loading branch information
wusyong committed Apr 7, 2023
1 parent 8698836 commit 3cc45cb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 56 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-webcontext.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": patch
---

On macOS and iOS, remove webcontext implementation since we don't actually use it. This also fix segfault if users drop webcontext early.
16 changes: 12 additions & 4 deletions src/webview/web_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
target_os = "openbsd"
))]
use crate::webview::webkitgtk::WebContextImpl;
#[cfg(any(target_os = "macos", target_os = "ios"))]
use crate::webview::wkwebview::WebContextImpl;

use std::path::{Path, PathBuf};

Expand Down Expand Up @@ -93,11 +91,21 @@ impl WebContextData {
}
}

#[cfg(any(target_os = "windows", target_os = "android"))]
#[cfg(any(
target_os = "windows",
target_os = "android",
target_os = "macos",
target_os = "ios"
))]
#[derive(Debug)]
pub(crate) struct WebContextImpl;

#[cfg(any(target_os = "windows", target_os = "android"))]
#[cfg(any(
target_os = "windows",
target_os = "android",
target_os = "macos",
target_os = "ios"
))]
impl WebContextImpl {
fn new(_data: &WebContextData) -> Self {
Self
Expand Down
10 changes: 2 additions & 8 deletions src/webview/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
mod download;
#[cfg(target_os = "macos")]
mod file_drop;
mod web_context;

use url::Url;
pub use web_context::WebContextImpl;

#[cfg(target_os = "macos")]
use cocoa::appkit::{NSView, NSViewHeightSizable, NSViewWidthSizable};
Expand Down Expand Up @@ -91,7 +89,7 @@ impl InnerWebView {
window: Rc<Window>,
attributes: WebViewAttributes,
_pl_attrs: super::PlatformSpecificWebViewAttributes,
mut web_context: Option<&mut WebContext>,
_web_context: Option<&mut WebContext>,
) -> Result<Self> {
// Function for ipc handler
extern "C" fn did_receive(this: &Object, _: Sel, _: id, msg: id) {
Expand Down Expand Up @@ -267,11 +265,7 @@ impl InnerWebView {
};
let handler: id = msg_send![cls, new];
let function = Box::into_raw(Box::new(function));
if let Some(context) = &mut web_context {
context.os.registered_protocols(function);
} else {
protocol_ptrs.push(function);
}
protocol_ptrs.push(function);

(*handler).set_ivar("function", function as *mut _ as *mut c_void);
let () = msg_send![config, setURLSchemeHandler:handler forURLScheme:NSString::new(&name)];
Expand Down
44 changes: 0 additions & 44 deletions src/webview/wkwebview/web_context.rs

This file was deleted.

0 comments on commit 3cc45cb

Please sign in to comment.