Skip to content

Commit

Permalink
Safelist distributed web schemes for "registerProtocolHandler"
Browse files Browse the repository at this point in the history
This CL adds "cabal", "dat", "did", "dweb", "ethereum", "hyper",
"ipfs", "ipns", "ssb" to the safelist of
navigator.registerProtocolHandler. Chrome status entry is [1]
and feature has been discussed in [2] [3] [4] [5]. Currently,
the WHATWG and WPT changes are pending on the Mozilla position
review [6].

[1] https://www.chromestatus.com/feature/4776602869170176
[2] https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/29sFh4tTdcs/K4XroilVBAAJ
[3] https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/7nHTRUP1EGY
[4] whatwg/html#3935
[5] whatwg/html#3998
[6] mozilla/standards-positions#339

Bug: 651311
Change-Id: Iba45706e985015cf86bd80adef990abd0980a638
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2153064
Reviewed-by: Mike West <[email protected]>
Reviewed-by: Dominick Ng <[email protected]>
Commit-Queue: Frédéric Wang <[email protected]>
Cr-Commit-Position: refs/heads/master@{#799626}
  • Loading branch information
fred-wang authored and Commit Bot committed Aug 19, 2020
1 parent 23e6fdb commit 4e8ed0c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1070,3 +1070,19 @@ TEST_F(ProtocolHandlerRegistryTest, ExtensionHandler) {
GURL("chrome-extension://abcdefghijklmnopqrstuvwxyzabcdef/test.html")));
ASSERT_TRUE(registry()->IsHandledProtocol("news"));
}

// See
// https://html.spec.whatwg.org/multipage/system-state.html#safelisted-scheme
TEST_F(ProtocolHandlerRegistryTest, SafelistedSchemes) {
std::string schemes[] = {
"bitcoin", "cabal", "dat", "did", "doi", "dweb",
"ethereum", "geo", "hyper", "im", "ipfs", "ipns",
"irc", "ircs", "magnet", "mailto", "mms", "news",
"nntp", "openpgp4fpr", "sip", "sms", "smsto", "ssb",
"ssh", "tel", "urn", "webcal", "wtai", "xmpp"};
for (auto& scheme : schemes) {
registry()->OnAcceptRegisterProtocolHandler(
CreateProtocolHandler(scheme, GURL("https://example.com/url=%s")));
ASSERT_TRUE(registry()->IsHandledProtocol(scheme));
}
}
8 changes: 5 additions & 3 deletions chrome/common/custom_handlers/protocol_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ bool ProtocolHandler::IsValid() const {
// From:
// https://html.spec.whatwg.org/multipage/system-state.html#safelisted-scheme
static constexpr const char* const kProtocolSafelist[] = {
"bitcoin", "geo", "im", "irc", "ircs", "magnet", "mailto",
"mms", "news", "nntp", "openpgp4fpr", "sip", "sms", "smsto",
"ssh", "tel", "urn", "webcal", "wtai", "xmpp"};
"bitcoin", "cabal", "dat", "did", "doi", "dweb",
"ethereum", "geo", "hyper", "im", "ipfs", "ipns",
"irc", "ircs", "magnet", "mailto", "mms", "news",
"nntp", "openpgp4fpr", "sip", "sms", "smsto", "ssb",
"ssh", "tel", "urn", "webcal", "wtai", "xmpp"};
static constexpr const char kWebPrefix[] = "web+";

bool has_web_prefix =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ static const HashSet<String>& SupportedSchemes() {
DEFINE_STATIC_LOCAL(
HashSet<String>, supported_schemes,
({
"bitcoin", "geo", "im", "irc", "ircs", "magnet", "mailto",
"mms", "news", "nntp", "openpgp4fpr", "sip", "sms", "smsto",
"ssh", "tel", "urn", "webcal", "wtai", "xmpp",
"bitcoin", "cabal", "dat", "did", "dweb", "ethereum",
"geo", "hyper", "im", "ipfs", "ipns", "irc",
"ircs", "magnet", "mailto", "mms", "news", "nntp",
"openpgp4fpr", "sip", "sms", "smsto", "ssb", "ssh",
"tel", "urn", "webcal", "wtai", "xmpp",
}));
return supported_schemes;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<meta charset='utf-8'>
<title>protocol handlers</title>

<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>

<script>
// This should be merged into protocol.https.html when/if
// https://github.com/whatwg/html/pull/5482 is approved.
[
'cabal',
'dat',
'did',
'dweb',
'ethereum',
'hyper',
'ipfs',
'ipns',
'ssb',
].forEach(scheme => {
test(() => {
navigator.registerProtocolHandler(scheme, location.href + '/%s', "foo");
}, 'registerProtocolHandler: overriding the "' + scheme + '" protocol should work');

test(() => {
navigator.unregisterProtocolHandler(scheme, location.href + '/%s');
}, 'unregisterProtocolHandler: overriding the "' + scheme + '" protocol should work');
});
</script>

0 comments on commit 4e8ed0c

Please sign in to comment.