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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/download/DownloadManagerDelegate.java

Issue 2876853007: Fix an issue that download fails for non-http(s) protocols (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
« no previous file with comments | « no previous file | 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 package org.chromium.chrome.browser.download; 5 package org.chromium.chrome.browser.download;
6 6
7 import android.app.DownloadManager; 7 import android.app.DownloadManager;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.SharedPreferences; 9 import android.content.SharedPreferences;
10 import android.database.Cursor; 10 import android.database.Cursor;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SER VICE); 92 (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SER VICE);
93 NotificationManagerCompat notificationManager = NotificationManagerCompa t.from(mContext); 93 NotificationManagerCompat notificationManager = NotificationManagerCompa t.from(mContext);
94 boolean useSystemNotification = !notificationManager.areNotificationsEna bled(); 94 boolean useSystemNotification = !notificationManager.areNotificationsEna bled();
95 long downloadId = -1; 95 long downloadId = -1;
96 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { 96 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
97 Class<?> c = manager.getClass(); 97 Class<?> c = manager.getClass();
98 try { 98 try {
99 Class[] args = {String.class, String.class, boolean.class, Strin g.class, 99 Class[] args = {String.class, String.class, boolean.class, Strin g.class,
100 String.class, long.class, boolean.class, Uri.class, Uri. class}; 100 String.class, long.class, boolean.class, Uri.class, Uri. class};
101 Method method = c.getMethod("addCompletedDownload", args); 101 Method method = c.getMethod("addCompletedDownload", args);
102 // OriginalUri has to be null or non-empty, and cannot be file s cheme. 102 // OriginalUri has to be null or non-empty, and cannot be file s cheme.
David Trainor- moved to gerrit 2017/05/14 05:55:14 Update the comment too
qinmin 2017/05/15 17:59:18 Done.
103 Uri originalUri = TextUtils.isEmpty(originalUrl) ? null : Uri.pa rse(originalUrl); 103 Uri originalUri = TextUtils.isEmpty(originalUrl) ? null : Uri.pa rse(originalUrl);
104 if (originalUri != null && UrlConstants.FILE_SCHEME.equals( 104 if (originalUri != null) {
105 originalUri.normalizeScheme().getScheme())) { 105 String scheme = originalUri.normalizeScheme().getScheme();
106 originalUri = null; 106 if (scheme == null || (!scheme.equals(UrlConstants.HTTPS_SCH EME)
107 && !scheme.equals(UrlConstants.HTTP_SCHEME))) {
108 originalUri = null;
109 }
107 } 110 }
108 Uri refererUri = TextUtils.isEmpty(referer) ? null : Uri.parse(r eferer); 111 Uri refererUri = TextUtils.isEmpty(referer) ? null : Uri.parse(r eferer);
109 downloadId = (Long) method.invoke(manager, fileName, description , true, mimeType, 112 downloadId = (Long) method.invoke(manager, fileName, description , true, mimeType,
110 path, length, useSystemNotification, originalUri, refere rUri); 113 path, length, useSystemNotification, originalUri, refere rUri);
111 } catch (SecurityException e) { 114 } catch (SecurityException e) {
112 Log.e(TAG, "Cannot access the needed method."); 115 Log.e(TAG, "Cannot access the needed method.");
113 } catch (NoSuchMethodException e) { 116 } catch (NoSuchMethodException e) {
114 Log.e(TAG, "Cannot find the needed method."); 117 Log.e(TAG, "Cannot find the needed method.");
115 } catch (InvocationTargetException e) { 118 } catch (InvocationTargetException e) {
116 Log.e(TAG, "Error calling the needed method."); 119 Log.e(TAG, "Error calling the needed method.");
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 } 401 }
399 402
400 @Override 403 @Override
401 protected void onPostExecute(Boolean result) { 404 protected void onPostExecute(Boolean result) {
402 mDownloadItem.setStartTime(mStartTime); 405 mDownloadItem.setStartTime(mStartTime);
403 mCallback.onDownloadEnqueued(result, mFailureReason, mDownloadItem, mDownloadId); 406 mCallback.onDownloadEnqueued(result, mFailureReason, mDownloadItem, mDownloadId);
404 mDownloadItem.setSystemDownloadId(mDownloadId); 407 mDownloadItem.setSystemDownloadId(mDownloadId);
405 } 408 }
406 } 409 }
407 } 410 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698