summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/FetchUrlMimeType.java
diff options
context:
space:
mode:
authorMattias Falk <mattias.falk@sonyericsson.com>2010-10-27 10:27:32 +0200
committerJohan Redestig <johan.redestig@sonyericsson.com>2010-10-27 10:27:32 +0200
commit65bb1acac5dca507c5f8e5c8cd6fd7cadce37d6c (patch)
treeadacf339f627368d23f37a51c9aaaf5b6ec2c625 /src/com/android/browser/FetchUrlMimeType.java
parent95e3548ed91c17f0d3b4d27eac6a8e57338caec3 (diff)
downloadandroid_packages_apps_Gello-65bb1acac5dca507c5f8e5c8cd6fd7cadce37d6c.tar.gz
android_packages_apps_Gello-65bb1acac5dca507c5f8e5c8cd6fd7cadce37d6c.tar.bz2
android_packages_apps_Gello-65bb1acac5dca507c5f8e5c8cd6fd7cadce37d6c.zip
Add support for Content-Disposition when save link
Content-Disposition isn't used when downloading an item by long-click the link. It'll result in different file name if the item is downloaded by clicking the link or if it's downloaded by long-click the link and select Save link if the HTTP response includes the Content-Disposition header with the filename attribute Change-Id: I7eacfd1128da261e0674bbdc3064208a82e46ab3
Diffstat (limited to 'src/com/android/browser/FetchUrlMimeType.java')
-rw-r--r--src/com/android/browser/FetchUrlMimeType.java21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/com/android/browser/FetchUrlMimeType.java b/src/com/android/browser/FetchUrlMimeType.java
index 9bd0cf91..62d877ed 100644
--- a/src/com/android/browser/FetchUrlMimeType.java
+++ b/src/com/android/browser/FetchUrlMimeType.java
@@ -47,7 +47,7 @@ import android.webkit.URLUtil;
* android.os.webkit.LoadListener rather than handling it here.
*
*/
-class FetchUrlMimeType extends AsyncTask<ContentValues, String, String> {
+class FetchUrlMimeType extends AsyncTask<ContentValues, String, ContentValues> {
BrowserActivity mActivity;
ContentValues mValues;
@@ -57,7 +57,7 @@ class FetchUrlMimeType extends AsyncTask<ContentValues, String, String> {
}
@Override
- public String doInBackground(ContentValues... values) {
+ public ContentValues doInBackground(ContentValues... values) {
mValues = values[0];
// Check to make sure we have a URI to download
@@ -87,7 +87,7 @@ class FetchUrlMimeType extends AsyncTask<ContentValues, String, String> {
}
HttpResponse response;
- String mimeType = null;
+ ContentValues result = new ContentValues();
try {
response = client.execute(request);
// We could get a redirect here, but if we do lets let
@@ -96,11 +96,16 @@ class FetchUrlMimeType extends AsyncTask<ContentValues, String, String> {
if (response.getStatusLine().getStatusCode() == 200) {
Header header = response.getFirstHeader("Content-Type");
if (header != null) {
- mimeType = header.getValue();
+ String mimeType = header.getValue();
final int semicolonIndex = mimeType.indexOf(';');
if (semicolonIndex != -1) {
mimeType = mimeType.substring(0, semicolonIndex);
}
+ result.put("Content-Type", mimeType);
+ }
+ Header contentDispositionHeader = response.getFirstHeader("Content-Disposition");
+ if (contentDispositionHeader != null) {
+ result.put("Content-Disposition", contentDispositionHeader.getValue());
}
}
} catch (IllegalArgumentException ex) {
@@ -111,11 +116,13 @@ class FetchUrlMimeType extends AsyncTask<ContentValues, String, String> {
client.close();
}
- return mimeType;
+ return result;
}
@Override
- public void onPostExecute(String mimeType) {
+ public void onPostExecute(ContentValues values) {
+ final String mimeType = values.getAsString("Content-Type");
+ final String contentDisposition = values.getAsString("Content-Disposition");
if (mimeType != null) {
String url = mValues.getAsString(Downloads.Impl.COLUMN_URI);
if (mimeType.equalsIgnoreCase("text/plain") ||
@@ -128,7 +135,7 @@ class FetchUrlMimeType extends AsyncTask<ContentValues, String, String> {
}
}
String filename = URLUtil.guessFileName(url,
- null, mimeType);
+ contentDisposition, mimeType);
mValues.put(Downloads.Impl.COLUMN_FILE_NAME_HINT, filename);
}