Merge change 6926 into donut

* changes:
  Fix #1976384. Add p12 to the MimeTypeMap. When downloading p12 in the WebView, send it to the certTool.
This commit is contained in:
Android (Google) Code Review
2009-07-15 09:47:05 -07:00
3 changed files with 26 additions and 9 deletions

View File

@@ -38,6 +38,7 @@ import com.android.internal.R;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Vector;
import java.util.regex.Pattern;
@@ -72,7 +73,12 @@ class LoadListener extends Handler implements EventHandler {
private static final int HTTP_NOT_FOUND = 404;
private static final int HTTP_PROXY_AUTH = 407;
private static final String CERT_MIMETYPE = "application/x-x509-ca-cert";
private static HashSet<String> sCertificateMimeTypeMap;
static {
sCertificateMimeTypeMap = new HashSet<String>();
sCertificateMimeTypeMap.add("application/x-x509-ca-cert");
sCertificateMimeTypeMap.add("application/x-pkcs12");
}
private static int sNativeLoaderCount;
@@ -318,7 +324,17 @@ class LoadListener extends Handler implements EventHandler {
if (mMimeType.equalsIgnoreCase("text/plain") ||
mMimeType.equalsIgnoreCase("application/octet-stream")) {
String newMimeType = guessMimeTypeFromExtension();
// for attachment, use the filename in the Content-Disposition
// to guess the mimetype
String contentDisposition = headers.getContentDisposition();
String url = null;
if (contentDisposition != null) {
url = URLUtil.parseContentDisposition(contentDisposition);
}
if (url == null) {
url = mUrl;
}
String newMimeType = guessMimeTypeFromExtension(url);
if (newMimeType != null) {
mMimeType = newMimeType;
}
@@ -936,7 +952,7 @@ class LoadListener extends Handler implements EventHandler {
// This commits the headers without checking the response status code.
private void commitHeaders() {
if (mIsMainPageLoader && CERT_MIMETYPE.equals(mMimeType)) {
if (mIsMainPageLoader && sCertificateMimeTypeMap.contains(mMimeType)) {
// In the case of downloading certificate, we will save it to the
// Keystore in commitLoad. Do not call webcore.
return;
@@ -982,7 +998,7 @@ class LoadListener extends Handler implements EventHandler {
private void commitLoad() {
if (mCancelled) return;
if (mIsMainPageLoader && CERT_MIMETYPE.equals(mMimeType)) {
if (mIsMainPageLoader && sCertificateMimeTypeMap.contains(mMimeType)) {
// In the case of downloading certificate, we will save it to the
// Keystore and stop the current loading so that it will not
// generate a new history page
@@ -1409,7 +1425,7 @@ class LoadListener extends Handler implements EventHandler {
// of frames. If no content-type was specified, it is fine to
// default to text/html.
mMimeType = "text/html";
String newMimeType = guessMimeTypeFromExtension();
String newMimeType = guessMimeTypeFromExtension(mUrl);
if (newMimeType != null) {
mMimeType = newMimeType;
}
@@ -1419,15 +1435,15 @@ class LoadListener extends Handler implements EventHandler {
/**
* guess MIME type based on the file extension.
*/
private String guessMimeTypeFromExtension() {
private String guessMimeTypeFromExtension(String url) {
// PENDING: need to normalize url
if (WebView.LOGV_ENABLED) {
Log.v(LOGTAG, "guessMimeTypeFromExtension: mURL = " + mUrl);
Log.v(LOGTAG, "guessMimeTypeFromExtension: url = " + url);
}
String mimeType =
MimeTypeMap.getSingleton().getMimeTypeFromExtension(
MimeTypeMap.getFileExtensionFromUrl(mUrl));
MimeTypeMap.getFileExtensionFromUrl(url));
if (mimeType != null) {
// XXX: Until the servers send us either correct xhtml or

View File

@@ -335,6 +335,7 @@ public /* package */ class MimeTypeMap {
sMimeTypeMap.loadEntry("application/x-object", "o", false);
sMimeTypeMap.loadEntry("application/x-oz-application", "oza",
false);
sMimeTypeMap.loadEntry("application/x-pkcs12", "p12", false);
sMimeTypeMap.loadEntry("application/x-pkcs7-certreqresp", "p7r",
false);
sMimeTypeMap.loadEntry("application/x-pkcs7-crl", "crl", false);

View File

@@ -348,7 +348,7 @@ public final class URLUtil {
* This header provides a filename for content that is going to be
* downloaded to the file system. We only support the attachment type.
*/
private static String parseContentDisposition(String contentDisposition) {
static String parseContentDisposition(String contentDisposition) {
try {
Matcher m = CONTENT_DISPOSITION_PATTERN.matcher(contentDisposition);
if (m.find()) {