| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 *did_suppress_message = true; | 174 *did_suppress_message = true; |
| 172 return; | 175 return; |
| 173 } | 176 } |
| 174 | 177 |
| 175 base::TimeDelta time_since_last_message = base::TimeTicks::Now() - | 178 base::TimeDelta time_since_last_message = base::TimeTicks::Now() - |
| 176 extra_data->last_javascript_message_dismissal_; | 179 extra_data->last_javascript_message_dismissal_; |
| 177 bool display_suppress_checkbox = false; | 180 bool display_suppress_checkbox = false; |
| 178 // Show a checkbox offering to suppress further messages if this message is | 181 // Show a checkbox offering to suppress further messages if this message is |
| 179 // being displayed within kJavaScriptMessageExpectedDelay of the last one. | 182 // being displayed within kJavaScriptMessageExpectedDelay of the last one. |
| 180 if (time_since_last_message < | 183 if (time_since_last_message < |
| 181 base::TimeDelta::FromMilliseconds( | 184 base::TimeDelta::FromMilliseconds(kJavaScriptMessageExpectedDelay)) { |
| 182 chrome::kJavaScriptMessageExpectedDelay)) { | |
| 183 display_suppress_checkbox = true; | 185 display_suppress_checkbox = true; |
| 184 } else { | 186 } else { |
| 185 display_suppress_checkbox = false; | 187 display_suppress_checkbox = false; |
| 186 } | 188 } |
| 187 | 189 |
| 188 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT; | 190 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT; |
| 189 base::string16 dialog_title = | 191 base::string16 dialog_title = |
| 190 GetTitle(web_contents, origin_url, accept_lang, is_alert); | 192 GetTitle(web_contents, origin_url, accept_lang, is_alert); |
| 191 | 193 |
| 192 IncrementLazyKeepaliveCount(web_contents); | 194 IncrementLazyKeepaliveCount(web_contents); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 DecrementLazyKeepaliveCount(web_contents); | 319 DecrementLazyKeepaliveCount(web_contents); |
| 318 | 320 |
| 319 callback.Run(success, user_input); | 321 callback.Run(success, user_input); |
| 320 } | 322 } |
| 321 | 323 |
| 322 } // namespace | 324 } // namespace |
| 323 | 325 |
| 324 content::JavaScriptDialogManager* GetJavaScriptDialogManagerInstance() { | 326 content::JavaScriptDialogManager* GetJavaScriptDialogManagerInstance() { |
| 325 return ChromeJavaScriptDialogManager::GetInstance(); | 327 return ChromeJavaScriptDialogManager::GetInstance(); |
| 326 } | 328 } |
| OLD | NEW |