Skip to content

Commit 41e7c6d

Browse files
author
Maura Winstanley
committed
Update spec from initial feedback
1 parent 60d6b96 commit 41e7c6d

1 file changed

Lines changed: 32 additions & 54 deletions

File tree

specs/LaunchingRegisteredProtocols.md

Lines changed: 32 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Background
22

3-
We are exposing an event that will be raised when an attempt to launch an external protocol is made. The host will be given the option to cancel the launch, handle the popup dialog to hide the dialog, as well as disable the checkbox that, if selected, will give permissions to always allow the launch.
3+
We are exposing an event that will be raised when an attempt to launch an external protocol is made. The host will be given the option to cancel the launch, hide the dialog, as well as disable the checkbox that, if selected, will give permissions to always allow the launch.
44

55
# Description
66

7-
This event will be raised before the external protocol launch occurs. Currently a popup dialog is displayed in which the user can click `Open` or `Cancel`. If the request is made from a [trustworthy origin](#https://w3c.github.io/webappsec-secure-contexts/#potentially-trustworthy-origin) a checkmark box will be displayed that will allow the user to always allow this external protocol from this origin. The `NavigationStarting`, `NavigationCompleted`, `SourceChanged`, `ContentLoading`, and `HistoryChanged` events will not be raised when a request is made to launch an external protocol.
7+
This event will be raised before the external protocol launch occurs. Currently a dialog is displayed in which the user can click `Open` or `Cancel`. If the request is made from a [trustworthy origin](https://w3c.github.io/webappsec-secure-contexts/#potentially-trustworthy-origin) a checkmark box will be displayed that will allow the user to always allow this external protocol from this origin. The `NavigationStarting`, `NavigationCompleted`, `SourceChanged`, `ContentLoading`, and `HistoryChanged` events will not be raised when a request is made to launch an external protocol.
88

9-
The `LaunchingExternalProtocol` event will be raised on either `CoreWebView2` or `CoreWebView2Frame` depending on if the launch request is originating from the main frame or a non-main frame. A current limitation of our `CoreWebView2Frame` API is that it only supports top level iframes. Any nested iframes will not have a `CoreWebView2Frame` associated with them. In the case of a nested iframe requesting the external protocol launch, the event will be raised from the top level iframe.
9+
The `LaunchingExternalProtocol` event will be raised on either `CoreWebView2` or `CoreWebView2Frame` depending on if the launch request is originating from the main frame or a non-main frame. In the case of a nested iframe requesting the external protocol launch, the event will be raised from the top level iframe.
1010
# Examples
1111

1212
## Win32 C++
@@ -34,26 +34,22 @@ void RegisterLaunchingExternalProtocolHandler()
3434
if (wcsicmp(uri.get(), L"calculator://") == 0)
3535
{
3636
CHECK_FAILURE(args->put_Handled(TRUE));
37-
// If this matches our desired protocol, then suppress the
38-
// popup dialog.
37+
// If this matches our desired protocol, then suppress the dialog.
3938
}
4039
else
4140
{
42-
// Otherwise allow the popup dialog, and allow the user to decide
41+
// Otherwise allow the dialog, and let the user to decide
4342
// whether or not to allow the protocol to launch.
4443
}
4544
return S_OK;
4645
})
4746
.Get(),
4847
&m_launchingExternalProtocolToken));
49-
}
50-
auto webView4 = m_webview.try_query<ICoreWebView2_4>();
51-
if (webView4)
52-
{
48+
5349
// Note that FrameCreated will only ever be raised for top level iframes.
54-
// However, any launching external protocol requests from nested iframes
50+
// Any launching external protocol requests from nested iframes
5551
// will be raised from the top level frame.
56-
CHECK_FAILURE(webView4->add_FrameCreated(
52+
CHECK_FAILURE(webView5->add_FrameCreated(
5753
Callback<ICoreWebView2FrameCreatedEventHandler>(
5854
[this](ICoreWebView2* sender, ICoreWebView2FrameCreatedEventArgs* args) -> HRESULT
5955
{
@@ -73,7 +69,7 @@ void RegisterLaunchingExternalProtocolHandler()
7369
if (wcsicmp(uri.get(), L"calculator://") == 0)
7470
{
7571
// If this matches our desired protocol, then suppress the
76-
// popup dialog.
72+
// dialog.
7773
CHECK_FAILURE(args->put_Handled(TRUE));
7874
}
7975
else
@@ -101,54 +97,36 @@ void RegisterLaunchingExternalProtocolHandler()
10197
private WebView2 webView;
10298
void RegisterLaunchingExternalProtocolHandler()
10399
{
104-
// Safeguarding the handler when unsupported runtime is used.
105-
try
100+
webView.CoreWebView2.LaunchingExternalProtocol += (CoreWebView2 sender, CoreWebView2LaunchingExternalProtocolEventArgs e) {
101+
if (e.Uri == "calculator:///")
102+
{
103+
// If this matches our desired protocol, then suppress the popup dialog.
104+
e.Handled = true;
105+
}
106+
else
107+
{
108+
// Otherwise allow the dialog, and let the user to decide
109+
// whether or not to allow the protocol to launch.
110+
}
111+
};
112+
113+
webView.CoreWebView2.FrameCreated += (CoreWebView2Frame sender, CoreWebView2FrameCreatedEventArgs args) =>
106114
{
107-
webView.CoreWebView2.LaunchingExternalProtocol += (CoreWebView2 sender, CoreWebView2LaunchingExternalProtocolEventArgs e) {
108-
if (e.Uri == "calculator:///")
115+
// Apply the same logic as above to non-main frame raising the event.
116+
args.Frame.LaunchingExternalProtocol += (LaunchingExternalProtocolSender, LaunchingExternalProtocolArgs) =>
117+
{
118+
if (LaunchingExternalProtocolArgs.Uri == "calculator:///")
109119
{
110-
// If this matches our desired protocol, then suppress the popup dialog.
111-
e.Handled = true;
120+
// If this matches our desired protocol, then suppress the dialog.
121+
LaunchingExternalProtocolArgs.Handled = true;
112122
}
113123
else
114124
{
115-
// Otherwise allow the popup dialog, and allow the user to decide
116-
// whether or not to allow the protocol to launch.
125+
// Otherwise revoke permissions previously granted to this protocol
126+
// from this origin as well as disable the always open checkbox.
127+
LaunchingExternalProtocolArgs.DisableAlwaysOpenCheckbox = true;
117128
}
118129
};
119-
}
120-
catch (NotImplementedException exception)
121-
{
122-
// If the runtime support is not there we probably want this
123-
// to be a no-op.
124-
}
125-
126-
webView.CoreWebView2.FrameCreated += (CoreWebView2Frame sender, CoreWebView2FrameCreatedEventArgs args) =>
127-
{
128-
// Safeguarding the handler when unsupported runtime is used.
129-
try
130-
{
131-
// Apply the same logic as above to non-main frame raising the event.
132-
args.Frame.LaunchingExternalProtocol += (LaunchingExternalProtocolSender, LaunchingExternalProtocolArgs) =>
133-
{
134-
if (LaunchingExternalProtocolArgs.Uri == "calculator:///")
135-
{
136-
// If this matches our desired protocol, then suppress the popup dialog.
137-
LaunchingExternalProtocolArgs.Handled = true;
138-
}
139-
else
140-
{
141-
// Otherwise revoke permissions previously granted to this protocol
142-
// from this origin as well as disable the always open checkbox.
143-
LaunchingExternalProtocolArgs.DisableAlwaysOpenCheckbox = true;
144-
}
145-
};
146-
}
147-
catch (NotImplementedException exception)
148-
{
149-
// If the runtime support is not there we probably want this
150-
// to be a no-op.
151-
}
152130
};
153131
}
154132

0 commit comments

Comments
 (0)