Add content-disposition into the cache header as it is needed by Flash.
As WebKit is using string version of "expires", pass it with the rest of the headers.
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package android.webkit;
|
||||
|
||||
import android.net.http.Headers;
|
||||
import android.text.TextUtils;
|
||||
|
||||
/**
|
||||
* This class is a concrete implementation of StreamLoader that uses a
|
||||
@@ -49,17 +50,22 @@ class CacheLoader extends StreamLoader {
|
||||
@Override
|
||||
protected void buildHeaders(Headers headers) {
|
||||
StringBuilder sb = new StringBuilder(mCacheResult.mimeType);
|
||||
if (mCacheResult.encoding != null &&
|
||||
mCacheResult.encoding.length() > 0) {
|
||||
if (!TextUtils.isEmpty(mCacheResult.encoding)) {
|
||||
sb.append(';');
|
||||
sb.append(mCacheResult.encoding);
|
||||
}
|
||||
headers.setContentType(sb.toString());
|
||||
|
||||
if (mCacheResult.location != null &&
|
||||
mCacheResult.location.length() > 0) {
|
||||
if (!TextUtils.isEmpty(mCacheResult.location)) {
|
||||
headers.setLocation(mCacheResult.location);
|
||||
}
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(mCacheResult.expiresString)) {
|
||||
headers.setExpires(mCacheResult.expiresString);
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(mCacheResult.contentdisposition)) {
|
||||
headers.setContentDisposition(mCacheResult.contentdisposition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ public final class CacheManager {
|
||||
String mimeType;
|
||||
String location;
|
||||
String encoding;
|
||||
String contentdisposition;
|
||||
|
||||
// these fields are NOT saved to the database
|
||||
InputStream inStream;
|
||||
@@ -135,6 +136,13 @@ public final class CacheManager {
|
||||
return encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide Pending API council approval
|
||||
*/
|
||||
public String getContentDisposition() {
|
||||
return contentdisposition;
|
||||
}
|
||||
|
||||
// For out-of-package access to the underlying streams.
|
||||
public InputStream getInputStream() {
|
||||
return inStream;
|
||||
@@ -627,6 +635,11 @@ public final class CacheManager {
|
||||
}
|
||||
}
|
||||
|
||||
String contentDisposition = headers.getContentDisposition();
|
||||
if (contentDisposition != null) {
|
||||
ret.contentdisposition = contentDisposition;
|
||||
}
|
||||
|
||||
String lastModified = headers.getLastModified();
|
||||
if (lastModified != null) ret.lastModified = lastModified;
|
||||
|
||||
|
||||
@@ -948,8 +948,7 @@ class LoadListener extends Handler implements EventHandler {
|
||||
// pass content-type content-length and content-encoding
|
||||
final int nativeResponse = nativeCreateResponse(
|
||||
mUrl, statusCode, mStatusText,
|
||||
mMimeType, mContentLength, mEncoding,
|
||||
mCacheResult == null ? null : mCacheResult.expiresString);
|
||||
mMimeType, mContentLength, mEncoding);
|
||||
if (mHeaders != null) {
|
||||
mHeaders.getHeaders(new Headers.HeaderCallback() {
|
||||
public void header(String name, String value) {
|
||||
@@ -1460,12 +1459,11 @@ class LoadListener extends Handler implements EventHandler {
|
||||
* @param expectedLength An estimate of the content length or the length
|
||||
* given by the server.
|
||||
* @param encoding HTTP encoding.
|
||||
* @param expireTime HTTP expires.
|
||||
* @return The native response pointer.
|
||||
*/
|
||||
private native int nativeCreateResponse(String url, int statusCode,
|
||||
String statusText, String mimeType, long expectedLength,
|
||||
String encoding, String expireTime);
|
||||
String encoding);
|
||||
|
||||
/**
|
||||
* Add a response header to the native object.
|
||||
|
||||
@@ -48,8 +48,9 @@ public class WebViewDatabase {
|
||||
// 6 -> 7 Change cache localPath from int to String
|
||||
// 7 -> 8 Move cache to its own db
|
||||
// 8 -> 9 Store both scheme and host when storing passwords
|
||||
private static final int CACHE_DATABASE_VERSION = 2;
|
||||
private static final int CACHE_DATABASE_VERSION = 3;
|
||||
// 1 -> 2 Add expires String
|
||||
// 2 -> 3 Add content-disposition
|
||||
|
||||
private static WebViewDatabase mInstance = null;
|
||||
|
||||
@@ -120,6 +121,8 @@ public class WebViewDatabase {
|
||||
|
||||
private static final String CACHE_CONTENTLENGTH_COL = "contentlength";
|
||||
|
||||
private static final String CACHE_CONTENTDISPOSITION_COL = "contentdisposition";
|
||||
|
||||
// column id strings for "password" table
|
||||
private static final String PASSWORD_HOST_COL = "host";
|
||||
|
||||
@@ -159,6 +162,7 @@ public class WebViewDatabase {
|
||||
private static int mCacheHttpStatusColIndex;
|
||||
private static int mCacheLocationColIndex;
|
||||
private static int mCacheContentLengthColIndex;
|
||||
private static int mCacheContentDispositionColIndex;
|
||||
|
||||
private static int mCacheTransactionRefcount;
|
||||
|
||||
@@ -236,6 +240,8 @@ public class WebViewDatabase {
|
||||
.getColumnIndex(CACHE_LOCATION_COL);
|
||||
mCacheContentLengthColIndex = mCacheInserter
|
||||
.getColumnIndex(CACHE_CONTENTLENGTH_COL);
|
||||
mCacheContentDispositionColIndex = mCacheInserter
|
||||
.getColumnIndex(CACHE_CONTENTDISPOSITION_COL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,8 +336,8 @@ public class WebViewDatabase {
|
||||
+ CACHE_MIMETYPE_COL + " TEXT, " + CACHE_ENCODING_COL
|
||||
+ " TEXT," + CACHE_HTTP_STATUS_COL + " INTEGER, "
|
||||
+ CACHE_LOCATION_COL + " TEXT, " + CACHE_CONTENTLENGTH_COL
|
||||
+ " INTEGER, " + " UNIQUE (" + CACHE_URL_COL
|
||||
+ ") ON CONFLICT REPLACE);");
|
||||
+ " INTEGER, " + CACHE_CONTENTDISPOSITION_COL + " TEXT, "
|
||||
+ " UNIQUE (" + CACHE_URL_COL + ") ON CONFLICT REPLACE);");
|
||||
mCacheDatabase.execSQL("CREATE INDEX cacheUrlIndex ON cache ("
|
||||
+ CACHE_URL_COL + ")");
|
||||
}
|
||||
@@ -544,8 +550,8 @@ public class WebViewDatabase {
|
||||
}
|
||||
|
||||
Cursor cursor = mCacheDatabase.rawQuery("SELECT filepath, lastmodify, etag, expires, "
|
||||
+ "expiresstring, mimetype, encoding, httpstatus, location, contentlength "
|
||||
+ "FROM cache WHERE url = ?",
|
||||
+ "expiresstring, mimetype, encoding, httpstatus, location, contentlength, "
|
||||
+ "contentdisposition FROM cache WHERE url = ?",
|
||||
new String[] { url });
|
||||
|
||||
try {
|
||||
@@ -561,6 +567,7 @@ public class WebViewDatabase {
|
||||
ret.httpStatusCode = cursor.getInt(7);
|
||||
ret.location = cursor.getString(8);
|
||||
ret.contentLength = cursor.getLong(9);
|
||||
ret.contentdisposition = cursor.getString(10);
|
||||
return ret;
|
||||
}
|
||||
} finally {
|
||||
@@ -605,6 +612,8 @@ public class WebViewDatabase {
|
||||
mCacheInserter.bind(mCacheHttpStatusColIndex, c.httpStatusCode);
|
||||
mCacheInserter.bind(mCacheLocationColIndex, c.location);
|
||||
mCacheInserter.bind(mCacheContentLengthColIndex, c.contentLength);
|
||||
mCacheInserter.bind(mCacheContentDispositionColIndex,
|
||||
c.contentdisposition);
|
||||
mCacheInserter.execute();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user