| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/android/download/download_controller.h" | 5 #include "chrome/browser/android/download/download_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/android/context_utils.h" | 10 #include "base/android/context_utils.h" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 228 |
| 229 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 229 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 230 DCHECK(!jwindow_android.is_null()); | 230 DCHECK(!jwindow_android.is_null()); |
| 231 | 231 |
| 232 JNIEnv* env = base::android::AttachCurrentThread(); | 232 JNIEnv* env = base::android::AttachCurrentThread(); |
| 233 return Java_DownloadController_hasFileAccess( | 233 return Java_DownloadController_hasFileAccess( |
| 234 env, GetJavaObject()->Controller(env), jwindow_android); | 234 env, GetJavaObject()->Controller(env), jwindow_android); |
| 235 } | 235 } |
| 236 | 236 |
| 237 void DownloadController::CreateGETDownload( | 237 void DownloadController::CreateGETDownload( |
| 238 int render_process_id, int render_view_id, bool must_download, | 238 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
| 239 bool must_download, |
| 239 const DownloadInfo& info) { | 240 const DownloadInfo& info) { |
| 240 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 241 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 241 | 242 |
| 242 // We are yielding the UI thread and render_view_host may go away by | 243 // We are yielding the UI thread and render_view_host may go away by |
| 243 // the time we come back. Pass along render_process_id and render_view_id | 244 // the time we come back. Pass along render_process_id and render_view_id |
| 244 // to retrieve it later (if it still exists). | 245 // to retrieve it later (if it still exists). |
| 245 BrowserThread::PostTask( | 246 BrowserThread::PostTask( |
| 246 BrowserThread::UI, FROM_HERE, | 247 BrowserThread::UI, FROM_HERE, |
| 247 base::Bind(&DownloadController::StartAndroidDownload, | 248 base::Bind(&DownloadController::StartAndroidDownload, |
| 248 base::Unretained(this), | 249 base::Unretained(this), |
| 249 render_process_id, render_view_id, must_download, info)); | 250 wc_getter, must_download, info)); |
| 250 } | 251 } |
| 251 | 252 |
| 252 void DownloadController::StartAndroidDownload( | 253 void DownloadController::StartAndroidDownload( |
| 253 int render_process_id, int render_view_id, bool must_download, | 254 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
| 254 const DownloadInfo& info) { | 255 bool must_download, const DownloadInfo& info) { |
| 255 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 256 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 256 | 257 |
| 257 WebContents* web_contents = GetWebContents(render_process_id, render_view_id); | 258 WebContents* web_contents = wc_getter.Run(); |
| 258 if (!web_contents) { | 259 if (!web_contents) { |
| 259 // The view went away. Can't proceed. | 260 // The view went away. Can't proceed. |
| 260 LOG(ERROR) << "Download failed on URL:" << info.url.spec(); | 261 LOG(ERROR) << "Download failed on URL:" << info.url.spec(); |
| 261 return; | 262 return; |
| 262 } | 263 } |
| 263 | 264 |
| 264 AcquireFileAccessPermission( | 265 AcquireFileAccessPermission( |
| 265 web_contents, | 266 web_contents, |
| 266 base::Bind(&DownloadController::StartAndroidDownloadInternal, | 267 base::Bind(&DownloadController::StartAndroidDownloadInternal, |
| 267 base::Unretained(this), render_process_id, render_view_id, | 268 base::Unretained(this), wc_getter, must_download, info)); |
| 268 must_download, info)); | |
| 269 } | 269 } |
| 270 | 270 |
| 271 void DownloadController::StartAndroidDownloadInternal( | 271 void DownloadController::StartAndroidDownloadInternal( |
| 272 int render_process_id, int render_view_id, bool must_download, | 272 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
| 273 const DownloadInfo& info, bool allowed) { | 273 bool must_download, const DownloadInfo& info, bool allowed) { |
| 274 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 274 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 275 if (!allowed) | 275 if (!allowed) |
| 276 return; | 276 return; |
| 277 | 277 |
| 278 WebContents* web_contents = GetWebContents(render_process_id, render_view_id); | 278 WebContents* web_contents = wc_getter.Run(); |
| 279 // The view went away. Can't proceed. | 279 // The view went away. Can't proceed. |
| 280 if (!web_contents) | 280 if (!web_contents) |
| 281 return; | 281 return; |
| 282 | 282 |
| 283 base::string16 filename = net::GetSuggestedFilename( | 283 base::string16 filename = net::GetSuggestedFilename( |
| 284 info.url, info.content_disposition, | 284 info.url, info.content_disposition, |
| 285 std::string(), // referrer_charset | 285 std::string(), // referrer_charset |
| 286 std::string(), // suggested_name | 286 std::string(), // suggested_name |
| 287 info.original_mime_type, | 287 info.original_mime_type, |
| 288 default_file_name_); | 288 default_file_name_); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 if (!item) | 428 if (!item) |
| 429 return; | 429 return; |
| 430 if (accept) { | 430 if (accept) { |
| 431 item->ValidateDangerousDownload(); | 431 item->ValidateDangerousDownload(); |
| 432 } else { | 432 } else { |
| 433 DownloadController::RecordDownloadCancelReason( | 433 DownloadController::RecordDownloadCancelReason( |
| 434 DownloadController::CANCEL_REASON_DANGEROUS_DOWNLOAD_INFOBAR_DISMISSED); | 434 DownloadController::CANCEL_REASON_DANGEROUS_DOWNLOAD_INFOBAR_DISMISSED); |
| 435 item->Remove(); | 435 item->Remove(); |
| 436 } | 436 } |
| 437 } | 437 } |
| OLD | NEW |