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 "content/browser/android/download_controller_android_impl.h" | 5 #include "content/browser/android/download_controller_android_impl.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 for (auto iter = deferred_downloads_.begin(); | 174 for (auto iter = deferred_downloads_.begin(); |
175 iter != deferred_downloads_.end(); ++iter) { | 175 iter != deferred_downloads_.end(); ++iter) { |
176 if (*iter == observer) { | 176 if (*iter == observer) { |
177 deferred_downloads_.erase(iter); | 177 deferred_downloads_.erase(iter); |
178 return; | 178 return; |
179 } | 179 } |
180 } | 180 } |
181 } | 181 } |
182 | 182 |
183 void DownloadControllerAndroidImpl::AcquireFileAccessPermission( | 183 void DownloadControllerAndroidImpl::AcquireFileAccessPermission( |
184 int render_process_id, | 184 WebContents* web_contents, |
185 int render_view_id, | |
186 const DownloadControllerAndroid::AcquireFileAccessPermissionCallback& cb) { | 185 const DownloadControllerAndroid::AcquireFileAccessPermissionCallback& cb) { |
187 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 186 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
188 WebContents* web_contents = GetWebContents(render_process_id, render_view_id); | |
189 if (!web_contents) { | 187 if (!web_contents) { |
davidben
2015/11/24 15:51:16
Nit: I'd probably have moved this into the caller.
clamy
2015/11/25 14:02:02
Done. Note that the caller now run the callback sy
| |
190 BrowserThread::PostTask( | 188 BrowserThread::PostTask( |
191 BrowserThread::UI, FROM_HERE, base::Bind(cb, false)); | 189 BrowserThread::UI, FROM_HERE, base::Bind(cb, false)); |
192 return; | 190 return; |
193 } | 191 } |
194 | 192 |
195 ScopedJavaLocalRef<jobject> view = | 193 ScopedJavaLocalRef<jobject> view = |
196 GetContentViewCoreFromWebContents(web_contents); | 194 GetContentViewCoreFromWebContents(web_contents); |
197 if (view.is_null()) { | 195 if (view.is_null()) { |
198 BrowserThread::PostTask( | 196 BrowserThread::PostTask( |
199 BrowserThread::UI, FROM_HERE, base::Bind(cb, false)); | 197 BrowserThread::UI, FROM_HERE, base::Bind(cb, false)); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 // ContentViewCore is created. | 345 // ContentViewCore is created. |
348 deferred_downloads_.push_back(new DeferredDownloadObserver( | 346 deferred_downloads_.push_back(new DeferredDownloadObserver( |
349 web_contents, | 347 web_contents, |
350 base::Bind(&DownloadControllerAndroidImpl::StartAndroidDownload, | 348 base::Bind(&DownloadControllerAndroidImpl::StartAndroidDownload, |
351 base::Unretained(this), render_process_id, render_view_id, | 349 base::Unretained(this), render_process_id, render_view_id, |
352 info))); | 350 info))); |
353 return; | 351 return; |
354 } | 352 } |
355 | 353 |
356 AcquireFileAccessPermission( | 354 AcquireFileAccessPermission( |
357 render_process_id, render_view_id, | 355 web_contents, |
358 base::Bind(&DownloadControllerAndroidImpl::StartAndroidDownloadInternal, | 356 base::Bind(&DownloadControllerAndroidImpl::StartAndroidDownloadInternal, |
359 base::Unretained(this), render_process_id, render_view_id, | 357 base::Unretained(this), render_process_id, render_view_id, |
360 info)); | 358 info)); |
361 } | 359 } |
362 | 360 |
363 void DownloadControllerAndroidImpl::StartAndroidDownloadInternal( | 361 void DownloadControllerAndroidImpl::StartAndroidDownloadInternal( |
364 int render_process_id, int render_view_id, | 362 int render_process_id, int render_view_id, |
365 const DownloadInfoAndroid& info, bool allowed) { | 363 const DownloadInfoAndroid& info, bool allowed) { |
366 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 364 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
367 if (!allowed) | 365 if (!allowed) |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
523 DCHECK(java_object_); | 521 DCHECK(java_object_); |
524 return java_object_; | 522 return java_object_; |
525 } | 523 } |
526 | 524 |
527 void DownloadControllerAndroidImpl::StartContextMenuDownload( | 525 void DownloadControllerAndroidImpl::StartContextMenuDownload( |
528 const ContextMenuParams& params, WebContents* web_contents, bool is_link, | 526 const ContextMenuParams& params, WebContents* web_contents, bool is_link, |
529 const std::string& extra_headers) { | 527 const std::string& extra_headers) { |
530 int process_id = web_contents->GetRenderProcessHost()->GetID(); | 528 int process_id = web_contents->GetRenderProcessHost()->GetID(); |
531 int routing_id = web_contents->GetRoutingID(); | 529 int routing_id = web_contents->GetRoutingID(); |
532 AcquireFileAccessPermission( | 530 AcquireFileAccessPermission( |
533 process_id, routing_id, | 531 web_contents, base::Bind(&CreateContextMenuDownload, process_id, |
534 base::Bind(&CreateContextMenuDownload, process_id, routing_id, params, | 532 routing_id, params, is_link, extra_headers)); |
535 is_link, extra_headers)); | |
536 } | 533 } |
537 | 534 |
538 void DownloadControllerAndroidImpl::DangerousDownloadValidated( | 535 void DownloadControllerAndroidImpl::DangerousDownloadValidated( |
539 WebContents* web_contents, int download_id, bool accept) { | 536 WebContents* web_contents, int download_id, bool accept) { |
540 if (!web_contents) | 537 if (!web_contents) |
541 return; | 538 return; |
542 DownloadManagerImpl* dlm = static_cast<DownloadManagerImpl*>( | 539 DownloadManagerImpl* dlm = static_cast<DownloadManagerImpl*>( |
543 BrowserContext::GetDownloadManager(web_contents->GetBrowserContext())); | 540 BrowserContext::GetDownloadManager(web_contents->GetBrowserContext())); |
544 DownloadItem* item = dlm->GetDownload(download_id); | 541 DownloadItem* item = dlm->GetDownload(download_id); |
545 if (!item) | 542 if (!item) |
(...skipping 25 matching lines...) Expand all Loading... | |
571 } | 568 } |
572 | 569 |
573 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 570 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
574 if (info) | 571 if (info) |
575 has_user_gesture = info->HasUserGesture(); | 572 has_user_gesture = info->HasUserGesture(); |
576 } | 573 } |
577 | 574 |
578 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} | 575 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} |
579 | 576 |
580 } // namespace content | 577 } // namespace content |
OLD | NEW |