Skip to content

Commit 8506ce1

Browse files
Selim GurunAndroid (Google) Code Review
authored andcommitted
Merge "Provide referer to browser on download request." into jb-mr1-dev
2 parents f0340d1 + a36dcfd commit 8506ce1

3 files changed

Lines changed: 70 additions & 5 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (C) 2012 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.webkit;
18+
19+
/**
20+
* An abstract download listener that allows passing extra information as
21+
* part of onDownloadStart callback.
22+
* @hide
23+
*/
24+
public abstract class BrowserDownloadListener implements DownloadListener {
25+
26+
/**
27+
* Notify the host application that a file should be downloaded
28+
* @param url The full url to the content that should be downloaded
29+
* @param userAgent the user agent to be used for the download.
30+
* @param contentDisposition Content-disposition http header, if
31+
* present.
32+
* @param mimetype The mimetype of the content reported by the server
33+
* @param referer The referer associated with this url
34+
* @param contentLength The file size reported by the server
35+
*/
36+
public abstract void onDownloadStart(String url, String userAgent,
37+
String contentDisposition, String mimetype, String referer,
38+
long contentLength);
39+
40+
41+
/**
42+
* Notify the host application that a file should be downloaded
43+
* @param url The full url to the content that should be downloaded
44+
* @param userAgent the user agent to be used for the download.
45+
* @param contentDisposition Content-disposition http header, if
46+
* present.
47+
* @param mimetype The mimetype of the content reported by the server
48+
* @param contentLength The file size reported by the server
49+
*/
50+
@Override
51+
public void onDownloadStart(String url, String userAgent,
52+
String contentDisposition, String mimetype, long contentLength) {
53+
54+
onDownloadStart(url, userAgent, contentDisposition, mimetype, null,
55+
contentLength);
56+
}
57+
}

core/java/android/webkit/BrowserFrame.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ private void requestClientCert(int handle, String hostAndPort) {
11371137
* DownloadListener.
11381138
*/
11391139
private void downloadStart(String url, String userAgent,
1140-
String contentDisposition, String mimeType, long contentLength) {
1140+
String contentDisposition, String mimeType, String referer, long contentLength) {
11411141
// This will only work if the url ends with the filename
11421142
if (mimeType.isEmpty()) {
11431143
try {
@@ -1157,7 +1157,7 @@ private void downloadStart(String url, String userAgent,
11571157
mKeyStoreHandler = new KeyStoreHandler(mimeType);
11581158
} else {
11591159
mCallbackProxy.onDownloadStart(url, userAgent,
1160-
contentDisposition, mimeType, contentLength);
1160+
contentDisposition, mimeType, referer, contentLength);
11611161
}
11621162
}
11631163

core/java/android/webkit/CallbackProxy.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,16 @@ public void handleMessage(Message msg) {
452452
String contentDisposition =
453453
msg.getData().getString("contentDisposition");
454454
String mimetype = msg.getData().getString("mimetype");
455+
String referer = msg.getData().getString("referer");
455456
Long contentLength = msg.getData().getLong("contentLength");
456457

457-
mDownloadListener.onDownloadStart(url, userAgent,
458-
contentDisposition, mimetype, contentLength);
458+
if (mDownloadListener instanceof BrowserDownloadListener) {
459+
((BrowserDownloadListener) mDownloadListener).onDownloadStart(url,
460+
userAgent, contentDisposition, mimetype, referer, contentLength);
461+
} else {
462+
mDownloadListener.onDownloadStart(url, userAgent,
463+
contentDisposition, mimetype, contentLength);
464+
}
459465
}
460466
break;
461467

@@ -1179,7 +1185,8 @@ void onReceivedLoginRequest(String realm, String account, String args) {
11791185
* return false.
11801186
*/
11811187
public boolean onDownloadStart(String url, String userAgent,
1182-
String contentDisposition, String mimetype, long contentLength) {
1188+
String contentDisposition, String mimetype, String referer,
1189+
long contentLength) {
11831190
// Do an unsynchronized quick check to avoid posting if no callback has
11841191
// been set.
11851192
if (mDownloadListener == null) {
@@ -1192,6 +1199,7 @@ public boolean onDownloadStart(String url, String userAgent,
11921199
bundle.putString("url", url);
11931200
bundle.putString("userAgent", userAgent);
11941201
bundle.putString("mimetype", mimetype);
1202+
bundle.putString("referer", referer);
11951203
bundle.putLong("contentLength", contentLength);
11961204
bundle.putString("contentDisposition", contentDisposition);
11971205
sendMessage(msg);

0 commit comments

Comments
 (0)