app_modal_dialog.cc revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
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 "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" 6 7#include "base/logging.h" 8#include "chrome/browser/chrome_notification_types.h" 9#include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" 10#include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" 11#include "content/public/browser/notification_service.h" 12#include "content/public/browser/web_contents.h" 13#include "content/public/browser/web_contents_delegate.h" 14 15using content::WebContents; 16 17AppModalDialog::AppModalDialog(WebContents* web_contents, const string16& title) 18 : title_(title), 19 completed_(false), 20 valid_(true), 21 native_dialog_(NULL), 22 web_contents_(web_contents) { 23} 24 25AppModalDialog::~AppModalDialog() { 26 CompleteDialog(); 27} 28 29void AppModalDialog::ShowModalDialog() { 30 web_contents_->GetDelegate()->ActivateContents(web_contents_); 31 CreateAndShowDialog(); 32 33 content::NotificationService::current()->Notify( 34 chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN, 35 content::Source<AppModalDialog>(this), 36 content::NotificationService::NoDetails()); 37} 38 39void AppModalDialog::CreateAndShowDialog() { 40 native_dialog_ = CreateNativeDialog(); 41 native_dialog_->ShowAppModalDialog(); 42} 43 44bool AppModalDialog::IsValid() { 45 return valid_; 46} 47 48void AppModalDialog::Invalidate() { 49 valid_ = false; 50} 51 52bool AppModalDialog::IsJavaScriptModalDialog() { 53 return false; 54} 55 56void AppModalDialog::ActivateModalDialog() { 57 DCHECK(native_dialog_); 58 native_dialog_->ActivateAppModalDialog(); 59} 60 61void AppModalDialog::CloseModalDialog() { 62 DCHECK(native_dialog_); 63 native_dialog_->CloseAppModalDialog(); 64} 65 66void AppModalDialog::CompleteDialog() { 67 if (!completed_) { 68 completed_ = true; 69 AppModalDialogQueue::GetInstance()->ShowNextDialog(); 70 } 71} 72