Bug 1653199 - Add web-share permissions policy r=ckerschb
☠☠ backed out by f5bfa5ea6f04 ☠ ☠
authorMarcos Cáceres <mcaceres@mozilla.com>
Mon, 20 Jul 2020 07:35:33 +0000
changeset 541369 e4b17772c446c6a2ca13ec51000a05807751aada
parent 541368 dbd8cf9a9c829672446f1b98e529d5c5d53ab8e7
child 541370 2a3440bf9f3d89d839a8da70a0916c888072dd7b
push id122198
push usermcaceres@mozilla.com
push dateMon, 20 Jul 2020 22:28:02 +0000
treeherderautoland@e4b17772c446 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb
bugs1653199
milestone80.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1653199 - Add web-share permissions policy r=ckerschb Adds "web-share" permissions policy Differential Revision: https://phabricator.services.mozilla.com/D84121
dom/base/Navigator.cpp
dom/security/featurepolicy/FeaturePolicyUtils.cpp
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -1368,16 +1368,24 @@ Promise* Navigator::GetBattery(ErrorResu
 
 Promise* Navigator::Share(const ShareData& aData, ErrorResult& aRv) {
   if (NS_WARN_IF(!mWindow || !mWindow->GetDocShell() ||
                  !mWindow->GetExtantDoc())) {
     aRv.Throw(NS_ERROR_UNEXPECTED);
     return nullptr;
   }
 
+  if (!FeaturePolicyUtils::IsFeatureAllowed(mWindow->GetExtantDoc(),
+                                            u"web-share"_ns)) {
+    aRv.ThrowNotAllowedError(
+        "Document's Permission Policy does not allow calling "
+        "share() from this context.");
+    return nullptr;
+  }
+
   if (mSharePromise) {
     NS_WARNING("Only one share picker at a time per navigator instance");
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return nullptr;
   }
 
   // null checked above
   auto* doc = mWindow->GetExtantDoc();
--- a/dom/security/featurepolicy/FeaturePolicyUtils.cpp
+++ b/dom/security/featurepolicy/FeaturePolicyUtils.cpp
@@ -27,16 +27,17 @@ struct FeatureMap {
  * DOM Security peer!
  */
 static FeatureMap sSupportedFeatures[] = {
     {"camera", FeaturePolicyUtils::FeaturePolicyValue::eSelf},
     {"geolocation", FeaturePolicyUtils::FeaturePolicyValue::eSelf},
     {"microphone", FeaturePolicyUtils::FeaturePolicyValue::eSelf},
     {"display-capture", FeaturePolicyUtils::FeaturePolicyValue::eSelf},
     {"fullscreen", FeaturePolicyUtils::FeaturePolicyValue::eSelf},
+    {"web-share", FeaturePolicyUtils::FeaturePolicyValue::eSelf},
 };
 
 /*
  * This is experimental features list, which is disabled by default by pref
  * dom.security.featurePolicy.experimental.enabled.
  */
 static FeatureMap sExperimentalFeatures[] = {
     // We don't support 'autoplay' for now, because it would be overwrote by