Commit 4ea51a0a authored by Charlie Hu's avatar Charlie Hu Committed by Commit Bot

Refactor ReportUnsizedMediaViolation

Renames media_element_parser_helpers::ReportUnsizedMediaViolation
to media_element_parser_helpers::CheckUnsizedMediaViolation

Combines logic of LayoutVideo::UpdateAfterLayout with
LayoutImage::UpdateAfterLayout because LayoutVideo is a subclass
of LayoutImage.

Calls Document::IsFeatureEnabled with ReportOption::kReportOnFailure
instead of Document::CountPotentialFeaturePolicyViolation and
Document::ReportFeaturePolicyViolation which are lower level
APIs.

This CL is also the prework for migration of UnsizedMedia
from feature policy to document policy.

Bug: 993790
Change-Id: I77eb2be3b5fe9d79d276800e12f4a0218fdb6e51
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2082480Reviewed-by: default avatarIan Clelland <iclelland@chromium.org>
Reviewed-by: default avatarPhilip Jägenstedt <foolip@chromium.org>
Commit-Queue: Charlie Hu <chenleihu@google.com>
Cr-Commit-Position: refs/heads/master@{#747324}
parent 4d4e25dd
...@@ -12,18 +12,16 @@ namespace blink { ...@@ -12,18 +12,16 @@ namespace blink {
namespace media_element_parser_helpers { namespace media_element_parser_helpers {
void ReportUnsizedMediaViolation(const LayoutObject* layout_object, void CheckUnsizedMediaViolation(const LayoutObject* layout_object,
bool send_report) { bool send_report) {
const ComputedStyle& style = layout_object->StyleRef(); const ComputedStyle& style = layout_object->StyleRef();
if (!style.LogicalWidth().IsSpecified() && bool is_unsized = !style.LogicalWidth().IsSpecified() &&
!style.LogicalHeight().IsSpecified()) { !style.LogicalHeight().IsSpecified();
layout_object->GetDocument().CountPotentialFeaturePolicyViolation( if (is_unsized) {
mojom::blink::FeaturePolicyFeature::kUnsizedMedia); layout_object->GetDocument().IsFeatureEnabled(
if (send_report) { mojom::blink::FeaturePolicyFeature::kUnsizedMedia,
layout_object->GetDocument().ReportFeaturePolicyViolation( send_report ? ReportOptions::kReportOnFailure
mojom::blink::FeaturePolicyFeature::kUnsizedMedia, : ReportOptions::kDoNotReport);
mojom::FeaturePolicyDisposition::kEnforce);
}
} }
} }
......
...@@ -15,8 +15,8 @@ namespace media_element_parser_helpers { ...@@ -15,8 +15,8 @@ namespace media_element_parser_helpers {
// FeaturePolicyFeature::kUnsizedMedia) this invocation counts a potential // FeaturePolicyFeature::kUnsizedMedia) this invocation counts a potential
// violation. If |send_report| is set, then an actual violation report is // violation. If |send_report| is set, then an actual violation report is
// generated. // generated.
void ReportUnsizedMediaViolation(const LayoutObject* layout_object, void CheckUnsizedMediaViolation(const LayoutObject* layout_object,
bool send_report); bool send_report);
} // namespace media_element_parser_helpers } // namespace media_element_parser_helpers
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "third_party/blink/renderer/core/frame/web_feature.h" #include "third_party/blink/renderer/core/frame/web_feature.h"
#include "third_party/blink/renderer/core/html/html_area_element.h" #include "third_party/blink/renderer/core/html/html_area_element.h"
#include "third_party/blink/renderer/core/html/html_image_element.h" #include "third_party/blink/renderer/core/html/html_image_element.h"
#include "third_party/blink/renderer/core/html/media/html_video_element.h"
#include "third_party/blink/renderer/core/html/media/media_element_parser_helpers.h" #include "third_party/blink/renderer/core/html/media/media_element_parser_helpers.h"
#include "third_party/blink/renderer/core/html_names.h" #include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/layout/hit_test_result.h" #include "third_party/blink/renderer/core/layout/hit_test_result.h"
...@@ -426,8 +427,11 @@ void LayoutImage::UpdateAfterLayout() { ...@@ -426,8 +427,11 @@ void LayoutImage::UpdateAfterLayout() {
LayoutBox::UpdateAfterLayout(); LayoutBox::UpdateAfterLayout();
Node* node = GetNode(); Node* node = GetNode();
if (auto* image_element = DynamicTo<HTMLImageElement>(node)) { if (auto* image_element = DynamicTo<HTMLImageElement>(node)) {
media_element_parser_helpers::ReportUnsizedMediaViolation( media_element_parser_helpers::CheckUnsizedMediaViolation(
this, image_element->IsDefaultIntrinsicSize()); this, image_element->IsDefaultIntrinsicSize());
} else if (auto* video_element = DynamicTo<HTMLVideoElement>(node)) {
media_element_parser_helpers::CheckUnsizedMediaViolation(
this, video_element->IsDefaultIntrinsicSize());
} }
} }
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "third_party/blink/public/platform/web_size.h" #include "third_party/blink/public/platform/web_size.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/html/media/html_video_element.h" #include "third_party/blink/renderer/core/html/media/html_video_element.h"
#include "third_party/blink/renderer/core/html/media/media_element_parser_helpers.h"
#include "third_party/blink/renderer/core/paint/video_painter.h" #include "third_party/blink/renderer/core/paint/video_painter.h"
namespace blink { namespace blink {
...@@ -200,13 +199,4 @@ CompositingReasons LayoutVideo::AdditionalCompositingReasons() const { ...@@ -200,13 +199,4 @@ CompositingReasons LayoutVideo::AdditionalCompositingReasons() const {
return CompositingReason::kNone; return CompositingReason::kNone;
} }
void LayoutVideo::UpdateAfterLayout() {
LayoutBox::UpdateAfterLayout();
// Report violation of unsized-media policy.
if (auto* video_element = DynamicTo<HTMLVideoElement>(GetNode())) {
media_element_parser_helpers::ReportUnsizedMediaViolation(
this, video_element->IsDefaultIntrinsicSize());
}
}
} // namespace blink } // namespace blink
...@@ -51,8 +51,6 @@ class LayoutVideo final : public LayoutMedia { ...@@ -51,8 +51,6 @@ class LayoutVideo final : public LayoutMedia {
void IntrinsicSizeChanged() override; void IntrinsicSizeChanged() override;
void UpdateAfterLayout() override;
bool ComputeShouldClipOverflow() const final { return true; } bool ComputeShouldClipOverflow() const final { return true; }
private: private:
......
...@@ -176,7 +176,7 @@ void LayoutSVGImage::UpdateLayout() { ...@@ -176,7 +176,7 @@ void LayoutSVGImage::UpdateLayout() {
DCHECK(!needs_transform_update_); DCHECK(!needs_transform_update_);
if (auto* svg_image_element = DynamicTo<SVGImageElement>(GetElement())) { if (auto* svg_image_element = DynamicTo<SVGImageElement>(GetElement())) {
media_element_parser_helpers::ReportUnsizedMediaViolation( media_element_parser_helpers::CheckUnsizedMediaViolation(
this, svg_image_element->IsDefaultIntrinsicSize()); this, svg_image_element->IsDefaultIntrinsicSize());
} }
ClearNeedsLayout(); ClearNeedsLayout();
......
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