Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 } |
| OLD | NEW |