summaryrefslogtreecommitdiffstats
path: root/content/public/android/java/src/org/chromium/content/browser/DownloadController.java
diff options
context:
space:
mode:
authorqinmin@chromium.org <qinmin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-04 20:35:51 +0000
committerqinmin@chromium.org <qinmin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-04 20:35:51 +0000
commitabae718f4a2cb855cea55879c314cf4673cb7165 (patch)
tree4d4cc2e41445dda7f1734ae05def15bbfb57e9dc /content/public/android/java/src/org/chromium/content/browser/DownloadController.java
parentb4e20b6fbb7814e9b20ba3c8ec366b3ae32a8bb3 (diff)
downloadchromium_src-abae718f4a2cb855cea55879c314cf4673cb7165.zip
chromium_src-abae718f4a2cb855cea55879c314cf4673cb7165.tar.gz
chromium_src-abae718f4a2cb855cea55879c314cf4673cb7165.tar.bz2
fix a problem that download dangerous files in a blank page can fail with authentication
With the chrome download path, when onDownloadStarted() is called, we close the tab if it is blank. The close call come too early as onDangerousDownload() has not been called yet. This CL sends the filename and mimeType to java side to check if we can close the tab or not. Also, if the tab is closed after user validates the dangerous item, the onDownloadComplete() should send a message to the app, rather than tab. BUG=244052 Review URL: https://chromiumcodereview.appspot.com/16140026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204030 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/public/android/java/src/org/chromium/content/browser/DownloadController.java')
-rw-r--r--content/public/android/java/src/org/chromium/content/browser/DownloadController.java48
1 files changed, 37 insertions, 11 deletions
diff --git a/content/public/android/java/src/org/chromium/content/browser/DownloadController.java b/content/public/android/java/src/org/chromium/content/browser/DownloadController.java
index 9577ba1..cac5f97 100644
--- a/content/public/android/java/src/org/chromium/content/browser/DownloadController.java
+++ b/content/public/android/java/src/org/chromium/content/browser/DownloadController.java
@@ -7,16 +7,38 @@ package org.chromium.content.browser;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
+import android.content.Context;
+
/**
* Java counterpart of android DownloadController.
*
* Its a singleton class instantiated by the C++ DownloadController.
*/
@JNINamespace("content")
-class DownloadController {
+public class DownloadController {
private static final String LOGTAG = "DownloadController";
private static DownloadController sInstance;
+ /**
+ * Class for notifying the application that download has completed.
+ */
+ public interface DownloadNotificationService {
+ /**
+ * Notify the host application that a download is finished.
+ * @param context Application context.
+ * @param url The full url to the content that was downloaded.
+ * @param mimetype The mimetype of downloaded file.
+ * @param path Path of the downloaded file.
+ * @param description Description of the downloaded file.
+ * @param contentLength The file size of the downloaded file (in bytes).
+ * @param successful Whether the download succeeded.
+ */
+ void onDownloadCompleted(Context context, String url, String mimetype, String path,
+ String description, long contentLength, boolean successful);
+ }
+
+ private static DownloadNotificationService sDownloadNotificationService;
+
@CalledByNative
public static DownloadController getInstance() {
if (sInstance == null) {
@@ -33,6 +55,10 @@ class DownloadController {
return view.getDownloadDelegate();
}
+ public static void setDownloadNotificationService(DownloadNotificationService service) {
+ sDownloadNotificationService = service;
+ }
+
/**
* Notifies the download delegate of a new GET download and passes all the information
* needed to download the file.
@@ -54,13 +80,16 @@ class DownloadController {
/**
* Notifies the download delegate that a new download has started. This can
* be either a POST download or a GET download with authentication.
+ * @param view ContentViewCore associated with the download item.
+ * @param filename File name of the downloaded file.
+ * @param mimeType Mime of the downloaded item.
*/
@CalledByNative
- public void onDownloadStarted(ContentViewCore view) {
+ public void onDownloadStarted(ContentViewCore view, String filename, String mimeType) {
ContentViewDownloadDelegate downloadDelagate = downloadDelegateFromView(view);
if (downloadDelagate != null) {
- downloadDelagate.onDownloadStarted();
+ downloadDelagate.onDownloadStarted(filename, mimeType);
}
}
@@ -69,14 +98,11 @@ class DownloadController {
* download. This can be either a POST download or a GET download with authentication.
*/
@CalledByNative
- public void onDownloadCompleted(ContentViewCore view, String url,
- String contentDisposition, String mimetype, String path,
- long contentLength, boolean successful) {
- ContentViewDownloadDelegate downloadDelagate = downloadDelegateFromView(view);
-
- if (downloadDelagate != null) {
- downloadDelagate.onDownloadCompleted(
- url, mimetype, path, contentLength, successful);
+ public void onDownloadCompleted(Context context, String url, String mimetype,
+ String filename, String path, long contentLength, boolean successful) {
+ if (sDownloadNotificationService != null) {
+ sDownloadNotificationService.onDownloadCompleted(context, url, mimetype, path,
+ filename, contentLength, successful);
}
}