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

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

Issue 2901583002: Fold AppModalDialog into its only subclass, JavaScriptAppModalDialog. (Closed)
Patch Set: fix collapse Created 3 years, 6 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
« no previous file with comments | « components/app_modal/javascript_app_modal_dialog.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
16 #include "components/app_modal/app_modal_dialog_queue.h" 15 #include "components/app_modal/app_modal_dialog_queue.h"
17 #include "components/app_modal/javascript_dialog_extensions_client.h" 16 #include "components/app_modal/javascript_dialog_extensions_client.h"
18 #include "components/app_modal/javascript_native_dialog_factory.h" 17 #include "components/app_modal/javascript_native_dialog_factory.h"
19 #include "components/app_modal/native_app_modal_dialog.h" 18 #include "components/app_modal/native_app_modal_dialog.h"
20 #include "components/strings/grit/components_strings.h" 19 #include "components/strings/grit/components_strings.h"
21 #include "components/url_formatter/elide_url.h" 20 #include "components/url_formatter/elide_url.h"
22 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
23 #include "content/public/common/javascript_dialog_type.h" 22 #include "content/public/common/javascript_dialog_type.h"
24 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/gfx/font_list.h" 24 #include "ui/gfx/font_list.h"
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 base::Bind(&JavaScriptDialogManager::OnBeforeUnloadDialogClosed, 236 base::Bind(&JavaScriptDialogManager::OnBeforeUnloadDialogClosed,
238 base::Unretained(this), web_contents, callback))); 237 base::Unretained(this), web_contents, callback)));
239 } 238 }
240 239
241 bool JavaScriptDialogManager::HandleJavaScriptDialog( 240 bool JavaScriptDialogManager::HandleJavaScriptDialog(
242 content::WebContents* web_contents, 241 content::WebContents* web_contents,
243 bool accept, 242 bool accept,
244 const base::string16* prompt_override) { 243 const base::string16* prompt_override) {
245 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); 244 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance();
246 if (!dialog_queue->HasActiveDialog() || 245 if (!dialog_queue->HasActiveDialog() ||
247 !dialog_queue->active_dialog()->IsJavaScriptModalDialog() ||
248 dialog_queue->active_dialog()->web_contents() != web_contents) { 246 dialog_queue->active_dialog()->web_contents() != web_contents) {
249 return false; 247 return false;
250 } 248 }
251 249
252 JavaScriptAppModalDialog* dialog = static_cast<JavaScriptAppModalDialog*>( 250 JavaScriptAppModalDialog* dialog = static_cast<JavaScriptAppModalDialog*>(
253 dialog_queue->active_dialog()); 251 dialog_queue->active_dialog());
254 252
255 if (dialog->javascript_dialog_type() == 253 if (dialog->javascript_dialog_type() ==
256 content::JavaScriptDialogType::JAVASCRIPT_DIALOG_TYPE_ALERT) { 254 content::JavaScriptDialogType::JAVASCRIPT_DIALOG_TYPE_ALERT) {
257 // Alert dialogs only have one button: OK. Any "handling" of this dialog has 255 // Alert dialogs only have one button: OK. Any "handling" of this dialog has
258 // to be a click on the OK button. 256 // to be a click on the OK button.
259 accept = true; 257 accept = true;
260 } 258 }
261 259
262 if (accept) { 260 if (accept) {
263 if (prompt_override) 261 if (prompt_override)
264 dialog->SetOverridePromptText(*prompt_override); 262 dialog->SetOverridePromptText(*prompt_override);
265 dialog->native_dialog()->AcceptAppModalDialog(); 263 dialog->native_dialog()->AcceptAppModalDialog();
266 } else { 264 } else {
267 dialog->native_dialog()->CancelAppModalDialog(); 265 dialog->native_dialog()->CancelAppModalDialog();
268 } 266 }
269 return true; 267 return true;
270 } 268 }
271 269
272 void JavaScriptDialogManager::CancelDialogs(content::WebContents* web_contents, 270 void JavaScriptDialogManager::CancelDialogs(content::WebContents* web_contents,
273 bool reset_state) { 271 bool reset_state) {
274 AppModalDialogQueue* queue = AppModalDialogQueue::GetInstance(); 272 AppModalDialogQueue* queue = AppModalDialogQueue::GetInstance();
275 AppModalDialog* active_dialog = queue->active_dialog(); 273 JavaScriptAppModalDialog* active_dialog = queue->active_dialog();
276 for (AppModalDialogQueue::iterator i = queue->begin(); 274 for (auto* dialog : *queue) {
277 i != queue->end(); ++i) {
278 // Invalidating the active dialog might trigger showing a not-yet 275 // Invalidating the active dialog might trigger showing a not-yet
279 // invalidated dialog, so invalidate the active dialog last. 276 // invalidated dialog, so invalidate the active dialog last.
280 if ((*i) == active_dialog) 277 if (dialog == active_dialog)
281 continue; 278 continue;
282 if ((*i)->web_contents() == web_contents) 279 if (dialog->web_contents() == web_contents)
283 (*i)->Invalidate(); 280 dialog->Invalidate();
284 } 281 }
285 if (active_dialog && active_dialog->web_contents() == web_contents) 282 if (active_dialog && active_dialog->web_contents() == web_contents)
286 active_dialog->Invalidate(); 283 active_dialog->Invalidate();
287 284
288 if (reset_state) 285 if (reset_state)
289 javascript_dialog_extra_data_.erase(web_contents); 286 javascript_dialog_extra_data_.erase(web_contents);
290 } 287 }
291 288
292 void JavaScriptDialogManager::OnBeforeUnloadDialogClosed( 289 void JavaScriptDialogManager::OnBeforeUnloadDialogClosed(
293 content::WebContents* web_contents, 290 content::WebContents* web_contents,
(...skipping 22 matching lines...) Expand all
316 // lazy background page after the dialog closes. (Dialogs are closed before 313 // lazy background page after the dialog closes. (Dialogs are closed before
317 // their WebContents is destroyed so |web_contents| is still valid here.) 314 // their WebContents is destroyed so |web_contents| is still valid here.)
318 extensions_client_->OnDialogClosed(web_contents); 315 extensions_client_->OnDialogClosed(web_contents);
319 316
320 last_close_time_ = base::TimeTicks::Now(); 317 last_close_time_ = base::TimeTicks::Now();
321 318
322 callback.Run(success, user_input); 319 callback.Run(success, user_input);
323 } 320 }
324 321
325 } // namespace app_modal 322 } // namespace app_modal
OLDNEW
« no previous file with comments | « components/app_modal/javascript_app_modal_dialog.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698