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.
5 #ifndef CHROME_BROWSER_UI_APP_MODAL_DIALOGS_APP_MODAL_DIALOG_H_
6 #define CHROME_BROWSER_UI_APP_MODAL_DIALOGS_APP_MODAL_DIALOG_H_
10 #include "base/basictypes.h"
11 #include "base/strings/string16.h"
12 #include "build/build_config.h"
14 class NativeAppModalDialog;
20 // A controller+model base class for modal dialogs.
21 class AppModalDialog {
23 // A union of data necessary to determine the type of message box to
25 AppModalDialog(content::WebContents* web_contents, const string16& title);
26 virtual ~AppModalDialog();
28 // Called by the AppModalDialogQueue to show this dialog.
29 void ShowModalDialog();
31 // Called by the AppModalDialogQueue to activate the dialog.
32 void ActivateModalDialog();
34 // Closes the dialog if it is showing.
35 void CloseModalDialog();
37 // Completes dialog handling, shows next modal dialog from the queue.
38 // TODO(beng): Get rid of this method.
39 void CompleteDialog();
41 string16 title() const { return title_; }
42 NativeAppModalDialog* native_dialog() const { return native_dialog_; }
43 content::WebContents* web_contents() const { return web_contents_; }
45 // Creates an implementation of NativeAppModalDialog and shows it.
46 // When the native dialog is closed, the implementation of
47 // NativeAppModalDialog should call OnAccept or OnCancel to notify the
48 // renderer of the user's action. The NativeAppModalDialog is also
49 // expected to delete the AppModalDialog associated with it.
50 void CreateAndShowDialog();
52 // Returns true if the dialog is still valid. As dialogs are created they are
53 // added to the AppModalDialogQueue. When the current modal dialog finishes
54 // and it's time to show the next dialog in the queue IsValid is invoked.
55 // If IsValid returns false the dialog is deleted and not shown.
58 // Methods overridable by AppModalDialog subclasses:
60 // Invalidates the dialog, therefore causing it to not be shown when its turn
61 // to be shown comes around.
62 virtual void Invalidate();
64 // Used only for testing. Returns whether the dialog is a JavaScript modal
66 virtual bool IsJavaScriptModalDialog();
69 // Overridden by subclasses to create the feature-specific native dialog box.
70 virtual NativeAppModalDialog* CreateNativeDialog() = 0;
73 // Information about the message box is held in the following variables.
76 // True if CompleteDialog was called.
79 // False if the dialog should no longer be shown, e.g. because the underlying
80 // tab navigated away while the dialog was queued.
83 // The toolkit-specific implementation of the app modal dialog box.
84 NativeAppModalDialog* native_dialog_;
86 content::WebContents* web_contents_;
88 DISALLOW_COPY_AND_ASSIGN(AppModalDialog);
91 #endif // CHROME_BROWSER_UI_APP_MODAL_DIALOGS_APP_MODAL_DIALOG_H_