| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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. | |
| 4 | |
| 5 #include "components/app_modal_dialogs/app_modal_dialog.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/run_loop.h" | |
| 9 #include "components/app_modal_dialogs/app_modal_dialog_queue.h" | |
| 10 #include "components/app_modal_dialogs/native_app_modal_dialog.h" | |
| 11 #include "content/public/browser/web_contents.h" | |
| 12 #include "content/public/browser/web_contents_delegate.h" | |
| 13 | |
| 14 using content::WebContents; | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 AppModalDialogObserver* app_modal_dialog_observer = NULL; | |
| 19 | |
| 20 } // namespace | |
| 21 | |
| 22 AppModalDialogObserver::AppModalDialogObserver() { | |
| 23 DCHECK(!app_modal_dialog_observer); | |
| 24 app_modal_dialog_observer = this; | |
| 25 } | |
| 26 | |
| 27 AppModalDialogObserver::~AppModalDialogObserver() { | |
| 28 DCHECK(app_modal_dialog_observer); | |
| 29 app_modal_dialog_observer = NULL; | |
| 30 } | |
| 31 | |
| 32 AppModalDialog::AppModalDialog(WebContents* web_contents, | |
| 33 const base::string16& title) | |
| 34 : title_(title), | |
| 35 completed_(false), | |
| 36 valid_(true), | |
| 37 native_dialog_(NULL), | |
| 38 web_contents_(web_contents) { | |
| 39 } | |
| 40 | |
| 41 AppModalDialog::~AppModalDialog() { | |
| 42 CompleteDialog(); | |
| 43 } | |
| 44 | |
| 45 void AppModalDialog::ShowModalDialog() { | |
| 46 web_contents_->GetDelegate()->ActivateContents(web_contents_); | |
| 47 CreateAndShowDialog(); | |
| 48 if (app_modal_dialog_observer) | |
| 49 app_modal_dialog_observer->Notify(this); | |
| 50 } | |
| 51 | |
| 52 void AppModalDialog::CreateAndShowDialog() { | |
| 53 native_dialog_ = CreateNativeDialog(); | |
| 54 native_dialog_->ShowAppModalDialog(); | |
| 55 } | |
| 56 | |
| 57 bool AppModalDialog::IsValid() { | |
| 58 return valid_; | |
| 59 } | |
| 60 | |
| 61 void AppModalDialog::Invalidate() { | |
| 62 valid_ = false; | |
| 63 } | |
| 64 | |
| 65 bool AppModalDialog::IsJavaScriptModalDialog() { | |
| 66 return false; | |
| 67 } | |
| 68 | |
| 69 void AppModalDialog::ActivateModalDialog() { | |
| 70 DCHECK(native_dialog_); | |
| 71 native_dialog_->ActivateAppModalDialog(); | |
| 72 } | |
| 73 | |
| 74 void AppModalDialog::CloseModalDialog() { | |
| 75 DCHECK(native_dialog_); | |
| 76 native_dialog_->CloseAppModalDialog(); | |
| 77 } | |
| 78 | |
| 79 void AppModalDialog::CompleteDialog() { | |
| 80 if (!completed_) { | |
| 81 completed_ = true; | |
| 82 AppModalDialogQueue::GetInstance()->ShowNextDialog(); | |
| 83 } | |
| 84 } | |
| OLD | NEW |