| 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/string16.h" | 10 #include "base/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 | 13 |
| 14 class WebContentsModalDialog; | |
| 15 | |
| 16 namespace content { | 14 namespace content { |
| 17 class WebContents; | 15 class WebContents; |
| 18 } | 16 } |
| 19 | 17 |
| 20 namespace gfx { | 18 namespace gfx { |
| 21 class Image; | 19 class Image; |
| 22 } | 20 } |
| 23 | 21 |
| 22 class TabModalConfirmDialogCloseDelegate { |
| 23 public: |
| 24 TabModalConfirmDialogCloseDelegate() {} |
| 25 virtual ~TabModalConfirmDialogCloseDelegate() {} |
| 26 |
| 27 virtual void CloseDialog() = 0; |
| 28 |
| 29 private: |
| 30 DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogCloseDelegate); |
| 31 }; |
| 32 |
| 24 // This class acts as the delegate for a simple tab-modal dialog confirming | 33 // This class acts as the delegate for a simple tab-modal dialog confirming |
| 25 // whether the user wants to execute a certain action. | 34 // whether the user wants to execute a certain action. |
| 26 class TabModalConfirmDialogDelegate : public content::NotificationObserver { | 35 class TabModalConfirmDialogDelegate : public content::NotificationObserver { |
| 27 public: | 36 public: |
| 28 explicit TabModalConfirmDialogDelegate(content::WebContents* web_contents); | 37 explicit TabModalConfirmDialogDelegate(content::WebContents* web_contents); |
| 29 virtual ~TabModalConfirmDialogDelegate(); | 38 virtual ~TabModalConfirmDialogDelegate(); |
| 30 | 39 |
| 31 void set_window(WebContentsModalDialog* window) { window_ = window; } | 40 void set_close_delegate(TabModalConfirmDialogCloseDelegate* close_delegate) { |
| 41 close_delegate_ = close_delegate; |
| 42 } |
| 32 | 43 |
| 33 // Accepts the confirmation prompt and calls |OnAccepted|. | 44 // Accepts the confirmation prompt and calls |OnAccepted|. |
| 34 // This method is safe to call even from an |OnAccepted| or |OnCanceled| | 45 // This method is safe to call even from an |OnAccepted| or |OnCanceled| |
| 35 // callback. It is guaranteed that exactly one of |OnAccepted| or |OnCanceled| | 46 // callback. It is guaranteed that exactly one of |OnAccepted| or |OnCanceled| |
| 36 // is eventually called. | 47 // is eventually called. |
| 37 void Accept(); | 48 void Accept(); |
| 38 | 49 |
| 39 // Cancels the confirmation prompt and calls |OnCanceled|. | 50 // Cancels the confirmation prompt and calls |OnCanceled|. |
| 40 // 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| |
| 41 // callback. It is guaranteed that exactly one of |OnAccepted| or |OnCanceled| | 52 // callback. It is guaranteed that exactly one of |OnAccepted| or |OnCanceled| |
| (...skipping 13 matching lines...) Expand all Loading... |
| 55 virtual string16 GetAcceptButtonTitle(); | 66 virtual string16 GetAcceptButtonTitle(); |
| 56 virtual string16 GetCancelButtonTitle(); | 67 virtual string16 GetCancelButtonTitle(); |
| 57 | 68 |
| 58 // GTK stock icon names for the accept and cancel buttons, respectively. | 69 // GTK stock icon names for the accept and cancel buttons, respectively. |
| 59 // The icons are only used on GTK. If these methods are not overriden, | 70 // The icons are only used on GTK. If these methods are not overriden, |
| 60 // the buttons have no stock icons. | 71 // the buttons have no stock icons. |
| 61 virtual const char* GetAcceptButtonIcon(); | 72 virtual const char* GetAcceptButtonIcon(); |
| 62 virtual const char* GetCancelButtonIcon(); | 73 virtual const char* GetCancelButtonIcon(); |
| 63 | 74 |
| 64 protected: | 75 protected: |
| 65 WebContentsModalDialog* window() { return window_; } | 76 TabModalConfirmDialogCloseDelegate* close_delegate() { |
| 77 return close_delegate_; |
| 78 } |
| 66 | 79 |
| 67 // content::NotificationObserver implementation. | 80 // content::NotificationObserver implementation. |
| 68 // Watch for a new load or a closed tab and dismiss the dialog if they occur. | 81 // Watch for a new load or a closed tab and dismiss the dialog if they occur. |
| 69 virtual void Observe(int type, | 82 virtual void Observe(int type, |
| 70 const content::NotificationSource& source, | 83 const content::NotificationSource& source, |
| 71 const content::NotificationDetails& details) OVERRIDE; | 84 const content::NotificationDetails& details) OVERRIDE; |
| 72 | 85 |
| 73 content::NotificationRegistrar registrar_; | 86 content::NotificationRegistrar registrar_; |
| 74 | 87 |
| 75 private: | 88 private: |
| 76 // Called when the user accepts or cancels the dialog, respectively. | 89 // Called when the user accepts or cancels the dialog, respectively. |
| 77 virtual void OnAccepted(); | 90 virtual void OnAccepted(); |
| 78 virtual void OnCanceled(); | 91 virtual void OnCanceled(); |
| 79 | 92 |
| 80 // Close the dialog. | 93 // Close the dialog. |
| 81 void CloseDialog(); | 94 void CloseDialog(); |
| 82 | 95 |
| 83 WebContentsModalDialog* window_; | 96 TabModalConfirmDialogCloseDelegate* close_delegate_; |
| 84 // True iff we are in the process of closing, to avoid running callbacks | 97 // True iff we are in the process of closing, to avoid running callbacks |
| 85 // multiple times. | 98 // multiple times. |
| 86 bool closing_; | 99 bool closing_; |
| 87 | 100 |
| 88 DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogDelegate); | 101 DISALLOW_COPY_AND_ASSIGN(TabModalConfirmDialogDelegate); |
| 89 }; | 102 }; |
| 90 | 103 |
| 91 #endif // CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_DELEGATE_H_ | 104 #endif // CHROME_BROWSER_UI_TAB_MODAL_CONFIRM_DIALOG_DELEGATE_H_ |
| OLD | NEW |