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
,
26 const base::string16
& title
);
27 virtual ~AppModalDialog();
29 // Called by the AppModalDialogQueue to show this dialog.
30 void ShowModalDialog();
32 // Called by the AppModalDialogQueue to activate the dialog.
33 void ActivateModalDialog();
35 // Closes the dialog if it is showing.
36 void CloseModalDialog();
38 // Completes dialog handling, shows next modal dialog from the queue.
39 // TODO(beng): Get rid of this method.
40 void CompleteDialog();
42 base::string16
title() const { return title_
; }
43 NativeAppModalDialog
* native_dialog() const { return native_dialog_
; }
44 content::WebContents
* web_contents() const { return web_contents_
; }
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 void CreateAndShowDialog();
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.
59 // Methods overridable by AppModalDialog subclasses:
61 // Invalidates the dialog, therefore causing it to not be shown when its turn
62 // to be shown comes around.
63 virtual void Invalidate();
65 // Used only for testing. Returns whether the dialog is a JavaScript modal
67 virtual bool IsJavaScriptModalDialog();
70 // Overridden by subclasses to create the feature-specific native dialog box.
71 virtual NativeAppModalDialog
* CreateNativeDialog() = 0;
74 // Information about the message box is held in the following variables.
75 base::string16 title_
;
77 // True if CompleteDialog was called.
80 // False if the dialog should no longer be shown, e.g. because the underlying
81 // tab navigated away while the dialog was queued.
84 // The toolkit-specific implementation of the app modal dialog box.
85 NativeAppModalDialog
* native_dialog_
;
87 content::WebContents
* web_contents_
;
89 DISALLOW_COPY_AND_ASSIGN(AppModalDialog
);
92 #endif // CHROME_BROWSER_UI_APP_MODAL_DIALOGS_APP_MODAL_DIALOG_H_