Commit e41da738 authored by Eric Willigers's avatar Eric Willigers Committed by Commit Bot

WebShare: Introduce web-share feature policy

share() requests fail with a rejected promise if the 'web-share'
feature is not enabled.

We define 'self' as the default feature policy for web-share.

The spec has been updated
https://github.com/w3c/web-share/pull/166

Intent to Ship
https://groups.google.com/a/chromium.org/g/blink-dev/c/fgme9KOd8CU/m/TCYPKQAXAwAJ

Bug: 1079104
Change-Id: Id4030448a54589eddb45185cbd6fd8970aee34c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2299791
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarIan Clelland <iclelland@chromium.org>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789872}
parent 5f757727
......@@ -134,6 +134,9 @@ enum FeaturePolicyFeature {
// Controls use of Clipboard API Write.
kClipboardWrite = 77,
// Controls use of Web Share API.
kWebShare = 78,
// Don't change assigned numbers of any item, and don't reuse removed slots.
// Add new features at the end of the enum.
// Also, run update_feature_policy_enum.py in
......
......@@ -41,6 +41,7 @@
"usb"
"vertical-scroll"
"vr"
"web-share"
"\"https://example.com/\""
"*"
"'self'"
......
......@@ -331,6 +331,11 @@
feature_default: "EnableForAll",
depends_on: ["ExperimentalProductivityFeatures"],
},
{
name: "WebShare",
feature_policy_name: "web-share",
depends_on: ["WebShare"],
},
{
name: "WebXr",
feature_policy_name: "xr-spatial-tracking",
......
......@@ -8,6 +8,7 @@
#include <utility>
#include "third_party/blink/public/common/browser_interface_broker_proxy.h"
#include "third_party/blink/public/mojom/feature_policy/feature_policy_feature.mojom-blink.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_share_data.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
......@@ -202,6 +203,13 @@ ScriptPromise NavigatorShare::share(ScriptState* script_state,
return ScriptPromise();
}
if (!ExecutionContext::From(script_state)
->IsFeatureEnabled(mojom::blink::FeaturePolicyFeature::kWebShare)) {
exception_state.ThrowDOMException(DOMExceptionCode::kNotAllowedError,
"Permission denied");
return ScriptPromise();
}
LocalDOMWindow* window = LocalDOMWindow::From(script_state);
if (!LocalFrame::ConsumeTransientUserActivation(window->GetFrame())) {
exception_state.ThrowDOMException(
......
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>WebShare Test: Can be disabled by feature policy</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
</head>
<body>
<script>
promise_test(async t => {
await test_driver.bless("web share");
await promise_rejects_dom(t, "NotAllowedError", navigator.share({}));
}, "share can be disabled by feature policy");
</script>
</body>
</html>
......@@ -58,5 +58,6 @@ top-navigation
trust-token-redemption
usb
vertical-scroll
web-share
xr-spatial-tracking
......@@ -28608,6 +28608,7 @@ Called by update_feature_policy_enum.py.-->
<int value="75" label="CrossOriginIsolated"/>
<int value="76" label="ClipboardRead"/>
<int value="77" label="ClipboardWrite"/>
<int value="78" label="WebShare"/>
</enum>
<enum name="FeaturePolicyImageCompressionFormat">
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment