Chromium Code Reviews| 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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 BrowserThread::UI, FROM_HERE, base::Bind(cb, true)); | 212 BrowserThread::UI, FROM_HERE, base::Bind(cb, true)); |
| 213 return; | 213 return; |
| 214 } | 214 } |
| 215 // Make copy on the heap so we can pass the pointer through JNI. | 215 // Make copy on the heap so we can pass the pointer through JNI. |
| 216 intptr_t callback_id = reinterpret_cast<intptr_t>( | 216 intptr_t callback_id = reinterpret_cast<intptr_t>( |
| 217 new DownloadControllerBase::AcquireFileAccessPermissionCallback(cb)); | 217 new DownloadControllerBase::AcquireFileAccessPermissionCallback(cb)); |
| 218 ChromeDownloadDelegate::FromWebContents(web_contents)-> | 218 ChromeDownloadDelegate::FromWebContents(web_contents)-> |
| 219 RequestFileAccess(callback_id); | 219 RequestFileAccess(callback_id); |
| 220 } | 220 } |
| 221 | 221 |
| 222 void DownloadController::CreateGETDownload( | |
| 223 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, | |
| 224 const DownloadInfo& info) { | |
| 225 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 226 | |
| 227 BrowserThread::PostTask( | |
| 228 BrowserThread::UI, FROM_HERE, | |
| 229 base::Bind(&DownloadController::StartAndroidDownload, | |
| 230 base::Unretained(this), | |
| 231 wc_getter, info)); | |
| 232 } | |
| 233 | |
| 234 void DownloadController::StartAndroidDownload( | |
| 235 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, | |
| 236 const DownloadInfo& info) { | |
| 237 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 238 | |
| 239 WebContents* web_contents = wc_getter.Run(); | |
| 240 if (!web_contents) { | |
| 241 // The view went away. Can't proceed. | |
| 242 LOG(ERROR) << "Download failed on URL:" << info.url.spec(); | |
| 243 return; | |
| 244 } | |
| 245 | |
| 246 AcquireFileAccessPermission( | |
| 247 web_contents, | |
| 248 base::Bind(&DownloadController::StartAndroidDownloadInternal, | |
| 249 base::Unretained(this), wc_getter, info)); | |
| 250 } | |
| 251 | |
| 252 void DownloadController::StartAndroidDownloadInternal( | |
| 253 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, | |
| 254 const DownloadInfo& info, bool allowed) { | |
| 255 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 256 if (!allowed) | |
| 257 return; | |
| 258 | |
| 259 WebContents* web_contents = wc_getter.Run(); | |
| 260 if (!web_contents) | |
| 261 return; | |
|
David Trainor- moved to gerrit
2017/01/24 17:13:35
Should this case log a similar error to StartAndro
qinmin
2017/01/24 17:32:23
Done.
| |
| 262 | |
| 263 ChromeDownloadDelegate::FromWebContents(web_contents)-> | |
| 264 EnqueueDownloadManagerRequest( | |
| 265 info.url.spec(), info.user_agent, | |
| 266 info.content_disposition, info.original_mime_type, | |
| 267 info.cookie, info.referer); | |
| 268 } | |
| 269 | |
| 222 bool DownloadController::HasFileAccessPermission( | 270 bool DownloadController::HasFileAccessPermission( |
| 223 ui::WindowAndroid* window_android) { | 271 ui::WindowAndroid* window_android) { |
| 224 ScopedJavaLocalRef<jobject> jwindow_android = window_android->GetJavaObject(); | 272 ScopedJavaLocalRef<jobject> jwindow_android = window_android->GetJavaObject(); |
| 225 | 273 |
| 226 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 274 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 227 DCHECK(!jwindow_android.is_null()); | 275 DCHECK(!jwindow_android.is_null()); |
| 228 | 276 |
| 229 JNIEnv* env = base::android::AttachCurrentThread(); | 277 JNIEnv* env = base::android::AttachCurrentThread(); |
| 230 return Java_DownloadController_hasFileAccess( | 278 return Java_DownloadController_hasFileAccess( |
| 231 env, GetJavaObject()->Controller(env), jwindow_android); | 279 env, GetJavaObject()->Controller(env), jwindow_android); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 void DownloadController::StartContextMenuDownload( | 377 void DownloadController::StartContextMenuDownload( |
| 330 const ContextMenuParams& params, WebContents* web_contents, bool is_link, | 378 const ContextMenuParams& params, WebContents* web_contents, bool is_link, |
| 331 const std::string& extra_headers) { | 379 const std::string& extra_headers) { |
| 332 int process_id = web_contents->GetRenderProcessHost()->GetID(); | 380 int process_id = web_contents->GetRenderProcessHost()->GetID(); |
| 333 int routing_id = web_contents->GetRenderViewHost()->GetRoutingID(); | 381 int routing_id = web_contents->GetRenderViewHost()->GetRoutingID(); |
| 334 AcquireFileAccessPermission( | 382 AcquireFileAccessPermission( |
| 335 web_contents, base::Bind(&CreateContextMenuDownload, process_id, | 383 web_contents, base::Bind(&CreateContextMenuDownload, process_id, |
| 336 routing_id, params, is_link, extra_headers)); | 384 routing_id, params, is_link, extra_headers)); |
| 337 } | 385 } |
| 338 | 386 |
| OLD | NEW |