Credential Manager API shouldn't save passwords from incognito.
[chromium-blink-merge.git] / components / app_modal / app_modal_dialog_queue.cc
blob2bb527d709af1e5ee4f377fd9c7dfae4f7bbde67
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 "components/app_modal/app_modal_dialog_queue.h"
7 #include "base/memory/singleton.h"
8 #include "components/app_modal/app_modal_dialog.h"
10 namespace app_modal {
12 // static
13 AppModalDialogQueue* AppModalDialogQueue::GetInstance() {
14 return Singleton<AppModalDialogQueue>::get();
17 void AppModalDialogQueue::AddDialog(AppModalDialog* dialog) {
18 if (!active_dialog_) {
19 ShowModalDialog(dialog);
20 return;
22 app_modal_dialog_queue_.push_back(dialog);
25 void AppModalDialogQueue::ShowNextDialog() {
26 AppModalDialog* dialog = GetNextDialog();
27 if (dialog)
28 ShowModalDialog(dialog);
29 else
30 active_dialog_ = NULL;
33 void AppModalDialogQueue::ActivateModalDialog() {
34 if (showing_modal_dialog_) {
35 // As part of showing a modal dialog we may end up back in this method
36 // (showing a dialog activates the WebContents, which can trigger a call
37 // to ActivateModalDialog). We ignore such a request as after the call to
38 // activate the tab contents the dialog is shown.
39 return;
41 if (active_dialog_)
42 active_dialog_->ActivateModalDialog();
45 bool AppModalDialogQueue::HasActiveDialog() const {
46 return active_dialog_ != NULL;
49 AppModalDialogQueue::AppModalDialogQueue()
50 : active_dialog_(NULL),
51 showing_modal_dialog_(false) {
54 AppModalDialogQueue::~AppModalDialogQueue() {
57 void AppModalDialogQueue::ShowModalDialog(AppModalDialog* dialog) {
58 // Be sure and set the active_dialog_ field first, otherwise if
59 // ShowModalDialog triggers a call back to the queue they'll get the old
60 // dialog. Also, if the dialog calls |ShowNextDialog()| before returning, that
61 // would write NULL into |active_dialog_| and this function would then undo
62 // that.
63 active_dialog_ = dialog;
64 showing_modal_dialog_ = true;
65 dialog->ShowModalDialog();
66 showing_modal_dialog_ = false;
69 AppModalDialog* AppModalDialogQueue::GetNextDialog() {
70 while (!app_modal_dialog_queue_.empty()) {
71 AppModalDialog* dialog = app_modal_dialog_queue_.front();
72 app_modal_dialog_queue_.pop_front();
73 if (dialog->IsValid())
74 return dialog;
75 delete dialog;
77 return NULL;
80 } // namespace app_modal