Skip to content

Commit

Permalink
feat: rename 'Webview' to 'WebView'
Browse files Browse the repository at this point in the history
Signed-off-by: rhysd <[email protected]>
  • Loading branch information
rhysd committed Nov 12, 2023
1 parent 9529b44 commit 06dbe68
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 25 deletions.
11 changes: 11 additions & 0 deletions .changes/Webview-to-WebView.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"wry": minor
---

Consistently use `WebView` in API names. The following APIs were renamed:
- `WebviewExtWindows``WebViewExtWindows`
- `WebviewExtUnix``WebViewExtUnix`
- `WebviewExtMacOS``WebViewExtMacOS`
- `WebviewExtIOS``WebViewExtIOS`
- `WebviewExtAndroid``WebViewExtAndroid`
- `WebviewUriLoader``WebViewUriLoader`
2 changes: 1 addition & 1 deletion .changes/add-api-to-set-memory-usage-for-windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 2 additions & 2 deletions .changes/rwh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 15 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down Expand Up @@ -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 `<protocol>://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
Expand Down Expand Up @@ -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<String> {
platform_webview_version()
}
Expand All @@ -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;

Expand All @@ -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()
}
Expand All @@ -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;
}

Expand All @@ -1476,15 +1476,15 @@ 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()
}
}

/// 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
Expand All @@ -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
}
Expand All @@ -1510,15 +1510,15 @@ 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
fn manager(&self) -> cocoa::base::id;
}

#[cfg(target_os = "ios")]
impl WebviewExtIOS for WebView {
impl WebViewExtIOS for WebView {
fn webview(&self) -> cocoa::base::id {
self.webview.webview
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/web_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
10 changes: 5 additions & 5 deletions src/webkitgtk/web_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use webkit2gtk::{
pub struct WebContextImpl {
context: WebContext,
manager: UserContentManager,
webview_uri_loader: Rc<WebviewUriLoader>,
webview_uri_loader: Rc<WebViewUriLoader>,
registered_protocols: HashSet<String>,
automation: bool,
app_info: Option<ApplicationInfo>,
Expand Down Expand Up @@ -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<http::HeaderMap>);

/// 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.
Expand Down Expand Up @@ -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<VecDeque<(WebView, Url, Option<http::HeaderMap>)>>,
}

impl WebviewUriLoader {
impl WebViewUriLoader {
/// Check if the lock is in use.
fn is_locked(&self) -> bool {
self.lock.swap(true, SeqCst)
Expand Down
2 changes: 1 addition & 1 deletion src/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 06dbe68

Please sign in to comment.