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/download/download_danger_prompt.h" | 5 #include "chrome/browser/download/download_danger_prompt.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 9 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
10 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" | 10 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 private: | 34 private: |
35 // content::DownloadItem::Observer | 35 // content::DownloadItem::Observer |
36 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; | 36 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; |
37 | 37 |
38 // TabModalConfirmDialogDelegate | 38 // TabModalConfirmDialogDelegate |
39 virtual string16 GetTitle() OVERRIDE; | 39 virtual string16 GetTitle() OVERRIDE; |
40 virtual string16 GetMessage() OVERRIDE; | 40 virtual string16 GetMessage() OVERRIDE; |
41 virtual string16 GetAcceptButtonTitle() OVERRIDE; | 41 virtual string16 GetAcceptButtonTitle() OVERRIDE; |
42 virtual void OnAccepted() OVERRIDE; | 42 virtual void OnAccepted() OVERRIDE; |
43 virtual void OnCanceled() OVERRIDE; | 43 virtual void OnCanceled() OVERRIDE; |
| 44 virtual void OnClosed() OVERRIDE; |
44 | 45 |
45 void RunDone(Action action); | 46 void RunDone(Action action); |
46 | 47 |
47 content::DownloadItem* download_; | 48 content::DownloadItem* download_; |
48 bool show_context_; | 49 bool show_context_; |
49 OnDone done_; | 50 OnDone done_; |
50 | 51 |
51 DISALLOW_COPY_AND_ASSIGN(DownloadDangerPromptImpl); | 52 DISALLOW_COPY_AND_ASSIGN(DownloadDangerPromptImpl); |
52 }; | 53 }; |
53 | 54 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } | 136 } |
136 | 137 |
137 void DownloadDangerPromptImpl::OnAccepted() { | 138 void DownloadDangerPromptImpl::OnAccepted() { |
138 RunDone(ACCEPT); | 139 RunDone(ACCEPT); |
139 } | 140 } |
140 | 141 |
141 void DownloadDangerPromptImpl::OnCanceled() { | 142 void DownloadDangerPromptImpl::OnCanceled() { |
142 RunDone(CANCEL); | 143 RunDone(CANCEL); |
143 } | 144 } |
144 | 145 |
| 146 void DownloadDangerPromptImpl::OnClosed() { |
| 147 RunDone(CANCEL); |
| 148 } |
| 149 |
145 void DownloadDangerPromptImpl::RunDone(Action action) { | 150 void DownloadDangerPromptImpl::RunDone(Action action) { |
146 // Invoking the callback can cause the download item state to change or cause | 151 // Invoking the callback can cause the download item state to change or cause |
147 // the constrained window to close, and |callback| refers to a member | 152 // the constrained window to close, and |callback| refers to a member |
148 // variable. | 153 // variable. |
149 OnDone done = done_; | 154 OnDone done = done_; |
150 done_.Reset(); | 155 done_.Reset(); |
151 if (download_ != NULL) { | 156 if (download_ != NULL) { |
152 download_->RemoveObserver(this); | 157 download_->RemoveObserver(this); |
153 download_ = NULL; | 158 download_ = NULL; |
154 } | 159 } |
155 if (!done.is_null()) | 160 if (!done.is_null()) |
156 done.Run(action); | 161 done.Run(action); |
157 } | 162 } |
158 | 163 |
159 } // namespace | 164 } // namespace |
160 | 165 |
161 // static | 166 // static |
162 DownloadDangerPrompt* DownloadDangerPrompt::Create( | 167 DownloadDangerPrompt* DownloadDangerPrompt::Create( |
163 content::DownloadItem* item, | 168 content::DownloadItem* item, |
164 content::WebContents* web_contents, | 169 content::WebContents* web_contents, |
165 bool show_context, | 170 bool show_context, |
166 const OnDone& done) { | 171 const OnDone& done) { |
167 DownloadDangerPromptImpl* prompt = new DownloadDangerPromptImpl( | 172 DownloadDangerPromptImpl* prompt = new DownloadDangerPromptImpl( |
168 item, web_contents, show_context, done); | 173 item, web_contents, show_context, done); |
169 // |prompt| will be deleted when the dialog is done. | 174 // |prompt| will be deleted when the dialog is done. |
170 TabModalConfirmDialog::Create(prompt, web_contents); | 175 TabModalConfirmDialog::Create(prompt, web_contents); |
171 return prompt; | 176 return prompt; |
172 } | 177 } |
OLD | NEW |