From 36f9e5db5b2f64cf49b952e707709da489483b9a Mon Sep 17 00:00:00 2001 From: plantree Date: Tue, 8 Nov 2022 16:27:39 +0800 Subject: [PATCH 1/8] Create DisableNavigatingBackAndForward.md --- specs/DisableNavigatingBackAndForward.md | 115 +++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 specs/DisableNavigatingBackAndForward.md diff --git a/specs/DisableNavigatingBackAndForward.md b/specs/DisableNavigatingBackAndForward.md new file mode 100644 index 000000000..dea0e200e --- /dev/null +++ b/specs/DisableNavigatingBackAndForward.md @@ -0,0 +1,115 @@ +# API spec for disable navigating back/forward + +# Background +This problem was first proposed by a developer on GitHub, who wants to prevent mouse Xbutton1 and XButton2. The reason for their superior level is to prevent users navigating back or forward. +Afterwards, Teams made similar demands. They wanted a mechanism which could support them in controlling the behaviors of `go back` and `go forward` freely, like disabling them. + +@Haichao Zhu has already finished some work on letting application developers handle all input and decide whether to suppress. This should be solvable in a generic way, as @Nic Champagne Williamson said. However, this feature hasn’t been released yet, and it might be better if we could provide a simpler and more direct way. + +Therefore, our job is to provide a mechanism for developers to disable navigating back and forward without effort. + + +# Examples +#### Win32 C++ + +##### Use `ICoreWebView2NavigationStartingEventArgs3` in `add_NavigationStarting` + +```c++ +//! [NavigationStarting] +// Register a handler for the NavigationStarting event. +// This handler will check the navigation status, and if the navigation is +// `GoBack` or `GoForward`, it will be canceled. +CHECK_FAILURE(m_webView->add_NavigationStarting( + Callback( + [this](ICoreWebView2* sender, ICoreWebView2NavigationStartingEventArgs* args) + -> HRESULT { + wil::com_ptr args3; + if (SUCCEEDED(args->QueryInterface(IID_PPV_ARGS(&args3)))) + { + int entry_offset; + CHECK_FAILURE(stage_args->get_NavigationEntryOffset(&entry_offset)); + if (entry_offset == -1 || entry_offset == 1) { + CHECK_FAILURE(args->put_Cancel(true)); + } + } + return S_OK; + }) + .Get(), + &m_navigationStartingToken)); +//! [NavigationStarting] +``` + +#### .NET and WinRT + +#### Use `CoreWebView2NavigationStartingEventArgs` in `NavigationStarting` + +```c# +// Register a handler for the NavigationStarting event. +// This handler will check the navigation status, and if the navigation is +// `GoBack` or `GoForward`, it will be canceled. +void WebView_NavigationStarting(object sender, CoreWebView2NavigationStartingEventArgs e) +{ + if (e.NavigationEntryOffset == -1 || e.NavigationEntryOffset == 1) { + e.Cancel = true; + } +} +``` + +# API Details +#### Win32 C++ + +```c++ +/// Extend `NavigationStartingEventArgs` by adding more information. +[uuid(39A27807-2365-470B-AF28-885502121049), object, pointer_default(unique)] +interface ICoreWebView2NavigationStartingEventArgs3 : ICoreWebView2NavigationStartingEventArgs2 { + + /// Get the entry offset of this navigation, which contains information about whether for back or forward. + /// + /// MSOWNERS: pengyuanwang@microsoft.com + [propget] HRESULT NavigationEntryOffset([out, retval] int* entry_offset); +} +``` + +#### .NET and WinRT + +```c# +namespace Microsoft.Web.WebView2.Core +{ + public partial class CoreWebView2NavigationStartingEventArgs + { + /// + public int NavigationEntryOffset + { + get + { + try + { + return + _nativeICoreWebView2NavigationStartingEventArgs3.NavigationEntryOffset; + + } + catch (InvalidCastException ex) + { + if (ex.HResult == -2147467262) // UI_E_WRONG_THREAD + throw new InvalidOperationException($"{nameof(CoreWebView2)} members can only be accessed from the UI thread.", ex); + + throw ex; + } + catch (System.Runtime.InteropServices.COMException ex) + { + if (ex.HResult == -2147019873) // 0x8007139F + throw new InvalidOperationException($"{nameof(CoreWebView2)} members cannot be accessed after the WebView2 control is disposed.", ex); + + throw ex; + } + } + } + } +} +``` + + +# Appendix +Relative scenario could be found here: https://dev.azure.com/microsoft/Edge/_workitems/edit/42081893. + +Design doc and reviews could be found here: https://microsoftapc-my.sharepoint.com/:w:/g/personal/pengyuanwang_microsoft_com/Ecu4x6kcjqxNrmvqQW7jr0QBCbHzd1PJ7M3h895rt_l_lg?e=ydF6ez. From c8001c1647bc51c77e16facd72caa5282f697bd2 Mon Sep 17 00:00:00 2001 From: plantree Date: Thu, 10 Nov 2022 15:52:10 +0800 Subject: [PATCH 2/8] Update DisableNavigatingBackAndForward.md Make some changes as suggested by the review --- specs/DisableNavigatingBackAndForward.md | 77 ++++++++++++------------ 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/specs/DisableNavigatingBackAndForward.md b/specs/DisableNavigatingBackAndForward.md index dea0e200e..1f1d7075d 100644 --- a/specs/DisableNavigatingBackAndForward.md +++ b/specs/DisableNavigatingBackAndForward.md @@ -1,12 +1,15 @@ # API spec for disable navigating back/forward # Background -This problem was first proposed by a developer on GitHub, who wants to prevent mouse Xbutton1 and XButton2. The reason for their superior level is to prevent users navigating back or forward. +This problem was first proposed by a developer on GitHub, who wants to prevent users navigating back or forward using any of the built-in shortcut keys or special mouse buttons. + Afterwards, Teams made similar demands. They wanted a mechanism which could support them in controlling the behaviors of `go back` and `go forward` freely, like disabling them. -@Haichao Zhu has already finished some work on letting application developers handle all input and decide whether to suppress. This should be solvable in a generic way, as @Nic Champagne Williamson said. However, this feature hasn’t been released yet, and it might be better if we could provide a simpler and more direct way. +@Haichao Zhu has already finished some work on letting application developers handle all input and decide whether to suppress. + +This should be solvable in a generic way. However, this feature hasn’t been released yet, and it might be better if we could provide a simpler and more direct way. -Therefore, our job is to provide a mechanism for developers to disable navigating back and forward without effort. +Therefore, our job is to provide a mechanism for developers to disable navigating back and forward without excessive effort. # Examples @@ -26,9 +29,9 @@ CHECK_FAILURE(m_webView->add_NavigationStarting( wil::com_ptr args3; if (SUCCEEDED(args->QueryInterface(IID_PPV_ARGS(&args3)))) { - int entry_offset; - CHECK_FAILURE(stage_args->get_NavigationEntryOffset(&entry_offset)); - if (entry_offset == -1 || entry_offset == 1) { + COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND history_change = COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_OTHER; + CHECK_FAILURE(args3->get_NavigationHistoryChange(&history_change)); + if (history_change != COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_OTHER) { CHECK_FAILURE(args->put_Cancel(true)); } } @@ -49,7 +52,8 @@ CHECK_FAILURE(m_webView->add_NavigationStarting( // `GoBack` or `GoForward`, it will be canceled. void WebView_NavigationStarting(object sender, CoreWebView2NavigationStartingEventArgs e) { - if (e.NavigationEntryOffset == -1 || e.NavigationEntryOffset == 1) { + if (e.NavigationHistoryChange != CoreWebView2NavigationHistoryChangeKind.Other) + { e.Cancel = true; } } @@ -59,50 +63,47 @@ void WebView_NavigationStarting(object sender, CoreWebView2NavigationStartingEve #### Win32 C++ ```c++ +// Enums and structs +[v1_enum] +typedef enum COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND { + /// go back + COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_BACK, + /// go forward + COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_FORWARD, + /// other + COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_OTHER, +} COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND; + /// Extend `NavigationStartingEventArgs` by adding more information. [uuid(39A27807-2365-470B-AF28-885502121049), object, pointer_default(unique)] interface ICoreWebView2NavigationStartingEventArgs3 : ICoreWebView2NavigationStartingEventArgs2 { - /// Get the entry offset of this navigation, which contains information about whether for back or forward. - /// - /// MSOWNERS: pengyuanwang@microsoft.com - [propget] HRESULT NavigationEntryOffset([out, retval] int* entry_offset); + /// Get the history change kind of the navigation + [propget] HRESULT NavigationHistoryChange([out, retval] COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND* history_change); +} } ``` #### .NET and WinRT -```c# +```c# (but really MIDL3) namespace Microsoft.Web.WebView2.Core { - public partial class CoreWebView2NavigationStartingEventArgs + enum CoreWebView2NavigationHistoryChangeKind { - /// - public int NavigationEntryOffset + Back = 0, + Forward = 1, + Other = 2, + }; + // .. + runtimeclass CoreWebView2NavigationStartingEventArgs + { + // ICoreWebView2NavigationStartingEventArgs members + // .. + [interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2NavigationStartingEventArgs3")] { - get - { - try - { - return - _nativeICoreWebView2NavigationStartingEventArgs3.NavigationEntryOffset; - - } - catch (InvalidCastException ex) - { - if (ex.HResult == -2147467262) // UI_E_WRONG_THREAD - throw new InvalidOperationException($"{nameof(CoreWebView2)} members can only be accessed from the UI thread.", ex); - - throw ex; - } - catch (System.Runtime.InteropServices.COMException ex) - { - if (ex.HResult == -2147019873) // 0x8007139F - throw new InvalidOperationException($"{nameof(CoreWebView2)} members cannot be accessed after the WebView2 control is disposed.", ex); - - throw ex; - } - } + // ICoreWebView2NavigationStartingEventArgs3 members + CoreWebView2NavigationHistoryChangeKind NavigationHistoryChange { get; }; } } } From 13a31b18cec0379fecb23270fcb11fbdd0183f4a Mon Sep 17 00:00:00 2001 From: plantree Date: Fri, 11 Nov 2022 10:51:04 +0800 Subject: [PATCH 3/8] Apply suggestions from code review Co-authored-by: David Risney --- specs/DisableNavigatingBackAndForward.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/specs/DisableNavigatingBackAndForward.md b/specs/DisableNavigatingBackAndForward.md index 1f1d7075d..aea79e2a2 100644 --- a/specs/DisableNavigatingBackAndForward.md +++ b/specs/DisableNavigatingBackAndForward.md @@ -31,7 +31,8 @@ CHECK_FAILURE(m_webView->add_NavigationStarting( { COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND history_change = COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_OTHER; CHECK_FAILURE(args3->get_NavigationHistoryChange(&history_change)); - if (history_change != COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_OTHER) { + if (history_change != COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_OTHER) + { CHECK_FAILURE(args->put_Cancel(true)); } } @@ -66,11 +67,11 @@ void WebView_NavigationStarting(object sender, CoreWebView2NavigationStartingEve // Enums and structs [v1_enum] typedef enum COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND { - /// go back + /// Indicates a navigation that is going back to a previous entry in the navigation history. For example, a navigation caused by `CoreWebView2.GoBack` or in script `window.history.go(-1)`. COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_BACK, - /// go forward + /// Indicates a navigation that is going forward to a later entry in the navigation history. For example, a navigation caused by `CoreWebView2.GoForward` or in script `window.history.go(1)`. COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_FORWARD, - /// other + /// Indicates a navigation that is not going back or forward to an existing entry in the navigation history. For example, a navigation caused by `CoreWebView2.Navigate`, or `CoreWebView2.Reload` or in script `window.location.href = 'https://example.com/'`. COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_OTHER, } COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND; @@ -78,7 +79,7 @@ typedef enum COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND { [uuid(39A27807-2365-470B-AF28-885502121049), object, pointer_default(unique)] interface ICoreWebView2NavigationStartingEventArgs3 : ICoreWebView2NavigationStartingEventArgs2 { - /// Get the history change kind of the navigation + /// Indicates if this navigation is going back or forward to an existing entry in the navigation history. [propget] HRESULT NavigationHistoryChange([out, retval] COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND* history_change); } } From 0a2e0141235dc96245bf742fc1d617479a6a9436 Mon Sep 17 00:00:00 2001 From: David Risney Date: Fri, 11 Nov 2022 09:37:10 -0800 Subject: [PATCH 4/8] Update DisableNavigatingBackAndForward.md Fix line lengths --- specs/DisableNavigatingBackAndForward.md | 34 ++++++++++++++++-------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/specs/DisableNavigatingBackAndForward.md b/specs/DisableNavigatingBackAndForward.md index aea79e2a2..2de8f2877 100644 --- a/specs/DisableNavigatingBackAndForward.md +++ b/specs/DisableNavigatingBackAndForward.md @@ -1,15 +1,20 @@ # API spec for disable navigating back/forward # Background -This problem was first proposed by a developer on GitHub, who wants to prevent users navigating back or forward using any of the built-in shortcut keys or special mouse buttons. +This problem was first proposed by a developer on GitHub, who wants to prevent users navigating +back or forward using any of the built-in shortcut keys or special mouse buttons. -Afterwards, Teams made similar demands. They wanted a mechanism which could support them in controlling the behaviors of `go back` and `go forward` freely, like disabling them. +Afterwards, Teams made similar demands. They wanted a mechanism which could support them in +controlling the behaviors of `go back` and `go forward` freely, like disabling them. -@Haichao Zhu has already finished some work on letting application developers handle all input and decide whether to suppress. +@Haichao Zhu has already finished some work on letting application developers handle all input and +decide whether to suppress. -This should be solvable in a generic way. However, this feature hasn’t been released yet, and it might be better if we could provide a simpler and more direct way. +This should be solvable in a generic way. However, this feature hasn’t been released yet, and it might +be better if we could provide a simpler and more direct way. -Therefore, our job is to provide a mechanism for developers to disable navigating back and forward without excessive effort. +Therefore, our job is to provide a mechanism for developers to disable navigating back and forward +without excessive effort. # Examples @@ -29,7 +34,8 @@ CHECK_FAILURE(m_webView->add_NavigationStarting( wil::com_ptr args3; if (SUCCEEDED(args->QueryInterface(IID_PPV_ARGS(&args3)))) { - COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND history_change = COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_OTHER; + COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND history_change = + COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_OTHER; CHECK_FAILURE(args3->get_NavigationHistoryChange(&history_change)); if (history_change != COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_OTHER) { @@ -67,11 +73,15 @@ void WebView_NavigationStarting(object sender, CoreWebView2NavigationStartingEve // Enums and structs [v1_enum] typedef enum COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND { - /// Indicates a navigation that is going back to a previous entry in the navigation history. For example, a navigation caused by `CoreWebView2.GoBack` or in script `window.history.go(-1)`. + /// Indicates a navigation that is going back to a previous entry in the navigation history. + /// For example, a navigation caused by `CoreWebView2.GoBack` or in script `window.history.go(-1)`. COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_BACK, - /// Indicates a navigation that is going forward to a later entry in the navigation history. For example, a navigation caused by `CoreWebView2.GoForward` or in script `window.history.go(1)`. + /// Indicates a navigation that is going forward to a later entry in the navigation history. + /// For example, a navigation caused by `CoreWebView2.GoForward` or in script `window.history.go(1)`. COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_FORWARD, - /// Indicates a navigation that is not going back or forward to an existing entry in the navigation history. For example, a navigation caused by `CoreWebView2.Navigate`, or `CoreWebView2.Reload` or in script `window.location.href = 'https://example.com/'`. + /// Indicates a navigation that is not going back or forward to an existing entry in the navigation + /// history. For example, a navigation caused by `CoreWebView2.Navigate`, or `CoreWebView2.Reload` + /// or in script `window.location.href = 'https://example.com/'`. COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_OTHER, } COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND; @@ -79,8 +89,10 @@ typedef enum COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND { [uuid(39A27807-2365-470B-AF28-885502121049), object, pointer_default(unique)] interface ICoreWebView2NavigationStartingEventArgs3 : ICoreWebView2NavigationStartingEventArgs2 { - /// Indicates if this navigation is going back or forward to an existing entry in the navigation history. - [propget] HRESULT NavigationHistoryChange([out, retval] COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND* history_change); + /// Indicates if this navigation is going back or forward to an existing entry in the navigation + /// history. + [propget] HRESULT NavigationHistoryChange( + [out, retval] COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND* history_change); } } ``` From 41ea0f7ff3978845a606129973a11244e7f1cf81 Mon Sep 17 00:00:00 2001 From: plantree Date: Thu, 17 Nov 2022 15:08:58 +0800 Subject: [PATCH 5/8] Apply suggestions from code review Wordsmithing Co-authored-by: Raymond Chen --- specs/DisableNavigatingBackAndForward.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/DisableNavigatingBackAndForward.md b/specs/DisableNavigatingBackAndForward.md index 2de8f2877..0aef1457b 100644 --- a/specs/DisableNavigatingBackAndForward.md +++ b/specs/DisableNavigatingBackAndForward.md @@ -1,7 +1,7 @@ # API spec for disable navigating back/forward # Background -This problem was first proposed by a developer on GitHub, who wants to prevent users navigating +This problem was first identified by a developer on GitHub, who wants to prevent users navigating back or forward using any of the built-in shortcut keys or special mouse buttons. Afterwards, Teams made similar demands. They wanted a mechanism which could support them in From e3c17939fa73437fc7ab419a0c8aed5c0121f4d0 Mon Sep 17 00:00:00 2001 From: plantree Date: Tue, 22 Nov 2022 14:46:22 +0800 Subject: [PATCH 6/8] Update DisableNavigatingBackAndForward.md using `NavigationKind` enum --- specs/DisableNavigatingBackAndForward.md | 50 ++++++++++++------------ 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/specs/DisableNavigatingBackAndForward.md b/specs/DisableNavigatingBackAndForward.md index 0aef1457b..4d4da5596 100644 --- a/specs/DisableNavigatingBackAndForward.md +++ b/specs/DisableNavigatingBackAndForward.md @@ -34,10 +34,10 @@ CHECK_FAILURE(m_webView->add_NavigationStarting( wil::com_ptr args3; if (SUCCEEDED(args->QueryInterface(IID_PPV_ARGS(&args3)))) { - COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND history_change = - COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_OTHER; - CHECK_FAILURE(args3->get_NavigationHistoryChange(&history_change)); - if (history_change != COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_OTHER) + COREWEBVIEW2_NAVIGATION_KIND kind; + CHECK_FAILURE(args3->get_NavigationKind(&kind)); + // disable navigation if it is back/forward + if (kind == COREWEBVIEW2_NAVIGATION_KIND_BACKORFORWARD) { CHECK_FAILURE(args->put_Cancel(true)); } @@ -59,7 +59,7 @@ CHECK_FAILURE(m_webView->add_NavigationStarting( // `GoBack` or `GoForward`, it will be canceled. void WebView_NavigationStarting(object sender, CoreWebView2NavigationStartingEventArgs e) { - if (e.NavigationHistoryChange != CoreWebView2NavigationHistoryChangeKind.Other) + if (e.NavigationKind == CoreWebView2NavigationKind.BackOrForward) { e.Cancel = true; } @@ -72,27 +72,25 @@ void WebView_NavigationStarting(object sender, CoreWebView2NavigationStartingEve ```c++ // Enums and structs [v1_enum] -typedef enum COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND { - /// Indicates a navigation that is going back to a previous entry in the navigation history. - /// For example, a navigation caused by `CoreWebView2.GoBack` or in script `window.history.go(-1)`. - COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_BACK, - /// Indicates a navigation that is going forward to a later entry in the navigation history. - /// For example, a navigation caused by `CoreWebView2.GoForward` or in script `window.history.go(1)`. - COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_FORWARD, - /// Indicates a navigation that is not going back or forward to an existing entry in the navigation - /// history. For example, a navigation caused by `CoreWebView2.Navigate`, or `CoreWebView2.Reload` - /// or in script `window.location.href = 'https://example.com/'`. - COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_OTHER, -} COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND; +typedef enum COREWEBVIEW2_NAVIGATION_KIND { + /// Indicates a navigation that is reloading the current document. + /// For example, a navigation caused by `CoreWebView2.Reload()` or in script `window.history.go()`. + COREWEBVIEW2_NAVIGATION_KIND_RELOAD, + /// Indicates a navigation that is going back or forward in the navigation history. + /// For example, a navigation caused by `CoreWebView2.GoBack()/Forward()` or in script `window.history.go(-1)/go(1)`. + COREWEBVIEW2_NAVIGATION_KIND_BACKORFORWARD, + /// Indicates a navigation that is navigating to a different document. + /// For example, a navigation caused by `CoreWebView2.Navigate()`, or a link click. + COREWEBVIEW2_NAVIGATION_KIND_DIFFERENT, +} COREWEBVIEW2_NAVIGATION_KIND; /// Extend `NavigationStartingEventArgs` by adding more information. [uuid(39A27807-2365-470B-AF28-885502121049), object, pointer_default(unique)] interface ICoreWebView2NavigationStartingEventArgs3 : ICoreWebView2NavigationStartingEventArgs2 { - /// Indicates if this navigation is going back or forward to an existing entry in the navigation - /// history. - [propget] HRESULT NavigationHistoryChange( - [out, retval] COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND* history_change); + /// Indicates if this navigation is reload, back/forward or navigating to a different document + [propget] HRESULT NavigationHistoryKind( + [out, retval] COREWEBVIEW2_NAVIGATION_KIND* kind); } } ``` @@ -102,11 +100,11 @@ interface ICoreWebView2NavigationStartingEventArgs3 : ICoreWebView2NavigationSta ```c# (but really MIDL3) namespace Microsoft.Web.WebView2.Core { - enum CoreWebView2NavigationHistoryChangeKind + enum CoreWebView2NavigationKind { - Back = 0, - Forward = 1, - Other = 2, + Reload = 0, + BackOrForward = 1, + Different = 2, }; // .. runtimeclass CoreWebView2NavigationStartingEventArgs @@ -116,7 +114,7 @@ namespace Microsoft.Web.WebView2.Core [interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2NavigationStartingEventArgs3")] { // ICoreWebView2NavigationStartingEventArgs3 members - CoreWebView2NavigationHistoryChangeKind NavigationHistoryChange { get; }; + CoreWebView2NavigationKind NavigationKind { get; }; } } } From 4b251eaec85a48f8b273cf1fbdb6983d2b781863 Mon Sep 17 00:00:00 2001 From: plantree Date: Tue, 22 Nov 2022 14:57:14 +0800 Subject: [PATCH 7/8] Update DisableNavigatingBackAndForward.md polish comments --- specs/DisableNavigatingBackAndForward.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/specs/DisableNavigatingBackAndForward.md b/specs/DisableNavigatingBackAndForward.md index 4d4da5596..8dd0c2e9a 100644 --- a/specs/DisableNavigatingBackAndForward.md +++ b/specs/DisableNavigatingBackAndForward.md @@ -73,14 +73,11 @@ void WebView_NavigationStarting(object sender, CoreWebView2NavigationStartingEve // Enums and structs [v1_enum] typedef enum COREWEBVIEW2_NAVIGATION_KIND { - /// Indicates a navigation that is reloading the current document. - /// For example, a navigation caused by `CoreWebView2.Reload()` or in script `window.history.go()`. + /// A navigation caused by CoreWebView2.Reload(), location.reload(), the end user using F5 or other UX, or other reload mechanisms to reload the current document without modifying the navigation history. COREWEBVIEW2_NAVIGATION_KIND_RELOAD, - /// Indicates a navigation that is going back or forward in the navigation history. - /// For example, a navigation caused by `CoreWebView2.GoBack()/Forward()` or in script `window.history.go(-1)/go(1)`. + /// A navigation back or forward to a different entry in the session navigation history. For example via CoreWebView2.Back(), location.back(), the end user pressing Alt+Left or other UX, or other mechanisms to navigate forward or backward in the current session navigation history. COREWEBVIEW2_NAVIGATION_KIND_BACKORFORWARD, - /// Indicates a navigation that is navigating to a different document. - /// For example, a navigation caused by `CoreWebView2.Navigate()`, or a link click. + /// A navigation to a different document. This can be caused by CoreWebView2.Navigate(), window.location.href = '...', or other WebView2 or DOM APIs that navigate to a specific URI. COREWEBVIEW2_NAVIGATION_KIND_DIFFERENT, } COREWEBVIEW2_NAVIGATION_KIND; @@ -89,7 +86,7 @@ typedef enum COREWEBVIEW2_NAVIGATION_KIND { interface ICoreWebView2NavigationStartingEventArgs3 : ICoreWebView2NavigationStartingEventArgs2 { /// Indicates if this navigation is reload, back/forward or navigating to a different document - [propget] HRESULT NavigationHistoryKind( + [propget] HRESULT NavigationKind( [out, retval] COREWEBVIEW2_NAVIGATION_KIND* kind); } } From ff47bcedf31fa93f31cb465461f2f4f0c2fda5f9 Mon Sep 17 00:00:00 2001 From: plantree Date: Wed, 23 Nov 2022 14:01:44 +0800 Subject: [PATCH 8/8] Update DisableNavigatingBackAndForward.md use line breaks to avoid horizontal scrolling and update enum name --- specs/DisableNavigatingBackAndForward.md | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/specs/DisableNavigatingBackAndForward.md b/specs/DisableNavigatingBackAndForward.md index 8dd0c2e9a..a50742ae8 100644 --- a/specs/DisableNavigatingBackAndForward.md +++ b/specs/DisableNavigatingBackAndForward.md @@ -37,7 +37,7 @@ CHECK_FAILURE(m_webView->add_NavigationStarting( COREWEBVIEW2_NAVIGATION_KIND kind; CHECK_FAILURE(args3->get_NavigationKind(&kind)); // disable navigation if it is back/forward - if (kind == COREWEBVIEW2_NAVIGATION_KIND_BACKORFORWARD) + if (kind == COREWEBVIEW2_NAVIGATION_KIND_BACK_OR_FORWARD) { CHECK_FAILURE(args->put_Cancel(true)); } @@ -73,12 +73,18 @@ void WebView_NavigationStarting(object sender, CoreWebView2NavigationStartingEve // Enums and structs [v1_enum] typedef enum COREWEBVIEW2_NAVIGATION_KIND { - /// A navigation caused by CoreWebView2.Reload(), location.reload(), the end user using F5 or other UX, or other reload mechanisms to reload the current document without modifying the navigation history. + /// A navigation caused by CoreWebView2.Reload(), location.reload(), the end user + /// using F5 or other UX, or other reload mechanisms to reload the current document + /// without modifying the navigation history. COREWEBVIEW2_NAVIGATION_KIND_RELOAD, - /// A navigation back or forward to a different entry in the session navigation history. For example via CoreWebView2.Back(), location.back(), the end user pressing Alt+Left or other UX, or other mechanisms to navigate forward or backward in the current session navigation history. - COREWEBVIEW2_NAVIGATION_KIND_BACKORFORWARD, - /// A navigation to a different document. This can be caused by CoreWebView2.Navigate(), window.location.href = '...', or other WebView2 or DOM APIs that navigate to a specific URI. - COREWEBVIEW2_NAVIGATION_KIND_DIFFERENT, + /// A navigation back or forward to a different entry in the session navigation history. + /// For example via CoreWebView2.Back(), location.back(), the end user pressing Alt+Left + /// or other UX, or other mechanisms to navigate forward or backward in the current + /// session navigation history. + COREWEBVIEW2_NAVIGATION_KIND_BACK_OR_FORWARD, + /// A navigation to a different document. This can be caused by CoreWebView2.Navigate(), + /// window.location.href = '...', or other WebView2 or DOM APIs that navigate to a specific URI. + COREWEBVIEW2_NAVIGATION_KIND_DIFFERENT_DOCUMENT, } COREWEBVIEW2_NAVIGATION_KIND; /// Extend `NavigationStartingEventArgs` by adding more information. @@ -101,7 +107,7 @@ namespace Microsoft.Web.WebView2.Core { Reload = 0, BackOrForward = 1, - Different = 2, + DifferentDocument = 2, }; // .. runtimeclass CoreWebView2NavigationStartingEventArgs