Commit 63cff337 authored by Paul Meyer's avatar Paul Meyer Committed by Commit Bot

Add |id| field to intervention reports.

Every intervention report should have a human-readable id, as specified
in the Reporting spec.

https://w3c.github.io/reporting/#dom-interventionreportbody-id

Bug: 564071
Change-Id: I82d1237fe9b45f28691e0772abd6d9995833e1ee
Reviewed-on: https://chromium-review.googlesource.com/1129469Reviewed-by: default avatarNate Chapin <japhet@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Paul Meyer <paulmeyer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#574183}
parent cb0e1e18
...@@ -17,6 +17,7 @@ async_test(function(test) { ...@@ -17,6 +17,7 @@ async_test(function(test) {
assert_equals(reports[0].type, "intervention"); assert_equals(reports[0].type, "intervention");
assert_true(reports[0].url.endsWith( assert_true(reports[0].url.endsWith(
"reporting-observer/intervention.html")); "reporting-observer/intervention.html"));
assert_equals(typeof reports[0].body.id, "string");
assert_true(reports[0].body.sourceFile.endsWith( assert_true(reports[0].body.sourceFile.endsWith(
"reporting-observer/resources/intervention.js")); "reporting-observer/resources/intervention.js"));
assert_equals(typeof reports[0].body.lineNumber, "number"); assert_equals(typeof reports[0].body.lineNumber, "number");
......
...@@ -3470,21 +3470,21 @@ bool Document::DispatchBeforeUnloadEvent(ChromeClient& chrome_client, ...@@ -3470,21 +3470,21 @@ bool Document::DispatchBeforeUnloadEvent(ChromeClient& chrome_client,
if (!GetFrame()->HasBeenActivated()) { if (!GetFrame()->HasBeenActivated()) {
beforeunload_dialog_histogram.Count(kNoDialogNoUserGesture); beforeunload_dialog_histogram.Count(kNoDialogNoUserGesture);
AddConsoleMessage(ConsoleMessage::Create( String message =
kInterventionMessageSource, kErrorMessageLevel,
"Blocked attempt to show a 'beforeunload' confirmation panel for a " "Blocked attempt to show a 'beforeunload' confirmation panel for a "
"frame that never had a user gesture since its load. " "frame that never had a user gesture since its load. "
"https://www.chromestatus.com/feature/5082396709879808")); "https://www.chromestatus.com/feature/5082396709879808";
Intervention::GenerateReport(frame_, "BeforeUnloadNoGesture", message);
return true; return true;
} }
if (did_allow_navigation) { if (did_allow_navigation) {
beforeunload_dialog_histogram.Count( beforeunload_dialog_histogram.Count(
kNoDialogMultipleConfirmationForNavigation); kNoDialogMultipleConfirmationForNavigation);
AddConsoleMessage(ConsoleMessage::Create( String message =
kInterventionMessageSource, kErrorMessageLevel,
"Blocked attempt to show multiple 'beforeunload' confirmation panels " "Blocked attempt to show multiple 'beforeunload' confirmation panels "
"for a single navigation.")); "for a single navigation.";
Intervention::GenerateReport(frame_, "BeforeUnloadMultiple", message);
return true; return true;
} }
String text = before_unload_event->returnValue(); String text = before_unload_event->returnValue();
...@@ -6504,10 +6504,7 @@ void Document::AddConsoleMessage(ConsoleMessage* console_message) { ...@@ -6504,10 +6504,7 @@ void Document::AddConsoleMessage(ConsoleMessage* console_message) {
console_message->SetNodes(frame_, std::move(nodes)); console_message->SetNodes(frame_, std::move(nodes));
} }
if (console_message->Source() == kInterventionMessageSource) frame_->Console().AddMessage(console_message);
Intervention::GenerateReport(frame_, console_message->Message());
else
frame_->Console().AddMessage(console_message);
} }
void Document::TasksWerePaused() { void Document::TasksWerePaused() {
......
...@@ -264,11 +264,13 @@ void TouchEvent::preventDefault() { ...@@ -264,11 +264,13 @@ void TouchEvent::preventDefault() {
// A common developer error is to wait too long before attempting to stop // A common developer error is to wait too long before attempting to stop
// scrolling by consuming a touchmove event. Generate an error if this // scrolling by consuming a touchmove event. Generate an error if this
// event is uncancelable. // event is uncancelable.
String id;
String message; String message;
switch (HandlingPassive()) { switch (HandlingPassive()) {
case PassiveMode::kNotPassive: case PassiveMode::kNotPassive:
case PassiveMode::kNotPassiveDefault: case PassiveMode::kNotPassiveDefault:
if (!cancelable()) { if (!cancelable()) {
id = "IgnoredEventCancel";
message = "Ignored attempt to cancel a " + type() + message = "Ignored attempt to cancel a " + type() +
" event with cancelable=false, for example " " event with cancelable=false, for example "
"because scrolling is in progress and " "because scrolling is in progress and "
...@@ -280,6 +282,7 @@ void TouchEvent::preventDefault() { ...@@ -280,6 +282,7 @@ void TouchEvent::preventDefault() {
// an author may use touch action but call preventDefault for interop with // an author may use touch action but call preventDefault for interop with
// browsers that don't support touch-action. // browsers that don't support touch-action.
if (current_touch_action_ == TouchAction::kTouchActionAuto) { if (current_touch_action_ == TouchAction::kTouchActionAuto) {
id = "PreventDefaultPassive";
message = message =
"Unable to preventDefault inside passive event listener due to " "Unable to preventDefault inside passive event listener due to "
"target being treated as passive. See " "target being treated as passive. See "
...@@ -292,7 +295,8 @@ void TouchEvent::preventDefault() { ...@@ -292,7 +295,8 @@ void TouchEvent::preventDefault() {
if (!message.IsEmpty() && view() && view()->IsLocalDOMWindow() && if (!message.IsEmpty() && view() && view()->IsLocalDOMWindow() &&
view()->GetFrame()) { view()->GetFrame()) {
Intervention::GenerateReport(ToLocalDOMWindow(view())->GetFrame(), message); Intervention::GenerateReport(ToLocalDOMWindow(view())->GetFrame(), id,
message);
} }
if ((type() == EventTypeNames::touchstart || if ((type() == EventTypeNames::touchstart ||
......
...@@ -19,22 +19,22 @@ namespace blink { ...@@ -19,22 +19,22 @@ namespace blink {
// static // static
void Intervention::GenerateReport(const LocalFrame* frame, void Intervention::GenerateReport(const LocalFrame* frame,
const String& id,
const String& message) { const String& message) {
if (!frame) if (!frame)
return; return;
// Send the message to the console. // Send the message to the console.
frame->Console().AddMessage(ConsoleMessage::Create( Document* document = frame->GetDocument();
document->AddConsoleMessage(ConsoleMessage::Create(
kInterventionMessageSource, kErrorMessageLevel, message)); kInterventionMessageSource, kErrorMessageLevel, message));
if (!frame->Client()) if (!frame->Client())
return; return;
Document* document = frame->GetDocument();
// Construct the intervention report. // Construct the intervention report.
InterventionReportBody* body = InterventionReportBody* body =
new InterventionReportBody(message, SourceLocation::Capture()); new InterventionReportBody(id, message, SourceLocation::Capture());
Report* report = Report* report =
new Report("intervention", document->Url().GetString(), body); new Report("intervention", document->Url().GetString(), body);
......
...@@ -23,7 +23,9 @@ class CORE_EXPORT Intervention { ...@@ -23,7 +23,9 @@ class CORE_EXPORT Intervention {
// Generates a intervention report, to be routed to the Reporting API and any // Generates a intervention report, to be routed to the Reporting API and any
// ReportingObservers. Also sends the intervention message to the console. // ReportingObservers. Also sends the intervention message to the console.
static void GenerateReport(const LocalFrame*, const String& message); static void GenerateReport(const LocalFrame*,
const String& id,
const String& message);
DISALLOW_COPY_AND_ASSIGN(Intervention); DISALLOW_COPY_AND_ASSIGN(Intervention);
}; };
......
...@@ -14,11 +14,17 @@ class CORE_EXPORT InterventionReportBody : public MessageReportBody { ...@@ -14,11 +14,17 @@ class CORE_EXPORT InterventionReportBody : public MessageReportBody {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
InterventionReportBody(const String& message, InterventionReportBody(const String& id,
const String& message,
std::unique_ptr<SourceLocation> location) std::unique_ptr<SourceLocation> location)
: MessageReportBody(message, std::move(location)) {} : MessageReportBody(message, std::move(location)), id_(id) {}
~InterventionReportBody() override = default; ~InterventionReportBody() override = default;
String id() const { return id_; }
private:
const String id_;
}; };
} // namespace blink } // namespace blink
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
NoInterfaceObject, NoInterfaceObject,
RuntimeEnabled=InterventionReporting RuntimeEnabled=InterventionReporting
] interface InterventionReportBody : ReportBody { ] interface InterventionReportBody : ReportBody {
// TODO(paulmeyer): Add additional data, such as id. readonly attribute DOMString id;
readonly attribute DOMString message; readonly attribute DOMString message;
readonly attribute DOMString? sourceFile; readonly attribute DOMString? sourceFile;
readonly attribute long? lineNumber; readonly attribute long? lineNumber;
......
...@@ -94,7 +94,7 @@ bool NavigatorVibration::vibrate(Navigator& navigator, ...@@ -94,7 +94,7 @@ bool NavigatorVibration::vibrate(Navigator& navigator,
"https://www.chromestatus.com/feature/5644273861001216."; "https://www.chromestatus.com/feature/5644273861001216.";
} }
Intervention::GenerateReport(frame, message); Intervention::GenerateReport(frame, "NavigatorVibrate", message);
return false; return false;
} }
......
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