DownloadController.java revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5package org.chromium.content.browser; 6 7import org.chromium.base.CalledByNative; 8import org.chromium.base.JNINamespace; 9 10/** 11 * Java counterpart of android DownloadController. 12 * 13 * Its a singleton class instantiated by the C++ DownloadController. 14 */ 15@JNINamespace("content") 16class DownloadController { 17 private static final String LOGTAG = "DownloadController"; 18 private static DownloadController sInstance; 19 20 @CalledByNative 21 public static DownloadController getInstance() { 22 if (sInstance == null) { 23 sInstance = new DownloadController(); 24 } 25 return sInstance; 26 } 27 28 private DownloadController() { 29 nativeInit(); 30 } 31 32 private static ContentViewDownloadDelegate downloadDelegateFromView(ContentViewCore view) { 33 return view.getDownloadDelegate(); 34 } 35 36 /** 37 * Notifies the download delegate of a new GET download and passes all the information 38 * needed to download the file. 39 * 40 * The download delegate is expected to handle the download. 41 */ 42 @CalledByNative 43 public void newHttpGetDownload(ContentViewCore view, String url, 44 String userAgent, String contentDisposition, String mimetype, 45 String cookie, String referer, long contentLength) { 46 ContentViewDownloadDelegate downloadDelagate = downloadDelegateFromView(view); 47 48 if (downloadDelagate != null) { 49 downloadDelagate.requestHttpGetDownload(url, userAgent, contentDisposition, 50 mimetype, cookie, referer, contentLength); 51 } 52 } 53 54 /** 55 * Notifies the download delegate that a new POST download has started. 56 */ 57 @CalledByNative 58 public void onHttpPostDownloadStarted(ContentViewCore view) { 59 ContentViewDownloadDelegate downloadDelagate = downloadDelegateFromView(view); 60 61 if (downloadDelagate != null) { 62 downloadDelagate.onHttpPostDownloadStarted(); 63 } 64 } 65 66 /** 67 * Notifies the download delegate that a POST download completed and passes along info about the 68 * download. 69 */ 70 @CalledByNative 71 public void onHttpPostDownloadCompleted(ContentViewCore view, String url, 72 String contentDisposition, String mimetype, String path, 73 long contentLength, boolean successful) { 74 ContentViewDownloadDelegate downloadDelagate = downloadDelegateFromView(view); 75 76 if (downloadDelagate != null) { 77 downloadDelagate.onHttpPostDownloadCompleted( 78 url, mimetype, path, contentLength, successful); 79 } 80 } 81 82 // native methods 83 private native void nativeInit(); 84} 85