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

Side by Side Diff: chrome/browser/android/download/download_controller.cc

Issue 2871123006: Missing webcontents shouldn't block download interception (Closed)
Patch Set: Created 3 years, 7 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 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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 base::Unretained(this), wc_getter, info)); 258 base::Unretained(this), wc_getter, info));
259 } 259 }
260 260
261 void DownloadController::StartAndroidDownloadInternal( 261 void DownloadController::StartAndroidDownloadInternal(
262 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, 262 const content::ResourceRequestInfo::WebContentsGetter& wc_getter,
263 const DownloadInfo& info, bool allowed) { 263 const DownloadInfo& info, bool allowed) {
264 DCHECK_CURRENTLY_ON(BrowserThread::UI); 264 DCHECK_CURRENTLY_ON(BrowserThread::UI);
265 if (!allowed) 265 if (!allowed)
266 return; 266 return;
267 267
268 WebContents* web_contents = wc_getter.Run(); 268 JNIEnv* env = base::android::AttachCurrentThread();
269 if (!web_contents) { 269 base::string16 file_name =
270 // The view went away. Can't proceed.
271 LOG(ERROR) << "Tab closed, download failed on URL:" << info.url.spec();
272 return;
273 }
274
275 base::string16 filename =
276 net::GetSuggestedFilename(info.url, info.content_disposition, 270 net::GetSuggestedFilename(info.url, info.content_disposition,
277 std::string(), // referrer_charset 271 std::string(), // referrer_charset
278 std::string(), // suggested_name 272 std::string(), // suggested_name
279 info.original_mime_type, default_file_name_); 273 info.original_mime_type, default_file_name_);
280 ChromeDownloadDelegate::FromWebContents(web_contents) 274 ScopedJavaLocalRef<jstring> jurl =
281 ->EnqueueDownloadManagerRequest(info.url.spec(), info.user_agent, 275 ConvertUTF8ToJavaString(env, info.url.spec());
282 filename, info.original_mime_type, 276 ScopedJavaLocalRef<jstring> juser_agent =
283 info.cookie, info.referer); 277 ConvertUTF8ToJavaString(env, info.user_agent);
278 ScopedJavaLocalRef<jstring> jmime_type =
279 ConvertUTF8ToJavaString(env, info.original_mime_type);
280 ScopedJavaLocalRef<jstring> jcookie =
281 ConvertUTF8ToJavaString(env, info.cookie);
282 ScopedJavaLocalRef<jstring> jreferer =
283 ConvertUTF8ToJavaString(env, info.referer);
284 ScopedJavaLocalRef<jstring> jfile_name =
285 base::android::ConvertUTF16ToJavaString(env, file_name);
286 Java_DownloadController_enqueueAndroidDownloadManagerRequest(
287 env, jurl, juser_agent, jfile_name, jmime_type, jcookie, jreferer);
288
289 WebContents* web_contents = wc_getter.Run();
290 if (web_contents) {
291 TabAndroid* tab = TabAndroid::FromWebContents(web_contents);
292 if (tab && !tab->GetJavaObject().is_null()) {
293 Java_DownloadController_closeTabIfBlank(env, tab->GetJavaObject());
294 }
295 }
284 } 296 }
285 297
286 bool DownloadController::HasFileAccessPermission() { 298 bool DownloadController::HasFileAccessPermission() {
287 DCHECK_CURRENTLY_ON(BrowserThread::UI); 299 DCHECK_CURRENTLY_ON(BrowserThread::UI);
288 300
289 JNIEnv* env = base::android::AttachCurrentThread(); 301 JNIEnv* env = base::android::AttachCurrentThread();
290 return Java_DownloadController_hasFileAccess( 302 return Java_DownloadController_hasFileAccess(
291 env, GetJavaObject()->Controller(env)); 303 env, GetJavaObject()->Controller(env));
292 } 304 }
293 305
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 int routing_id = web_contents->GetRenderViewHost()->GetRoutingID(); 410 int routing_id = web_contents->GetRenderViewHost()->GetRoutingID();
399 411
400 const content::ResourceRequestInfo::WebContentsGetter& wc_getter( 412 const content::ResourceRequestInfo::WebContentsGetter& wc_getter(
401 base::Bind(&GetWebContents, process_id, routing_id)); 413 base::Bind(&GetWebContents, process_id, routing_id));
402 414
403 AcquireFileAccessPermission( 415 AcquireFileAccessPermission(
404 wc_getter, base::Bind(&CreateContextMenuDownload, wc_getter, params, 416 wc_getter, base::Bind(&CreateContextMenuDownload, wc_getter, params,
405 is_link, extra_headers)); 417 is_link, extra_headers));
406 } 418 }
407 419
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698