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 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" | 5 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" |
6 | 6 |
7 #include "chrome/common/chrome_notification_types.h" | 7 #include "chrome/common/chrome_notification_types.h" |
8 #include "content/public/browser/navigation_controller.h" | 8 #include "content/public/browser/navigation_controller.h" |
9 #include "content/public/browser/notification_source.h" | 9 #include "content/public/browser/notification_source.h" |
10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 } | 26 } |
27 | 27 |
28 TabModalConfirmDialogDelegate::~TabModalConfirmDialogDelegate() { | 28 TabModalConfirmDialogDelegate::~TabModalConfirmDialogDelegate() { |
29 // If we end up here, the window has been closed, so make sure we don't close | 29 // If we end up here, the window has been closed, so make sure we don't close |
30 // it again. | 30 // it again. |
31 close_delegate_ = NULL; | 31 close_delegate_ = NULL; |
32 // Make sure everything is cleaned up. | 32 // Make sure everything is cleaned up. |
33 Cancel(); | 33 Cancel(); |
34 } | 34 } |
35 | 35 |
36 void TabModalConfirmDialogDelegate::Cancel() { | 36 bool TabModalConfirmDialogDelegate::Cancel() { |
37 if (closing_) | 37 if (closing_) |
38 return; | 38 return false; |
39 // Make sure we won't do anything when |Cancel()| or |Accept()| is called | 39 // Make sure we won't do anything when another action occurs. |
40 // again. | |
41 closing_ = true; | 40 closing_ = true; |
42 OnCanceled(); | 41 OnCanceled(); |
43 CloseDialog(); | 42 CloseDialog(); |
| 43 return true; |
44 } | 44 } |
45 | 45 |
46 void TabModalConfirmDialogDelegate::Accept() { | 46 bool TabModalConfirmDialogDelegate::Accept() { |
47 if (closing_) | 47 if (closing_) |
48 return; | 48 return false; |
49 // Make sure we won't do anything when |Cancel()| or |Accept()| is called | 49 // Make sure we won't do anything when another action occurs. |
50 // again. | |
51 closing_ = true; | 50 closing_ = true; |
52 OnAccepted(); | 51 OnAccepted(); |
53 CloseDialog(); | 52 CloseDialog(); |
| 53 return true; |
54 } | 54 } |
55 | 55 |
56 void TabModalConfirmDialogDelegate::LinkClicked( | 56 bool TabModalConfirmDialogDelegate::LinkClicked( |
57 WindowOpenDisposition disposition) { | 57 WindowOpenDisposition disposition) { |
58 if (closing_) | 58 if (closing_) |
59 return; | 59 return false; |
60 // Make sure we won't do anything when another action occurs. | 60 // Make sure we won't do anything when another action occurs. |
61 closing_ = true; | 61 closing_ = true; |
62 OnLinkClicked(disposition); | 62 OnLinkClicked(disposition); |
63 CloseDialog(); | 63 CloseDialog(); |
| 64 return true; |
| 65 } |
| 66 |
| 67 bool TabModalConfirmDialogDelegate::Dismissed() { |
| 68 if (closing_) |
| 69 return false; |
| 70 // Make sure we won't do anything when another action occurs. |
| 71 closing_ = true; |
| 72 OnDismissed(); |
| 73 CloseDialog(); |
| 74 return true; |
64 } | 75 } |
65 | 76 |
66 void TabModalConfirmDialogDelegate::Observe( | 77 void TabModalConfirmDialogDelegate::Observe( |
67 int type, | 78 int type, |
68 const content::NotificationSource& source, | 79 const content::NotificationSource& source, |
69 const content::NotificationDetails& details) { | 80 const content::NotificationDetails& details) { |
70 // Close the dialog if we load a page (because the action might not apply to | 81 // Close the dialog if we load a page (because the action might not apply to |
71 // the same page anymore) or if the tab is closed. | 82 // the same page anymore) or if the tab is closed. |
72 if (type == content::NOTIFICATION_LOAD_START || | 83 if (type == content::NOTIFICATION_LOAD_START || |
73 type == chrome::NOTIFICATION_TAB_CLOSING) { | 84 type == chrome::NOTIFICATION_TAB_CLOSING) { |
74 Cancel(); | 85 Dismissed(); |
75 } else { | 86 } else { |
76 NOTREACHED(); | 87 NOTREACHED(); |
77 } | 88 } |
78 } | 89 } |
79 | 90 |
80 gfx::Image* TabModalConfirmDialogDelegate::GetIcon() { | 91 gfx::Image* TabModalConfirmDialogDelegate::GetIcon() { |
81 return NULL; | 92 return NULL; |
82 } | 93 } |
83 | 94 |
84 string16 TabModalConfirmDialogDelegate::GetAcceptButtonTitle() { | 95 string16 TabModalConfirmDialogDelegate::GetAcceptButtonTitle() { |
(...skipping 19 matching lines...) Expand all Loading... |
104 void TabModalConfirmDialogDelegate::OnAccepted() { | 115 void TabModalConfirmDialogDelegate::OnAccepted() { |
105 } | 116 } |
106 | 117 |
107 void TabModalConfirmDialogDelegate::OnCanceled() { | 118 void TabModalConfirmDialogDelegate::OnCanceled() { |
108 } | 119 } |
109 | 120 |
110 void TabModalConfirmDialogDelegate::OnLinkClicked( | 121 void TabModalConfirmDialogDelegate::OnLinkClicked( |
111 WindowOpenDisposition disposition) { | 122 WindowOpenDisposition disposition) { |
112 } | 123 } |
113 | 124 |
| 125 void TabModalConfirmDialogDelegate::OnDismissed() { |
| 126 } |
| 127 |
114 void TabModalConfirmDialogDelegate::CloseDialog() { | 128 void TabModalConfirmDialogDelegate::CloseDialog() { |
115 if (close_delegate_) | 129 if (close_delegate_) |
116 close_delegate_->CloseDialog(); | 130 close_delegate_->CloseDialog(); |
117 } | 131 } |
OLD | NEW |