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

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

Issue 2871663004: Remove webContents check when download starts (Closed)
Patch Set: nits 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
« no previous file with comments | « chrome/browser/android/download/chrome_download_delegate.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/android/jni_android.h" 11 #include "base/android/jni_android.h"
12 #include "base/android/jni_string.h" 12 #include "base/android/jni_string.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
17 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
18 #include "chrome/browser/android/download/chrome_download_delegate.h" 18 #include "chrome/browser/android/download/chrome_download_delegate.h"
19 #include "chrome/browser/android/download/dangerous_download_infobar_delegate.h" 19 #include "chrome/browser/android/download/dangerous_download_infobar_delegate.h"
20 #include "chrome/browser/android/download/download_manager_service.h" 20 #include "chrome/browser/android/download/download_manager_service.h"
21 #include "chrome/browser/android/tab_android.h"
21 #include "chrome/browser/infobars/infobar_service.h" 22 #include "chrome/browser/infobars/infobar_service.h"
22 #include "chrome/browser/permissions/permission_update_infobar_delegate_android. h" 23 #include "chrome/browser/permissions/permission_update_infobar_delegate_android. h"
23 #include "chrome/browser/ui/android/view_android_helper.h" 24 #include "chrome/browser/ui/android/view_android_helper.h"
24 #include "chrome/grit/chromium_strings.h" 25 #include "chrome/grit/chromium_strings.h"
25 #include "content/public/browser/browser_context.h" 26 #include "content/public/browser/browser_context.h"
26 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/download_manager.h" 28 #include "content/public/browser/download_manager.h"
28 #include "content/public/browser/download_url_parameters.h" 29 #include "content/public/browser/download_url_parameters.h"
29 #include "content/public/browser/render_process_host.h" 30 #include "content/public/browser/render_process_host.h"
30 #include "content/public/browser/render_view_host.h" 31 #include "content/public/browser/render_view_host.h"
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 DCHECK_CURRENTLY_ON(BrowserThread::UI); 287 DCHECK_CURRENTLY_ON(BrowserThread::UI);
287 288
288 JNIEnv* env = base::android::AttachCurrentThread(); 289 JNIEnv* env = base::android::AttachCurrentThread();
289 return Java_DownloadController_hasFileAccess( 290 return Java_DownloadController_hasFileAccess(
290 env, GetJavaObject()->Controller(env)); 291 env, GetJavaObject()->Controller(env));
291 } 292 }
292 293
293 void DownloadController::OnDownloadStarted( 294 void DownloadController::OnDownloadStarted(
294 DownloadItem* download_item) { 295 DownloadItem* download_item) {
295 DCHECK_CURRENTLY_ON(BrowserThread::UI); 296 DCHECK_CURRENTLY_ON(BrowserThread::UI);
296 WebContents* web_contents = download_item->GetWebContents();
297 if (!web_contents)
298 return;
299 297
300 // Register for updates to the DownloadItem. 298 // Register for updates to the DownloadItem.
301 download_item->AddObserver(this); 299 download_item->AddObserver(this);
302 300
303 ChromeDownloadDelegate* delegate =
304 ChromeDownloadDelegate::FromWebContents(web_contents);
305 // For dangerous item, we need to show the dangerous infobar before the 301 // For dangerous item, we need to show the dangerous infobar before the
306 // download can start. 302 // download can start.
307 if (!download_item->IsDangerous() && delegate) { 303 JNIEnv* env = base::android::AttachCurrentThread();
308 delegate->OnDownloadStarted( 304 if (!download_item->IsDangerous()) {
309 download_item->GetTargetFilePath().BaseName().value()); 305 Java_DownloadController_onDownloadStarted(
306 env, GetJavaObject()->Controller(env));
310 } 307 }
308
309 WebContents* web_contents = download_item->GetWebContents();
310 if (web_contents) {
311 TabAndroid* tab = TabAndroid::FromWebContents(web_contents);
312 if (tab && !tab->GetJavaObject().is_null()) {
313 Java_DownloadController_closeTabIfBlank(env, tab->GetJavaObject());
314 }
315 }
316
311 OnDownloadUpdated(download_item); 317 OnDownloadUpdated(download_item);
312 } 318 }
313 319
314 void DownloadController::OnDownloadUpdated(DownloadItem* item) { 320 void DownloadController::OnDownloadUpdated(DownloadItem* item) {
315 DCHECK_CURRENTLY_ON(BrowserThread::UI); 321 DCHECK_CURRENTLY_ON(BrowserThread::UI);
316 if (item->IsDangerous() && (item->GetState() != DownloadItem::CANCELLED)) { 322 if (item->IsDangerous() && (item->GetState() != DownloadItem::CANCELLED)) {
317 // Dont't show notification for a dangerous download, as user can resume 323 // Dont't show notification for a dangerous download, as user can resume
318 // the download after browser crash through notification. 324 // the download after browser crash through notification.
319 OnDangerousDownload(item); 325 OnDangerousDownload(item);
320 return; 326 return;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 int routing_id = web_contents->GetRenderViewHost()->GetRoutingID(); 398 int routing_id = web_contents->GetRenderViewHost()->GetRoutingID();
393 399
394 const content::ResourceRequestInfo::WebContentsGetter& wc_getter( 400 const content::ResourceRequestInfo::WebContentsGetter& wc_getter(
395 base::Bind(&GetWebContents, process_id, routing_id)); 401 base::Bind(&GetWebContents, process_id, routing_id));
396 402
397 AcquireFileAccessPermission( 403 AcquireFileAccessPermission(
398 wc_getter, base::Bind(&CreateContextMenuDownload, wc_getter, params, 404 wc_getter, base::Bind(&CreateContextMenuDownload, wc_getter, params,
399 is_link, extra_headers)); 405 is_link, extra_headers));
400 } 406 }
401 407
OLDNEW
« no previous file with comments | « chrome/browser/android/download/chrome_download_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698