Bug 1653199 - Add web-share permission policy r=ckerschb

Restrict navigator.share() to web-share permission policy

Differential Revision: https://phabricator.services.mozilla.com/D83903
This commit is contained in:
Marcos Cáceres 2020-08-04 05:30:35 +00:00
parent a315a1a0f0
commit c40f16142f
3 changed files with 10 additions and 0 deletions

View File

@ -1373,6 +1373,14 @@ Promise* Navigator::Share(const ShareData& aData, ErrorResult& aRv) {
return nullptr; 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) { if (mSharePromise) {
NS_WARNING("Only one share picker at a time per navigator instance"); NS_WARNING("Only one share picker at a time per navigator instance");
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);

View File

@ -33,6 +33,7 @@ static FeatureMap sSupportedFeatures[] = {
{"microphone", FeaturePolicyUtils::FeaturePolicyValue::eSelf}, {"microphone", FeaturePolicyUtils::FeaturePolicyValue::eSelf},
{"display-capture", FeaturePolicyUtils::FeaturePolicyValue::eSelf}, {"display-capture", FeaturePolicyUtils::FeaturePolicyValue::eSelf},
{"fullscreen", FeaturePolicyUtils::FeaturePolicyValue::eSelf}, {"fullscreen", FeaturePolicyUtils::FeaturePolicyValue::eSelf},
{"web-share", FeaturePolicyUtils::FeaturePolicyValue::eSelf},
}; };
/* /*

View File

@ -22,6 +22,7 @@ let supportedFeatures = [
"document-domain", "document-domain",
"speaker", "speaker",
"vr", "vr",
"web-share",
]; ];
function checkFeatures(features) { function checkFeatures(features) {