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 authored and amrbashir committed Apr 18, 2023
1 parent 0c568dc commit 7a84919
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 55 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 @@ -80,11 +78,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
9 changes: 2 additions & 7 deletions src/webview/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ mod file_drop;
mod synthetic_mouse_events;

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

#[cfg(target_os = "macos")]
use cocoa::appkit::{NSView, NSViewHeightSizable, NSViewWidthSizable};
Expand Down Expand Up @@ -90,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 @@ -258,11 +257,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 7a84919

Please sign in to comment.