diff options
author | navabi@google.com <navabi@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-26 21:05:56 +0000 |
---|---|---|
committer | navabi@google.com <navabi@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-26 21:05:56 +0000 |
commit | dccbbb1d1c707faab941be02f0f68ab805d0a7a7 (patch) | |
tree | 3e15c351fbc74f4c8e8399fb1489e7837fe31287 /content/public/android/java/src/org/chromium/content/browser/DownloadController.java | |
parent | 6f5fac9d1b4c8bfc924ed555f46c3e67a8a8f962 (diff) | |
download | chromium_src-dccbbb1d1c707faab941be02f0f68ab805d0a7a7.zip chromium_src-dccbbb1d1c707faab941be02f0f68ab805d0a7a7.tar.gz chromium_src-dccbbb1d1c707faab941be02f0f68ab805d0a7a7.tar.bz2 |
Move java files into src parent directory.
BUG=134704
TEST=
TBR=jam@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10668039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144272 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.java | 101 |
1 files changed, 101 insertions, 0 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 new file mode 100644 index 0000000..496e1c9 --- /dev/null +++ b/content/public/android/java/src/org/chromium/content/browser/DownloadController.java @@ -0,0 +1,101 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.content.browser; + +import android.content.Context; +import android.webkit.DownloadListener; + +import org.chromium.base.CalledByNative; + +/** + * Java counterpart of android DownloadController. + * + * Its a singleton class instantiated by the C++ DownloadController. + */ +class DownloadController { + private static final String LOGTAG = "DownloadController"; + private static DownloadController sInstance; + + public static DownloadController getInstance() { + if (sInstance == null) { + sInstance = new DownloadController(); + } + return sInstance; + } + + private Context mContext; + + private DownloadController() { + nativeInit(); + } + + private static DownloadListener listenerFromView(ContentView view) { + return view.downloadListener(); + } + + private static ContentViewDownloadDelegate downloadDelegateFromView(ContentView view) { + return view.getDownloadDelegate(); + } + + public void setContext(Context context) { + mContext = context; + } + + /** + * Notifies the DownloadListener of a new GET download and passes all the information + * needed to download the file. + * + * The DownloadListener is expected to handle the download. + */ + @CalledByNative + public void newHttpGetDownload(ContentView view, String url, + String userAgent, String contentDisposition, String mimetype, + String cookie, long contentLength) { + ContentViewDownloadDelegate downloadDelagate = downloadDelegateFromView(view); + + if (downloadDelagate != null) { + downloadDelagate.requestHttpGetDownload(url, userAgent, + contentDisposition, mimetype, cookie, contentLength); + return; + } + + DownloadListener listener = listenerFromView(view); + if (listener != null) { + listener.onDownloadStart(url, userAgent, contentDisposition, + mimetype, contentLength); + } + } + + /** + * Notifies the DownloadListener that a new POST download has started. + */ + @CalledByNative + public void onHttpPostDownloadStarted(ContentView view) { + ContentViewDownloadDelegate downloadDelagate = downloadDelegateFromView(view); + + if (downloadDelagate != null) { + downloadDelagate.onHttpPostDownloadStarted(); + } + } + + /** + * Notifies the DownloadListener that a POST download completed and passes along info about the + * download. + */ + @CalledByNative + public void onHttpPostDownloadCompleted(ContentView view, String url, + String contentDisposition, String mimetype, String path, + long contentLength, boolean successful) { + ContentViewDownloadDelegate downloadDelagate = downloadDelegateFromView(view); + + if (downloadDelagate != null) { + downloadDelagate.onHttpPostDownloadCompleted( + url, mimetype, path, contentLength, successful); + } + } + + // native methods + private native void nativeInit(); +} |