1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_UI_APP_MODAL_DIALOGS_APP_MODAL_DIALOG_H_ 6 #define CHROME_BROWSER_UI_APP_MODAL_DIALOGS_APP_MODAL_DIALOG_H_ 7 #pragma once 8 9 #include <string> 10 11 #include "base/basictypes.h" 12 #include "build/build_config.h" 13 14 class NativeAppModalDialog; 15 class TabContents; 16 17 // A controller+model base class for modal dialogs. 18 class AppModalDialog { 19 public: 20 // A union of data necessary to determine the type of message box to 21 // show. |tab_contents| parameter is optional, if provided that tab will be 22 // activated before the modal dialog is displayed. 23 AppModalDialog(TabContents* tab_contents, const std::wstring& title); 24 virtual ~AppModalDialog(); 25 26 // Called by the AppModalDialogQueue to show this dialog. 27 void ShowModalDialog(); 28 29 // Called by the AppModalDialogQueue to activate the dialog. 30 void ActivateModalDialog(); 31 32 // Closes the dialog if it is showing. 33 void CloseModalDialog(); 34 35 // Completes dialog handling, shows next modal dialog from the queue. 36 // TODO(beng): Get rid of this method. 37 void CompleteDialog(); 38 39 // Dialog window title. 40 std::wstring title() const { return title_; } 41 42 NativeAppModalDialog* native_dialog() const { return native_dialog_; } 43 44 // Methods overridable by AppModalDialog subclasses: 45 46 // Creates an implementation of NativeAppModalDialog and shows it. 47 // When the native dialog is closed, the implementation of 48 // NativeAppModalDialog should call OnAccept or OnCancel to notify the 49 // renderer of the user's action. The NativeAppModalDialog is also 50 // expected to delete the AppModalDialog associated with it. 51 virtual void CreateAndShowDialog(); 52 53 // Returns true if the dialog is still valid. As dialogs are created they are 54 // added to the AppModalDialogQueue. When the current modal dialog finishes 55 // and it's time to show the next dialog in the queue IsValid is invoked. 56 // If IsValid returns false the dialog is deleted and not shown. 57 virtual bool IsValid(); 58 59 protected: 60 // Overridden by subclasses to create the feature-specific native dialog box. 61 virtual NativeAppModalDialog* CreateNativeDialog() = 0; 62 63 // True if the dialog should no longer be shown, e.g. because the underlying 64 // tab navigated away while the dialog was queued. 65 bool skip_this_dialog_; 66 67 // Parent tab contents. 68 TabContents* tab_contents_; 69 70 // The toolkit-specific implementation of the app modal dialog box. 71 NativeAppModalDialog* native_dialog_; 72 73 private: 74 // Information about the message box is held in the following variables. 75 std::wstring title_; 76 77 DISALLOW_COPY_AND_ASSIGN(AppModalDialog); 78 }; 79 80 #endif // CHROME_BROWSER_UI_APP_MODAL_DIALOGS_APP_MODAL_DIALOG_H_ 81