From 505f421d0a73adae4f74924b3022996c731de40e Mon Sep 17 00:00:00 2001 From: joenotcharles Date: Thu, 11 Feb 2016 11:28:53 -0800 Subject: Include suppressed dialogs in the FineTiming histogram Review URL: https://codereview.chromium.org/1688183002 Cr-Commit-Position: refs/heads/master@{#374920} --- components/app_modal/javascript_app_modal_dialog.cc | 3 ++- components/app_modal/javascript_app_modal_dialog.h | 3 +++ components/app_modal/javascript_dialog_manager.cc | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/components/app_modal/javascript_app_modal_dialog.cc b/components/app_modal/javascript_app_modal_dialog.cc index efce144..26d1b03 100644 --- a/components/app_modal/javascript_app_modal_dialog.cc +++ b/components/app_modal/javascript_app_modal_dialog.cc @@ -54,7 +54,8 @@ void EnforceMaxPromptSize(const base::string16& in_string, ChromeJavaScriptDialogExtraData::ChromeJavaScriptDialogExtraData() : has_already_shown_a_dialog_(false), - suppress_javascript_messages_(false) {} + suppress_javascript_messages_(false), + suppressed_dialog_count_(0) {} JavaScriptAppModalDialog::JavaScriptAppModalDialog( content::WebContents* web_contents, diff --git a/components/app_modal/javascript_app_modal_dialog.h b/components/app_modal/javascript_app_modal_dialog.h index 111ba7d..76c09e3 100644 --- a/components/app_modal/javascript_app_modal_dialog.h +++ b/components/app_modal/javascript_app_modal_dialog.h @@ -26,6 +26,9 @@ class ChromeJavaScriptDialogExtraData { // True if the user has decided to block future JavaScript dialogs. bool suppress_javascript_messages_; + + // Number of dialogs from the origin that were suppressed. + int suppressed_dialog_count_; }; // A controller + model class for JavaScript alert, confirm, prompt, and diff --git a/components/app_modal/javascript_dialog_manager.cc b/components/app_modal/javascript_dialog_manager.cc index f654f8bf3..7c4db07 100644 --- a/components/app_modal/javascript_dialog_manager.cc +++ b/components/app_modal/javascript_dialog_manager.cc @@ -104,6 +104,21 @@ void JavaScriptDialogManager::RunJavaScriptDialog( web_contents)]; if (extra_data->suppress_javascript_messages_) { + // If a page tries to open dialogs in a tight loop, the number of + // suppressions logged can grow out of control. Arbitrarily cap the number + // logged at 100. That many suppressed dialogs is enough to indicate the + // page is doing something very hinky. + if (extra_data->suppressed_dialog_count_ < 100) { + // Log a suppressed dialog as one that opens and then closes immediately. + UMA_HISTOGRAM_MEDIUM_TIMES( + "JSDialogs.FineTiming.TimeBetweenDialogCreatedAndSameDialogClosed", + base::TimeDelta()); + + // Only increment the count if it's not already at the limit, to prevent + // overflow. + extra_data->suppressed_dialog_count_++; + } + *did_suppress_message = true; return; } -- cgit v1.1