[email protected] | 7f070d4 | 2011-03-09 20:25:32 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
oshima | f6539842 | 2014-11-18 23:30:42 | [diff] [blame] | 5 | #include "components/app_modal/app_modal_dialog.h" |
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 6 | |
[email protected] | 83a2610a | 2012-01-05 01:00:27 | [diff] [blame] | 7 | #include "base/logging.h" |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 8 | #include "base/run_loop.h" |
oshima | f6539842 | 2014-11-18 23:30:42 | [diff] [blame] | 9 | #include "components/app_modal/app_modal_dialog_queue.h" |
10 | #include "components/app_modal/native_app_modal_dialog.h" | ||||
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 11 | |
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 12 | using content::WebContents; |
13 | |||||
oshima | 0929be2a | 2014-11-19 22:21:03 | [diff] [blame] | 14 | namespace app_modal { |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 15 | namespace { |
16 | |||||
17 | AppModalDialogObserver* app_modal_dialog_observer = NULL; | ||||
18 | |||||
19 | } // namespace | ||||
20 | |||||
21 | AppModalDialogObserver::AppModalDialogObserver() { | ||||
22 | DCHECK(!app_modal_dialog_observer); | ||||
23 | app_modal_dialog_observer = this; | ||||
24 | } | ||||
25 | |||||
26 | AppModalDialogObserver::~AppModalDialogObserver() { | ||||
27 | DCHECK(app_modal_dialog_observer); | ||||
28 | app_modal_dialog_observer = NULL; | ||||
29 | } | ||||
30 | |||||
[email protected] | dcd024987 | 2013-12-06 23:58:45 | [diff] [blame] | 31 | AppModalDialog::AppModalDialog(WebContents* web_contents, |
32 | const base::string16& title) | ||||
[email protected] | 1f422a7c | 2013-05-15 17:06:41 | [diff] [blame] | 33 | : title_(title), |
34 | completed_(false), | ||||
35 | valid_(true), | ||||
[email protected] | 160ad3d | 2010-09-28 15:40:20 | [diff] [blame] | 36 | native_dialog_(NULL), |
[email protected] | 1f422a7c | 2013-05-15 17:06:41 | [diff] [blame] | 37 | web_contents_(web_contents) { |
[email protected] | 160ad3d | 2010-09-28 15:40:20 | [diff] [blame] | 38 | } |
39 | |||||
40 | AppModalDialog::~AppModalDialog() { | ||||
[email protected] | 9403690 | 2012-08-22 03:15:56 | [diff] [blame] | 41 | CompleteDialog(); |
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 42 | } |
43 | |||||
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 44 | void AppModalDialog::ShowModalDialog() { |
jochen | 55ff350 | 2014-12-18 20:52:57 | [diff] [blame] | 45 | native_dialog_ = CreateNativeDialog(); |
jochen | 55ff350 | 2014-12-18 20:52:57 | [diff] [blame] | 46 | native_dialog_->ShowAppModalDialog(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 47 | if (app_modal_dialog_observer) |
48 | app_modal_dialog_observer->Notify(this); | ||||
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 49 | } |
50 | |||||
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 51 | bool AppModalDialog::IsValid() { |
[email protected] | a1e97f0 | 2011-06-30 14:04:34 | [diff] [blame] | 52 | return valid_; |
53 | } | ||||
54 | |||||
55 | void AppModalDialog::Invalidate() { | ||||
56 | valid_ = false; | ||||
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 57 | } |
58 | |||||
[email protected] | 1662374 | 2011-05-16 20:04:26 | [diff] [blame] | 59 | bool AppModalDialog::IsJavaScriptModalDialog() { |
60 | return false; | ||||
61 | } | ||||
62 | |||||
[email protected] | 160ad3d | 2010-09-28 15:40:20 | [diff] [blame] | 63 | void AppModalDialog::ActivateModalDialog() { |
64 | DCHECK(native_dialog_); | ||||
65 | native_dialog_->ActivateAppModalDialog(); | ||||
66 | } | ||||
67 | |||||
68 | void AppModalDialog::CloseModalDialog() { | ||||
69 | DCHECK(native_dialog_); | ||||
70 | native_dialog_->CloseAppModalDialog(); | ||||
[email protected] | 571e3115 | 2009-05-15 19:34:02 | [diff] [blame] | 71 | } |
[email protected] | 12f74a9 | 2010-02-05 22:32:14 | [diff] [blame] | 72 | |
73 | void AppModalDialog::CompleteDialog() { | ||||
[email protected] | 9403690 | 2012-08-22 03:15:56 | [diff] [blame] | 74 | if (!completed_) { |
75 | completed_ = true; | ||||
76 | AppModalDialogQueue::GetInstance()->ShowNextDialog(); | ||||
77 | } | ||||
[email protected] | 12f74a9 | 2010-02-05 22:32:14 | [diff] [blame] | 78 | } |
oshima | 0929be2a | 2014-11-19 22:21:03 | [diff] [blame] | 79 | |
80 | } // namespace app_modal |