Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / app_modal_dialogs / app_modal_dialog_queue.cc
blob99af7ad303b8e7aa2955d8f010ede4d09fb07236
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h"
7 #include "base/memory/singleton.h"
8 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h"
10 // static
11 AppModalDialogQueue* AppModalDialogQueue::GetInstance() {
12 return Singleton<AppModalDialogQueue>::get();
15 void AppModalDialogQueue::AddDialog(AppModalDialog* dialog) {
16 if (!active_dialog_) {
17 ShowModalDialog(dialog);
18 return;
20 app_modal_dialog_queue_.push_back(dialog);
23 void AppModalDialogQueue::ShowNextDialog() {
24 AppModalDialog* dialog = GetNextDialog();
25 if (dialog)
26 ShowModalDialog(dialog);
27 else
28 active_dialog_ = NULL;
31 void AppModalDialogQueue::ActivateModalDialog() {
32 if (showing_modal_dialog_) {
33 // As part of showing a modal dialog we may end up back in this method
34 // (showing a dialog activates the WebContents, which can trigger a call
35 // to ActivateModalDialog). We ignore such a request as after the call to
36 // activate the tab contents the dialog is shown.
37 return;
39 if (active_dialog_)
40 active_dialog_->ActivateModalDialog();
43 bool AppModalDialogQueue::HasActiveDialog() const {
44 return active_dialog_ != NULL;
47 AppModalDialogQueue::AppModalDialogQueue()
48 : active_dialog_(NULL),
49 showing_modal_dialog_(false) {
52 AppModalDialogQueue::~AppModalDialogQueue() {
55 void AppModalDialogQueue::ShowModalDialog(AppModalDialog* dialog) {
56 // Be sure and set the active_dialog_ field first, otherwise if
57 // ShowModalDialog triggers a call back to the queue they'll get the old
58 // dialog. Also, if the dialog calls |ShowNextDialog()| before returning, that
59 // would write NULL into |active_dialog_| and this function would then undo
60 // that.
61 active_dialog_ = dialog;
62 showing_modal_dialog_ = true;
63 dialog->ShowModalDialog();
64 showing_modal_dialog_ = false;
67 AppModalDialog* AppModalDialogQueue::GetNextDialog() {
68 while (!app_modal_dialog_queue_.empty()) {
69 AppModalDialog* dialog = app_modal_dialog_queue_.front();
70 app_modal_dialog_queue_.pop_front();
71 if (dialog->IsValid())
72 return dialog;
73 delete dialog;
75 return NULL;