Chromium Code Reviews| 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/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "components/app_modal/app_modal_dialog.h" | 14 #include "components/app_modal/app_modal_dialog.h" |
| 15 #include "components/app_modal/app_modal_dialog_queue.h" | 15 #include "components/app_modal/app_modal_dialog_queue.h" |
| 16 #include "components/app_modal/javascript_app_modal_dialog.h" | 16 #include "components/app_modal/javascript_app_modal_dialog.h" |
| 17 #include "components/app_modal/javascript_dialog_extensions_client.h" | 17 #include "components/app_modal/javascript_dialog_extensions_client.h" |
| 18 #include "components/app_modal/javascript_native_dialog_factory.h" | 18 #include "components/app_modal/javascript_native_dialog_factory.h" |
| 19 #include "components/app_modal/native_app_modal_dialog.h" | 19 #include "components/app_modal/native_app_modal_dialog.h" |
| 20 #include "components/url_formatter/elide_url.h" | 20 #include "components/url_formatter/elide_url.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/common/javascript_message_type.h" | 22 #include "content/public/common/javascript_message_type.h" |
| 23 #include "grit/components_strings.h" | 23 #include "grit/components_strings.h" |
| 24 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "ui/gfx/font_list.h" | 26 #include "ui/gfx/font_list.h" |
| 27 #include "ui/gfx/text_elider.h" | |
| 27 | 28 |
| 28 namespace app_modal { | 29 namespace app_modal { |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 #if !defined(OS_ANDROID) | 32 #if !defined(OS_ANDROID) |
| 32 // Keep in sync with kDefaultMessageWidth, but allow some space for the rest of | 33 // Keep in sync with kDefaultMessageWidth, but allow some space for the rest of |
| 33 // the text. | 34 // the text. |
| 34 const int kUrlElideWidth = 350; | 35 const int kUrlElideWidth = 350; |
| 35 #endif | 36 #endif |
| 36 | 37 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 if (!last_close_time_.is_null()) { | 139 if (!last_close_time_.is_null()) { |
| 139 UMA_HISTOGRAM_MEDIUM_TIMES( | 140 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 140 "JSDialogs.FineTiming.TimeBetweenDialogClosedAndNextDialogCreated", | 141 "JSDialogs.FineTiming.TimeBetweenDialogClosedAndNextDialogCreated", |
| 141 now - last_close_time_); | 142 now - last_close_time_); |
| 142 last_close_time_ = base::TimeTicks(); | 143 last_close_time_ = base::TimeTicks(); |
| 143 } | 144 } |
| 144 | 145 |
| 145 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT; | 146 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT; |
| 146 base::string16 dialog_title = | 147 base::string16 dialog_title = |
| 147 GetTitle(web_contents, origin_url, accept_lang, is_alert); | 148 GetTitle(web_contents, origin_url, accept_lang, is_alert); |
| 149 // If you can't say it in 100 characters, it doesn't need to be said. | |
| 150 base::string16 message = | |
| 151 gfx::TruncateString(message_text, 100, gfx::CHARACTER_BREAK); | |
| 148 | 152 |
| 149 extensions_client_->OnDialogOpened(web_contents); | 153 extensions_client_->OnDialogOpened(web_contents); |
| 150 | 154 |
| 151 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( | 155 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( |
| 152 web_contents, | 156 web_contents, |
| 153 &javascript_dialog_extra_data_, | 157 &javascript_dialog_extra_data_, |
| 154 dialog_title, | 158 dialog_title, |
| 155 message_type, | 159 message_type, |
| 156 message_text, | 160 message, |
| 157 default_prompt_text, | 161 default_prompt_text, |
| 158 ShouldDisplaySuppressCheckbox(extra_data), | 162 ShouldDisplaySuppressCheckbox(extra_data), |
| 159 false, // is_before_unload_dialog | 163 false, // is_before_unload_dialog |
| 160 false, // is_reload | 164 false, // is_reload |
| 161 base::Bind(&JavaScriptDialogManager::OnDialogClosed, | 165 base::Bind(&JavaScriptDialogManager::OnDialogClosed, |
| 162 base::Unretained(this), web_contents, callback))); | 166 base::Unretained(this), web_contents, callback))); |
| 163 } | 167 } |
| 164 | 168 |
| 165 void JavaScriptDialogManager::RunBeforeUnloadDialog( | 169 void JavaScriptDialogManager::RunBeforeUnloadDialog( |
| 166 content::WebContents* web_contents, | 170 content::WebContents* web_contents, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 177 // lost its privilege to deny unloading. | 181 // lost its privilege to deny unloading. |
| 178 callback.Run(true, base::string16()); | 182 callback.Run(true, base::string16()); |
| 179 return; | 183 return; |
| 180 } | 184 } |
| 181 | 185 |
| 182 const base::string16 title = l10n_util::GetStringUTF16(is_reload ? | 186 const base::string16 title = l10n_util::GetStringUTF16(is_reload ? |
| 183 IDS_BEFORERELOAD_MESSAGEBOX_TITLE : IDS_BEFOREUNLOAD_MESSAGEBOX_TITLE); | 187 IDS_BEFORERELOAD_MESSAGEBOX_TITLE : IDS_BEFOREUNLOAD_MESSAGEBOX_TITLE); |
| 184 const base::string16 footer = l10n_util::GetStringUTF16(is_reload ? | 188 const base::string16 footer = l10n_util::GetStringUTF16(is_reload ? |
| 185 IDS_BEFORERELOAD_MESSAGEBOX_FOOTER : IDS_BEFOREUNLOAD_MESSAGEBOX_FOOTER); | 189 IDS_BEFORERELOAD_MESSAGEBOX_FOOTER : IDS_BEFOREUNLOAD_MESSAGEBOX_FOOTER); |
| 186 | 190 |
| 191 // If you can't say it in 100 characters, it doesn't need to be said. | |
| 187 base::string16 full_message = | 192 base::string16 full_message = |
| 188 message_text + base::ASCIIToUTF16("\n\n") + footer; | 193 gfx::TruncateString(message_text, 100, gfx::CHARACTER_BREAK) + |
|
palmer
2016/02/18 21:51:10
Rather than repeat the code and comment, abstract
| |
| 194 base::ASCIIToUTF16("\n\n") + footer; | |
| 189 | 195 |
| 190 extensions_client_->OnDialogOpened(web_contents); | 196 extensions_client_->OnDialogOpened(web_contents); |
| 191 | 197 |
| 192 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( | 198 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( |
| 193 web_contents, | 199 web_contents, |
| 194 &javascript_dialog_extra_data_, | 200 &javascript_dialog_extra_data_, |
| 195 title, | 201 title, |
| 196 content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM, | 202 content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM, |
| 197 full_message, | 203 full_message, |
| 198 base::string16(), // default_prompt_text | 204 base::string16(), // default_prompt_text |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 // lazy background page after the dialog closes. (Dialogs are closed before | 301 // lazy background page after the dialog closes. (Dialogs are closed before |
| 296 // their WebContents is destroyed so |web_contents| is still valid here.) | 302 // their WebContents is destroyed so |web_contents| is still valid here.) |
| 297 extensions_client_->OnDialogClosed(web_contents); | 303 extensions_client_->OnDialogClosed(web_contents); |
| 298 | 304 |
| 299 last_close_time_ = base::TimeTicks::Now(); | 305 last_close_time_ = base::TimeTicks::Now(); |
| 300 | 306 |
| 301 callback.Run(success, user_input); | 307 callback.Run(success, user_input); |
| 302 } | 308 } |
| 303 | 309 |
| 304 } // namespace app_modal | 310 } // namespace app_modal |
| OLD | NEW |