Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.h" | 5 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "components/app_modal_dialogs/app_modal_dialog.h" |
| 13 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" | 13 #include "components/app_modal_dialogs/app_modal_dialog_queue.h" |
| 14 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" | 14 #include "components/app_modal_dialogs/javascript_app_modal_dialog.h" |
| 15 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" | 15 #include "components/app_modal_dialogs/native_app_modal_dialog.h" |
| 16 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" | |
| 17 #include "chrome/common/chrome_constants.h" | |
| 18 #include "chrome/grit/generated_resources.h" | |
| 19 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/common/content_client.h" | 17 #include "content/public/common/content_client.h" |
| 21 #include "content/public/common/javascript_message_type.h" | 18 #include "content/public/common/javascript_message_type.h" |
| 19 #include "grit/components_strings.h" | |
| 22 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 24 | 22 |
| 25 #if defined(ENABLE_EXTENSIONS) | 23 #if defined(ENABLE_EXTENSIONS) |
| 26 #include "extensions/browser/extension_system.h" | 24 #include "extensions/browser/extension_system.h" |
| 27 #include "extensions/browser/process_manager.h" | 25 #include "extensions/browser/process_manager.h" |
| 28 #endif // defined(ENABLE_EXTENSIONS) | 26 #endif // defined(ENABLE_EXTENSIONS) |
| 29 | 27 |
| 30 using content::BrowserContext; | 28 using content::BrowserContext; |
| 31 using content::JavaScriptDialogManager; | 29 using content::JavaScriptDialogManager; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 | 149 |
| 152 void ChromeJavaScriptDialogManager::RunJavaScriptDialog( | 150 void ChromeJavaScriptDialogManager::RunJavaScriptDialog( |
| 153 WebContents* web_contents, | 151 WebContents* web_contents, |
| 154 const GURL& origin_url, | 152 const GURL& origin_url, |
| 155 const std::string& accept_lang, | 153 const std::string& accept_lang, |
| 156 content::JavaScriptMessageType message_type, | 154 content::JavaScriptMessageType message_type, |
| 157 const base::string16& message_text, | 155 const base::string16& message_text, |
| 158 const base::string16& default_prompt_text, | 156 const base::string16& default_prompt_text, |
| 159 const DialogClosedCallback& callback, | 157 const DialogClosedCallback& callback, |
| 160 bool* did_suppress_message) { | 158 bool* did_suppress_message) { |
| 159 | |
| 160 // If a WebContents is impolite and displays a second JavaScript | |
|
msw
2014/10/23 18:41:21
nit: Move down, combine this comment with the one
oshima
2014/10/23 21:44:18
Done.
| |
| 161 // alert within kJavaScriptMessageExpectedDelay of a previous | |
| 162 // JavaScript alert being dismissed, display an option to suppress | |
| 163 // future alerts from this WebContents. | |
| 164 const int kJavaScriptMessageExpectedDelay = 1000; | |
| 165 | |
| 161 *did_suppress_message = false; | 166 *did_suppress_message = false; |
| 162 | 167 |
| 163 ChromeJavaScriptDialogExtraData* extra_data = | 168 ChromeJavaScriptDialogExtraData* extra_data = |
| 164 &javascript_dialog_extra_data_[web_contents]; | 169 &javascript_dialog_extra_data_[web_contents]; |
| 165 | 170 |
| 166 if (extra_data->suppress_javascript_messages_) { | 171 if (extra_data->suppress_javascript_messages_) { |
| 167 *did_suppress_message = true; | 172 *did_suppress_message = true; |
| 168 return; | 173 return; |
| 169 } | 174 } |
| 170 | 175 |
| 171 base::TimeDelta time_since_last_message = base::TimeTicks::Now() - | 176 base::TimeDelta time_since_last_message = base::TimeTicks::Now() - |
| 172 extra_data->last_javascript_message_dismissal_; | 177 extra_data->last_javascript_message_dismissal_; |
| 173 bool display_suppress_checkbox = false; | 178 bool display_suppress_checkbox = false; |
| 174 // Show a checkbox offering to suppress further messages if this message is | 179 // Show a checkbox offering to suppress further messages if this message is |
| 175 // being displayed within kJavaScriptMessageExpectedDelay of the last one. | 180 // being displayed within kJavaScriptMessageExpectedDelay of the last one. |
| 176 if (time_since_last_message < | 181 if (time_since_last_message < |
| 177 base::TimeDelta::FromMilliseconds( | 182 base::TimeDelta::FromMilliseconds(kJavaScriptMessageExpectedDelay)) { |
| 178 chrome::kJavaScriptMessageExpectedDelay)) { | |
| 179 display_suppress_checkbox = true; | 183 display_suppress_checkbox = true; |
| 180 } else { | 184 } else { |
| 181 display_suppress_checkbox = false; | 185 display_suppress_checkbox = false; |
| 182 } | 186 } |
| 183 | 187 |
| 184 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT; | 188 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT; |
| 185 base::string16 dialog_title = | 189 base::string16 dialog_title = |
| 186 GetTitle(web_contents, origin_url, accept_lang, is_alert); | 190 GetTitle(web_contents, origin_url, accept_lang, is_alert); |
| 187 | 191 |
| 188 IncrementLazyKeepaliveCount(web_contents); | 192 IncrementLazyKeepaliveCount(web_contents); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 DecrementLazyKeepaliveCount(web_contents); | 317 DecrementLazyKeepaliveCount(web_contents); |
| 314 | 318 |
| 315 callback.Run(success, user_input); | 319 callback.Run(success, user_input); |
| 316 } | 320 } |
| 317 | 321 |
| 318 } // namespace | 322 } // namespace |
| 319 | 323 |
| 320 content::JavaScriptDialogManager* GetJavaScriptDialogManagerInstance() { | 324 content::JavaScriptDialogManager* GetJavaScriptDialogManagerInstance() { |
| 321 return ChromeJavaScriptDialogManager::GetInstance(); | 325 return ChromeJavaScriptDialogManager::GetInstance(); |
| 322 } | 326 } |
| OLD | NEW |