| 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; |
| 32 using content::WebContents; | 30 using content::WebContents; |
| 33 | 31 |
| 34 #if defined(ENABLE_EXTENSIONS) | 32 #if defined(ENABLE_EXTENSIONS) |
| 35 using extensions::Extension; | 33 using extensions::Extension; |
| 36 #endif // defined(ENABLE_EXTENSIONS) | 34 #endif // defined(ENABLE_EXTENSIONS) |
| 37 | 35 |
| 38 namespace { | 36 namespace { |
| 39 | 37 |
| 38 // If a WebContents is impolite and displays a second JavaScript alert within |
| 39 // kJavaScriptMessageExpectedDelay of a previous JavaScript alert being |
| 40 // dismissed, display an option to suppress future alerts from this WebContents. |
| 41 const int kJavaScriptMessageExpectedDelay = 1000; |
| 42 |
| 40 #if defined(ENABLE_EXTENSIONS) | 43 #if defined(ENABLE_EXTENSIONS) |
| 41 // Returns the ProcessManager for the browser context from |web_contents|. | 44 // Returns the ProcessManager for the browser context from |web_contents|. |
| 42 extensions::ProcessManager* GetExtensionsProcessManager( | 45 extensions::ProcessManager* GetExtensionsProcessManager( |
| 43 WebContents* web_contents) { | 46 WebContents* web_contents) { |
| 44 return extensions::ExtensionSystem::Get( | 47 return extensions::ExtensionSystem::Get( |
| 45 web_contents->GetBrowserContext())->process_manager(); | 48 web_contents->GetBrowserContext())->process_manager(); |
| 46 } | 49 } |
| 47 | 50 |
| 48 // Returns the extension associated with |web_contents| or NULL if there is no | 51 // Returns the extension associated with |web_contents| or NULL if there is no |
| 49 // associated extension (or extensions are not supported). | 52 // associated extension (or extensions are not supported). |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 *did_suppress_message = true; | 170 *did_suppress_message = true; |
| 168 return; | 171 return; |
| 169 } | 172 } |
| 170 | 173 |
| 171 base::TimeDelta time_since_last_message = base::TimeTicks::Now() - | 174 base::TimeDelta time_since_last_message = base::TimeTicks::Now() - |
| 172 extra_data->last_javascript_message_dismissal_; | 175 extra_data->last_javascript_message_dismissal_; |
| 173 bool display_suppress_checkbox = false; | 176 bool display_suppress_checkbox = false; |
| 174 // Show a checkbox offering to suppress further messages if this message is | 177 // Show a checkbox offering to suppress further messages if this message is |
| 175 // being displayed within kJavaScriptMessageExpectedDelay of the last one. | 178 // being displayed within kJavaScriptMessageExpectedDelay of the last one. |
| 176 if (time_since_last_message < | 179 if (time_since_last_message < |
| 177 base::TimeDelta::FromMilliseconds( | 180 base::TimeDelta::FromMilliseconds(kJavaScriptMessageExpectedDelay)) { |
| 178 chrome::kJavaScriptMessageExpectedDelay)) { | |
| 179 display_suppress_checkbox = true; | 181 display_suppress_checkbox = true; |
| 180 } else { | 182 } else { |
| 181 display_suppress_checkbox = false; | 183 display_suppress_checkbox = false; |
| 182 } | 184 } |
| 183 | 185 |
| 184 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT; | 186 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT; |
| 185 base::string16 dialog_title = | 187 base::string16 dialog_title = |
| 186 GetTitle(web_contents, origin_url, accept_lang, is_alert); | 188 GetTitle(web_contents, origin_url, accept_lang, is_alert); |
| 187 | 189 |
| 188 IncrementLazyKeepaliveCount(web_contents); | 190 IncrementLazyKeepaliveCount(web_contents); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 DecrementLazyKeepaliveCount(web_contents); | 315 DecrementLazyKeepaliveCount(web_contents); |
| 314 | 316 |
| 315 callback.Run(success, user_input); | 317 callback.Run(success, user_input); |
| 316 } | 318 } |
| 317 | 319 |
| 318 } // namespace | 320 } // namespace |
| 319 | 321 |
| 320 content::JavaScriptDialogManager* GetJavaScriptDialogManagerInstance() { | 322 content::JavaScriptDialogManager* GetJavaScriptDialogManagerInstance() { |
| 321 return ChromeJavaScriptDialogManager::GetInstance(); | 323 return ChromeJavaScriptDialogManager::GetInstance(); |
| 322 } | 324 } |
| OLD | NEW |