blob: c50a604e4ddcf808aabdce1c6d514349e6f165d4 [file] [log] [blame]
[email protected]7f070d42011-03-09 20:25:321// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]0bfa713f2009-04-07 20:18:282// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
oshimaf65398422014-11-18 23:30:425#include "components/app_modal/app_modal_dialog.h"
[email protected]0bfa713f2009-04-07 20:18:286
[email protected]83a2610a2012-01-05 01:00:277#include "base/logging.h"
oshima82f72482014-10-24 14:14:328#include "base/run_loop.h"
oshimaf65398422014-11-18 23:30:429#include "components/app_modal/app_modal_dialog_queue.h"
10#include "components/app_modal/native_app_modal_dialog.h"
[email protected]51da7e32012-01-30 19:24:5211#include "content/public/browser/web_contents.h"
12#include "content/public/browser/web_contents_delegate.h"
[email protected]0bfa713f2009-04-07 20:18:2813
[email protected]51da7e32012-01-30 19:24:5214using content::WebContents;
15
oshima0929be2a2014-11-19 22:21:0316namespace app_modal {
oshima82f72482014-10-24 14:14:3217namespace {
18
19AppModalDialogObserver* app_modal_dialog_observer = NULL;
20
21} // namespace
22
23AppModalDialogObserver::AppModalDialogObserver() {
24 DCHECK(!app_modal_dialog_observer);
25 app_modal_dialog_observer = this;
26}
27
28AppModalDialogObserver::~AppModalDialogObserver() {
29 DCHECK(app_modal_dialog_observer);
30 app_modal_dialog_observer = NULL;
31}
32
[email protected]dcd0249872013-12-06 23:58:4533AppModalDialog::AppModalDialog(WebContents* web_contents,
34 const base::string16& title)
[email protected]1f422a7c2013-05-15 17:06:4135 : title_(title),
36 completed_(false),
37 valid_(true),
[email protected]160ad3d2010-09-28 15:40:2038 native_dialog_(NULL),
[email protected]1f422a7c2013-05-15 17:06:4139 web_contents_(web_contents) {
[email protected]160ad3d2010-09-28 15:40:2040}
41
42AppModalDialog::~AppModalDialog() {
[email protected]94036902012-08-22 03:15:5643 CompleteDialog();
[email protected]0bfa713f2009-04-07 20:18:2844}
45
[email protected]0bfa713f2009-04-07 20:18:2846void AppModalDialog::ShowModalDialog() {
jochen55ff3502014-12-18 20:52:5747 native_dialog_ = CreateNativeDialog();
[email protected]51da7e32012-01-30 19:24:5248 web_contents_->GetDelegate()->ActivateContents(web_contents_);
jochen55ff3502014-12-18 20:52:5749 native_dialog_->ShowAppModalDialog();
oshima82f72482014-10-24 14:14:3250 if (app_modal_dialog_observer)
51 app_modal_dialog_observer->Notify(this);
[email protected]0bfa713f2009-04-07 20:18:2852}
53
[email protected]ddb1e5a2010-12-13 20:10:4554bool AppModalDialog::IsValid() {
[email protected]a1e97f02011-06-30 14:04:3455 return valid_;
56}
57
58void AppModalDialog::Invalidate() {
59 valid_ = false;
[email protected]ddb1e5a2010-12-13 20:10:4560}
61
[email protected]16623742011-05-16 20:04:2662bool AppModalDialog::IsJavaScriptModalDialog() {
63 return false;
64}
65
[email protected]160ad3d2010-09-28 15:40:2066void AppModalDialog::ActivateModalDialog() {
67 DCHECK(native_dialog_);
68 native_dialog_->ActivateAppModalDialog();
69}
70
71void AppModalDialog::CloseModalDialog() {
72 DCHECK(native_dialog_);
73 native_dialog_->CloseAppModalDialog();
[email protected]571e31152009-05-15 19:34:0274}
[email protected]12f74a92010-02-05 22:32:1475
76void AppModalDialog::CompleteDialog() {
[email protected]94036902012-08-22 03:15:5677 if (!completed_) {
78 completed_ = true;
79 AppModalDialogQueue::GetInstance()->ShowNextDialog();
80 }
[email protected]12f74a92010-02-05 22:32:1481}
oshima0929be2a2014-11-19 22:21:0382
83} // namespace app_modal