summaryrefslogtreecommitdiffstats
path: root/chrome/browser/app_modal_dialog_queue.cc
blob: c3888bd0b8828fa0523084d17750ee61b201550d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/app_modal_dialog_queue.h"

#include "chrome/browser/browser_list.h"

// static
std::queue<views::AppModalDialogDelegate*>*
    AppModalDialogQueue::app_modal_dialog_queue_ = NULL;
views::AppModalDialogDelegate* AppModalDialogQueue::active_dialog_ = NULL;

// static
void AppModalDialogQueue::AddDialog(views::AppModalDialogDelegate* dialog) {
  DCHECK(dialog->IsModal());
  if (!app_modal_dialog_queue_) {
    app_modal_dialog_queue_ = new std::queue<views::AppModalDialogDelegate*>;
    ShowModalDialog(dialog);
  }

  // ShowModalDialog can wind up calling ShowNextDialog in some cases, which
  // can then make app_modal_dialog_queue_ NULL.
  if (app_modal_dialog_queue_)
    app_modal_dialog_queue_->push(dialog);
}

// static
void AppModalDialogQueue::ShowNextDialog() {
  app_modal_dialog_queue_->pop();
  active_dialog_ = NULL;
  if (!app_modal_dialog_queue_->empty()) {
    ShowModalDialog(app_modal_dialog_queue_->front());
  } else {
    delete app_modal_dialog_queue_;
    app_modal_dialog_queue_ = NULL;
  }
}

// static
void AppModalDialogQueue::ActivateModalDialog() {
  if (!app_modal_dialog_queue_->empty())
    app_modal_dialog_queue_->front()->ActivateModalDialog();
}

// static
void AppModalDialogQueue::ShowModalDialog(
    views::AppModalDialogDelegate* dialog) {
  // ShowModalDialog can wind up calling ShowNextDialog in some cases,
  // which will wind up calling this method recursively, so active_dialog_
  // must be set first.
  active_dialog_ = dialog;
  dialog->ShowModalDialog();
}