From 4f42acb4bd5ea7f16bf0ed18ea8113a9bd957659 Mon Sep 17 00:00:00 2001 From: Linda_pp Date: Sun, 12 Nov 2023 23:32:55 +0900 Subject: [PATCH] refactor: rename 'Webview' to 'WebView' (#1074) * feat: rename 'Webview' to 'WebView' Signed-off-by: rhysd * Update .changes/Webview-to-WebView.md --------- Signed-off-by: rhysd --- .changes/Webview-to-WebView.md | 11 +++++++ ...add-api-to-set-memory-usage-for-windows.md | 2 +- .changes/rwh.md | 4 +-- src/lib.rs | 30 +++++++++---------- src/web_context.rs | 2 +- src/webkitgtk/web_context.rs | 10 +++---- src/wkwebview/mod.rs | 2 +- 7 files changed, 36 insertions(+), 25 deletions(-) create mode 100644 .changes/Webview-to-WebView.md diff --git a/.changes/Webview-to-WebView.md b/.changes/Webview-to-WebView.md new file mode 100644 index 000000000..b5edc5aa1 --- /dev/null +++ b/.changes/Webview-to-WebView.md @@ -0,0 +1,11 @@ +--- +"wry": minor +--- + +**Breaking change** Consistently use `WebView` in API names. The following APIs were renamed: + - `WebviewExtWindows` → `WebViewExtWindows` + - `WebviewExtUnix` → `WebViewExtUnix` + - `WebviewExtMacOS` → `WebViewExtMacOS` + - `WebviewExtIOS` → `WebViewExtIOS` + - `WebviewExtAndroid` → `WebViewExtAndroid` + - `WebviewUriLoader` → `WebViewUriLoader` diff --git a/.changes/add-api-to-set-memory-usage-for-windows.md b/.changes/add-api-to-set-memory-usage-for-windows.md index d10eb88fe..45e20f15c 100644 --- a/.changes/add-api-to-set-memory-usage-for-windows.md +++ b/.changes/add-api-to-set-memory-usage-for-windows.md @@ -2,4 +2,4 @@ "wry": patch --- -Add `WebviewExtWindows::set_memory_usage_level` API to set the [memory usage target level](https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2memoryusagetargetlevel) on Windows. Setting 'Low' memory usage target level when an application is going to inactive can significantly reduce the memory consumption. Please read the [guide for WebView2](https://github.com/MicrosoftEdge/WebView2Feedback/blob/main/specs/MemoryUsageTargetLevel.md) for more details. +Add `WebViewExtWindows::set_memory_usage_level` API to set the [memory usage target level](https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2memoryusagetargetlevel) on Windows. Setting 'Low' memory usage target level when an application is going to inactive can significantly reduce the memory consumption. Please read the [guide for WebView2](https://github.com/MicrosoftEdge/WebView2Feedback/blob/main/specs/MemoryUsageTargetLevel.md) for more details. diff --git a/.changes/rwh.md b/.changes/rwh.md index 2ecfd315e..054e2af03 100644 --- a/.changes/rwh.md +++ b/.changes/rwh.md @@ -4,12 +4,12 @@ Refactor new method to take raw window handle instead. Following are APIs got affected: - `application` module is removed, and `webivew` module is moved to root module. - - `WebviewBuilder::new`, `Webview::new` now take `RawWindowHandle` instead. + - `WebViewBuilder::new`, `WebView::new` now take `RawWindowHandle` instead. - Attributes `ipc_handler`, `file_drop_handler`, `document_change_handler` don't have window parameter anymore. Users should use closure to capture the types they want to use. - Position field in `FileDrop` event is now `Position` instead of `PhysicalPosition`. Users need to handle scale factor depend on the situation they have. - - `Webview::inner_size` is removed. + - `WebView::inner_size` is removed. - [raw-window-handle](https://docs.rs/raw-window-handle/latest/raw_window_handle/) crate is re-exported as `wry::raw_window_handle`. This also means that we removed `tao` as a dependency completely which required some changes to the Android backend: diff --git a/src/lib.rs b/src/lib.rs index 193c0baa3..f939132a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1051,7 +1051,7 @@ impl Default for PlatformSpecificWebViewAttributes { #[cfg(windows)] pub trait WebViewBuilderExtWindows { - /// Pass additional args to Webview2 upon creating the webview. + /// Pass additional args to WebView2 upon creating the webview. /// /// ## Warning /// @@ -1124,7 +1124,7 @@ pub trait WebViewBuilderExtAndroid { f: F, ) -> Self; - /// Use [WebviewAssetLoader](https://developer.android.com/reference/kotlin/androidx/webkit/WebViewAssetLoader) + /// Use [WebViewAssetLoader](https://developer.android.com/reference/kotlin/androidx/webkit/WebViewAssetLoader) /// to load assets from Android's `asset` folder when using `with_url` as `://assets/` (e.g.: /// `wry://assets/index.html`). Note that this registers a custom protocol with the provided /// String, similar to [`with_custom_protocol`], but also sets the WebViewAssetLoader with the @@ -1395,7 +1395,7 @@ pub enum FileDropEvent { Cancelled, } -/// Get Webview/Webkit version on current platform. +/// Get WebView/Webkit version on current platform. pub fn webview_version() -> Result { platform_webview_version() } @@ -1419,7 +1419,7 @@ pub enum MemoryUsageLevel { /// Additional methods on `WebView` that are specific to Windows. #[cfg(target_os = "windows")] -pub trait WebviewExtWindows { +pub trait WebViewExtWindows { /// Returns WebView2 Controller fn controller(&self) -> ICoreWebView2Controller; @@ -1442,7 +1442,7 @@ pub trait WebviewExtWindows { } #[cfg(target_os = "windows")] -impl WebviewExtWindows for WebView { +impl WebViewExtWindows for WebView { fn controller(&self) -> ICoreWebView2Controller { self.webview.controller.clone() } @@ -1464,8 +1464,8 @@ impl WebviewExtWindows for WebView { target_os = "netbsd", target_os = "openbsd", ))] -pub trait WebviewExtUnix { - /// Returns Webkit2gtk Webview handle +pub trait WebViewExtUnix { + /// Returns Webkit2gtk WebView handle fn webview(&self) -> webkit2gtk::WebView; } @@ -1476,7 +1476,7 @@ pub trait WebviewExtUnix { target_os = "netbsd", target_os = "openbsd", ))] -impl WebviewExtUnix for WebView { +impl WebViewExtUnix for WebView { fn webview(&self) -> webkit2gtk::WebView { self.webview.webview.clone() } @@ -1484,7 +1484,7 @@ impl WebviewExtUnix for WebView { /// Additional methods on `WebView` that are specific to macOS. #[cfg(target_os = "macos")] -pub trait WebviewExtMacOS { +pub trait WebViewExtMacOS { /// Returns WKWebView handle fn webview(&self) -> cocoa::base::id; /// Returns WKWebView manager [(userContentController)](https://developer.apple.com/documentation/webkit/wkscriptmessagehandler/1396222-usercontentcontroller) handle @@ -1494,7 +1494,7 @@ pub trait WebviewExtMacOS { } #[cfg(target_os = "macos")] -impl WebviewExtMacOS for WebView { +impl WebViewExtMacOS for WebView { fn webview(&self) -> cocoa::base::id { self.webview.webview } @@ -1510,7 +1510,7 @@ impl WebviewExtMacOS for WebView { /// Additional methods on `WebView` that are specific to iOS. #[cfg(target_os = "ios")] -pub trait WebviewExtIOS { +pub trait WebViewExtIOS { /// Returns WKWebView handle fn webview(&self) -> cocoa::base::id; /// Returns WKWebView manager [(userContentController)](https://developer.apple.com/documentation/webkit/wkscriptmessagehandler/1396222-usercontentcontroller) handle @@ -1518,7 +1518,7 @@ pub trait WebviewExtIOS { } #[cfg(target_os = "ios")] -impl WebviewExtIOS for WebView { +impl WebViewExtIOS for WebView { fn webview(&self) -> cocoa::base::id { self.webview.webview } @@ -1530,18 +1530,18 @@ impl WebviewExtIOS for WebView { #[cfg(target_os = "android")] /// Additional methods on `WebView` that are specific to Android -pub trait WebviewExtAndroid { +pub trait WebViewExtAndroid { fn handle(&self) -> JniHandle; } #[cfg(target_os = "android")] -impl WebviewExtAndroid for WebView { +impl WebViewExtAndroid for WebView { fn handle(&self) -> JniHandle { JniHandle } } -/// Webview theme. +/// WebView theme. #[derive(Debug, Clone, Copy)] pub enum Theme { /// Dark diff --git a/src/web_context.rs b/src/web_context.rs index 2266b350a..de5a4451d 100644 --- a/src/web_context.rs +++ b/src/web_context.rs @@ -19,7 +19,7 @@ use std::path::{Path, PathBuf}; /// private/incognito tabs. /// /// # Warning -/// If [`Webview`] is created by a WebContext. Dropping `WebContext` will cause [`WebView`] lose +/// If [`WebView`] is created by a WebContext. Dropping `WebContext` will cause [`WebView`] lose /// some actions like custom protocol on Mac. Please keep both instances when you still wish to /// interact with them. /// diff --git a/src/webkitgtk/web_context.rs b/src/webkitgtk/web_context.rs index 7b54bbdb9..30bba6c69 100644 --- a/src/webkitgtk/web_context.rs +++ b/src/webkitgtk/web_context.rs @@ -29,7 +29,7 @@ use webkit2gtk::{ pub struct WebContextImpl { context: WebContext, manager: UserContentManager, - webview_uri_loader: Rc, + webview_uri_loader: Rc, registered_protocols: HashSet, automation: bool, app_info: Option, @@ -132,12 +132,12 @@ pub trait WebContextExt { /// Add a [`WebView`] to the queue waiting to be opened. /// - /// See the `WebviewUriLoader` for more information. + /// See the [`WebViewUriLoader`] for more information. fn queue_load_uri(&self, webview: WebView, url: Url, headers: Option); /// Flush all queued [`WebView`]s waiting to load a uri. /// - /// See the `WebviewUriLoader` for more information. + /// See the [`WebViewUriLoader`] for more information. fn flush_queue_loader(&self); /// If the context allows automation. @@ -434,12 +434,12 @@ where /// fixing threading issues are not working. Ideally, the locks are not needed if we can understand /// the true cause of the bug. #[derive(Debug, Default)] -struct WebviewUriLoader { +struct WebViewUriLoader { lock: AtomicBool, queue: Mutex)>>, } -impl WebviewUriLoader { +impl WebViewUriLoader { /// Check if the lock is in use. fn is_locked(&self) -> bool { self.lock.swap(true, SeqCst) diff --git a/src/wkwebview/mod.rs b/src/wkwebview/mod.rs index b13291dbc..254c99c57 100644 --- a/src/wkwebview/mod.rs +++ b/src/wkwebview/mod.rs @@ -314,7 +314,7 @@ impl InnerWebView { let () = msg_send![config, setURLSchemeHandler:handler forURLScheme:NSString::new(&name)]; } - // Webview and manager + // WebView and manager let manager: id = msg_send![config, userContentController]; let cls = match ClassDecl::new("WryWebView", class!(WKWebView)) { #[allow(unused_mut)]