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