| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 &javascript_dialog_extra_data_[web_contents]; | 162 &javascript_dialog_extra_data_[web_contents]; |
| 165 | 163 |
| 166 if (extra_data->suppress_javascript_messages_) { | 164 if (extra_data->suppress_javascript_messages_) { |
| 167 *did_suppress_message = true; | 165 *did_suppress_message = true; |
| 168 return; | 166 return; |
| 169 } | 167 } |
| 170 | 168 |
| 171 base::TimeDelta time_since_last_message = base::TimeTicks::Now() - | 169 base::TimeDelta time_since_last_message = base::TimeTicks::Now() - |
| 172 extra_data->last_javascript_message_dismissal_; | 170 extra_data->last_javascript_message_dismissal_; |
| 173 bool display_suppress_checkbox = false; | 171 bool display_suppress_checkbox = false; |
| 174 // Show a checkbox offering to suppress further messages if this message is | 172 // If a WebContents is impolite and displays a second JavaScript |
| 175 // being displayed within kJavaScriptMessageExpectedDelay of the last one. | 173 // alert within kJavaScriptMessageExpectedDelay of a previous |
| 174 // JavaScript alert being dismissed, show a checkbox offering to |
| 175 // suppress future alerts from this WebContents. |
| 176 const int kJavaScriptMessageExpectedDelay = 1000; |
| 177 |
| 176 if (time_since_last_message < | 178 if (time_since_last_message < |
| 177 base::TimeDelta::FromMilliseconds( | 179 base::TimeDelta::FromMilliseconds(kJavaScriptMessageExpectedDelay)) { |
| 178 chrome::kJavaScriptMessageExpectedDelay)) { | |
| 179 display_suppress_checkbox = true; | 180 display_suppress_checkbox = true; |
| 180 } else { | 181 } else { |
| 181 display_suppress_checkbox = false; | 182 display_suppress_checkbox = false; |
| 182 } | 183 } |
| 183 | 184 |
| 184 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT; | 185 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT; |
| 185 base::string16 dialog_title = | 186 base::string16 dialog_title = |
| 186 GetTitle(web_contents, origin_url, accept_lang, is_alert); | 187 GetTitle(web_contents, origin_url, accept_lang, is_alert); |
| 187 | 188 |
| 188 IncrementLazyKeepaliveCount(web_contents); | 189 IncrementLazyKeepaliveCount(web_contents); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 DecrementLazyKeepaliveCount(web_contents); | 314 DecrementLazyKeepaliveCount(web_contents); |
| 314 | 315 |
| 315 callback.Run(success, user_input); | 316 callback.Run(success, user_input); |
| 316 } | 317 } |
| 317 | 318 |
| 318 } // namespace | 319 } // namespace |
| 319 | 320 |
| 320 content::JavaScriptDialogManager* GetJavaScriptDialogManagerInstance() { | 321 content::JavaScriptDialogManager* GetJavaScriptDialogManagerInstance() { |
| 321 return ChromeJavaScriptDialogManager::GetInstance(); | 322 return ChromeJavaScriptDialogManager::GetInstance(); |
| 322 } | 323 } |
| OLD | NEW |