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