OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/app_modal/javascript_dialog_manager.h" | 5 #include "components/app_modal/javascript_dialog_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 JavaScriptDialogManager::JavaScriptDialogManager() | 94 JavaScriptDialogManager::JavaScriptDialogManager() |
95 : extensions_client_(new DefaultExtensionsClient) { | 95 : extensions_client_(new DefaultExtensionsClient) { |
96 } | 96 } |
97 | 97 |
98 JavaScriptDialogManager::~JavaScriptDialogManager() { | 98 JavaScriptDialogManager::~JavaScriptDialogManager() { |
99 } | 99 } |
100 | 100 |
101 void JavaScriptDialogManager::RunJavaScriptDialog( | 101 void JavaScriptDialogManager::RunJavaScriptDialog( |
102 content::WebContents* web_contents, | 102 content::WebContents* web_contents, |
103 const GURL& origin_url, | 103 const GURL& origin_url, |
104 const std::string& accept_lang, | |
105 content::JavaScriptMessageType message_type, | 104 content::JavaScriptMessageType message_type, |
106 const base::string16& message_text, | 105 const base::string16& message_text, |
107 const base::string16& default_prompt_text, | 106 const base::string16& default_prompt_text, |
108 const DialogClosedCallback& callback, | 107 const DialogClosedCallback& callback, |
109 bool* did_suppress_message) { | 108 bool* did_suppress_message) { |
110 *did_suppress_message = false; | 109 *did_suppress_message = false; |
111 | 110 |
112 ChromeJavaScriptDialogExtraData* extra_data = | 111 ChromeJavaScriptDialogExtraData* extra_data = |
113 &javascript_dialog_extra_data_[web_contents]; | 112 &javascript_dialog_extra_data_[web_contents]; |
114 | 113 |
(...skipping 30 matching lines...) Expand all Loading... |
145 // Also log the time since a dialog was closed, but only if this is the first | 144 // Also log the time since a dialog was closed, but only if this is the first |
146 // dialog that was opened since the closing. | 145 // dialog that was opened since the closing. |
147 if (!last_close_time_.is_null()) { | 146 if (!last_close_time_.is_null()) { |
148 UMA_HISTOGRAM_MEDIUM_TIMES( | 147 UMA_HISTOGRAM_MEDIUM_TIMES( |
149 "JSDialogs.FineTiming.TimeBetweenDialogClosedAndNextDialogCreated", | 148 "JSDialogs.FineTiming.TimeBetweenDialogClosedAndNextDialogCreated", |
150 now - last_close_time_); | 149 now - last_close_time_); |
151 last_close_time_ = base::TimeTicks(); | 150 last_close_time_ = base::TimeTicks(); |
152 } | 151 } |
153 | 152 |
154 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT; | 153 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT; |
155 base::string16 dialog_title = | 154 base::string16 dialog_title = GetTitle(web_contents, origin_url, is_alert); |
156 GetTitle(web_contents, origin_url, accept_lang, is_alert); | |
157 | 155 |
158 extensions_client_->OnDialogOpened(web_contents); | 156 extensions_client_->OnDialogOpened(web_contents); |
159 | 157 |
160 LogUMAMessageLengthStats(message_text); | 158 LogUMAMessageLengthStats(message_text); |
161 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( | 159 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( |
162 web_contents, | 160 web_contents, |
163 &javascript_dialog_extra_data_, | 161 &javascript_dialog_extra_data_, |
164 dialog_title, | 162 dialog_title, |
165 message_type, | 163 message_type, |
166 message_text, | 164 message_text, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 243 |
246 void JavaScriptDialogManager::ResetDialogState( | 244 void JavaScriptDialogManager::ResetDialogState( |
247 content::WebContents* web_contents) { | 245 content::WebContents* web_contents) { |
248 CancelActiveAndPendingDialogs(web_contents); | 246 CancelActiveAndPendingDialogs(web_contents); |
249 javascript_dialog_extra_data_.erase(web_contents); | 247 javascript_dialog_extra_data_.erase(web_contents); |
250 } | 248 } |
251 | 249 |
252 base::string16 JavaScriptDialogManager::GetTitle( | 250 base::string16 JavaScriptDialogManager::GetTitle( |
253 content::WebContents* web_contents, | 251 content::WebContents* web_contents, |
254 const GURL& origin_url, | 252 const GURL& origin_url, |
255 const std::string& accept_lang, | |
256 bool is_alert) { | 253 bool is_alert) { |
257 // For extensions, show the extension name, but only if the origin of | 254 // For extensions, show the extension name, but only if the origin of |
258 // the alert matches the top-level WebContents. | 255 // the alert matches the top-level WebContents. |
259 std::string name; | 256 std::string name; |
260 if (extensions_client_->GetExtensionName(web_contents, origin_url, &name)) | 257 if (extensions_client_->GetExtensionName(web_contents, origin_url, &name)) |
261 return base::UTF8ToUTF16(name); | 258 return base::UTF8ToUTF16(name); |
262 | 259 |
263 // Otherwise, return the formatted URL. For non-standard URLs such as |data:|, | 260 // Otherwise, return the formatted URL. For non-standard URLs such as |data:|, |
264 // just say "This page". | 261 // just say "This page". |
265 bool is_same_origin_as_main_frame = | 262 bool is_same_origin_as_main_frame = |
266 (web_contents->GetURL().GetOrigin() == origin_url.GetOrigin()); | 263 (web_contents->GetURL().GetOrigin() == origin_url.GetOrigin()); |
267 if (origin_url.IsStandard() && !origin_url.SchemeIsFile() && | 264 if (origin_url.IsStandard() && !origin_url.SchemeIsFile() && |
268 !origin_url.SchemeIsFileSystem()) { | 265 !origin_url.SchemeIsFileSystem()) { |
269 #if !defined(OS_ANDROID) | 266 #if !defined(OS_ANDROID) |
270 base::string16 url_string = | 267 base::string16 url_string = |
271 url_formatter::ElideHost(origin_url, gfx::FontList(), kUrlElideWidth); | 268 url_formatter::ElideHost(origin_url, gfx::FontList(), kUrlElideWidth); |
272 #else | 269 #else |
273 base::string16 url_string = | 270 base::string16 url_string = |
274 url_formatter::FormatUrlForSecurityDisplayOmitScheme(origin_url, | 271 url_formatter::FormatUrlForSecurityDisplayOmitScheme(origin_url); |
275 accept_lang); | |
276 #endif | 272 #endif |
277 return l10n_util::GetStringFUTF16( | 273 return l10n_util::GetStringFUTF16( |
278 is_same_origin_as_main_frame ? IDS_JAVASCRIPT_MESSAGEBOX_TITLE | 274 is_same_origin_as_main_frame ? IDS_JAVASCRIPT_MESSAGEBOX_TITLE |
279 : IDS_JAVASCRIPT_MESSAGEBOX_TITLE_IFRAME, | 275 : IDS_JAVASCRIPT_MESSAGEBOX_TITLE_IFRAME, |
280 base::i18n::GetDisplayStringInLTRDirectionality(url_string)); | 276 base::i18n::GetDisplayStringInLTRDirectionality(url_string)); |
281 } | 277 } |
282 return l10n_util::GetStringUTF16( | 278 return l10n_util::GetStringUTF16( |
283 is_same_origin_as_main_frame | 279 is_same_origin_as_main_frame |
284 ? IDS_JAVASCRIPT_MESSAGEBOX_TITLE_NONSTANDARD_URL | 280 ? IDS_JAVASCRIPT_MESSAGEBOX_TITLE_NONSTANDARD_URL |
285 : IDS_JAVASCRIPT_MESSAGEBOX_TITLE_NONSTANDARD_URL_IFRAME); | 281 : IDS_JAVASCRIPT_MESSAGEBOX_TITLE_NONSTANDARD_URL_IFRAME); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 // lazy background page after the dialog closes. (Dialogs are closed before | 325 // lazy background page after the dialog closes. (Dialogs are closed before |
330 // their WebContents is destroyed so |web_contents| is still valid here.) | 326 // their WebContents is destroyed so |web_contents| is still valid here.) |
331 extensions_client_->OnDialogClosed(web_contents); | 327 extensions_client_->OnDialogClosed(web_contents); |
332 | 328 |
333 last_close_time_ = base::TimeTicks::Now(); | 329 last_close_time_ = base::TimeTicks::Now(); |
334 | 330 |
335 callback.Run(success, user_input); | 331 callback.Run(success, user_input); |
336 } | 332 } |
337 | 333 |
338 } // namespace app_modal | 334 } // namespace app_modal |
OLD | NEW |