Commit c32d950b authored by Charlie Hu's avatar Charlie Hu Committed by Commit Bot

Migrate UnsizedMedia from feature policy to document policy

This CL migrates UnsizedMedia from feature policy to document policy.

Following web tests are being migrated:
- unsized-media.tentative.https.sub.html
- unsized-media-reporting.html

Following web tests are removed, because document policy currently
does not have a js API to list all features available.
- feature-policy-unsized-media-disabled.html
- feature-policy-unsized-media-enabled.html

Bug: 993790
Change-Id: Id5e0189c0277c940177460380970eab0015109d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2097028
Commit-Queue: Charlie Hu <chenleihu@google.com>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarPhilip Jägenstedt <foolip@chromium.org>
Reviewed-by: default avatarIan Clelland <iclelland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750246}
parent 27d1fe94
......@@ -589,9 +589,6 @@ const FeaturePolicy::FeatureList& FeaturePolicy::GetDefaultFeatureList() {
{mojom::FeaturePolicyFeature::kTopNavigation,
FeatureDefaultValue(FeaturePolicy::FeatureDefault::EnableForAll,
mojom::PolicyValueType::kBool)},
{mojom::FeaturePolicyFeature::kUnsizedMedia,
FeatureDefaultValue(FeaturePolicy::FeatureDefault::EnableForAll,
mojom::PolicyValueType::kBool)},
{mojom::FeaturePolicyFeature::kUsb,
FeatureDefaultValue(FeaturePolicy::FeatureDefault::EnableForSelf,
mojom::PolicyValueType::kBool)},
......
......@@ -20,6 +20,9 @@ enum DocumentPolicyFeature {
// Takes a parameter, |scale_ratio|, and restricts source image sizes to be
// no more than |scale_ratio| x larger than the image's containing block.
kOversizedImages = 6,
// Controls the layout size of intrinsically sized images and videos. When
// disabled, default size (300 x 150) is used to prevent relayout.
kUnsizedMedia = 7,
// Don't change assigned numbers of any item, and don't reuse removed slots.
// Add new features at the end of the enum.
};
......@@ -51,9 +51,6 @@ enum FeaturePolicyFeature {
kAmbientLightSensor = 18,
kGyroscope = 19,
kMagnetometer = 20,
// Controls the layout size of intrinsically sized images and videos. When
// disabled, default size (300 x 150) is used to prevent relayout.
kUnsizedMedia = 21,
// Controls access to Picture-in-Picture.
kPictureInPicture = 26,
// Controls the ability to block and interfere with vertical scrolling.
......
......@@ -81,5 +81,13 @@
default_value: "max",
depends_on: ["UnoptimizedImagePolicies"],
},
{
name: "UnsizedMedia",
document_policy_name: "unsized-media",
value_name: "",
value_type: "Bool",
default_value: "true",
depends_on: ["UnsizedMediaPolicy"],
},
],
}
......@@ -269,11 +269,6 @@
feature_policy_name: "top-navigation",
depends_on: ["FeaturePolicyForSandbox"],
},
{
name: "UnsizedMedia",
feature_policy_name: "unsized-media",
depends_on: ["UnsizedMediaPolicy"],
},
{
name: "Usb",
feature_policy_name: "usb",
......
......@@ -145,16 +145,6 @@ ParsedFeaturePolicy FeaturePolicyParser::Parse(
bool allowlist_includes_none = false;
bool allowlist_includes_origin = false;
// Detect usage of UnsizedMediaPolicy origin trial
if (feature == mojom::blink::FeaturePolicyFeature::kUnsizedMedia) {
if (delegate) {
delegate->CountFeaturePolicyUsage(
mojom::WebFeature::kUnsizedMediaPolicy);
}
// Don't analyze allowlists for origin trial features.
count_allowlist_type = false;
}
ParsedFeaturePolicyDeclaration allowlist(feature, feature_type);
// TODO(loonybear): fallback value should be parsed from the new syntax.
allowlist.fallback_value = GetFallbackValueForFeature(feature);
......
......@@ -563,36 +563,6 @@ TEST_F(FeaturePolicyParserTest, AllowHistogramDifferentDocument) {
1);
}
// These declarations should each trigger the Unsized Media origin trial use
// counter.
const char* const kUnsizedMediaOriginTrialPolicyDeclarations[] = {
"unsized-media", "unsized-media; fullscreen", "fullscreen; unsized-media",
"unsized-media 'self'", "unsized-media 'none'"};
TEST_F(FeaturePolicyParserTest, UnsizedMediaOriginTrialFeatureUseCounter) {
Vector<String> messages;
// Validate that features which are not in the origin trial do not trigger
// the use counter.
{
auto dummy = std::make_unique<DummyPageHolder>();
FeaturePolicyParser::ParseHeader("payment; fullscreen", origin_a_.get(),
&messages, &dummy->GetDocument());
EXPECT_FALSE(
dummy->GetDocument().IsUseCounted(WebFeature::kUnsizedMediaPolicy));
}
// Validate that declarations which should trigger the use counter do.
for (const char* declaration : kUnsizedMediaOriginTrialPolicyDeclarations) {
auto dummy = std::make_unique<DummyPageHolder>();
FeaturePolicyParser::ParseHeader(declaration, origin_a_.get(), &messages,
&dummy->GetDocument());
EXPECT_TRUE(
dummy->GetDocument().IsUseCounted(WebFeature::kUnsizedMediaPolicy))
<< declaration << " should trigger the origin trial use counter.";
}
}
// Tests the use counter for comma separator in declarations.
TEST_F(FeaturePolicyParserTest, CommaSeparatedUseCounter) {
Vector<String> messages;
......
......@@ -104,7 +104,7 @@ HTMLImageElement::HTMLImageElement(Document& document, bool created_by_parser)
is_default_overridden_intrinsic_size_(
!document.IsImageDocument() &&
!document.IsFeatureEnabled(
mojom::blink::FeaturePolicyFeature::kUnsizedMedia)),
mojom::blink::DocumentPolicyFeature::kUnsizedMedia)),
is_legacy_format_or_unoptimized_image_(false),
referrer_policy_(network::mojom::ReferrerPolicy::kDefault) {
SetHasCustomStyleCallbacks();
......
......@@ -88,7 +88,7 @@ HTMLVideoElement::HTMLVideoElement(Document& document)
is_default_overridden_intrinsic_size_(
!document.IsMediaDocument() &&
!document.IsFeatureEnabled(
mojom::blink::FeaturePolicyFeature::kUnsizedMedia)),
mojom::blink::DocumentPolicyFeature::kUnsizedMedia)),
video_has_played_(false),
mostly_filling_viewport_(false) {
if (document.GetSettings()) {
......
......@@ -19,7 +19,7 @@ void CheckUnsizedMediaViolation(const LayoutObject* layout_object,
!style.LogicalHeight().IsSpecified();
if (is_unsized) {
layout_object->GetDocument().IsFeatureEnabled(
mojom::blink::FeaturePolicyFeature::kUnsizedMedia,
mojom::blink::DocumentPolicyFeature::kUnsizedMedia,
send_report ? ReportOptions::kReportOnFailure
: ReportOptions::kDoNotReport);
}
......
......@@ -37,7 +37,7 @@ SVGImageElement::SVGImageElement(Document& document)
: SVGGraphicsElement(svg_names::kImageTag, document),
SVGURIReference(this),
is_default_overridden_intrinsic_size_(!document.IsFeatureEnabled(
mojom::blink::FeaturePolicyFeature::kUnsizedMedia)),
mojom::blink::DocumentPolicyFeature::kUnsizedMedia)),
x_(MakeGarbageCollected<SVGAnimatedLength>(
this,
svg_names::kXAttr,
......
......@@ -3,7 +3,7 @@
<script>
window.addEventListener('load', function() {
var img = document.createElement('IMG');
img.setAttribute("src", "/feature-policy/experimental-features/resources/image.jpg");
img.setAttribute("src", "/document-policy/experimental-features/resources/image.jpg");
img.addEventListener('load', function() {
parent.postMessage({width: img.width, height: img.height}, '*');
});
......
......@@ -8,9 +8,9 @@
const default_width = 300;
const default_height = 150;
const srcs = [
"/feature-policy/experimental-features/resources/image.jpg",
"/feature-policy/experimental-features/resources/image.png",
"/feature-policy/experimental-features/resources/image.svg"
"/document-policy/experimental-features/resources/image.jpg",
"/document-policy/experimental-features/resources/image.png",
"/document-policy/experimental-features/resources/image.svg"
];
const test_cases = [
// Test when no size is specified, img/video is laid out by the default size.
......@@ -60,7 +60,7 @@ for (var test of test_cases) {
}));
var expected_width = test.expected_width;
var expected_height = test.expected_height;
video.setAttribute("src", "/feature-policy/experimental-features/resources/video.ogv");
video.setAttribute("src", "/document-policy/experimental-features/resources/video.ogv");
if (typeof test.attribute !== "undefined") {
video.setAttribute(test.attribute, test.value);
}
......@@ -72,11 +72,12 @@ for (var test of test_cases) {
' and attribute ' + test.attribute1 + '=' + test.value1);
}
// Test unsized-image works in local and remote iframes.
// Subframes do not inherit document policy from parent frame.
// Unsized-Media should not work in subframes.
var iframe = document.querySelector('iframe');
var iframe_srcs = [
"/feature-policy/experimental-features/resources/feature-policy-image.html",
"https://{{domains[www]}}:{{ports[https][0]}}/feature-policy/experimental-features/resources/feature-policy-image.html"];
"/document-policy/experimental-features/resources/document-policy-image.html",
"https://{{domains[www]}}:{{ports[https][0]}}/document-policy/experimental-features/resources/document-policy-image.html"];
for (var src of iframe_srcs) {
promise_test(function() {
iframe.src = src;
......@@ -85,8 +86,8 @@ for (var src of iframe_srcs) {
resolve(e.data);
});
}).then(function(data) {
assert_equals(data.width, default_width, 'width');
assert_equals(data.height, default_height, 'height');
assert_not_equals(data.width, default_width, 'width');
assert_not_equals(data.height, default_height, 'height');
});
}, 'Test image size is correctly rendered in iframe of src ' + src);
}
......
......@@ -9,7 +9,7 @@
<script>
var check_report_format = (reports, observer) => {
let report = reports[0];
assert_equals(report.type, "feature-policy-violation");
assert_equals(report.type, "document-policy-violation");
assert_equals(report.url, document.location.href);
assert_equals(report.body.featureId, "unsized-media");
assert_equals(report.body.disposition, "enforce");
......@@ -17,7 +17,7 @@ var check_report_format = (reports, observer) => {
async_test(t => {
new ReportingObserver(t.step_func_done(check_report_format),
{types: ['feature-policy-violation'], buffered: true}).observe();
{types: ['document-policy-violation'], buffered: true}).observe();
}, "Unsized-media Report Format");
</script>
</body>
......
<!DOCTYPE html>
<meta charset="utf-8">
<title>Unsized Media feature policy - disabled without origin trial token</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../../resources/origin-trials-helper.js"></script>
<script>
test(t => {
if (OriginTrialsHelper.is_runtime_flag_enabled('unsizedMediaPolicyEnabled')) {
// The runtime flag overrides the absence of a token.
assert_in_array("unsized-media", document.featurePolicy.features());
} else {
// Runtime flag disabled and no token, so policy should not be available.
assert_equals(document.featurePolicy.features().indexOf('unsized-media'), -1,
'The unsized-media feature should not be available');
}
}, 'The unsized-media policy is not available without origin trial token');
</script>
<?php
# Generate token with the command:
# generate_token.py http://127.0.0.1:8000 UnsizedMediaPolicy --expire-timestamp=2000000000
header("Origin-Trial: Aihrm6c554aujVxiV9NcwvJnL4DuAWEIuHPcoByCCeIQB4Tm1Ok3RpftS2JosN4mvtIuQlYNaLGylvC/tndGdwYAAABaeyJvcmlnaW4iOiAiaHR0cDovLzEyNy4wLjAuMTo4MDAwIiwgImZlYXR1cmUiOiAiVW5zaXplZE1lZGlhUG9saWN5IiwgImV4cGlyeSI6IDIwMDAwMDAwMDB9");
?>
<title>Unsized Media feature policy - enabled by origin trial</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(t => {
assert_in_array('unsized-media', document.featurePolicy.features());
}, 'The unsized-media policy is available via origin trial');
</script>
......@@ -50,7 +50,6 @@ serial
sync-script
sync-xhr
top-navigation
unsized-media
usb
vertical-scroll
wake-lock
......
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