Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(macos): remove webcontext implementation on wkwebview #922

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.