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); | 187 DCHECK(web_contents); |
189 if (!web_contents) { | |
190 BrowserThread::PostTask( | |
191 BrowserThread::UI, FROM_HERE, base::Bind(cb, false)); | |
192 return; | |
193 } | |
194 | 188 |
195 ScopedJavaLocalRef<jobject> view = | 189 ScopedJavaLocalRef<jobject> view = |
196 GetContentViewCoreFromWebContents(web_contents); | 190 GetContentViewCoreFromWebContents(web_contents); |
197 if (view.is_null()) { | 191 if (view.is_null()) { |
198 BrowserThread::PostTask( | 192 BrowserThread::PostTask( |
199 BrowserThread::UI, FROM_HERE, base::Bind(cb, false)); | 193 BrowserThread::UI, FROM_HERE, base::Bind(cb, false)); |
200 return; | 194 return; |
201 } | 195 } |
202 | 196 |
203 if (HasFileAccessPermission(view)) { | 197 if (HasFileAccessPermission(view)) { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 // ContentViewCore is created. | 341 // ContentViewCore is created. |
348 deferred_downloads_.push_back(new DeferredDownloadObserver( | 342 deferred_downloads_.push_back(new DeferredDownloadObserver( |
349 web_contents, | 343 web_contents, |
350 base::Bind(&DownloadControllerAndroidImpl::StartAndroidDownload, | 344 base::Bind(&DownloadControllerAndroidImpl::StartAndroidDownload, |
351 base::Unretained(this), render_process_id, render_view_id, | 345 base::Unretained(this), render_process_id, render_view_id, |
352 info))); | 346 info))); |
353 return; | 347 return; |
354 } | 348 } |
355 | 349 |
356 AcquireFileAccessPermission( | 350 AcquireFileAccessPermission( |
357 render_process_id, render_view_id, | 351 web_contents, |
358 base::Bind(&DownloadControllerAndroidImpl::StartAndroidDownloadInternal, | 352 base::Bind(&DownloadControllerAndroidImpl::StartAndroidDownloadInternal, |
359 base::Unretained(this), render_process_id, render_view_id, | 353 base::Unretained(this), render_process_id, render_view_id, |
360 info)); | 354 info)); |
361 } | 355 } |
362 | 356 |
363 void DownloadControllerAndroidImpl::StartAndroidDownloadInternal( | 357 void DownloadControllerAndroidImpl::StartAndroidDownloadInternal( |
364 int render_process_id, int render_view_id, | 358 int render_process_id, int render_view_id, |
365 const DownloadInfoAndroid& info, bool allowed) { | 359 const DownloadInfoAndroid& info, bool allowed) { |
366 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 360 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
367 if (!allowed) | 361 if (!allowed) |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 DCHECK(java_object_); | 517 DCHECK(java_object_); |
524 return java_object_; | 518 return java_object_; |
525 } | 519 } |
526 | 520 |
527 void DownloadControllerAndroidImpl::StartContextMenuDownload( | 521 void DownloadControllerAndroidImpl::StartContextMenuDownload( |
528 const ContextMenuParams& params, WebContents* web_contents, bool is_link, | 522 const ContextMenuParams& params, WebContents* web_contents, bool is_link, |
529 const std::string& extra_headers) { | 523 const std::string& extra_headers) { |
530 int process_id = web_contents->GetRenderProcessHost()->GetID(); | 524 int process_id = web_contents->GetRenderProcessHost()->GetID(); |
531 int routing_id = web_contents->GetRoutingID(); | 525 int routing_id = web_contents->GetRoutingID(); |
532 AcquireFileAccessPermission( | 526 AcquireFileAccessPermission( |
533 process_id, routing_id, | 527 web_contents, base::Bind(&CreateContextMenuDownload, process_id, |
534 base::Bind(&CreateContextMenuDownload, process_id, routing_id, params, | 528 routing_id, params, is_link, extra_headers)); |
535 is_link, extra_headers)); | |
536 } | 529 } |
537 | 530 |
538 void DownloadControllerAndroidImpl::DangerousDownloadValidated( | 531 void DownloadControllerAndroidImpl::DangerousDownloadValidated( |
539 WebContents* web_contents, int download_id, bool accept) { | 532 WebContents* web_contents, int download_id, bool accept) { |
540 if (!web_contents) | 533 if (!web_contents) |
541 return; | 534 return; |
542 DownloadManagerImpl* dlm = static_cast<DownloadManagerImpl*>( | 535 DownloadManagerImpl* dlm = static_cast<DownloadManagerImpl*>( |
543 BrowserContext::GetDownloadManager(web_contents->GetBrowserContext())); | 536 BrowserContext::GetDownloadManager(web_contents->GetBrowserContext())); |
544 DownloadItem* item = dlm->GetDownload(download_id); | 537 DownloadItem* item = dlm->GetDownload(download_id); |
545 if (!item) | 538 if (!item) |
(...skipping 25 matching lines...) Expand all Loading... |
571 } | 564 } |
572 | 565 |
573 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 566 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
574 if (info) | 567 if (info) |
575 has_user_gesture = info->HasUserGesture(); | 568 has_user_gesture = info->HasUserGesture(); |
576 } | 569 } |
577 | 570 |
578 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} | 571 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} |
579 | 572 |
580 } // namespace content | 573 } // namespace content |
OLD | NEW |