Skip to content

Commit c8001c1

Browse files
authored
Update DisableNavigatingBackAndForward.md
Make some changes as suggested by the review
1 parent 36f9e5d commit c8001c1

File tree

1 file changed

+39
-38
lines changed

1 file changed

+39
-38
lines changed

specs/DisableNavigatingBackAndForward.md

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# API spec for disable navigating back/forward
22

33
# Background
4-
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.
4+
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.
5+
56
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.
67

7-
@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.
8+
@Haichao Zhu has already finished some work on letting application developers handle all input and decide whether to suppress.
9+
10+
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.
811

9-
Therefore, our job is to provide a mechanism for developers to disable navigating back and forward without effort.
12+
Therefore, our job is to provide a mechanism for developers to disable navigating back and forward without excessive effort.
1013

1114

1215
# Examples
@@ -26,9 +29,9 @@ CHECK_FAILURE(m_webView->add_NavigationStarting(
2629
wil::com_ptr<ICoreWebView2NavigationStartingEventArgs3> args3;
2730
if (SUCCEEDED(args->QueryInterface(IID_PPV_ARGS(&args3))))
2831
{
29-
int entry_offset;
30-
CHECK_FAILURE(stage_args->get_NavigationEntryOffset(&entry_offset));
31-
if (entry_offset == -1 || entry_offset == 1) {
32+
COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND history_change = COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_OTHER;
33+
CHECK_FAILURE(args3->get_NavigationHistoryChange(&history_change));
34+
if (history_change != COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_OTHER) {
3235
CHECK_FAILURE(args->put_Cancel(true));
3336
}
3437
}
@@ -49,7 +52,8 @@ CHECK_FAILURE(m_webView->add_NavigationStarting(
4952
// `GoBack` or `GoForward`, it will be canceled.
5053
void WebView_NavigationStarting(object sender, CoreWebView2NavigationStartingEventArgs e)
5154
{
52-
if (e.NavigationEntryOffset == -1 || e.NavigationEntryOffset == 1) {
55+
if (e.NavigationHistoryChange != CoreWebView2NavigationHistoryChangeKind.Other)
56+
{
5357
e.Cancel = true;
5458
}
5559
}
@@ -59,50 +63,47 @@ void WebView_NavigationStarting(object sender, CoreWebView2NavigationStartingEve
5963
#### Win32 C++
6064

6165
```c++
66+
// Enums and structs
67+
[v1_enum]
68+
typedef enum COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND {
69+
/// go back
70+
COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_BACK,
71+
/// go forward
72+
COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_FORWARD,
73+
/// other
74+
COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND_OTHER,
75+
} COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND;
76+
6277
/// Extend `NavigationStartingEventArgs` by adding more information.
6378
[uuid(39A27807-2365-470B-AF28-885502121049), object, pointer_default(unique)]
6479
interface ICoreWebView2NavigationStartingEventArgs3 : ICoreWebView2NavigationStartingEventArgs2 {
6580

66-
/// Get the entry offset of this navigation, which contains information about whether for back or forward.
67-
///
68-
/// MSOWNERS: [email protected]
69-
[propget] HRESULT NavigationEntryOffset([out, retval] int* entry_offset);
81+
/// Get the history change kind of the navigation
82+
[propget] HRESULT NavigationHistoryChange([out, retval] COREWEBVIEW2_NAVIGATION_HISTORY_CHANGE_KIND* history_change);
83+
}
7084
}
7185
```
7286

7387
#### .NET and WinRT
7488

75-
```c#
89+
```c# (but really MIDL3)
7690
namespace Microsoft.Web.WebView2.Core
7791
{
78-
public partial class CoreWebView2NavigationStartingEventArgs
92+
enum CoreWebView2NavigationHistoryChangeKind
7993
{
80-
///
81-
public int NavigationEntryOffset
94+
Back = 0,
95+
Forward = 1,
96+
Other = 2,
97+
};
98+
// ..
99+
runtimeclass CoreWebView2NavigationStartingEventArgs
100+
{
101+
// ICoreWebView2NavigationStartingEventArgs members
102+
// ..
103+
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2NavigationStartingEventArgs3")]
82104
{
83-
get
84-
{
85-
try
86-
{
87-
return
88-
_nativeICoreWebView2NavigationStartingEventArgs3.NavigationEntryOffset;
89-
90-
}
91-
catch (InvalidCastException ex)
92-
{
93-
if (ex.HResult == -2147467262) // UI_E_WRONG_THREAD
94-
throw new InvalidOperationException($"{nameof(CoreWebView2)} members can only be accessed from the UI thread.", ex);
95-
96-
throw ex;
97-
}
98-
catch (System.Runtime.InteropServices.COMException ex)
99-
{
100-
if (ex.HResult == -2147019873) // 0x8007139F
101-
throw new InvalidOperationException($"{nameof(CoreWebView2)} members cannot be accessed after the WebView2 control is disposed.", ex);
102-
103-
throw ex;
104-
}
105-
}
105+
// ICoreWebView2NavigationStartingEventArgs3 members
106+
CoreWebView2NavigationHistoryChangeKind NavigationHistoryChange { get; };
106107
}
107108
}
108109
}

0 commit comments

Comments
 (0)