Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: components/app_modal/javascript_dialog_manager.cc

Issue 2684093002: Rename JavaScript "messages" to "dialogs". (Closed)
Patch Set: win fox Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "components/app_modal/app_modal_dialog.h" 15 #include "components/app_modal/app_modal_dialog.h"
16 #include "components/app_modal/app_modal_dialog_queue.h" 16 #include "components/app_modal/app_modal_dialog_queue.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_dialog_type.h"
23 #include "grit/components_strings.h" 23 #include "grit/components_strings.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 #include "ui/gfx/font_list.h"
26 26
27 namespace app_modal { 27 namespace app_modal {
28 28
29 namespace { 29 namespace {
30 30
31 #if !defined(OS_ANDROID) 31 #if !defined(OS_ANDROID)
32 // Keep in sync with kDefaultMessageWidth, but allow some space for the rest of 32 // Keep in sync with kDefaultMessageWidth, but allow some space for the rest of
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 121 }
122 return l10n_util::GetStringUTF16( 122 return l10n_util::GetStringUTF16(
123 is_same_origin_as_main_frame 123 is_same_origin_as_main_frame
124 ? IDS_JAVASCRIPT_MESSAGEBOX_TITLE_NONSTANDARD_URL 124 ? IDS_JAVASCRIPT_MESSAGEBOX_TITLE_NONSTANDARD_URL
125 : IDS_JAVASCRIPT_MESSAGEBOX_TITLE_NONSTANDARD_URL_IFRAME); 125 : IDS_JAVASCRIPT_MESSAGEBOX_TITLE_NONSTANDARD_URL_IFRAME);
126 } 126 }
127 127
128 void JavaScriptDialogManager::RunJavaScriptDialog( 128 void JavaScriptDialogManager::RunJavaScriptDialog(
129 content::WebContents* web_contents, 129 content::WebContents* web_contents,
130 const GURL& origin_url, 130 const GURL& origin_url,
131 content::JavaScriptMessageType message_type, 131 content::JavaScriptDialogType dialog_type,
132 const base::string16& message_text, 132 const base::string16& message_text,
133 const base::string16& default_prompt_text, 133 const base::string16& default_prompt_text,
134 const DialogClosedCallback& callback, 134 const DialogClosedCallback& callback,
135 bool* did_suppress_message) { 135 bool* did_suppress_message) {
136 *did_suppress_message = false; 136 *did_suppress_message = false;
137 137
138 ChromeJavaScriptDialogExtraData* extra_data = 138 ChromeJavaScriptDialogExtraData* extra_data =
139 &javascript_dialog_extra_data_[web_contents]; 139 &javascript_dialog_extra_data_[web_contents];
140 140
141 if (extra_data->suppress_javascript_messages_) { 141 if (extra_data->suppress_javascript_messages_) {
142 // If a page tries to open dialogs in a tight loop, the number of 142 // If a page tries to open dialogs in a tight loop, the number of
143 // suppressions logged can grow out of control. Arbitrarily cap the number 143 // suppressions logged can grow out of control. Arbitrarily cap the number
144 // logged at 100. That many suppressed dialogs is enough to indicate the 144 // logged at 100. That many suppressed dialogs is enough to indicate the
145 // page is doing something very hinky. 145 // page is doing something very hinky.
(...skipping 30 matching lines...) Expand all
176 now - last_close_time_); 176 now - last_close_time_);
177 last_close_time_ = base::TimeTicks(); 177 last_close_time_ = base::TimeTicks();
178 } 178 }
179 179
180 base::string16 dialog_title = GetTitle(web_contents, origin_url); 180 base::string16 dialog_title = GetTitle(web_contents, origin_url);
181 181
182 extensions_client_->OnDialogOpened(web_contents); 182 extensions_client_->OnDialogOpened(web_contents);
183 183
184 LogUMAMessageLengthStats(message_text); 184 LogUMAMessageLengthStats(message_text);
185 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( 185 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog(
186 web_contents, 186 web_contents, &javascript_dialog_extra_data_, dialog_title, dialog_type,
187 &javascript_dialog_extra_data_, 187 message_text, default_prompt_text,
188 dialog_title,
189 message_type,
190 message_text,
191 default_prompt_text,
192 ShouldDisplaySuppressCheckbox(extra_data), 188 ShouldDisplaySuppressCheckbox(extra_data),
193 false, // is_before_unload_dialog 189 false, // is_before_unload_dialog
194 false, // is_reload 190 false, // is_reload
195 base::Bind(&JavaScriptDialogManager::OnDialogClosed, 191 base::Bind(&JavaScriptDialogManager::OnDialogClosed,
196 base::Unretained(this), web_contents, callback))); 192 base::Unretained(this), web_contents, callback)));
197 } 193 }
198 194
199 void JavaScriptDialogManager::RunBeforeUnloadDialog( 195 void JavaScriptDialogManager::RunBeforeUnloadDialog(
200 content::WebContents* web_contents, 196 content::WebContents* web_contents,
201 bool is_reload, 197 bool is_reload,
(...skipping 23 matching lines...) Expand all
225 // is why we can't have nice things. 221 // is why we can't have nice things.
226 222
227 const base::string16 title = l10n_util::GetStringUTF16(is_reload ? 223 const base::string16 title = l10n_util::GetStringUTF16(is_reload ?
228 IDS_BEFORERELOAD_MESSAGEBOX_TITLE : IDS_BEFOREUNLOAD_MESSAGEBOX_TITLE); 224 IDS_BEFORERELOAD_MESSAGEBOX_TITLE : IDS_BEFOREUNLOAD_MESSAGEBOX_TITLE);
229 const base::string16 message = 225 const base::string16 message =
230 l10n_util::GetStringUTF16(IDS_BEFOREUNLOAD_MESSAGEBOX_MESSAGE); 226 l10n_util::GetStringUTF16(IDS_BEFOREUNLOAD_MESSAGEBOX_MESSAGE);
231 227
232 extensions_client_->OnDialogOpened(web_contents); 228 extensions_client_->OnDialogOpened(web_contents);
233 229
234 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( 230 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog(
235 web_contents, 231 web_contents, &javascript_dialog_extra_data_, title,
236 &javascript_dialog_extra_data_, 232 content::JAVASCRIPT_DIALOG_TYPE_CONFIRM, message,
237 title,
238 content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
239 message,
240 base::string16(), // default_prompt_text 233 base::string16(), // default_prompt_text
241 ShouldDisplaySuppressCheckbox(extra_data), 234 ShouldDisplaySuppressCheckbox(extra_data),
242 true, // is_before_unload_dialog 235 true, // is_before_unload_dialog
243 is_reload, 236 is_reload,
244 base::Bind(&JavaScriptDialogManager::OnBeforeUnloadDialogClosed, 237 base::Bind(&JavaScriptDialogManager::OnBeforeUnloadDialogClosed,
245 base::Unretained(this), web_contents, callback))); 238 base::Unretained(this), web_contents, callback)));
246 } 239 }
247 240
248 bool JavaScriptDialogManager::HandleJavaScriptDialog( 241 bool JavaScriptDialogManager::HandleJavaScriptDialog(
249 content::WebContents* web_contents, 242 content::WebContents* web_contents,
250 bool accept, 243 bool accept,
251 const base::string16* prompt_override) { 244 const base::string16* prompt_override) {
252 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); 245 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 // lazy background page after the dialog closes. (Dialogs are closed before 307 // lazy background page after the dialog closes. (Dialogs are closed before
315 // their WebContents is destroyed so |web_contents| is still valid here.) 308 // their WebContents is destroyed so |web_contents| is still valid here.)
316 extensions_client_->OnDialogClosed(web_contents); 309 extensions_client_->OnDialogClosed(web_contents);
317 310
318 last_close_time_ = base::TimeTicks::Now(); 311 last_close_time_ = base::TimeTicks::Now();
319 312
320 callback.Run(success, user_input); 313 callback.Run(success, user_input);
321 } 314 }
322 315
323 } // namespace app_modal 316 } // namespace app_modal
OLDNEW
« no previous file with comments | « components/app_modal/javascript_dialog_manager.h ('k') | components/app_modal/views/javascript_app_modal_dialog_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698