summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvi Drissman <avi@chromium.org>2015-04-20 19:34:14 -0400
committerAvi Drissman <avi@chromium.org>2015-04-20 23:35:02 +0000
commitffed915e346d15e41d79937a506bee06c7e81b49 (patch)
tree5f1494d1d599a6358e9d6e16f815269d264750ad
parent0345c8f5b8f53b98f866b60e67fa8aa9b00bb10f (diff)
downloadchromium_src-ffed915e346d15e41d79937a506bee06c7e81b49.zip
chromium_src-ffed915e346d15e41d79937a506bee06c7e81b49.tar.gz
chromium_src-ffed915e346d15e41d79937a506bee06c7e81b49.tar.bz2
Make JavaScript dialog suppression even more aggressive.
Allow the "prevent additional dialogs" checkbox button to appear on beforeunload dialogs. BUG=473903 TEST=Repeated beforeunload dialogs show a suppression checkbox Review URL: https://codereview.chromium.org/1092123002 Cr-Commit-Position: refs/heads/master@{#325726} (cherry picked from commit 86578a8adcdc518724b7d62cfaae6415c72888e4) TBR=ben@chromium.org Review URL: https://codereview.chromium.org/1098993002 Cr-Commit-Position: refs/branch-heads/2357@{#173} Cr-Branched-From: 59d4494849b405682265ed5d3f5164573b9a939b-refs/heads/master@{#323860}
-rw-r--r--components/app_modal/javascript_dialog_manager.cc35
1 files changed, 17 insertions, 18 deletions
diff --git a/components/app_modal/javascript_dialog_manager.cc b/components/app_modal/javascript_dialog_manager.cc
index 6d72439..24ab262 100644
--- a/components/app_modal/javascript_dialog_manager.cc
+++ b/components/app_modal/javascript_dialog_manager.cc
@@ -38,6 +38,21 @@ class DefaultExtensionsClient : public JavaScriptDialogExtensionsClient {
DISALLOW_COPY_AND_ASSIGN(DefaultExtensionsClient);
};
+bool ShouldDisplaySuppressCheckbox(
+ ChromeJavaScriptDialogExtraData* extra_data) {
+ base::TimeDelta time_since_last_message = base::TimeTicks::Now() -
+ extra_data->last_javascript_message_dismissal_;
+
+ // If a WebContents is impolite and displays a second JavaScript
+ // alert within kJavaScriptMessageExpectedDelay of a previous
+ // JavaScript alert being dismissed, show a checkbox offering to
+ // suppress future alerts from this WebContents.
+ const int kJavaScriptMessageExpectedDelay = 1000;
+
+ return time_since_last_message <
+ base::TimeDelta::FromMilliseconds(kJavaScriptMessageExpectedDelay);
+}
+
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -87,22 +102,6 @@ void JavaScriptDialogManager::RunJavaScriptDialog(
return;
}
- base::TimeDelta time_since_last_message = base::TimeTicks::Now() -
- extra_data->last_javascript_message_dismissal_;
- bool display_suppress_checkbox = false;
- // If a WebContents is impolite and displays a second JavaScript
- // alert within kJavaScriptMessageExpectedDelay of a previous
- // JavaScript alert being dismissed, show a checkbox offering to
- // suppress future alerts from this WebContents.
- const int kJavaScriptMessageExpectedDelay = 1000;
-
- if (time_since_last_message <
- base::TimeDelta::FromMilliseconds(kJavaScriptMessageExpectedDelay)) {
- display_suppress_checkbox = true;
- } else {
- display_suppress_checkbox = false;
- }
-
bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT;
base::string16 dialog_title =
GetTitle(web_contents, origin_url, accept_lang, is_alert);
@@ -116,7 +115,7 @@ void JavaScriptDialogManager::RunJavaScriptDialog(
message_type,
message_text,
default_prompt_text,
- display_suppress_checkbox,
+ ShouldDisplaySuppressCheckbox(extra_data),
false, // is_before_unload_dialog
false, // is_reload
base::Bind(&JavaScriptDialogManager::OnDialogClosed,
@@ -155,7 +154,7 @@ void JavaScriptDialogManager::RunBeforeUnloadDialog(
content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
full_message,
base::string16(), // default_prompt_text
- false, // display_suppress_checkbox
+ ShouldDisplaySuppressCheckbox(extra_data),
true, // is_before_unload_dialog
is_reload,
base::Bind(&JavaScriptDialogManager::OnDialogClosed,