app_modal_dialog.h revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
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#ifndef CHROME_BROWSER_UI_APP_MODAL_DIALOGS_APP_MODAL_DIALOG_H_
6#define CHROME_BROWSER_UI_APP_MODAL_DIALOGS_APP_MODAL_DIALOG_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/strings/string16.h"
12#include "build/build_config.h"
13
14class NativeAppModalDialog;
15
16namespace content {
17class WebContents;
18}
19
20// A controller+model base class for modal dialogs.
21class AppModalDialog {
22 public:
23  // A union of data necessary to determine the type of message box to
24  // show.
25  AppModalDialog(content::WebContents* web_contents, const string16& title);
26  virtual ~AppModalDialog();
27
28  // Called by the AppModalDialogQueue to show this dialog.
29  void ShowModalDialog();
30
31  // Called by the AppModalDialogQueue to activate the dialog.
32  void ActivateModalDialog();
33
34  // Closes the dialog if it is showing.
35  void CloseModalDialog();
36
37  // Completes dialog handling, shows next modal dialog from the queue.
38  // TODO(beng): Get rid of this method.
39  void CompleteDialog();
40
41  string16 title() const { return title_; }
42  NativeAppModalDialog* native_dialog() const { return native_dialog_; }
43  content::WebContents* web_contents() const { return web_contents_; }
44
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();
51
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.
56  bool IsValid();
57
58  // Methods overridable by AppModalDialog subclasses:
59
60  // Invalidates the dialog, therefore causing it to not be shown when its turn
61  // to be shown comes around.
62  virtual void Invalidate();
63
64  // Used only for testing. Returns whether the dialog is a JavaScript modal
65  // dialog.
66  virtual bool IsJavaScriptModalDialog();
67
68 protected:
69  // Overridden by subclasses to create the feature-specific native dialog box.
70  virtual NativeAppModalDialog* CreateNativeDialog() = 0;
71
72 private:
73  // Information about the message box is held in the following variables.
74  string16 title_;
75
76  // True if CompleteDialog was called.
77  bool completed_;
78
79  // False if the dialog should no longer be shown, e.g. because the underlying
80  // tab navigated away while the dialog was queued.
81  bool valid_;
82
83  // The toolkit-specific implementation of the app modal dialog box.
84  NativeAppModalDialog* native_dialog_;
85
86  content::WebContents* web_contents_;
87
88  DISALLOW_COPY_AND_ASSIGN(AppModalDialog);
89};
90
91#endif  // CHROME_BROWSER_UI_APP_MODAL_DIALOGS_APP_MODAL_DIALOG_H_
92