Commit 20cffe68 authored by arthursonzogni's avatar arthursonzogni Committed by Commit Bot

[COOP] access reporting: expose the other window URL to ReportingObserver.

This makes network reports and ReportingObserver's report similar.

Bug: 1090273
Change-Id: Ic2da07e1ff9d66fe1a29ceda198c3663f00ed122
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2440840Reviewed-by: default avatarMike West <mkwst@chromium.org>
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814194}
parent 9dc82411
...@@ -10,20 +10,76 @@ namespace blink { ...@@ -10,20 +10,76 @@ namespace blink {
CoopAccessViolationReportBody::CoopAccessViolationReportBody( CoopAccessViolationReportBody::CoopAccessViolationReportBody(
std::unique_ptr<SourceLocation> source_location, std::unique_ptr<SourceLocation> source_location,
network::mojom::blink::CoopAccessReportType type, network::mojom::blink::CoopAccessReportType type,
const String& property) const String& property,
const String& reported_url)
: LocationReportBody(std::move(source_location)), : LocationReportBody(std::move(source_location)),
type_(type), type_(type),
property_(property) {} property_(property),
reported_url_(reported_url) {}
String CoopAccessViolationReportBody::type() const { String CoopAccessViolationReportBody::type() const {
return network::CoopAccessReportTypeToString(type_); return network::CoopAccessReportTypeToString(type_);
} }
String CoopAccessViolationReportBody::openeeURL() const {
switch (type_) {
case network::mojom::CoopAccessReportType::kAccessFromCoopPageToOpenee:
return reported_url_;
case network::mojom::CoopAccessReportType::kAccessToCoopPageFromOpener:
case network::mojom::CoopAccessReportType::kAccessToCoopPageFromOpenee:
case network::mojom::CoopAccessReportType::kAccessToCoopPageFromOther:
NOTREACHED();
FALLTHROUGH;
case network::mojom::CoopAccessReportType::kAccessFromCoopPageToOpener:
case network::mojom::CoopAccessReportType::kAccessFromCoopPageToOther:
return String();
}
}
String CoopAccessViolationReportBody::openerURL() const {
switch (type_) {
case network::mojom::CoopAccessReportType::kAccessFromCoopPageToOpener:
return reported_url_;
case network::mojom::CoopAccessReportType::kAccessToCoopPageFromOpener:
case network::mojom::CoopAccessReportType::kAccessToCoopPageFromOpenee:
case network::mojom::CoopAccessReportType::kAccessToCoopPageFromOther:
NOTREACHED();
FALLTHROUGH;
case network::mojom::CoopAccessReportType::kAccessFromCoopPageToOpenee:
case network::mojom::CoopAccessReportType::kAccessFromCoopPageToOther:
return String();
}
}
String CoopAccessViolationReportBody::otherDocumentURL() const {
switch (type_) {
case network::mojom::CoopAccessReportType::kAccessFromCoopPageToOther:
return reported_url_;
case network::mojom::CoopAccessReportType::kAccessToCoopPageFromOpener:
case network::mojom::CoopAccessReportType::kAccessToCoopPageFromOpenee:
case network::mojom::CoopAccessReportType::kAccessToCoopPageFromOther:
NOTREACHED();
FALLTHROUGH;
case network::mojom::CoopAccessReportType::kAccessFromCoopPageToOpenee:
case network::mojom::CoopAccessReportType::kAccessFromCoopPageToOpener:
return String();
}
}
void CoopAccessViolationReportBody::BuildJSONValue( void CoopAccessViolationReportBody::BuildJSONValue(
V8ObjectBuilder& builder) const { V8ObjectBuilder& builder) const {
LocationReportBody::BuildJSONValue(builder); LocationReportBody::BuildJSONValue(builder);
builder.AddString("type", type()); builder.AddString("type", type());
builder.AddString("property", property()); builder.AddString("property", property());
if (String opener_url = openerURL())
builder.AddString("openerURL", opener_url);
if (String openee_url = openeeURL())
builder.AddString("openeeURL", openee_url);
if (String other_document_url = otherDocumentURL())
builder.AddString("otherDocumentURL", other_document_url);
} }
} // namespace blink } // namespace blink
...@@ -19,15 +19,20 @@ class CORE_EXPORT CoopAccessViolationReportBody : public LocationReportBody { ...@@ -19,15 +19,20 @@ class CORE_EXPORT CoopAccessViolationReportBody : public LocationReportBody {
CoopAccessViolationReportBody( CoopAccessViolationReportBody(
std::unique_ptr<SourceLocation> source_location, std::unique_ptr<SourceLocation> source_location,
network::mojom::blink::CoopAccessReportType type, network::mojom::blink::CoopAccessReportType type,
const String& property); const String& property,
const String& reported_url);
~CoopAccessViolationReportBody() final = default; ~CoopAccessViolationReportBody() final = default;
String type() const; String type() const;
String openeeURL() const;
String openerURL() const;
String otherDocumentURL() const;
const String& property() const { return property_; } const String& property() const { return property_; }
void BuildJSONValue(V8ObjectBuilder& builder) const final; void BuildJSONValue(V8ObjectBuilder& builder) const final;
private: private:
network::mojom::blink::CoopAccessReportType type_; network::mojom::blink::CoopAccessReportType type_;
const String property_; const String property_;
const String reported_url_;
}; };
} // namespace blink } // namespace blink
......
...@@ -12,5 +12,8 @@ ...@@ -12,5 +12,8 @@
readonly attribute unsigned long? columnNumber; readonly attribute unsigned long? columnNumber;
readonly attribute DOMString type; readonly attribute DOMString type;
readonly attribute DOMString property; readonly attribute DOMString property;
readonly attribute DOMString? openeeURL;
readonly attribute DOMString? openerURL;
readonly attribute DOMString? otherDocumentURL;
[CallWith=ScriptState] object toJSON(); [CallWith=ScriptState] object toJSON();
}; };
...@@ -540,15 +540,13 @@ void DOMWindow::ReportCoopAccess(const char* property_name) { ...@@ -540,15 +540,13 @@ void DOMWindow::ReportCoopAccess(const char* property_name) {
std::move(it->reported_window_url)); std::move(it->reported_window_url));
// Send a coop-access-violation report. // Send a coop-access-violation report.
if (network::IsAccessFromCoopPage(it->report_type)) { if (network::IsAccessFromCoopPage(it->report_type)) {
// TODO(arthursonzogni): Fill the openeeURL, openerURL and
// otherDocumentURL.
ReportingContext::From(accessing_main_frame.DomWindow()) ReportingContext::From(accessing_main_frame.DomWindow())
->QueueReport(MakeGarbageCollected<Report>( ->QueueReport(MakeGarbageCollected<Report>(
ReportType::kCoopAccessViolation, ReportType::kCoopAccessViolation,
accessing_main_frame.GetDocument()->Url().GetString(), accessing_main_frame.GetDocument()->Url().GetString(),
MakeGarbageCollected<CoopAccessViolationReportBody>( MakeGarbageCollected<CoopAccessViolationReportBody>(
std::move(location), it->report_type, std::move(location), it->report_type, String(property_name),
String(property_name)))); it->reported_window_url)));
} }
} }
......
...@@ -65,6 +65,9 @@ promise_test(async t => { ...@@ -65,6 +65,9 @@ promise_test(async t => {
assert_source_location_found(report_access_from[0]) assert_source_location_found(report_access_from[0])
assert_equals(report_access_from[0].body.type, assert_equals(report_access_from[0].body.type,
"access-from-coop-page-to-openee"); "access-from-coop-page-to-openee");
assert_equals(report_access_from[0].body.openeeURL, openee_url);
assert_equals(report_access_from[0].body.openerURL, undefined);
assert_equals(report_access_from[0].body.otherDocumentURL, undefined);
// 5. The openee tries to access its opener. No reports for blocked access // 5. The openee tries to access its opener. No reports for blocked access
// to the COOP page should be dispatched. // to the COOP page should be dispatched.
...@@ -122,6 +125,9 @@ promise_test(async t => { ...@@ -122,6 +125,9 @@ promise_test(async t => {
assert_source_location_found(report_access_from[0]) assert_source_location_found(report_access_from[0])
assert_equals(report_access_from[0].body.type, assert_equals(report_access_from[0].body.type,
"access-from-coop-page-to-opener"); "access-from-coop-page-to-opener");
assert_equals(report_access_from[0].body.openeeURL, undefined);
assert_equals(report_access_from[0].body.openerURL, opener_url);
assert_equals(report_access_from[0].body.otherDocumentURL, undefined);
// 4. The opener tries to access its openee. No reports for blocked access // 4. The opener tries to access its openee. No reports for blocked access
// to the COOP page should be dispatched. // to the COOP page should be dispatched.
...@@ -198,6 +204,9 @@ promise_test(async t => { ...@@ -198,6 +204,9 @@ promise_test(async t => {
assert_source_location_found(reports[0]); assert_source_location_found(reports[0]);
assert_equals(reports[0].body.type, assert_equals(reports[0].body.type,
"access-from-coop-page-to-openee"); "access-from-coop-page-to-openee");
assert_equals(reports[0].body.openeeURL, openee_url);
assert_equals(reports[0].body.openerURL, undefined);
assert_equals(reports[0].body.otherDocumentURL, undefined);
}, "Access from same-origin iframe") }, "Access from same-origin iframe")
promise_test(async t => { promise_test(async t => {
......
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