OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_DELEGATE_H_ |
6 #define CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_DELEGATE_H_ | 6 #define CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_DELEGATE_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
35 // whether the user wants to execute a certain action. | 35 // whether the user wants to execute a certain action. |
36 class TabModalConfirmDialogDelegate : public content::NotificationObserver { | 36 class TabModalConfirmDialogDelegate : public content::NotificationObserver { |
37 public: | 37 public: |
38 explicit TabModalConfirmDialogDelegate(content::WebContents* web_contents); | 38 explicit TabModalConfirmDialogDelegate(content::WebContents* web_contents); |
39 virtual ~TabModalConfirmDialogDelegate(); | 39 virtual ~TabModalConfirmDialogDelegate(); |
40 | 40 |
41 void set_close_delegate(TabModalConfirmDialogCloseDelegate* close_delegate) { | 41 void set_close_delegate(TabModalConfirmDialogCloseDelegate* close_delegate) { |
42 close_delegate_ = close_delegate; | 42 close_delegate_ = close_delegate; |
43 } | 43 } |
44 | 44 |
45 // Accepts the confirmation prompt and calls |OnAccepted|. | 45 // Accepts the confirmation prompt and calls |OnAccepted| if no other call |
46 // to |Accept|, |Cancel|, |LinkClicked| or |Dismissed| has been made before. | |
46 // This method is safe to call even from an |OnAccepted| or |OnCanceled| | 47 // This method is safe to call even from an |OnAccepted| or |OnCanceled| |
47 // callback. | 48 // callback. |
48 void Accept(); | 49 // Returns true if |OnAccepted| has been called, false otherwise. |
50 bool Accept(); | |
fdoray
2013/06/28 15:32:59
Changing the return value is helpful to avoid mult
| |
49 | 51 |
50 // Cancels the confirmation prompt and calls |OnCanceled|. | 52 // Cancels the confirmation prompt and calls |OnCanceled| if no other call |
53 // to |Accept|, |Cancel|, |LinkClicked| or |Dismissed| has been made before. | |
51 // This method is safe to call even from an |OnAccepted| or |OnCanceled| | 54 // This method is safe to call even from an |OnAccepted| or |OnCanceled| |
52 // callback. | 55 // callback. |
53 void Cancel(); | 56 // Returns true if |OnCanceled| has been called, false otherwise. |
57 bool Cancel(); | |
54 | 58 |
55 // Called when the link (if any) is clicked. Calls |OnLinkClicked| and closes | 59 // Called when the link (if any) is clicked. Calls |OnLinkClicked| and closes |
56 // the dialog. The |disposition| specifies how the resulting document should | 60 // the dialog if no other call to |Accept|, |Cancel|, |LinkClicked| or |
57 // be loaded (based on the event flags present when the link was clicked). | 61 // |Dismissed| has been made before. The |disposition| specifies how the |
58 void LinkClicked(WindowOpenDisposition disposition); | 62 // resulting document should be loaded (based on the event flags present when |
63 // the link was clicked). | |
64 // Returns true if |OnLinkClicked| has been called, false otherwise. | |
65 bool LinkClicked(WindowOpenDisposition disposition); | |
66 | |
67 // Called when the dialog is dismissed (by clicking on the Close button, | |
68 // closing the parent tab or navigating to another page in the parent tab). | |
69 // Calls |OnDismissed| and closes the dialog if no other call to |Accept|, | |
70 // |Cancel|, |LinkClicked| or |Dismissed| has been made before. | |
71 // Returns true if |OnDismissed| has been called, false otherwise. | |
72 bool Dismissed(); | |
59 | 73 |
60 // The title of the dialog. Note that the title is not shown on all platforms. | 74 // The title of the dialog. Note that the title is not shown on all platforms. |
61 virtual string16 GetTitle() = 0; | 75 virtual string16 GetTitle() = 0; |
62 virtual string16 GetMessage() = 0; | 76 virtual string16 GetMessage() = 0; |
63 | 77 |
64 // Icon to show for the dialog. If this method is not overridden, a default | 78 // Icon to show for the dialog. If this method is not overridden, a default |
65 // icon (like the application icon) is shown. | 79 // icon (like the application icon) is shown. |
66 virtual gfx::Image* GetIcon(); | 80 virtual gfx::Image* GetIcon(); |
67 | 81 |
68 // Title for the accept and the cancel buttons. | 82 // Title for the accept and the cancel buttons. |
(...skipping 18 matching lines...) Expand all Loading... | |
87 | 101 |
88 // content::NotificationObserver implementation. | 102 // content::NotificationObserver implementation. |
89 // Watch for a new load or a closed tab and dismiss the dialog if they occur. | 103 // Watch for a new load or a closed tab and dismiss the dialog if they occur. |
90 virtual void Observe(int type, | 104 virtual void Observe(int type, |
91 const content::NotificationSource& source, | 105 const content::NotificationSource& source, |
92 const content::NotificationDetails& details) OVERRIDE; | 106 const content::NotificationDetails& details) OVERRIDE; |
93 | 107 |
94 content::NotificationRegistrar registrar_; | 108 content::NotificationRegistrar registrar_; |
95 | 109 |
96 private: | 110 private: |
97 // It is guaranteed that exactly one of |OnAccepted|, |OnCanceled| or | 111 // It is guaranteed that exactly one of the |On...| methods is eventually |
98 // |OnLinkClicked| is eventually called. These method are private to | 112 // called. These method are private to enforce this guarantee. Access to them |
99 // enforce this guarantee. Access to them is controlled by |Accept|, | 113 // is controlled by |Accept|, |Cancel|, |LinkClicked| and |Dismissed|. |
100 // |Cancel| and |LinkClicked|. | |
101 | 114 |
102 // Called when the user accepts or cancels the dialog, respectively. | 115 // Called when the user accepts or cancels the dialog, respectively. |
103 virtual void OnAccepted(); | 116 virtual void OnAccepted(); |
104 virtual void OnCanceled(); | 117 virtual void OnCanceled(); |
105 | 118 |
106 // Called when the user clicks on the link (if any). | 119 // Called when the user clicks on the link (if any). |
107 virtual void OnLinkClicked(WindowOpenDisposition disposition); | 120 virtual void OnLinkClicked(WindowOpenDisposition disposition); |
108 | 121 |
122 // Called when the dialog is dismissed. | |
123 virtual void OnDismissed(); | |
124 | |
109 // Close the dialog. | 125 // Close the dialog. |
110 void CloseDialog(); | 126 void CloseDialog(); |
111 | 127 |
112 TabModalConfirmDialogCloseDelegate* close_delegate_; | 128 TabModalConfirmDialogCloseDelegate* close_delegate_; |
113 // True iff we are in the process of closing, to avoid running callbacks | 129 // True iff we are in the process of closing, to avoid running callbacks |
114 // multiple times. | 130 // multiple times. |
115 bool closing_; | 131 bool closing_; |
116 | 132 |
117 DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogDelegate); | 133 DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogDelegate); |
118 }; | 134 }; |
119 | 135 |
120 #endif // CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_DELEGATE_H_ | 136 #endif // CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_DELEGATE_H_ |
OLD | NEW |