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 const int kJavaScriptMessageExpectedDelay = 1000; | |
msw
2014/10/23 22:01:24
nit: move this down to where it's used too... or r
oshima
2014/10/24 11:17:04
Done.
| |
161 | |
161 *did_suppress_message = false; | 162 *did_suppress_message = false; |
162 | 163 |
163 ChromeJavaScriptDialogExtraData* extra_data = | 164 ChromeJavaScriptDialogExtraData* extra_data = |
164 &javascript_dialog_extra_data_[web_contents]; | 165 &javascript_dialog_extra_data_[web_contents]; |
165 | 166 |
166 if (extra_data->suppress_javascript_messages_) { | 167 if (extra_data->suppress_javascript_messages_) { |
167 *did_suppress_message = true; | 168 *did_suppress_message = true; |
168 return; | 169 return; |
169 } | 170 } |
170 | 171 |
171 base::TimeDelta time_since_last_message = base::TimeTicks::Now() - | 172 base::TimeDelta time_since_last_message = base::TimeTicks::Now() - |
172 extra_data->last_javascript_message_dismissal_; | 173 extra_data->last_javascript_message_dismissal_; |
173 bool display_suppress_checkbox = false; | 174 bool display_suppress_checkbox = false; |
174 // Show a checkbox offering to suppress further messages if this message is | 175 // If a WebContents is impolite and displays a second JavaScript |
175 // being displayed within kJavaScriptMessageExpectedDelay of the last one. | 176 // alert within kJavaScriptMessageExpectedDelay of a previous |
177 // JavaScript alert being dismissed, show a checkbox offering to | |
178 // suppress future alerts from this WebContents. | |
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 |