Infobar material design refresh: layout
[chromium-blink-merge.git] / chrome / browser / ui / tab_modal_confirm_dialog_delegate.h
blobf8f71251368fc2d22dd0fc67562c5803333f6c60
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_DELEGATE_H_
6 #define CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_DELEGATE_H_
8 #include "base/callback.h"
9 #include "base/compiler_specific.h"
10 #include "base/strings/string16.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
13 #include "ui/base/window_open_disposition.h"
15 namespace content {
16 class WebContents;
19 namespace gfx {
20 class Image;
23 class TabModalConfirmDialogCloseDelegate {
24 public:
25 TabModalConfirmDialogCloseDelegate() {}
26 virtual ~TabModalConfirmDialogCloseDelegate() {}
28 virtual void CloseDialog() = 0;
30 private:
31 DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogCloseDelegate);
34 // This class acts as the delegate for a simple tab-modal dialog confirming
35 // whether the user wants to execute a certain action.
36 class TabModalConfirmDialogDelegate : public content::NotificationObserver {
37 public:
38 explicit TabModalConfirmDialogDelegate(content::WebContents* web_contents);
39 ~TabModalConfirmDialogDelegate() override;
41 void set_close_delegate(TabModalConfirmDialogCloseDelegate* close_delegate) {
42 close_delegate_ = close_delegate;
45 // Accepts the confirmation prompt and calls OnAccepted() if no other call
46 // to Accept(), Cancel() or Close() has been made before.
47 // This method is safe to call even from an OnAccepted(), OnCanceled(),
48 // OnClosed() or OnLinkClicked() callback.
49 void Accept();
51 // Cancels the confirmation prompt and calls OnCanceled() if no other call
52 // to Accept(), Cancel() or Close() has been made before.
53 // This method is safe to call even from an OnAccepted(), OnCanceled(),
54 // OnClosed() or OnLinkClicked() callback.
55 void Cancel();
57 // Called when the dialog is closed without selecting an option, e.g. by
58 // pressing the close button on the dialog, using a window manager gesture,
59 // closing the parent tab or navigating in the parent tab.
60 // Calls OnClosed() and closes the dialog if no other call to Accept(),
61 // Cancel() or Close() has been made before.
62 // This method is safe to call even from an OnAccepted(), OnCanceled(),
63 // OnClosed() or OnLinkClicked() callback.
64 void Close();
66 // Called when the link is clicked. Calls OnLinkClicked() if the dialog is
67 // not in the process of closing. The |disposition| specifies how the
68 // resulting document should be loaded (based on the event flags present when
69 // the link was clicked).
70 void LinkClicked(WindowOpenDisposition disposition);
72 // The title of the dialog. Note that the title is not shown on all platforms.
73 virtual base::string16 GetTitle() = 0;
74 virtual base::string16 GetDialogMessage() = 0;
76 // Icon to show for the dialog. If this method is not overridden, a default
77 // icon (like the application icon) is shown.
78 virtual gfx::Image* GetIcon();
80 // Title for the accept and the cancel buttons.
81 // The default implementation uses IDS_OK and IDS_CANCEL.
82 virtual base::string16 GetAcceptButtonTitle();
83 virtual base::string16 GetCancelButtonTitle();
85 // Returns the text of the link to be displayed, if any. Otherwise returns
86 // an empty string.
87 virtual base::string16 GetLinkText() const;
89 // GTK stock icon names for the accept and cancel buttons, respectively.
90 // The icons are only used on GTK. If these methods are not overriden,
91 // the buttons have no stock icons.
92 virtual const char* GetAcceptButtonIcon();
93 virtual const char* GetCancelButtonIcon();
95 protected:
96 TabModalConfirmDialogCloseDelegate* close_delegate() {
97 return close_delegate_;
100 // content::NotificationObserver implementation.
101 // Watch for a new load or a closed tab and dismiss the dialog if they occur.
102 void Observe(int type,
103 const content::NotificationSource& source,
104 const content::NotificationDetails& details) override;
106 content::NotificationRegistrar registrar_;
108 private:
109 // It is guaranteed that exactly one of OnAccepted(), OnCanceled() or
110 // OnClosed() is eventually called. These method are private to enforce this
111 // guarantee. Access to them is controlled by Accept(), Cancel() and Close().
113 // Called when the user accepts or cancels the dialog, respectively.
114 virtual void OnAccepted();
115 virtual void OnCanceled();
117 // Called when the dialog is closed.
118 virtual void OnClosed();
120 // Called when the link is clicked. Acces to the method is controlled by
121 // LinkClicked(), which checks that the dialog is not in the process of
122 // closing. It's correct to close the dialog by calling Accept(), Cancel()
123 // or Close() from this callback.
124 virtual void OnLinkClicked(WindowOpenDisposition disposition);
126 // Close the dialog.
127 void CloseDialog();
129 TabModalConfirmDialogCloseDelegate* close_delegate_;
131 // True iff we are in the process of closing, to avoid running callbacks
132 // multiple times.
133 bool closing_;
135 DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogDelegate);
138 #endif // CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_DELEGATE_H_