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

WebShare: hide measurement-only permission policy

The web-share policy is currently only for use counters
https://groups.google.com/a/chromium.org/d/msg/blink-dev/fgme9KOd8CU/0xJW9MAPAgAJ

We ensure it is not visible by introspection using document.featurePolicy

Bug: 1121034
Change-Id: I3ff271efa45eca43055e975fefc4a8db43960b41
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2371447Reviewed-by: default avatarIan Clelland <iclelland@chromium.org>
Auto-Submit: Eric Willigers <ericwilligers@chromium.org>
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802635}
parent 921ff86f
......@@ -18,7 +18,8 @@ namespace blink {
bool FeatureAvailable(const String& feature, ExecutionContext* ec) {
return GetDefaultFeatureNameMap().Contains(feature) &&
(!DisabledByOriginTrial(feature, ec));
(!DisabledByOriginTrial(feature, ec)) &&
(!IsFeatureForMeasurementOnly(GetDefaultFeatureNameMap().at(feature)));
}
DOMFeaturePolicy::DOMFeaturePolicy(ExecutionContext* context)
......
......@@ -607,6 +607,10 @@ void DisallowFeature(mojom::blink::FeaturePolicyFeature feature,
DisallowFeatureIfNotPresent(feature, policy);
}
bool IsFeatureForMeasurementOnly(mojom::blink::FeaturePolicyFeature feature) {
return feature == mojom::blink::FeaturePolicyFeature::kWebShare;
}
void AllowFeatureEverywhere(mojom::blink::FeaturePolicyFeature feature,
ParsedFeaturePolicy& policy) {
RemoveFeatureIfPresent(feature, policy);
......@@ -616,8 +620,10 @@ void AllowFeatureEverywhere(mojom::blink::FeaturePolicyFeature feature,
const Vector<String> GetAvailableFeatures(ExecutionContext* execution_context) {
Vector<String> available_features;
for (const auto& feature : GetDefaultFeatureNameMap()) {
if (!DisabledByOriginTrial(feature.key, execution_context))
if (!DisabledByOriginTrial(feature.key, execution_context) &&
!IsFeatureForMeasurementOnly(feature.value)) {
available_features.push_back(feature.key);
}
}
return available_features;
}
......
......@@ -118,6 +118,10 @@ CORE_EXPORT bool AllowFeatureEverywhereIfNotPresent(
CORE_EXPORT void DisallowFeature(mojom::blink::FeaturePolicyFeature,
ParsedFeaturePolicy&);
// Returns true iff the feature should not be exposed to script.
CORE_EXPORT bool IsFeatureForMeasurementOnly(
mojom::blink::FeaturePolicyFeature);
// Replaces any existing declarations in the policy for the given feature with
// a declaration which allows the feature in all origins.
CORE_EXPORT void AllowFeatureEverywhere(mojom::blink::FeaturePolicyFeature,
......
This is a testharness.js-based test.
FAIL allowsFeature() returns true for web-share assert_true: expected true got false
FAIL features() includes web-share assert_true: expected true got false
FAIL allowedFeatures() includes web-share assert_true: expected true got false
FAIL allowsFeature() returns a single entry for web-share assert_equals: expected 1 but got 0
Harness: the test ran to completion.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebShare Test: policy is listed</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
'use strict';
test(() => {
assert_true(document.featurePolicy.allowsFeature('web-share'));
}, 'allowsFeature() returns true for web-share');
test(() => {
assert_true(document.featurePolicy.features().includes('web-share'));
}, 'features() includes web-share');
test(() => {
assert_true(document.featurePolicy.allowedFeatures().includes('web-share'));
}, 'allowedFeatures() includes web-share');
test(() => {
assert_equals(Array.from(document.featurePolicy.getAllowlistForFeature('web-share')).length, 1);
}, 'allowsFeature() returns a single entry for web-share');
</script>
</body>
</html>
......@@ -56,6 +56,5 @@ top-navigation
trust-token-redemption
usb
vertical-scroll
web-share
xr-spatial-tracking
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