Pass referer on download requests

Bug: 6662557
Change-Id: Ib7fdc4b3f1e0f7370631d8a222565faaee550bfb
diff --git a/src/com/android/browser/DownloadHandler.java b/src/com/android/browser/DownloadHandler.java
index 5517e59..dee10ae 100644
--- a/src/com/android/browser/DownloadHandler.java
+++ b/src/com/android/browser/DownloadHandler.java
@@ -21,7 +21,6 @@
 import android.app.DownloadManager;
 import android.content.ActivityNotFoundException;
 import android.content.ComponentName;
-import android.content.ContentValues;
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageManager;
@@ -53,11 +52,12 @@
      * @param userAgent User agent of the downloading application.
      * @param contentDisposition Content-disposition http header, if present.
      * @param mimetype The mimetype of the content reported by the server
+     * @param referer The referer associated with the downloaded url
      * @param privateBrowsing If the request is coming from a private browsing tab.
      */
     public static void onDownloadStart(Activity activity, String url,
             String userAgent, String contentDisposition, String mimetype,
-            boolean privateBrowsing) {
+            String referer, boolean privateBrowsing) {
         // if we're dealing wih A/V content that's not explicitly marked
         //     for download, check if it's streamable.
         if (contentDisposition == null
@@ -95,7 +95,7 @@
             }
         }
         onDownloadStartNoStream(activity, url, userAgent, contentDisposition,
-                mimetype, privateBrowsing);
+                mimetype, referer, privateBrowsing);
     }
 
     // This is to work around the fact that java.net.URI throws Exceptions
@@ -136,11 +136,12 @@
      * @param userAgent User agent of the downloading application.
      * @param contentDisposition Content-disposition http header, if present.
      * @param mimetype The mimetype of the content reported by the server
+     * @param referer The referer associated with the downloaded url
      * @param privateBrowsing If the request is coming from a private browsing tab.
      */
     /*package */ static void onDownloadStartNoStream(Activity activity,
             String url, String userAgent, String contentDisposition,
-            String mimetype, boolean privateBrowsing) {
+            String mimetype, String referer, boolean privateBrowsing) {
 
         String filename = URLUtil.guessFileName(url,
                 contentDisposition, mimetype);
@@ -204,6 +205,7 @@
         String cookies = CookieManager.getInstance().getCookie(url, privateBrowsing);
         request.addRequestHeader("cookie", cookies);
         request.addRequestHeader("User-Agent", userAgent);
+        request.addRequestHeader("Referer", referer);
         request.setNotificationVisibility(
                 DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
         if (mimetype == null) {