Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import org.chromium.base.CalledByNative; | 7 import org.chromium.base.CalledByNative; |
| 8 import org.chromium.base.JNINamespace; | 8 import org.chromium.base.JNINamespace; |
| 9 | 9 |
| 10 import java.util.Map; | 10 import java.util.Map; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 public static int LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; | 22 public static int LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; |
| 23 public static int LOAD_TYPE_DATA; | 23 public static int LOAD_TYPE_DATA; |
| 24 | 24 |
| 25 // Should match NavigationController::UserAgentOverrideOption exactly. | 25 // Should match NavigationController::UserAgentOverrideOption exactly. |
| 26 // See comments there for proper usage. Values are initialized in | 26 // See comments there for proper usage. Values are initialized in |
| 27 // initializeConstants. | 27 // initializeConstants. |
| 28 public static int UA_OVERRIDE_INHERIT; | 28 public static int UA_OVERRIDE_INHERIT; |
| 29 public static int UA_OVERRIDE_FALSE; | 29 public static int UA_OVERRIDE_FALSE; |
| 30 public static int UA_OVERRIDE_TRUE; | 30 public static int UA_OVERRIDE_TRUE; |
| 31 | 31 |
| 32 // The default character encoding for data URLs as defined in | |
| 33 // RFC 2397. | |
| 34 private static final String DATA_URL_DEFAULT_CHARSET = "US-ASCII"; | |
| 35 | |
| 32 // Fields with counterparts in NavigationController::LoadURLParams. | 36 // Fields with counterparts in NavigationController::LoadURLParams. |
| 33 // Package private so that ContentViewCore.loadUrl can pass them down to | 37 // Package private so that ContentViewCore.loadUrl can pass them down to |
| 34 // native code. Should not be accessed directly anywhere else outside of | 38 // native code. Should not be accessed directly anywhere else outside of |
| 35 // this class. | 39 // this class. |
| 36 final String mUrl; | 40 final String mUrl; |
| 37 int mLoadUrlType; | 41 int mLoadUrlType; |
| 38 int mTransitionType; | 42 int mTransitionType; |
| 39 int mUaOverrideOption; | 43 int mUaOverrideOption; |
| 40 private Map<String, String> mExtraHeaders; | 44 private Map<String, String> mExtraHeaders; |
| 41 byte[] mPostData; | 45 byte[] mPostData; |
| 42 String mBaseUrlForDataUrl; | 46 String mBaseUrlForDataUrl; |
| 43 String mVirtualUrlForDataUrl; | 47 String mVirtualUrlForDataUrl; |
| 44 boolean mCanLoadLocalResources; | 48 boolean mCanLoadLocalResources; |
| 45 | 49 |
| 46 public LoadUrlParams(String url) { | 50 public LoadUrlParams(String url) { |
| 47 // Check initializeConstants was called. | 51 // Check initializeConstants was called. |
| 48 assert LOAD_TYPE_DEFAULT != LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; | 52 assert LOAD_TYPE_DEFAULT != LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; |
| 49 | 53 |
| 50 mUrl = url; | 54 mUrl = url; |
| 51 mLoadUrlType = LOAD_TYPE_DEFAULT; | 55 mLoadUrlType = LOAD_TYPE_DEFAULT; |
| 52 mTransitionType = ContentViewCore.PAGE_TRANSITION_LINK; | 56 mTransitionType = ContentViewCore.PAGE_TRANSITION_LINK; |
| 53 mUaOverrideOption = UA_OVERRIDE_INHERIT; | 57 mUaOverrideOption = UA_OVERRIDE_INHERIT; |
| 54 mPostData = null; | 58 mPostData = null; |
| 55 mBaseUrlForDataUrl = null; | 59 mBaseUrlForDataUrl = null; |
| 56 mVirtualUrlForDataUrl = null; | 60 mVirtualUrlForDataUrl = null; |
| 57 } | 61 } |
| 58 | 62 |
| 59 /** | 63 /** |
| 64 * Helper method to create a LoadUrlParams object for data url. Defaults | |
| 65 * to US-ASCII charset, as per RFC2397. | |
| 66 * @param data Data to be loaded. | |
| 67 * @param mimeType Mime type of the data. | |
| 68 * @param isBase64Encoded True if the data is encoded in Base 64 format. | |
| 69 */ | |
| 70 public static LoadUrlParams createLoadDataParams( | |
| 71 String data, String mimeType, boolean isBase64Encoded) { | |
| 72 return createLoadDataParams(data, mimeType, isBase64Encoded, DATA_URL_DE FAULT_CHARSET); | |
| 73 } | |
| 74 | |
| 75 /** | |
| 60 * Helper method to create a LoadUrlParams object for data url. | 76 * Helper method to create a LoadUrlParams object for data url. |
| 61 * @param data Data to be loaded. | 77 * @param data Data to be loaded. |
| 62 * @param mimeType Mime type of the data. | 78 * @param mimeType Mime type of the data. |
| 63 * @param isBase64Encoded True if the data is encoded in Base 64 format. | 79 * @param isBase64Encoded True if the data is encoded in Base 64 format. |
| 80 * @param charset The character set for the data. | |
| 64 */ | 81 */ |
| 65 public static LoadUrlParams createLoadDataParams( | 82 public static LoadUrlParams createLoadDataParams( |
| 66 String data, String mimeType, boolean isBase64Encoded) { | 83 String data, String mimeType, boolean isBase64Encoded, String charse t) { |
| 67 StringBuilder dataUrl = new StringBuilder("data:"); | 84 StringBuilder dataUrl = new StringBuilder("data:"); |
| 68 dataUrl.append(mimeType); | 85 dataUrl.append(mimeType); |
| 86 dataUrl.append(";charset=" + charset); | |
|
joth
2012/12/14 18:02:51
-AIUI the charset is spurious if the mimetype is n
benm (inactive)
2012/12/14 18:13:58
Good point. I think the charset is considered a pa
| |
| 69 if (isBase64Encoded) { | 87 if (isBase64Encoded) { |
| 70 dataUrl.append(";base64"); | 88 dataUrl.append(";base64"); |
| 71 } | 89 } |
| 72 dataUrl.append(","); | 90 dataUrl.append(","); |
| 73 dataUrl.append(data); | 91 dataUrl.append(data); |
| 74 | 92 |
| 75 LoadUrlParams params = new LoadUrlParams(dataUrl.toString()); | 93 LoadUrlParams params = new LoadUrlParams(dataUrl.toString()); |
| 76 params.setLoadType(LoadUrlParams.LOAD_TYPE_DATA); | 94 params.setLoadType(LoadUrlParams.LOAD_TYPE_DATA); |
| 77 params.setTransitionType(ContentViewCore.PAGE_TRANSITION_TYPED); | 95 params.setTransitionType(ContentViewCore.PAGE_TRANSITION_TYPED); |
| 78 return params; | 96 return params; |
| 79 } | 97 } |
| 80 | 98 |
| 81 /** | 99 /** |
| 82 * Helper method to create a LoadUrlParams object for data url with base | 100 * Helper method to create a LoadUrlParams object for data url with base |
| 83 * and virtual url. | 101 * and virtual url. Defaults to US-ASCII charset, as per RFC2397. |
| 84 * @param data Data to be loaded. | 102 * @param data Data to be loaded. |
| 85 * @param mimeType Mime type of the data. | 103 * @param mimeType Mime type of the data. |
| 86 * @param isBase64Encoded True if the data is encoded in Base 64 format. | 104 * @param isBase64Encoded True if the data is encoded in Base 64 format. |
| 87 * @param baseUrl Base url of this data load. Note that for WebView compatib ility, | 105 * @param baseUrl Base url of this data load. Note that for WebView compatib ility, |
| 88 * baseUrl and historyUrl are ignored if this is a data: url. | 106 * baseUrl and historyUrl are ignored if this is a data: url. |
| 89 * Defaults to about:blank if null. | 107 * Defaults to about:blank if null. |
| 90 * @param historyUrl History url for this data load. Note that for WebView c ompatibility, | 108 * @param historyUrl History url for this data load. Note that for WebView c ompatibility, |
| 91 * this is ignored if baseUrl is a data: url. Defaults to about:blank | 109 * this is ignored if baseUrl is a data: url. Defaults to about:blank |
| 92 * if null. | 110 * if null. |
| 93 */ | 111 */ |
| 94 public static LoadUrlParams createLoadDataParamsWithBaseUrl( | 112 public static LoadUrlParams createLoadDataParamsWithBaseUrl( |
| 95 String data, String mimeType, boolean isBase64Encoded, | 113 String data, String mimeType, boolean isBase64Encoded, |
| 96 String baseUrl, String historyUrl) { | 114 String baseUrl, String historyUrl) { |
| 97 LoadUrlParams params = createLoadDataParams(data, mimeType, isBase64Enco ded); | 115 return createLoadDataParamsWithBaseUrl(data, mimeType, isBase64Encoded, |
| 116 baseUrl, historyUrl, DATA_URL_DEFAULT_CHARSET); | |
| 117 } | |
| 118 | |
| 119 /** | |
| 120 * Helper method to create a LoadUrlParams object for data url with base | |
| 121 * and virtual url. | |
| 122 * @param data Data to be loaded. | |
| 123 * @param mimeType Mime type of the data. | |
| 124 * @param isBase64Encoded True if the data is encoded in Base 64 format. | |
| 125 * @param baseUrl Base url of this data load. Note that for WebView compatib ility, | |
| 126 * baseUrl and historyUrl are ignored if this is a data: url. | |
| 127 * Defaults to about:blank if null. | |
| 128 * @param historyUrl History url for this data load. Note that for WebView c ompatibility, | |
| 129 * this is ignored if baseUrl is a data: url. Defaults to about:blank | |
| 130 * if null. | |
| 131 * @param charset The character set for the data. | |
| 132 */ | |
| 133 public static LoadUrlParams createLoadDataParamsWithBaseUrl( | |
| 134 String data, String mimeType, boolean isBase64Encoded, | |
| 135 String baseUrl, String historyUrl, String charset) { | |
| 136 LoadUrlParams params = createLoadDataParams(data, mimeType, isBase64Enco ded, charset); | |
| 98 // For WebView compatibility, when the base URL has the 'data:' | 137 // For WebView compatibility, when the base URL has the 'data:' |
| 99 // scheme, we treat it as a regular data URL load and skip setting | 138 // scheme, we treat it as a regular data URL load and skip setting |
| 100 // baseUrl and historyUrl. | 139 // baseUrl and historyUrl. |
| 101 if (baseUrl == null || !baseUrl.toLowerCase().startsWith("data:")) { | 140 if (baseUrl == null || !baseUrl.toLowerCase().startsWith("data:")) { |
| 102 params.setBaseUrlForDataUrl(baseUrl != null ? baseUrl : "about:blank "); | 141 params.setBaseUrlForDataUrl(baseUrl != null ? baseUrl : "about:blank "); |
| 103 params.setVirtualUrlForDataUrl(historyUrl != null ? historyUrl : "ab out:blank"); | 142 params.setVirtualUrlForDataUrl(historyUrl != null ? historyUrl : "ab out:blank"); |
| 104 } | 143 } |
| 105 return params; | 144 return params; |
| 106 } | 145 } |
| 107 | 146 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 UA_OVERRIDE_FALSE = ua_override_false; | 291 UA_OVERRIDE_FALSE = ua_override_false; |
| 253 UA_OVERRIDE_TRUE = ua_override_true; | 292 UA_OVERRIDE_TRUE = ua_override_true; |
| 254 } | 293 } |
| 255 | 294 |
| 256 /** | 295 /** |
| 257 * Parses |url| as a GURL on the native side, and | 296 * Parses |url| as a GURL on the native side, and |
| 258 * returns true if it's scheme is data:. | 297 * returns true if it's scheme is data:. |
| 259 */ | 298 */ |
| 260 private static native boolean nativeIsDataScheme(String url); | 299 private static native boolean nativeIsDataScheme(String url); |
| 261 } | 300 } |
| OLD | NEW |