[email protected] | 1662374 | 2011-05-16 20:04:26 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
oshima | f6539842 | 2014-11-18 23:30:42 | [diff] [blame] | 5 | #ifndef COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_H_ |
6 | #define COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_H_ | ||||
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 7 | |
8 | #include <string> | ||||
9 | |||||
avi | bc5337b | 2015-12-25 23:16:33 | [diff] [blame] | 10 | #include "base/macros.h" |
[email protected] | b54c253 | 2013-06-12 00:17:48 | [diff] [blame] | 11 | #include "base/strings/string16.h" |
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 12 | #include "build/build_config.h" |
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 13 | |
[email protected] | a1e97f0 | 2011-06-30 14:04:34 | [diff] [blame] | 14 | namespace content { |
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 15 | class WebContents; |
[email protected] | a1e97f0 | 2011-06-30 14:04:34 | [diff] [blame] | 16 | } |
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 17 | |
oshima | 0929be2a | 2014-11-19 22:21:03 | [diff] [blame] | 18 | namespace app_modal { |
19 | |||||
20 | class NativeAppModalDialog; | ||||
21 | |||||
[email protected] | 12f74a9 | 2010-02-05 22:32:14 | [diff] [blame] | 22 | // A controller+model base class for modal dialogs. |
23 | class AppModalDialog { | ||||
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 24 | public: |
25 | // A union of data necessary to determine the type of message box to | ||||
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 26 | // show. |
[email protected] | dcd024987 | 2013-12-06 23:58:45 | [diff] [blame] | 27 | AppModalDialog(content::WebContents* web_contents, |
28 | const base::string16& title); | ||||
[email protected] | 12f74a9 | 2010-02-05 22:32:14 | [diff] [blame] | 29 | virtual ~AppModalDialog(); |
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 30 | |
[email protected] | 160ad3d | 2010-09-28 15:40:20 | [diff] [blame] | 31 | // Called by the AppModalDialogQueue to show this dialog. |
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 32 | void ShowModalDialog(); |
33 | |||||
[email protected] | 160ad3d | 2010-09-28 15:40:20 | [diff] [blame] | 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 | |||||
[email protected] | dcd024987 | 2013-12-06 23:58:45 | [diff] [blame] | 44 | base::string16 title() const { return title_; } |
[email protected] | 160ad3d | 2010-09-28 15:40:20 | [diff] [blame] | 45 | NativeAppModalDialog* native_dialog() const { return native_dialog_; } |
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 46 | content::WebContents* web_contents() const { return web_contents_; } |
[email protected] | 160ad3d | 2010-09-28 15:40:20 | [diff] [blame] | 47 | |
[email protected] | 1e1baa4 | 2010-02-18 03:51:50 | [diff] [blame] | 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. | ||||
[email protected] | a1e97f0 | 2011-06-30 14:04:34 | [diff] [blame] | 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. | ||||
avi | 6879fcf | 2017-01-21 05:27:53 | [diff] [blame] | 58 | virtual void Invalidate(); |
[email protected] | 1e1baa4 | 2010-02-18 03:51:50 | [diff] [blame] | 59 | |
[email protected] | 1662374 | 2011-05-16 20:04:26 | [diff] [blame] | 60 | // Used only for testing. Returns whether the dialog is a JavaScript modal |
61 | // dialog. | ||||
62 | virtual bool IsJavaScriptModalDialog(); | ||||
63 | |||||
[email protected] | 12f74a9 | 2010-02-05 22:32:14 | [diff] [blame] | 64 | protected: |
[email protected] | 160ad3d | 2010-09-28 15:40:20 | [diff] [blame] | 65 | // Overridden by subclasses to create the feature-specific native dialog box. |
66 | virtual NativeAppModalDialog* CreateNativeDialog() = 0; | ||||
[email protected] | 66bd33d | 2009-11-24 00:19:54 | [diff] [blame] | 67 | |
[email protected] | 1f422a7c | 2013-05-15 17:06:41 | [diff] [blame] | 68 | private: |
69 | // Information about the message box is held in the following variables. | ||||
[email protected] | dcd024987 | 2013-12-06 23:58:45 | [diff] [blame] | 70 | base::string16 title_; |
[email protected] | 1f422a7c | 2013-05-15 17:06:41 | [diff] [blame] | 71 | |
72 | // True if CompleteDialog was called. | ||||
73 | bool completed_; | ||||
74 | |||||
[email protected] | a1e97f0 | 2011-06-30 14:04:34 | [diff] [blame] | 75 | // False if the dialog should no longer be shown, e.g. because the underlying |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 76 | // tab navigated away while the dialog was queued. |
[email protected] | a1e97f0 | 2011-06-30 14:04:34 | [diff] [blame] | 77 | bool valid_; |
[email protected] | 1e1baa4 | 2010-02-18 03:51:50 | [diff] [blame] | 78 | |
[email protected] | 160ad3d | 2010-09-28 15:40:20 | [diff] [blame] | 79 | // The toolkit-specific implementation of the app modal dialog box. |
80 | NativeAppModalDialog* native_dialog_; | ||||
81 | |||||
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 82 | content::WebContents* web_contents_; |
83 | |||||
[email protected] | 1e1baa4 | 2010-02-18 03:51:50 | [diff] [blame] | 84 | DISALLOW_COPY_AND_ASSIGN(AppModalDialog); |
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 85 | }; |
86 | |||||
oshima | 82f7248 | 2014-10-24 14:14:32 | [diff] [blame] | 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 | |||||
oshima | 0929be2a | 2014-11-19 22:21:03 | [diff] [blame] | 100 | } // namespace app_modal |
101 | |||||
oshima | f6539842 | 2014-11-18 23:30:42 | [diff] [blame] | 102 | #endif // COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_H_ |