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 COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_H_
6 #define COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_H_
10 #include "base/basictypes.h"
11 #include "base/strings/string16.h"
12 #include "build/build_config.h"
20 class NativeAppModalDialog
;
22 // A controller+model base class for modal dialogs.
23 class AppModalDialog
{
25 // A union of data necessary to determine the type of message box to
27 AppModalDialog(content::WebContents
* web_contents
,
28 const base::string16
& title
);
29 virtual ~AppModalDialog();
31 // Called by the AppModalDialogQueue to show this dialog.
32 void ShowModalDialog();
34 // Called by the AppModalDialogQueue to activate the dialog.
35 void ActivateModalDialog();
37 // Closes the dialog if it is showing.
38 void CloseModalDialog();
40 // Completes dialog handling, shows next modal dialog from the queue.
41 // TODO(beng): Get rid of this method.
42 void CompleteDialog();
44 base::string16
title() const { return title_
; }
45 NativeAppModalDialog
* native_dialog() const { return native_dialog_
; }
46 content::WebContents
* web_contents() const { return web_contents_
; }
48 // Returns true if the dialog is still valid. As dialogs are created they are
49 // added to the AppModalDialogQueue. When the current modal dialog finishes
50 // and it's time to show the next dialog in the queue IsValid is invoked.
51 // If IsValid returns false the dialog is deleted and not shown.
54 // Methods overridable by AppModalDialog subclasses:
56 // Invalidates the dialog, therefore causing it to not be shown when its turn
57 // to be shown comes around.
58 virtual void Invalidate();
60 // Used only for testing. Returns whether the dialog is a JavaScript modal
62 virtual bool IsJavaScriptModalDialog();
65 // Overridden by subclasses to create the feature-specific native dialog box.
66 virtual NativeAppModalDialog
* CreateNativeDialog() = 0;
69 // Information about the message box is held in the following variables.
70 base::string16 title_
;
72 // True if CompleteDialog was called.
75 // False if the dialog should no longer be shown, e.g. because the underlying
76 // tab navigated away while the dialog was queued.
79 // The toolkit-specific implementation of the app modal dialog box.
80 NativeAppModalDialog
* native_dialog_
;
82 content::WebContents
* web_contents_
;
84 DISALLOW_COPY_AND_ASSIGN(AppModalDialog
);
87 // An interface to observe that a modal dialog is shown.
88 class AppModalDialogObserver
{
90 AppModalDialogObserver();
91 virtual ~AppModalDialogObserver();
93 // Called when the modal dialog is shown.
94 virtual void Notify(AppModalDialog
* dialog
) = 0;
97 DISALLOW_COPY_AND_ASSIGN(AppModalDialogObserver
);
100 } // namespace app_modal
102 #endif // COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_H_