Commit 849358ed authored by Ian Clelland's avatar Ian Clelland Committed by Commit Bot

Move feature policy checks for Image policies

This CL moves the IsFeatureAllowed checks for image policies
from the old location on Frame to the new methods on Document.

Bug: 888668
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I3d44ce3f0263e2b9f3dec3f33f2a9c89f57f76ab
Reviewed-on: https://chromium-review.googlesource.com/c/1243168Reviewed-by: default avatarLuna Lu <loonybear@chromium.org>
Reviewed-by: default avatarSteve Kobes <skobes@chromium.org>
Commit-Queue: Ian Clelland <iclelland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607660}
parent bf137c2a
......@@ -107,7 +107,7 @@ HTMLImageElement::HTMLImageElement(Document& document, bool created_by_parser)
referrer_policy_(kReferrerPolicyDefault) {
SetHasCustomStyleCallbacks();
if (media_element_parser_helpers::IsMediaElement(this) &&
!media_element_parser_helpers::IsUnsizedMediaEnabled(document)) {
!document.IsFeatureEnabled(mojom::FeaturePolicyFeature::kUnsizedMedia)) {
is_default_overridden_intrinsic_size_ = true;
overridden_intrinsic_size_ =
IntSize(LayoutReplaced::kDefaultWidth, LayoutReplaced::kDefaultHeight);
......
......@@ -90,7 +90,7 @@ inline HTMLVideoElement::HTMLVideoElement(Document& document)
}
if (media_element_parser_helpers::IsMediaElement(this) &&
!media_element_parser_helpers::IsUnsizedMediaEnabled(document)) {
!document.IsFeatureEnabled(mojom::FeaturePolicyFeature::kUnsizedMedia)) {
is_default_overridden_intrinsic_size_ = true;
overridden_intrinsic_size_ =
IntSize(LayoutReplaced::kDefaultWidth, LayoutReplaced::kDefaultHeight);
......
......@@ -28,16 +28,6 @@ bool IsMediaElement(const Element* element) {
return false;
}
bool IsUnsizedMediaEnabled(const Document& document) {
if (auto* frame = document.GetFrame()) {
return frame->DeprecatedIsFeatureEnabled(
mojom::FeaturePolicyFeature::kUnsizedMedia);
}
// Unsized media is by default enabled every where, so when the frame is not
// available return default policy (true).
return true;
}
bool ParseIntrinsicSizeAttribute(const String& value,
const Element* element,
IntSize* intrinsic_size,
......@@ -59,7 +49,8 @@ bool ParseIntrinsicSizeAttribute(const String& value,
new_height = 0;
}
if (new_width == 0 && new_height == 0 && IsMediaElement(element) &&
!IsUnsizedMediaEnabled(element->GetDocument())) {
!element->GetDocument().IsFeatureEnabled(
mojom::FeaturePolicyFeature::kUnsizedMedia)) {
new_width = LayoutReplaced::kDefaultWidth;
new_height = LayoutReplaced::kDefaultHeight;
*is_default_intrinsic_size = true;
......@@ -76,8 +67,8 @@ bool ParseIntrinsicSizeAttribute(const String& value,
void ReportUnsizedMediaViolation(const LayoutObject* layout_object) {
const ComputedStyle& style = layout_object->StyleRef();
if (!style.LogicalWidth().IsSpecified() &&
!style.LogicalHeight().IsSpecified() && layout_object->GetFrame()) {
layout_object->GetFrame()->DeprecatedReportFeaturePolicyViolation(
!style.LogicalHeight().IsSpecified()) {
layout_object->GetDocument().ReportFeaturePolicyViolation(
mojom::FeaturePolicyFeature::kUnsizedMedia);
}
}
......
......@@ -10,7 +10,6 @@
namespace blink {
class Element;
class Document;
class LayoutObject;
namespace media_element_parser_helpers {
......@@ -28,10 +27,6 @@ bool ParseIntrinsicSizeAttribute(const String& value,
// are not in an image or media document; returns false otherwise.
bool IsMediaElement(const Element* element);
// Returns if the document is allowed to use
// FeaturePolicyFeature::kUnsizedMedia.
bool IsUnsizedMediaEnabled(const Document& document);
void ReportUnsizedMediaViolation(const LayoutObject* layout_object);
} // namespace media_element_parser_helpers
......
......@@ -52,14 +52,14 @@ namespace blink {
namespace {
constexpr float kmax_oversize_ratio = 2.0f;
bool CheckForOptimizedImagePolicy(const LocalFrame& frame,
bool CheckForOptimizedImagePolicy(const Document& document,
LayoutImage* layout_image,
ImageResourceContent* new_image) {
// Render the image as a placeholder image if the document does not have the
// 'legacy-image-formats' feature enabled, and the image is not one of the
// allowed formats.
if (RuntimeEnabledFeatures::ExperimentalProductivityFeaturesEnabled() &&
!frame.DeprecatedIsFeatureEnabled(
!document.IsFeatureEnabled(
mojom::FeaturePolicyFeature::kLegacyImageFormats)) {
if (!new_image->IsAcceptableContentType()) {
return true;
......@@ -69,7 +69,7 @@ bool CheckForOptimizedImagePolicy(const LocalFrame& frame,
// 'unoptimized-images' feature enabled and the image is not
// sufficiently-well-compressed.
if (RuntimeEnabledFeatures::ExperimentalProductivityFeaturesEnabled() &&
!frame.DeprecatedIsFeatureEnabled(
!document.IsFeatureEnabled(
mojom::FeaturePolicyFeature::kUnoptimizedImages)) {
if (!new_image->IsAcceptableCompressionRatio())
return true;
......@@ -77,13 +77,12 @@ bool CheckForOptimizedImagePolicy(const LocalFrame& frame,
return false;
}
bool CheckForOversizedImagesPolicy(const LocalFrame& frame,
bool CheckForOversizedImagesPolicy(const Document& document,
ImageResourceContent* new_image,
LayoutImage* layout_image) {
DCHECK(new_image);
if (!RuntimeEnabledFeatures::ExperimentalProductivityFeaturesEnabled() ||
frame.DeprecatedIsFeatureEnabled(
mojom::FeaturePolicyFeature::kOversizedImages))
document.IsFeatureEnabled(mojom::FeaturePolicyFeature::kOversizedImages))
return false;
if (auto* image = new_image->GetImage()) {
// Render the image as a placeholder image if the image's size is more
......@@ -95,7 +94,7 @@ bool CheckForOversizedImagesPolicy(const LocalFrame& frame,
if (layout_width > 0 && layout_height > 0 && image_width > 0 &&
image_height > 0) {
double device_pixel_ratio = frame.DevicePixelRatio();
double device_pixel_ratio = document.GetFrame()->DevicePixelRatio();
if (LayoutUnit(image_width / (kmax_oversize_ratio * device_pixel_ratio)) >
layout_width ||
LayoutUnit(image_height / (kmax_oversize_ratio *
......@@ -274,14 +273,11 @@ void LayoutImage::ImageNotifyFinished(ImageResourceContent* new_image) {
InvalidateBackgroundObscurationStatus();
// Check for optimized image policies.
if (View() && View()->GetFrameView()) {
const LocalFrame& frame = View()->GetFrameView()->GetFrame();
is_legacy_format_or_unoptimized_image_ =
CheckForOptimizedImagePolicy(frame, this, new_image);
if (auto* image_element = ToHTMLImageElementOrNull(GetNode())) {
is_oversized_image_ =
CheckForOversizedImagesPolicy(frame, new_image, this);
}
is_legacy_format_or_unoptimized_image_ =
CheckForOptimizedImagePolicy(GetDocument(), this, new_image);
if (auto* image_element = ToHTMLImageElementOrNull(GetNode())) {
is_oversized_image_ =
CheckForOversizedImagesPolicy(GetDocument(), new_image, this);
}
if (new_image == image_resource_->CachedImage()) {
......@@ -499,14 +495,10 @@ void LayoutImage::UpdateAfterLayout() {
LayoutBox::UpdateAfterLayout();
Node* node = GetNode();
if (auto* image_element = ToHTMLImageElementOrNull(node)) {
if (View() && View()->GetFrameView()) {
const LocalFrame& frame = View()->GetFrameView()->GetFrame();
if (image_resource_ && image_resource_->CachedImage()) {
// Check for optimized image policies.
is_oversized_image_ = CheckForOversizedImagesPolicy(
frame, image_resource_->CachedImage(), this);
}
if (image_resource_ && image_resource_->CachedImage()) {
// Check for optimized image policies.
is_oversized_image_ = CheckForOversizedImagesPolicy(
GetDocument(), image_resource_->CachedImage(), this);
}
// Report violation of unsized-media policy.
......
......@@ -21,6 +21,7 @@
#include "third_party/blink/renderer/core/svg/svg_image_element.h"
#include "third_party/blink/public/mojom/feature_policy/feature_policy.mojom-blink.h"
#include "third_party/blink/renderer/core/css/style_change_reason.h"
#include "third_party/blink/renderer/core/css_property_names.h"
#include "third_party/blink/renderer/core/frame/use_counter.h"
......@@ -68,7 +69,7 @@ inline SVGImageElement::SVGImageElement(Document& document)
AddToPropertyMap(preserve_aspect_ratio_);
if (media_element_parser_helpers::IsMediaElement(this) &&
!media_element_parser_helpers::IsUnsizedMediaEnabled(document)) {
!document.IsFeatureEnabled(mojom::FeaturePolicyFeature::kUnsizedMedia)) {
is_default_overridden_intrinsic_size_ = true;
overridden_intrinsic_size_ =
IntSize(LayoutReplaced::kDefaultWidth, LayoutReplaced::kDefaultHeight);
......
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