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/download/chrome_download_manager_delegate.h" | 8 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
9 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" | 9 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" |
10 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" | 10 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
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 virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE; | 37 virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE; |
38 | 38 |
39 // TabModalConfirmDialogDelegate | 39 // TabModalConfirmDialogDelegate |
40 virtual string16 GetTitle() OVERRIDE; | 40 virtual string16 GetTitle() OVERRIDE; |
41 virtual string16 GetMessage() OVERRIDE; | 41 virtual string16 GetMessage() OVERRIDE; |
42 virtual string16 GetAcceptButtonTitle() OVERRIDE; | 42 virtual string16 GetAcceptButtonTitle() OVERRIDE; |
43 virtual void OnAccepted() OVERRIDE; | 43 virtual void OnAccepted() OVERRIDE; |
44 virtual void OnCanceled() OVERRIDE; | 44 virtual void OnCanceled() OVERRIDE; |
45 virtual void OnDismissed() OVERRIDE; | |
45 | 46 |
46 // Runs |callback|. PrepareToClose() is called beforehand. Doing so prevents | 47 // Runs |callback|. PrepareToClose() is called beforehand. Doing so prevents |
47 // this object from responding to state changes in |download_| that might | 48 // this object from responding to state changes in |download_| that might |
48 // result from invoking the callback. |callback| must refer to either | 49 // result from invoking the callback. |callback| must refer to either |
49 // |accepted_| or |canceled_|. | 50 // |accepted_| or |canceled_|. |
50 void RunCallback(const base::Closure& callback); | 51 void RunCallback(const base::Closure& callback); |
51 | 52 |
52 // Resets |accepted_|, |canceled_| and removes the observer from |download_|, | 53 // Resets |accepted_|, |canceled_| and removes the observer from |download_|, |
53 // in preparation for closing the prompt. | 54 // in preparation for closing the prompt. |
54 void PrepareToClose(); | 55 void PrepareToClose(); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 } | 140 } |
140 | 141 |
141 void DownloadDangerPromptImpl::OnAccepted() { | 142 void DownloadDangerPromptImpl::OnAccepted() { |
142 RunCallback(accepted_); | 143 RunCallback(accepted_); |
143 } | 144 } |
144 | 145 |
145 void DownloadDangerPromptImpl::OnCanceled() { | 146 void DownloadDangerPromptImpl::OnCanceled() { |
146 RunCallback(canceled_); | 147 RunCallback(canceled_); |
147 } | 148 } |
148 | 149 |
150 void DownloadDangerPromptImpl::OnDismissed() { | |
151 RunCallback(canceled_); | |
fdoray
2013/06/28 15:32:59
Should I call OnCanceled here to avoid code duplic
benjhayden
2013/06/28 16:05:46
I have a slight preference for calling RunCallback
| |
152 } | |
153 | |
149 void DownloadDangerPromptImpl::RunCallback(const base::Closure& callback) { | 154 void DownloadDangerPromptImpl::RunCallback(const base::Closure& callback) { |
150 // Invoking the callback can cause the download item state to change or cause | 155 // Invoking the callback can cause the download item state to change or cause |
151 // the constrained window to close, and |callback| refers to a member | 156 // the constrained window to close, and |callback| refers to a member |
152 // variable. | 157 // variable. |
153 base::Closure callback_copy = callback; | 158 base::Closure callback_copy = callback; |
154 PrepareToClose(); | 159 PrepareToClose(); |
155 if (!callback_copy.is_null()) | 160 if (!callback_copy.is_null()) |
156 callback_copy.Run(); | 161 callback_copy.Run(); |
157 } | 162 } |
158 | 163 |
(...skipping 14 matching lines...) Expand all Loading... | |
173 content::WebContents* web_contents, | 178 content::WebContents* web_contents, |
174 bool show_context, | 179 bool show_context, |
175 const base::Closure& accepted, | 180 const base::Closure& accepted, |
176 const base::Closure& canceled) { | 181 const base::Closure& canceled) { |
177 DownloadDangerPromptImpl* prompt = new DownloadDangerPromptImpl( | 182 DownloadDangerPromptImpl* prompt = new DownloadDangerPromptImpl( |
178 item, web_contents, show_context, accepted, canceled); | 183 item, web_contents, show_context, accepted, canceled); |
179 // |prompt| will be deleted when the dialog is done. | 184 // |prompt| will be deleted when the dialog is done. |
180 TabModalConfirmDialog::Create(prompt, web_contents); | 185 TabModalConfirmDialog::Create(prompt, web_contents); |
181 return prompt; | 186 return prompt; |
182 } | 187 } |
OLD | NEW |