blob: c4923eaf88aa3bd4c2fcdf1c563a42be506cc5ca [file] [log] [blame]
[email protected]16623742011-05-16 20:04:261// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]0bfa713f2009-04-07 20:18:282// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
oshimaf65398422014-11-18 23:30:425#ifndef COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_H_
6#define COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_H_
[email protected]0bfa713f2009-04-07 20:18:287
8#include <string>
9
avibc5337b2015-12-25 23:16:3310#include "base/macros.h"
[email protected]b54c2532013-06-12 00:17:4811#include "base/strings/string16.h"
[email protected]0bfa713f2009-04-07 20:18:2812#include "build/build_config.h"
[email protected]0bfa713f2009-04-07 20:18:2813
[email protected]a1e97f02011-06-30 14:04:3414namespace content {
[email protected]51da7e32012-01-30 19:24:5215class WebContents;
[email protected]a1e97f02011-06-30 14:04:3416}
[email protected]0bfa713f2009-04-07 20:18:2817
oshima0929be2a2014-11-19 22:21:0318namespace app_modal {
19
20class NativeAppModalDialog;
21
[email protected]12f74a92010-02-05 22:32:1422// A controller+model base class for modal dialogs.
23class AppModalDialog {
[email protected]0bfa713f2009-04-07 20:18:2824 public:
25 // A union of data necessary to determine the type of message box to
[email protected]51da7e32012-01-30 19:24:5226 // show.
[email protected]dcd0249872013-12-06 23:58:4527 AppModalDialog(content::WebContents* web_contents,
28 const base::string16& title);
[email protected]12f74a92010-02-05 22:32:1429 virtual ~AppModalDialog();
[email protected]0bfa713f2009-04-07 20:18:2830
[email protected]160ad3d2010-09-28 15:40:2031 // Called by the AppModalDialogQueue to show this dialog.
[email protected]0bfa713f2009-04-07 20:18:2832 void ShowModalDialog();
33
[email protected]160ad3d2010-09-28 15:40:2034 // 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]dcd0249872013-12-06 23:58:4544 base::string16 title() const { return title_; }
[email protected]160ad3d2010-09-28 15:40:2045 NativeAppModalDialog* native_dialog() const { return native_dialog_; }
[email protected]51da7e32012-01-30 19:24:5246 content::WebContents* web_contents() const { return web_contents_; }
[email protected]160ad3d2010-09-28 15:40:2047
[email protected]1e1baa42010-02-18 03:51:5048 // 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]a1e97f02011-06-30 14:04:3452 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.
avi6879fcf2017-01-21 05:27:5358 virtual void Invalidate();
[email protected]1e1baa42010-02-18 03:51:5059
[email protected]16623742011-05-16 20:04:2660 // Used only for testing. Returns whether the dialog is a JavaScript modal
61 // dialog.
62 virtual bool IsJavaScriptModalDialog();
63
[email protected]12f74a92010-02-05 22:32:1464 protected:
[email protected]160ad3d2010-09-28 15:40:2065 // Overridden by subclasses to create the feature-specific native dialog box.
66 virtual NativeAppModalDialog* CreateNativeDialog() = 0;
[email protected]66bd33d2009-11-24 00:19:5467
[email protected]1f422a7c2013-05-15 17:06:4168 private:
69 // Information about the message box is held in the following variables.
[email protected]dcd0249872013-12-06 23:58:4570 base::string16 title_;
[email protected]1f422a7c2013-05-15 17:06:4171
72 // True if CompleteDialog was called.
73 bool completed_;
74
[email protected]a1e97f02011-06-30 14:04:3475 // False if the dialog should no longer be shown, e.g. because the underlying
[email protected]beb440c2009-11-06 04:08:5476 // tab navigated away while the dialog was queued.
[email protected]a1e97f02011-06-30 14:04:3477 bool valid_;
[email protected]1e1baa42010-02-18 03:51:5078
[email protected]160ad3d2010-09-28 15:40:2079 // The toolkit-specific implementation of the app modal dialog box.
80 NativeAppModalDialog* native_dialog_;
81
[email protected]51da7e32012-01-30 19:24:5282 content::WebContents* web_contents_;
83
[email protected]1e1baa42010-02-18 03:51:5084 DISALLOW_COPY_AND_ASSIGN(AppModalDialog);
[email protected]0bfa713f2009-04-07 20:18:2885};
86
oshima82f72482014-10-24 14:14:3287// An interface to observe that a modal dialog is shown.
88class 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
oshima0929be2a2014-11-19 22:21:03100} // namespace app_modal
101
oshimaf65398422014-11-18 23:30:42102#endif // COMPONENTS_APP_MODAL_APP_MODAL_DIALOG_H_