Commit 6b10d6d5 authored by ckitagawa's avatar ckitagawa Committed by Commit Bot

[Paint Preview] Add URL to proto

Adds a URL to the PaintPreviewProto. This is a simple addition that is
used to attribute the Paint Preview to originating from a URL. This only
applies to the root frame rather than any of its children.

Bug: 1030419
Change-Id: I59028fbebf3305cb52b04fca9c190712a2bb40f3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1949280
Commit-Queue: Calder Kitagawa <ckitagawa@chromium.org>
Reviewed-by: default avatarIan Vollick <vollick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721546}
parent 395daf6a
...@@ -108,6 +108,7 @@ void PaintPreviewClient::CapturePaintPreview( ...@@ -108,6 +108,7 @@ void PaintPreviewClient::CapturePaintPreview(
auto* document_data = &all_document_data_[params.document_guid]; auto* document_data = &all_document_data_[params.document_guid];
document_data->root_dir = params.root_dir; document_data->root_dir = params.root_dir;
document_data->callback = std::move(callback); document_data->callback = std::move(callback);
document_data->root_url = render_frame_host->GetLastCommittedURL();
CapturePaintPreviewInternal(params, render_frame_host); CapturePaintPreviewInternal(params, render_frame_host);
} }
...@@ -266,8 +267,11 @@ mojom::PaintPreviewStatus PaintPreviewClient::RecordFrame( ...@@ -266,8 +267,11 @@ mojom::PaintPreviewStatus PaintPreviewClient::RecordFrame(
content::RenderFrameHost* render_frame_host, content::RenderFrameHost* render_frame_host,
mojom::PaintPreviewCaptureResponsePtr response) { mojom::PaintPreviewCaptureResponsePtr response) {
auto it = all_document_data_.find(guid); auto it = all_document_data_.find(guid);
if (!it->second.proto) if (!it->second.proto) {
it->second.proto = std::make_unique<PaintPreviewProto>(); it->second.proto = std::make_unique<PaintPreviewProto>();
it->second.proto->mutable_metadata()->set_url(
all_document_data_[guid].root_url.spec());
}
PaintPreviewProto* proto_ptr = it->second.proto.get(); PaintPreviewProto* proto_ptr = it->second.proto.get();
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "content/public/browser/web_contents_user_data.h" #include "content/public/browser/web_contents_user_data.h"
#include "mojo/public/cpp/bindings/associated_remote.h" #include "mojo/public/cpp/bindings/associated_remote.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "url/gurl.h"
namespace paint_preview { namespace paint_preview {
...@@ -90,6 +91,9 @@ class PaintPreviewClient ...@@ -90,6 +91,9 @@ class PaintPreviewClient
// Root directory to store artifacts to. // Root directory to store artifacts to.
base::FilePath root_dir; base::FilePath root_dir;
// URL of the root frame.
GURL root_url;
// Callback that is invoked on completion of data. // Callback that is invoked on completion of data.
PaintPreviewCallback callback; PaintPreviewCallback callback;
......
...@@ -141,11 +141,13 @@ TEST_F(PaintPreviewClientRenderViewHostTest, CaptureMainFrameMock) { ...@@ -141,11 +141,13 @@ TEST_F(PaintPreviewClientRenderViewHostTest, CaptureMainFrameMock) {
content::RenderFrameHost* rfh = main_rfh(); content::RenderFrameHost* rfh = main_rfh();
uint64_t frame_guid = FrameGuid(rfh); uint64_t frame_guid = FrameGuid(rfh);
GURL expected_url = rfh->GetLastCommittedURL();
auto response = mojom::PaintPreviewCaptureResponse::New(); auto response = mojom::PaintPreviewCaptureResponse::New();
response->id = rfh->GetRoutingID(); response->id = rfh->GetRoutingID();
PaintPreviewProto expected_proto; PaintPreviewProto expected_proto;
expected_proto.mutable_metadata()->set_url(expected_url.spec());
PaintPreviewFrameProto* main_frame = expected_proto.mutable_root_frame(); PaintPreviewFrameProto* main_frame = expected_proto.mutable_root_frame();
main_frame->set_is_main_frame(true); main_frame->set_is_main_frame(true);
main_frame->set_id(frame_guid); main_frame->set_id(frame_guid);
......
...@@ -44,11 +44,19 @@ message PaintPreviewFrameProto { ...@@ -44,11 +44,19 @@ message PaintPreviewFrameProto {
map<uint32, int64> content_id_proxy_id_map = 5; map<uint32, int64> content_id_proxy_id_map = 5;
} }
// Metadata for the capture.
// NEXT_TAG = 2
message MetadataProto {
// URL of the root frame.
required string url = 1;
}
// A paint preview of the entire page. // A paint preview of the entire page.
// NEXT_TAG = 3 // NEXT_TAG = 4
message PaintPreviewProto { message PaintPreviewProto {
// The root frame of the RenderFrame tree. This is often the main frame, but // The root frame of the RenderFrame tree. This is often the main frame, but
// may be a root node of a subtree (e.g. paint preview of an iframe). // may be a root node of a subtree (e.g. paint preview of an iframe).
required PaintPreviewFrameProto root_frame = 1; required PaintPreviewFrameProto root_frame = 1;
repeated PaintPreviewFrameProto subframes = 2; repeated PaintPreviewFrameProto subframes = 2;
required MetadataProto metadata = 3;
} }
...@@ -175,6 +175,7 @@ TEST(PaintPreviewCompositorTest, TestBeginComposite) { ...@@ -175,6 +175,7 @@ TEST(PaintPreviewCompositorTest, TestBeginComposite) {
gfx::Rect subframe_1_clip_rect(0, 0, 1, 1); gfx::Rect subframe_1_clip_rect(0, 0, 1, 1);
PaintPreviewProto proto; PaintPreviewProto proto;
proto.mutable_metadata()->set_url(url.spec());
base::flat_map<uint64_t, base::File> file_map; base::flat_map<uint64_t, base::File> file_map;
base::flat_map<uint64_t, mojom::FrameDataPtr> expected_data; base::flat_map<uint64_t, mojom::FrameDataPtr> expected_data;
PopulateFrameProto(proto.mutable_root_frame(), kRootFrameID, true, PopulateFrameProto(proto.mutable_root_frame(), kRootFrameID, true,
...@@ -223,6 +224,7 @@ TEST(PaintPreviewCompositorTest, TestBeginCompositeDuplicate) { ...@@ -223,6 +224,7 @@ TEST(PaintPreviewCompositorTest, TestBeginCompositeDuplicate) {
PaintPreviewCompositorImpl compositor(mojo::NullReceiver(), PaintPreviewCompositorImpl compositor(mojo::NullReceiver(),
base::BindOnce([]() {})); base::BindOnce([]() {}));
GURL url("https://www.chromium.org");
const uint64_t kRootFrameID = 1; const uint64_t kRootFrameID = 1;
gfx::Size root_frame_scroll_extent(100, 200); gfx::Size root_frame_scroll_extent(100, 200);
const uint64_t kSubframe_0_ID = 2; const uint64_t kSubframe_0_ID = 2;
...@@ -230,6 +232,7 @@ TEST(PaintPreviewCompositorTest, TestBeginCompositeDuplicate) { ...@@ -230,6 +232,7 @@ TEST(PaintPreviewCompositorTest, TestBeginCompositeDuplicate) {
gfx::Rect subframe_0_clip_rect(10, 20, 30, 40); gfx::Rect subframe_0_clip_rect(10, 20, 30, 40);
PaintPreviewProto proto; PaintPreviewProto proto;
proto.mutable_metadata()->set_url(url.spec());
base::flat_map<uint64_t, base::File> file_map; base::flat_map<uint64_t, base::File> file_map;
base::flat_map<uint64_t, mojom::FrameDataPtr> expected_data; base::flat_map<uint64_t, mojom::FrameDataPtr> expected_data;
PopulateFrameProto(proto.mutable_root_frame(), kRootFrameID, true, PopulateFrameProto(proto.mutable_root_frame(), kRootFrameID, true,
...@@ -262,6 +265,7 @@ TEST(PaintPreviewCompositorTest, TestBeginCompositeLoop) { ...@@ -262,6 +265,7 @@ TEST(PaintPreviewCompositorTest, TestBeginCompositeLoop) {
PaintPreviewCompositorImpl compositor(mojo::NullReceiver(), PaintPreviewCompositorImpl compositor(mojo::NullReceiver(),
base::BindOnce([]() {})); base::BindOnce([]() {}));
GURL url("https://www.chromium.org");
const uint64_t kRootFrameID = 1; const uint64_t kRootFrameID = 1;
gfx::Size root_frame_scroll_extent(100, 200); gfx::Size root_frame_scroll_extent(100, 200);
const uint64_t kSubframe_0_ID = 2; const uint64_t kSubframe_0_ID = 2;
...@@ -269,6 +273,7 @@ TEST(PaintPreviewCompositorTest, TestBeginCompositeLoop) { ...@@ -269,6 +273,7 @@ TEST(PaintPreviewCompositorTest, TestBeginCompositeLoop) {
gfx::Rect subframe_0_clip_rect(10, 20, 30, 40); gfx::Rect subframe_0_clip_rect(10, 20, 30, 40);
PaintPreviewProto proto; PaintPreviewProto proto;
proto.mutable_metadata()->set_url(url.spec());
base::flat_map<uint64_t, base::File> file_map; base::flat_map<uint64_t, base::File> file_map;
base::flat_map<uint64_t, mojom::FrameDataPtr> expected_data; base::flat_map<uint64_t, mojom::FrameDataPtr> expected_data;
PopulateFrameProto( PopulateFrameProto(
...@@ -301,11 +306,13 @@ TEST(PaintPreviewCompositorTest, TestBeginCompositeSelfReference) { ...@@ -301,11 +306,13 @@ TEST(PaintPreviewCompositorTest, TestBeginCompositeSelfReference) {
PaintPreviewCompositorImpl compositor(mojo::NullReceiver(), PaintPreviewCompositorImpl compositor(mojo::NullReceiver(),
base::BindOnce([]() {})); base::BindOnce([]() {}));
GURL url("https://www.chromium.org");
const uint64_t kRootFrameID = 1; const uint64_t kRootFrameID = 1;
gfx::Size root_frame_scroll_extent(100, 200); gfx::Size root_frame_scroll_extent(100, 200);
gfx::Rect root_frame_clip_rect(10, 20, 30, 40); gfx::Rect root_frame_clip_rect(10, 20, 30, 40);
PaintPreviewProto proto; PaintPreviewProto proto;
proto.mutable_metadata()->set_url(url.spec());
base::flat_map<uint64_t, base::File> file_map; base::flat_map<uint64_t, base::File> file_map;
base::flat_map<uint64_t, mojom::FrameDataPtr> expected_data; base::flat_map<uint64_t, mojom::FrameDataPtr> expected_data;
PopulateFrameProto( PopulateFrameProto(
...@@ -377,8 +384,10 @@ TEST(PaintPreviewCompositorTest, TestInvalidRootFrame) { ...@@ -377,8 +384,10 @@ TEST(PaintPreviewCompositorTest, TestInvalidRootFrame) {
mojom::PaintPreviewBeginCompositeRequestPtr request = mojom::PaintPreviewBeginCompositeRequestPtr request =
mojom::PaintPreviewBeginCompositeRequest::New(); mojom::PaintPreviewBeginCompositeRequest::New();
PaintPreviewProto proto; GURL url("https://www.chromium.org");
const uint64_t kRootFrameID = 1; const uint64_t kRootFrameID = 1;
PaintPreviewProto proto;
proto.mutable_metadata()->set_url(url.spec());
base::flat_map<uint64_t, base::File> file_map; base::flat_map<uint64_t, base::File> file_map;
base::flat_map<uint64_t, mojom::FrameDataPtr> expected_data; base::flat_map<uint64_t, mojom::FrameDataPtr> expected_data;
PopulateFrameProto(proto.mutable_root_frame(), kRootFrameID, true, PopulateFrameProto(proto.mutable_root_frame(), kRootFrameID, true,
...@@ -399,9 +408,11 @@ TEST(PaintPreviewCompositorTest, TestComposite) { ...@@ -399,9 +408,11 @@ TEST(PaintPreviewCompositorTest, TestComposite) {
ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
PaintPreviewCompositorImpl compositor(mojo::NullReceiver(), PaintPreviewCompositorImpl compositor(mojo::NullReceiver(),
base::BindOnce([]() {})); base::BindOnce([]() {}));
GURL url("https://www.chromium.org");
const uint64_t kRootFrameID = 1; const uint64_t kRootFrameID = 1;
gfx::Size root_frame_scroll_extent(100, 200); gfx::Size root_frame_scroll_extent(100, 200);
PaintPreviewProto proto; PaintPreviewProto proto;
proto.mutable_metadata()->set_url(url.spec());
base::flat_map<uint64_t, base::File> file_map; base::flat_map<uint64_t, base::File> file_map;
base::flat_map<uint64_t, mojom::FrameDataPtr> expected_data; base::flat_map<uint64_t, mojom::FrameDataPtr> expected_data;
PopulateFrameProto(proto.mutable_root_frame(), kRootFrameID, true, PopulateFrameProto(proto.mutable_root_frame(), kRootFrameID, true,
......
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