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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "components/app_modal/app_modal_dialog.h" | 13 #include "components/app_modal/app_modal_dialog.h" |
14 #include "components/app_modal/app_modal_dialog_queue.h" | 14 #include "components/app_modal/app_modal_dialog_queue.h" |
15 #include "components/app_modal/javascript_app_modal_dialog.h" | 15 #include "components/app_modal/javascript_app_modal_dialog.h" |
16 #include "components/app_modal/javascript_dialog_extensions_client.h" | 16 #include "components/app_modal/javascript_dialog_extensions_client.h" |
17 #include "components/app_modal/javascript_native_dialog_factory.h" | 17 #include "components/app_modal/javascript_native_dialog_factory.h" |
18 #include "components/app_modal/native_app_modal_dialog.h" | 18 #include "components/app_modal/native_app_modal_dialog.h" |
19 #include "components/url_formatter/elide_url.h" | 19 #include "components/url_formatter/elide_url.h" |
20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
21 #include "content/public/common/javascript_message_type.h" | 21 #include "content/public/common/javascript_message_type.h" |
22 #include "grit/components_strings.h" | 22 #include "grit/components_strings.h" |
23 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
24 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/gfx/font_list.h" |
25 | 26 |
26 namespace app_modal { | 27 namespace app_modal { |
27 namespace { | 28 namespace { |
28 | 29 |
| 30 #if !defined(OS_ANDROID) |
| 31 // Keep in sync with kDefaultMessageWidth, but allow some space for the rest of |
| 32 // the text. |
| 33 const int kUrlElideWidth = 350; |
| 34 #endif |
| 35 |
29 class DefaultExtensionsClient : public JavaScriptDialogExtensionsClient { | 36 class DefaultExtensionsClient : public JavaScriptDialogExtensionsClient { |
30 public: | 37 public: |
31 DefaultExtensionsClient() {} | 38 DefaultExtensionsClient() {} |
32 ~DefaultExtensionsClient() override {} | 39 ~DefaultExtensionsClient() override {} |
33 | 40 |
34 private: | 41 private: |
35 // JavaScriptDialogExtensionsClient: | 42 // JavaScriptDialogExtensionsClient: |
36 void OnDialogOpened(content::WebContents* web_contents) override {} | 43 void OnDialogOpened(content::WebContents* web_contents) override {} |
37 void OnDialogClosed(content::WebContents* web_contents) override {} | 44 void OnDialogClosed(content::WebContents* web_contents) override {} |
38 bool GetExtensionName(content::WebContents* web_contents, | 45 bool GetExtensionName(content::WebContents* web_contents, |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 std::string name; | 208 std::string name; |
202 if (extensions_client_->GetExtensionName(web_contents, origin_url, &name)) | 209 if (extensions_client_->GetExtensionName(web_contents, origin_url, &name)) |
203 return base::UTF8ToUTF16(name); | 210 return base::UTF8ToUTF16(name); |
204 | 211 |
205 // Otherwise, return the formatted URL. For non-standard URLs such as |data:|, | 212 // Otherwise, return the formatted URL. For non-standard URLs such as |data:|, |
206 // just say "This page". | 213 // just say "This page". |
207 bool is_same_origin_as_main_frame = | 214 bool is_same_origin_as_main_frame = |
208 (web_contents->GetURL().GetOrigin() == origin_url.GetOrigin()); | 215 (web_contents->GetURL().GetOrigin() == origin_url.GetOrigin()); |
209 if (origin_url.IsStandard() && !origin_url.SchemeIsFile() && | 216 if (origin_url.IsStandard() && !origin_url.SchemeIsFile() && |
210 !origin_url.SchemeIsFileSystem()) { | 217 !origin_url.SchemeIsFileSystem()) { |
| 218 #if !defined(OS_ANDROID) |
| 219 base::string16 url_string = |
| 220 url_formatter::ElideHost(origin_url, gfx::FontList(), kUrlElideWidth); |
| 221 #else |
211 base::string16 url_string = | 222 base::string16 url_string = |
212 url_formatter::FormatUrlForSecurityDisplayOmitScheme(origin_url, | 223 url_formatter::FormatUrlForSecurityDisplayOmitScheme(origin_url, |
213 accept_lang); | 224 accept_lang); |
| 225 #endif |
214 return l10n_util::GetStringFUTF16( | 226 return l10n_util::GetStringFUTF16( |
215 is_same_origin_as_main_frame ? IDS_JAVASCRIPT_MESSAGEBOX_TITLE | 227 is_same_origin_as_main_frame ? IDS_JAVASCRIPT_MESSAGEBOX_TITLE |
216 : IDS_JAVASCRIPT_MESSAGEBOX_TITLE_IFRAME, | 228 : IDS_JAVASCRIPT_MESSAGEBOX_TITLE_IFRAME, |
217 base::i18n::GetDisplayStringInLTRDirectionality(url_string)); | 229 base::i18n::GetDisplayStringInLTRDirectionality(url_string)); |
218 } | 230 } |
219 return l10n_util::GetStringUTF16( | 231 return l10n_util::GetStringUTF16( |
220 is_same_origin_as_main_frame | 232 is_same_origin_as_main_frame |
221 ? IDS_JAVASCRIPT_MESSAGEBOX_TITLE_NONSTANDARD_URL | 233 ? IDS_JAVASCRIPT_MESSAGEBOX_TITLE_NONSTANDARD_URL |
222 : IDS_JAVASCRIPT_MESSAGEBOX_TITLE_NONSTANDARD_URL_IFRAME); | 234 : IDS_JAVASCRIPT_MESSAGEBOX_TITLE_NONSTANDARD_URL_IFRAME); |
223 } | 235 } |
(...skipping 22 matching lines...) Expand all Loading... |
246 const base::string16& user_input) { | 258 const base::string16& user_input) { |
247 // If an extension opened this dialog then the extension may shut down its | 259 // If an extension opened this dialog then the extension may shut down its |
248 // lazy background page after the dialog closes. (Dialogs are closed before | 260 // lazy background page after the dialog closes. (Dialogs are closed before |
249 // their WebContents is destroyed so |web_contents| is still valid here.) | 261 // their WebContents is destroyed so |web_contents| is still valid here.) |
250 extensions_client_->OnDialogClosed(web_contents); | 262 extensions_client_->OnDialogClosed(web_contents); |
251 | 263 |
252 callback.Run(success, user_input); | 264 callback.Run(success, user_input); |
253 } | 265 } |
254 | 266 |
255 } // namespace app_modal | 267 } // namespace app_modal |
OLD | NEW |