| 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 21 matching lines...) Expand all Loading... |
| 32 // Fields with counterparts in NavigationController::LoadURLParams. | 32 // Fields with counterparts in NavigationController::LoadURLParams. |
| 33 // Package private so that ContentViewCore.loadUrl can pass them down to | 33 // Package private so that ContentViewCore.loadUrl can pass them down to |
| 34 // native code. Should not be accessed directly anywhere else outside of | 34 // native code. Should not be accessed directly anywhere else outside of |
| 35 // this class. | 35 // this class. |
| 36 final String mUrl; | 36 final String mUrl; |
| 37 int mLoadUrlType; | 37 int mLoadUrlType; |
| 38 int mTransitionType; | 38 int mTransitionType; |
| 39 int mUaOverrideOption; | 39 int mUaOverrideOption; |
| 40 private Map<String, String> mExtraHeaders; | 40 private Map<String, String> mExtraHeaders; |
| 41 byte[] mPostData; | 41 byte[] mPostData; |
| 42 String mDataForDataUrl; |
| 42 String mBaseUrlForDataUrl; | 43 String mBaseUrlForDataUrl; |
| 43 String mVirtualUrlForDataUrl; | 44 String mVirtualUrlForDataUrl; |
| 44 boolean mCanLoadLocalResources; | 45 boolean mCanLoadLocalResources; |
| 45 | 46 |
| 46 public LoadUrlParams(String url) { | 47 public LoadUrlParams(String url) { |
| 47 // Check initializeConstants was called. | 48 // Check initializeConstants was called. |
| 48 assert LOAD_TYPE_DEFAULT != LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; | 49 assert LOAD_TYPE_DEFAULT != LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; |
| 49 | 50 |
| 50 mUrl = url; | 51 mUrl = url; |
| 51 mLoadUrlType = LOAD_TYPE_DEFAULT; | 52 mLoadUrlType = LOAD_TYPE_DEFAULT; |
| 52 mTransitionType = PageTransitionTypes.PAGE_TRANSITION_LINK; | 53 mTransitionType = PageTransitionTypes.PAGE_TRANSITION_LINK; |
| 53 mUaOverrideOption = UA_OVERRIDE_INHERIT; | 54 mUaOverrideOption = UA_OVERRIDE_INHERIT; |
| 54 mPostData = null; | 55 mPostData = null; |
| 56 mDataForDataUrl = null; |
| 55 mBaseUrlForDataUrl = null; | 57 mBaseUrlForDataUrl = null; |
| 56 mVirtualUrlForDataUrl = null; | 58 mVirtualUrlForDataUrl = null; |
| 57 } | 59 } |
| 58 | 60 |
| 59 /** | 61 /** |
| 60 * Helper method to create a LoadUrlParams object for data url. | 62 * Helper method to create a LoadUrlParams object for data url. |
| 61 * @param data Data to be loaded. | 63 * @param data Data to be loaded. |
| 62 * @param mimeType Mime type of the data. | 64 * @param mimeType Mime type of the data. |
| 63 * @param isBase64Encoded True if the data is encoded in Base 64 format. | 65 * @param isBase64Encoded True if the data is encoded in Base 64 format. |
| 64 */ | 66 */ |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 * Defaults to about:blank if null. | 127 * Defaults to about:blank if null. |
| 126 * @param historyUrl History url for this data load. Note that for WebView c
ompatibility, | 128 * @param historyUrl History url for this data load. Note that for WebView c
ompatibility, |
| 127 * this is ignored if baseUrl is a data: url. Defaults to
about:blank | 129 * this is ignored if baseUrl is a data: url. Defaults to
about:blank |
| 128 * if null. | 130 * if null. |
| 129 * @param charset The character set for the data. Pass null if the mime type | 131 * @param charset The character set for the data. Pass null if the mime type |
| 130 * does not require a special charset. | 132 * does not require a special charset. |
| 131 */ | 133 */ |
| 132 public static LoadUrlParams createLoadDataParamsWithBaseUrl( | 134 public static LoadUrlParams createLoadDataParamsWithBaseUrl( |
| 133 String data, String mimeType, boolean isBase64Encoded, | 135 String data, String mimeType, boolean isBase64Encoded, |
| 134 String baseUrl, String historyUrl, String charset) { | 136 String baseUrl, String historyUrl, String charset) { |
| 135 LoadUrlParams params = createLoadDataParams(data, mimeType, isBase64Enco
ded, charset); | 137 // This method is only used in WebView. For backward compatibility, data
: base URLs |
| 136 // For WebView compatibility, when the base URL has the 'data:' | 138 // should never be passed in here, and instead handled as per loadData()
call. |
| 137 // scheme, we treat it as a regular data URL load and skip setting | 139 assert !baseUrl.startsWith("data:"); |
| 138 // baseUrl and historyUrl. | 140 LoadUrlParams params = createLoadDataParams("", mimeType, isBase64Encode
d, charset); |
| 139 // TODO(joth): we should just append baseURL and historyURL here, and mo
ve the | 141 params.mDataForDataUrl = data; |
| 140 // WebView specific transform up to a wrapper factory function in androi
d_webview/. | 142 params.setBaseUrlForDataUrl(baseUrl); |
| 141 if (baseUrl == null || !baseUrl.toLowerCase().startsWith("data:")) { | 143 params.setVirtualUrlForDataUrl(historyUrl); |
| 142 params.setBaseUrlForDataUrl(baseUrl != null ? baseUrl : "about:blank
"); | |
| 143 params.setVirtualUrlForDataUrl(historyUrl != null ? historyUrl : "ab
out:blank"); | |
| 144 } | |
| 145 return params; | 144 return params; |
| 146 } | 145 } |
| 147 | 146 |
| 148 /** | 147 /** |
| 149 * Helper method to create a LoadUrlParams object for an HTTP POST load. | 148 * Helper method to create a LoadUrlParams object for an HTTP POST load. |
| 150 * @param url URL of the load. | 149 * @param url URL of the load. |
| 151 * @param postData Post data of the load. Can be null. | 150 * @param postData Post data of the load. Can be null. |
| 152 */ | 151 */ |
| 153 public static LoadUrlParams createLoadHttpPostParams( | 152 public static LoadUrlParams createLoadHttpPostParams( |
| 154 String url, byte[] postData) { | 153 String url, byte[] postData) { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 * defaults to false. | 266 * defaults to false. |
| 268 */ | 267 */ |
| 269 public void setCanLoadLocalResources(boolean canLoad) { | 268 public void setCanLoadLocalResources(boolean canLoad) { |
| 270 mCanLoadLocalResources = canLoad; | 269 mCanLoadLocalResources = canLoad; |
| 271 } | 270 } |
| 272 | 271 |
| 273 public int getLoadUrlType() { | 272 public int getLoadUrlType() { |
| 274 return mLoadUrlType; | 273 return mLoadUrlType; |
| 275 } | 274 } |
| 276 | 275 |
| 277 public boolean isBaseUrlDataScheme() { | |
| 278 // If there's no base url set, but this is a data load then | |
| 279 // treat the scheme as data:. | |
| 280 if (mBaseUrlForDataUrl == null && mLoadUrlType == LOAD_TYPE_DATA) { | |
| 281 return true; | |
| 282 } | |
| 283 return nativeIsDataScheme(mBaseUrlForDataUrl); | |
| 284 } | |
| 285 | |
| 286 @SuppressWarnings("unused") | 276 @SuppressWarnings("unused") |
| 287 @CalledByNative | 277 @CalledByNative |
| 288 private static void initializeConstants( | 278 private static void initializeConstants( |
| 289 int load_type_default, | 279 int load_type_default, |
| 290 int load_type_browser_initiated_http_post, | 280 int load_type_browser_initiated_http_post, |
| 291 int load_type_data, | 281 int load_type_data, |
| 292 int ua_override_inherit, | 282 int ua_override_inherit, |
| 293 int ua_override_false, | 283 int ua_override_false, |
| 294 int ua_override_true) { | 284 int ua_override_true) { |
| 295 LOAD_TYPE_DEFAULT = load_type_default; | 285 LOAD_TYPE_DEFAULT = load_type_default; |
| 296 LOAD_TYPE_BROWSER_INITIATED_HTTP_POST = load_type_browser_initiated_http
_post; | 286 LOAD_TYPE_BROWSER_INITIATED_HTTP_POST = load_type_browser_initiated_http
_post; |
| 297 LOAD_TYPE_DATA = load_type_data; | 287 LOAD_TYPE_DATA = load_type_data; |
| 298 UA_OVERRIDE_INHERIT = ua_override_inherit; | 288 UA_OVERRIDE_INHERIT = ua_override_inherit; |
| 299 UA_OVERRIDE_FALSE = ua_override_false; | 289 UA_OVERRIDE_FALSE = ua_override_false; |
| 300 UA_OVERRIDE_TRUE = ua_override_true; | 290 UA_OVERRIDE_TRUE = ua_override_true; |
| 301 } | 291 } |
| 302 | |
| 303 /** | |
| 304 * Parses |url| as a GURL on the native side, and | |
| 305 * returns true if it's scheme is data:. | |
| 306 */ | |
| 307 private static native boolean nativeIsDataScheme(String url); | |
| 308 } | 292 } |
| OLD | NEW |