Commit 66dc0ceb authored by Ian Vollick's avatar Ian Vollick Committed by Commit Bot

Record URL for video elements in paint previews

With this change, the paint preview tracker will associate the page URL
with the video rect.

Bug: 1026308
Change-Id: I074639face279875e5def0bf158cb53a32f2afdc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1999292Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarCalder Kitagawa <ckitagawa@chromium.org>
Commit-Queue: Ian Vollick <vollick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732404}
parent 0593d72b
...@@ -1602,6 +1602,7 @@ jumbo_source_set("unit_tests") { ...@@ -1602,6 +1602,7 @@ jumbo_source_set("unit_tests") {
deps = [ deps = [
":core", ":core",
":unit_test_support", ":unit_test_support",
"//components/paint_preview/common:common",
"//mojo/public/cpp/system", "//mojo/public/cpp/system",
"//skia:skcms", "//skia:skcms",
"//testing/gmock", "//testing/gmock",
......
...@@ -17,4 +17,7 @@ specific_include_rules = { ...@@ -17,4 +17,7 @@ specific_include_rules = {
"(object_painter_base|paint_layer_scrollable_area|theme_painter|theme_painter_default)\.cc": [ "(object_painter_base|paint_layer_scrollable_area|theme_painter|theme_painter_default)\.cc": [
"+ui/base/ui_base_features.h", "+ui/base/ui_base_features.h",
], ],
"video_painter_test.cc": [
"+components/paint_preview/common/paint_preview_tracker.h",
],
} }
...@@ -41,6 +41,11 @@ void VideoPainter::PaintReplaced(const PaintInfo& paint_info, ...@@ -41,6 +41,11 @@ void VideoPainter::PaintReplaced(const PaintInfo& paint_info,
PhysicalRect content_box_rect = layout_video_.PhysicalContentBoxRect(); PhysicalRect content_box_rect = layout_video_.PhysicalContentBoxRect();
content_box_rect.Move(paint_offset); content_box_rect.Move(paint_offset);
if (context.IsPaintingPreview()) {
context.SetURLForRect(layout_video_.GetDocument().Url(),
snapped_replaced_rect);
}
// Since we may have changed the location of the replaced content, we need to // Since we may have changed the location of the replaced content, we need to
// notify PaintArtifactCompositor. // notify PaintArtifactCompositor.
if (layout_video_.GetFrameView()) if (layout_video_.GetFrameView())
......
...@@ -4,9 +4,13 @@ ...@@ -4,9 +4,13 @@
#include "third_party/blink/renderer/core/paint/video_painter.h" #include "third_party/blink/renderer/core/paint/video_painter.h"
#include "base/unguessable_token.h"
#include "cc/layers/layer.h" #include "cc/layers/layer.h"
#include "components/paint_preview/common/paint_preview_tracker.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_size.h" #include "third_party/blink/public/platform/web_size.h"
#include "third_party/blink/renderer/core/frame/frame_test_helpers.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
#include "third_party/blink/renderer/core/html/media/html_media_element.h" #include "third_party/blink/renderer/core/html/media/html_media_element.h"
#include "third_party/blink/renderer/core/paint/paint_controller_paint_test.h" #include "third_party/blink/renderer/core/paint/paint_controller_paint_test.h"
#include "third_party/blink/renderer/platform/testing/empty_web_media_player.h" #include "third_party/blink/renderer/platform/testing/empty_web_media_player.h"
...@@ -97,5 +101,74 @@ TEST_F(VideoPainterTestForCAP, VideoLayerAppearsInLayerTree) { ...@@ -97,5 +101,74 @@ TEST_F(VideoPainterTestForCAP, VideoLayerAppearsInLayerTree) {
EXPECT_EQ(gfx::Size(300, 150), layer->bounds()); EXPECT_EQ(gfx::Size(300, 150), layer->bounds());
} }
class VideoPaintPreviewTest : public testing::Test,
public PaintTestConfigurations {
public:
void SetUp() override {
web_view_helper_.Initialize();
WebLocalFrameImpl& frame_impl = GetLocalMainFrame();
frame_impl.ViewImpl()->MainFrameWidget()->Resize(WebSize(bounds().size()));
frame_test_helpers::LoadFrame(&GetLocalMainFrame(), "about:blank");
GetDocument().View()->SetParentVisible(true);
GetDocument().View()->SetSelfVisible(true);
}
void SetBodyInnerHTML(const std::string& content) {
frame_test_helpers::LoadHTMLString(&GetLocalMainFrame(), content,
KURL("http://test.com"));
}
Document& GetDocument() { return *GetFrame()->GetDocument(); }
WebLocalFrameImpl& GetLocalMainFrame() {
return *web_view_helper_.LocalMainFrame();
}
const gfx::Rect& bounds() { return bounds_; }
private:
LocalFrame* GetFrame() { return GetLocalMainFrame().GetFrame(); }
frame_test_helpers::WebViewHelper web_view_helper_;
gfx::Rect bounds_ = {0, 0, 640, 480};
};
INSTANTIATE_PAINT_TEST_SUITE_P(VideoPaintPreviewTest);
TEST_P(VideoPaintPreviewTest, URLIsRecordedWhenPaintingPreview) {
// Insert a <video> and allow it to begin loading. The image was taken from
// the RFC for the data URI scheme https://tools.ietf.org/html/rfc2397.
SetBodyInnerHTML(R"HTML(
<style>body{margin:0}</style>
<video width=300 height=300 src="test.ogv" poster="data:image/gif;base64,R0
lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAwAAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yq
mCYsapyuvUUlvONmOZtfzgFzByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP
5yLWGsEbtLiOSpa/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGe
jmJlZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uisF81M1O
IcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PHhhx4dbgYKAAA7"
controls>
)HTML");
test::RunPendingTasks();
auto token = base::UnguessableToken::Create();
const int32_t routing_id = 1;
const bool is_main_frame = true;
cc::PaintRecorder recorder;
paint_preview::PaintPreviewTracker tracker(token, routing_id, is_main_frame);
cc::PaintCanvas* canvas =
recorder.beginRecording(bounds().width(), bounds().height());
canvas->SetPaintPreviewTracker(&tracker);
EXPECT_EQ(0lu, tracker.GetLinks().size());
GetLocalMainFrame().CapturePaintPreview(WebRect(bounds()), canvas);
ASSERT_EQ(1lu, tracker.GetLinks().size());
EXPECT_EQ("http://test.com/", tracker.GetLinks()[0].url);
EXPECT_EQ(gfx::Rect(300, 300), tracker.GetLinks()[0].rect);
}
} // namespace } // namespace
} // namespace blink } // namespace blink
...@@ -1418,7 +1418,7 @@ void GraphicsContext::SetURLForRect(const KURL& link, ...@@ -1418,7 +1418,7 @@ void GraphicsContext::SetURLForRect(const KURL& link,
const IntRect& dest_rect) { const IntRect& dest_rect) {
if (ContextDisabled()) if (ContextDisabled())
return; return;
DCHECK(canvas_); DCHECK(canvas_ || tracker_);
// Intercept URL rects when painting previews. // Intercept URL rects when painting previews.
if (IsPaintingPreview() && tracker_) { if (IsPaintingPreview() && tracker_) {
...@@ -1435,7 +1435,7 @@ void GraphicsContext::SetURLFragmentForRect(const String& dest_name, ...@@ -1435,7 +1435,7 @@ void GraphicsContext::SetURLFragmentForRect(const String& dest_name,
const IntRect& rect) { const IntRect& rect) {
if (ContextDisabled()) if (ContextDisabled())
return; return;
DCHECK(canvas_); DCHECK(canvas_ || tracker_);
// Intercept URL rects when painting previews. // Intercept URL rects when painting previews.
if (IsPaintingPreview() && tracker_) { if (IsPaintingPreview() && tracker_) {
......
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