| 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" |
| 11 #include "content/public/browser/notification_observer.h" | |
| 12 #include "content/public/browser/notification_registrar.h" | |
| 13 #include "ui/base/window_open_disposition.h" | 11 #include "ui/base/window_open_disposition.h" |
| 14 | 12 |
| 15 namespace content { | 13 namespace content { |
| 16 class WebContents; | 14 class WebContents; |
| 17 } | 15 } |
| 18 | 16 |
| 19 namespace gfx { | 17 namespace gfx { |
| 20 class Image; | 18 class Image; |
| 21 } | 19 } |
| 22 | 20 |
| 23 // Operations to be performed on the dialog by the | 21 // Operations to be performed on the dialog by the |
| 24 // TabModalConfirmDialogDelegate. | 22 // TabModalConfirmDialogDelegate. |
| 25 class TabModalConfirmDialogOperationsDelegate { | 23 class TabModalConfirmDialogOperationsDelegate { |
| 26 public: | 24 public: |
| 27 TabModalConfirmDialogOperationsDelegate() {} | 25 TabModalConfirmDialogOperationsDelegate() {} |
| 28 virtual ~TabModalConfirmDialogOperationsDelegate() {} | 26 virtual ~TabModalConfirmDialogOperationsDelegate() {} |
| 29 | 27 |
| 30 virtual void CloseDialog() = 0; | 28 virtual void CloseDialog() = 0; |
| 31 virtual void SetPreventCloseOnLoadStart(bool prevent) = 0; | 29 virtual void SetPreventCloseOnLoadStart(bool prevent) = 0; |
| 32 | 30 |
| 33 private: | 31 private: |
| 34 DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogOperationsDelegate); | 32 DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogOperationsDelegate); |
| 35 }; | 33 }; |
| 36 | 34 |
| 37 // This class acts as the delegate for a simple tab-modal dialog confirming | 35 // This class acts as the delegate for a simple tab-modal dialog confirming |
| 38 // whether the user wants to execute a certain action. | 36 // whether the user wants to execute a certain action. |
| 39 class TabModalConfirmDialogDelegate : public content::NotificationObserver { | 37 class TabModalConfirmDialogDelegate { |
| 40 public: | 38 public: |
| 41 explicit TabModalConfirmDialogDelegate(content::WebContents* web_contents); | 39 TabModalConfirmDialogDelegate(); |
| 42 virtual ~TabModalConfirmDialogDelegate(); | 40 virtual ~TabModalConfirmDialogDelegate(); |
| 43 | 41 |
| 44 void set_operations_delegate( | 42 void set_operations_delegate( |
| 45 TabModalConfirmDialogOperationsDelegate* operations_delegate) { | 43 TabModalConfirmDialogOperationsDelegate* operations_delegate) { |
| 46 operations_delegate_ = operations_delegate; | 44 operations_delegate_ = operations_delegate; |
| 47 } | 45 } |
| 48 | 46 |
| 49 // Accepts the confirmation prompt and calls |OnAccepted|. | 47 // Accepts the confirmation prompt and calls |OnAccepted|. |
| 50 // This method is safe to call even from an |OnAccepted| or |OnCanceled| | 48 // This method is safe to call even from an |OnAccepted| or |OnCanceled| |
| 51 // callback. | 49 // callback. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 82 // The icons are only used on GTK. If these methods are not overriden, | 80 // The icons are only used on GTK. If these methods are not overriden, |
| 83 // the buttons have no stock icons. | 81 // the buttons have no stock icons. |
| 84 virtual const char* GetAcceptButtonIcon(); | 82 virtual const char* GetAcceptButtonIcon(); |
| 85 virtual const char* GetCancelButtonIcon(); | 83 virtual const char* GetCancelButtonIcon(); |
| 86 | 84 |
| 87 protected: | 85 protected: |
| 88 TabModalConfirmDialogOperationsDelegate* operations_delegate() { | 86 TabModalConfirmDialogOperationsDelegate* operations_delegate() { |
| 89 return operations_delegate_; | 87 return operations_delegate_; |
| 90 } | 88 } |
| 91 | 89 |
| 92 // content::NotificationObserver implementation. | |
| 93 // Watch for a closed tab and dismiss the dialog if it occurs. | |
| 94 virtual void Observe(int type, | |
| 95 const content::NotificationSource& source, | |
| 96 const content::NotificationDetails& details) OVERRIDE; | |
| 97 | |
| 98 content::NotificationRegistrar registrar_; | |
| 99 | |
| 100 private: | 90 private: |
| 101 // It is guaranteed that exactly one of |OnAccepted|, |OnCanceled| or | 91 // It is guaranteed that exactly one of |OnAccepted|, |OnCanceled| or |
| 102 // |OnLinkClicked| is eventually called. These method are private to | 92 // |OnLinkClicked| is eventually called. These method are private to |
| 103 // enforce this guarantee. Access to them is controlled by |Accept|, | 93 // enforce this guarantee. Access to them is controlled by |Accept|, |
| 104 // |Cancel| and |LinkClicked|. | 94 // |Cancel| and |LinkClicked|. |
| 105 | 95 |
| 106 // Called when the user accepts or cancels the dialog, respectively. | 96 // Called when the user accepts or cancels the dialog, respectively. |
| 107 virtual void OnAccepted(); | 97 virtual void OnAccepted(); |
| 108 virtual void OnCanceled(); | 98 virtual void OnCanceled(); |
| 109 | 99 |
| 110 // Called when the user clicks on the link (if any). | 100 // Called when the user clicks on the link (if any). |
| 111 virtual void OnLinkClicked(WindowOpenDisposition disposition); | 101 virtual void OnLinkClicked(WindowOpenDisposition disposition); |
| 112 | 102 |
| 113 // Close the dialog. | 103 // Close the dialog. |
| 114 void CloseDialog(); | 104 void CloseDialog(); |
| 115 | 105 |
| 116 TabModalConfirmDialogOperationsDelegate* operations_delegate_; | 106 TabModalConfirmDialogOperationsDelegate* operations_delegate_; |
| 117 // True iff we are in the process of closing, to avoid running callbacks | 107 // True iff we are in the process of closing, to avoid running callbacks |
| 118 // multiple times. | 108 // multiple times. |
| 119 bool closing_; | 109 bool closing_; |
| 120 | 110 |
| 121 DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogDelegate); | 111 DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogDelegate); |
| 122 }; | 112 }; |
| 123 | 113 |
| 124 #endif // CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_DELEGATE_H_ | 114 #endif // CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_DELEGATE_H_ |
| OLD | NEW |