Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(663)

Side by Side Diff: content/browser/android/download_controller_android_impl.cc

Issue 1854523002: If a download is initiated by download attribute, don't use stream viewer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/android/context_utils.h" 9 #include "base/android/context_utils.h"
10 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 ScopedJavaLocalRef<jobject> j_content_view_core) { 232 ScopedJavaLocalRef<jobject> j_content_view_core) {
233 DCHECK_CURRENTLY_ON(BrowserThread::UI); 233 DCHECK_CURRENTLY_ON(BrowserThread::UI);
234 DCHECK(!j_content_view_core.is_null()); 234 DCHECK(!j_content_view_core.is_null());
235 235
236 JNIEnv* env = base::android::AttachCurrentThread(); 236 JNIEnv* env = base::android::AttachCurrentThread();
237 return Java_DownloadController_hasFileAccess( 237 return Java_DownloadController_hasFileAccess(
238 env, GetJavaObject()->Controller(env).obj(), j_content_view_core.obj()); 238 env, GetJavaObject()->Controller(env).obj(), j_content_view_core.obj());
239 } 239 }
240 240
241 void DownloadControllerAndroidImpl::CreateGETDownload( 241 void DownloadControllerAndroidImpl::CreateGETDownload(
242 int render_process_id, int render_view_id, int request_id) { 242 int render_process_id, int render_view_id, int request_id,
243 bool must_download) {
243 DCHECK_CURRENTLY_ON(BrowserThread::IO); 244 DCHECK_CURRENTLY_ON(BrowserThread::IO);
244 GlobalRequestID global_id(render_process_id, request_id); 245 GlobalRequestID global_id(render_process_id, request_id);
245 246
246 // We are yielding the UI thread and render_view_host may go away by 247 // We are yielding the UI thread and render_view_host may go away by
247 // the time we come back. Pass along render_process_id and render_view_id 248 // the time we come back. Pass along render_process_id and render_view_id
248 // to retrieve it later (if it still exists). 249 // to retrieve it later (if it still exists).
249 GetDownloadInfoCB cb = base::Bind( 250 GetDownloadInfoCB cb = base::Bind(
250 &DownloadControllerAndroidImpl::StartAndroidDownload, 251 &DownloadControllerAndroidImpl::StartAndroidDownload,
251 base::Unretained(this), render_process_id, 252 base::Unretained(this), render_process_id,
252 render_view_id); 253 render_view_id, must_download);
253 254
254 PrepareDownloadInfo( 255 PrepareDownloadInfo(
255 global_id, 256 global_id,
256 base::Bind(&DownloadControllerAndroidImpl::StartDownloadOnUIThread, 257 base::Bind(&DownloadControllerAndroidImpl::StartDownloadOnUIThread,
257 base::Unretained(this), cb)); 258 base::Unretained(this), cb));
258 } 259 }
259 260
260 void DownloadControllerAndroidImpl::PrepareDownloadInfo( 261 void DownloadControllerAndroidImpl::PrepareDownloadInfo(
261 const GlobalRequestID& global_id, 262 const GlobalRequestID& global_id,
262 const GetDownloadInfoCB& callback) { 263 const GetDownloadInfoCB& callback) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 337
337 void DownloadControllerAndroidImpl::StartDownloadOnUIThread( 338 void DownloadControllerAndroidImpl::StartDownloadOnUIThread(
338 const GetDownloadInfoCB& callback, 339 const GetDownloadInfoCB& callback,
339 const DownloadInfoAndroid& info) { 340 const DownloadInfoAndroid& info) {
340 DCHECK_CURRENTLY_ON(BrowserThread::IO); 341 DCHECK_CURRENTLY_ON(BrowserThread::IO);
341 BrowserThread::PostTask( 342 BrowserThread::PostTask(
342 BrowserThread::UI, FROM_HERE, base::Bind(callback, info)); 343 BrowserThread::UI, FROM_HERE, base::Bind(callback, info));
343 } 344 }
344 345
345 void DownloadControllerAndroidImpl::StartAndroidDownload( 346 void DownloadControllerAndroidImpl::StartAndroidDownload(
346 int render_process_id, int render_view_id, 347 int render_process_id, int render_view_id, bool must_download,
347 const DownloadInfoAndroid& info) { 348 const DownloadInfoAndroid& info) {
348 DCHECK_CURRENTLY_ON(BrowserThread::UI); 349 DCHECK_CURRENTLY_ON(BrowserThread::UI);
349 350
350 WebContents* web_contents = GetWebContents(render_process_id, render_view_id); 351 WebContents* web_contents = GetWebContents(render_process_id, render_view_id);
351 if (!web_contents) { 352 if (!web_contents) {
352 // The view went away. Can't proceed. 353 // The view went away. Can't proceed.
353 LOG(ERROR) << "Download failed on URL:" << info.url.spec(); 354 LOG(ERROR) << "Download failed on URL:" << info.url.spec();
354 return; 355 return;
355 } 356 }
356 ScopedJavaLocalRef<jobject> view = 357 ScopedJavaLocalRef<jobject> view =
357 GetContentViewCoreFromWebContents(web_contents); 358 GetContentViewCoreFromWebContents(web_contents);
358 if (view.is_null()) { 359 if (view.is_null()) {
359 // ContentViewCore might not have been created yet, pass a callback to 360 // ContentViewCore might not have been created yet, pass a callback to
360 // DeferredDownloadTaskManager so that the download can restart when 361 // DeferredDownloadTaskManager so that the download can restart when
361 // ContentViewCore is created. 362 // ContentViewCore is created.
362 deferred_downloads_.push_back(new DeferredDownloadObserver( 363 deferred_downloads_.push_back(new DeferredDownloadObserver(
363 web_contents, 364 web_contents,
364 base::Bind(&DownloadControllerAndroidImpl::StartAndroidDownload, 365 base::Bind(&DownloadControllerAndroidImpl::StartAndroidDownload,
365 base::Unretained(this), render_process_id, render_view_id, 366 base::Unretained(this), render_process_id, render_view_id,
366 info))); 367 must_download, info)));
367 return; 368 return;
368 } 369 }
369 370
370 AcquireFileAccessPermission( 371 AcquireFileAccessPermission(
371 web_contents, 372 web_contents,
372 base::Bind(&DownloadControllerAndroidImpl::StartAndroidDownloadInternal, 373 base::Bind(&DownloadControllerAndroidImpl::StartAndroidDownloadInternal,
373 base::Unretained(this), render_process_id, render_view_id, 374 base::Unretained(this), render_process_id, render_view_id,
374 info)); 375 must_download, info));
375 } 376 }
376 377
377 void DownloadControllerAndroidImpl::StartAndroidDownloadInternal( 378 void DownloadControllerAndroidImpl::StartAndroidDownloadInternal(
378 int render_process_id, int render_view_id, 379 int render_process_id, int render_view_id, bool must_download,
379 const DownloadInfoAndroid& info, bool allowed) { 380 const DownloadInfoAndroid& info, bool allowed) {
380 DCHECK_CURRENTLY_ON(BrowserThread::UI); 381 DCHECK_CURRENTLY_ON(BrowserThread::UI);
381 if (!allowed) 382 if (!allowed)
382 return; 383 return;
383 384
384 // Call newHttpGetDownload 385 // Call newHttpGetDownload
385 WebContents* web_contents = GetWebContents(render_process_id, render_view_id); 386 WebContents* web_contents = GetWebContents(render_process_id, render_view_id);
386 // The view went away. Can't proceed. 387 // The view went away. Can't proceed.
387 if (!web_contents) 388 if (!web_contents)
388 return; 389 return;
(...skipping 22 matching lines...) Expand all
411 env, net::GetSuggestedFilename(info.url, info.content_disposition, 412 env, net::GetSuggestedFilename(info.url, info.content_disposition,
412 std::string(), // referrer_charset 413 std::string(), // referrer_charset
413 std::string(), // suggested_name 414 std::string(), // suggested_name
414 info.original_mime_type, 415 info.original_mime_type,
415 default_file_name_)); 416 default_file_name_));
416 417
417 Java_DownloadController_newHttpGetDownload( 418 Java_DownloadController_newHttpGetDownload(
418 env, GetJavaObject()->Controller(env).obj(), view.obj(), jurl.obj(), 419 env, GetJavaObject()->Controller(env).obj(), view.obj(), jurl.obj(),
419 juser_agent.obj(), jcontent_disposition.obj(), jmime_type.obj(), 420 juser_agent.obj(), jcontent_disposition.obj(), jmime_type.obj(),
420 jcookie.obj(), jreferer.obj(), info.has_user_gesture, jfilename.obj(), 421 jcookie.obj(), jreferer.obj(), info.has_user_gesture, jfilename.obj(),
421 info.total_bytes); 422 info.total_bytes, must_download);
422 } 423 }
423 424
424 void DownloadControllerAndroidImpl::OnDownloadStarted( 425 void DownloadControllerAndroidImpl::OnDownloadStarted(
425 DownloadItem* download_item) { 426 DownloadItem* download_item) {
426 DCHECK_CURRENTLY_ON(BrowserThread::UI); 427 DCHECK_CURRENTLY_ON(BrowserThread::UI);
427 if (!download_item->GetWebContents()) 428 if (!download_item->GetWebContents())
428 return; 429 return;
429 430
430 JNIEnv* env = base::android::AttachCurrentThread(); 431 JNIEnv* env = base::android::AttachCurrentThread();
431 432
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 } 604 }
604 605
605 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 606 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
606 if (info) 607 if (info)
607 has_user_gesture = info->HasUserGesture(); 608 has_user_gesture = info->HasUserGesture();
608 } 609 }
609 610
610 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} 611 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {}
611 612
612 } // namespace content 613 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698