[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] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 11 | #include "content/public/browser/web_contents.h" |
12 | #include "content/public/browser/web_contents_delegate.h" | ||||
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 13 | |
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 14 | using content::WebContents; |
15 | |||||
oshima | 0929be2a | 2014-11-19 22:21:03 | [diff] [blame] | 16 | namespace app_modal { |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 17 | namespace { |
18 | |||||
19 | AppModalDialogObserver* app_modal_dialog_observer = NULL; | ||||
20 | |||||
21 | } // namespace | ||||
22 | |||||
23 | AppModalDialogObserver::AppModalDialogObserver() { | ||||
24 | DCHECK(!app_modal_dialog_observer); | ||||
25 | app_modal_dialog_observer = this; | ||||
26 | } | ||||
27 | |||||
28 | AppModalDialogObserver::~AppModalDialogObserver() { | ||||
29 | DCHECK(app_modal_dialog_observer); | ||||
30 | app_modal_dialog_observer = NULL; | ||||
31 | } | ||||
32 | |||||
[email protected] | dcd024987 | 2013-12-06 23:58:45 | [diff] [blame] | 33 | AppModalDialog::AppModalDialog(WebContents* web_contents, |
34 | const base::string16& title) | ||||
[email protected] | 1f422a7c | 2013-05-15 17:06:41 | [diff] [blame] | 35 | : title_(title), |
36 | completed_(false), | ||||
37 | valid_(true), | ||||
[email protected] | 160ad3d | 2010-09-28 15:40:20 | [diff] [blame] | 38 | native_dialog_(NULL), |
[email protected] | 1f422a7c | 2013-05-15 17:06:41 | [diff] [blame] | 39 | web_contents_(web_contents) { |
[email protected] | 160ad3d | 2010-09-28 15:40:20 | [diff] [blame] | 40 | } |
41 | |||||
42 | AppModalDialog::~AppModalDialog() { | ||||
[email protected] | 9403690 | 2012-08-22 03:15:56 | [diff] [blame] | 43 | CompleteDialog(); |
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 44 | } |
45 | |||||
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 46 | void AppModalDialog::ShowModalDialog() { |
jochen | 55ff350 | 2014-12-18 20:52:57 | [diff] [blame^] | 47 | native_dialog_ = CreateNativeDialog(); |
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 48 | web_contents_->GetDelegate()->ActivateContents(web_contents_); |
jochen | 55ff350 | 2014-12-18 20:52:57 | [diff] [blame^] | 49 | native_dialog_->ShowAppModalDialog(); |
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 50 | if (app_modal_dialog_observer) |
51 | app_modal_dialog_observer->Notify(this); | ||||
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 52 | } |
53 | |||||
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 54 | bool AppModalDialog::IsValid() { |
[email protected] | a1e97f0 | 2011-06-30 14:04:34 | [diff] [blame] | 55 | return valid_; |
56 | } | ||||
57 | |||||
58 | void AppModalDialog::Invalidate() { | ||||
59 | valid_ = false; | ||||
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 60 | } |
61 | |||||
[email protected] | 1662374 | 2011-05-16 20:04:26 | [diff] [blame] | 62 | bool AppModalDialog::IsJavaScriptModalDialog() { |
63 | return false; | ||||
64 | } | ||||
65 | |||||
[email protected] | 160ad3d | 2010-09-28 15:40:20 | [diff] [blame] | 66 | void AppModalDialog::ActivateModalDialog() { |
67 | DCHECK(native_dialog_); | ||||
68 | native_dialog_->ActivateAppModalDialog(); | ||||
69 | } | ||||
70 | |||||
71 | void AppModalDialog::CloseModalDialog() { | ||||
72 | DCHECK(native_dialog_); | ||||
73 | native_dialog_->CloseAppModalDialog(); | ||||
[email protected] | 571e3115 | 2009-05-15 19:34:02 | [diff] [blame] | 74 | } |
[email protected] | 12f74a9 | 2010-02-05 22:32:14 | [diff] [blame] | 75 | |
76 | void AppModalDialog::CompleteDialog() { | ||||
[email protected] | 9403690 | 2012-08-22 03:15:56 | [diff] [blame] | 77 | if (!completed_) { |
78 | completed_ = true; | ||||
79 | AppModalDialogQueue::GetInstance()->ShowNextDialog(); | ||||
80 | } | ||||
[email protected] | 12f74a9 | 2010-02-05 22:32:14 | [diff] [blame] | 81 | } |
oshima | 0929be2a | 2014-11-19 22:21:03 | [diff] [blame] | 82 | |
83 | } // namespace app_modal |