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