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