Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(480)

Side by Side Diff: content/public/android/java/src/org/chromium/content_public/browser/LoadUrlParams.java

Issue 834133004: Don't initialize C++ constants in Java during JNI registration. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: multi-line package name yet again Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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_public.browser; 5 package org.chromium.content_public.browser;
6 6
7 import org.chromium.base.CalledByNative;
8 import org.chromium.base.JNINamespace; 7 import org.chromium.base.JNINamespace;
8 import org.chromium.content_public.browser.navigation_controller.LoadURLType;
9 import org.chromium.content_public.browser.navigation_controller.UserAgentOverri deOption;
9 import org.chromium.content_public.common.Referrer; 10 import org.chromium.content_public.common.Referrer;
10 import org.chromium.ui.base.PageTransition; 11 import org.chromium.ui.base.PageTransition;
11 12
12 import java.util.Locale; 13 import java.util.Locale;
13 import java.util.Map; 14 import java.util.Map;
14 15
15 /** 16 /**
16 * Holds parameters for NavigationController.LoadUrl. Parameters should match 17 * Holds parameters for NavigationController.LoadUrl. Parameters should match
17 * counterparts in NavigationController::LoadURLParams, including default 18 * counterparts in NavigationController::LoadURLParams, including default
18 * values. 19 * values.
19 */ 20 */
20 @JNINamespace("content") 21 @JNINamespace("content")
21 public class LoadUrlParams { 22 public class LoadUrlParams {
22 // Should match NavigationController::LoadUrlType exactly. See comments 23 // These fields have been replaced by build-time generated enums and should be removed when
23 // there for proper usage. initializeConstants() checks that the values 24 // no longer used downstream.
24 // are correct. 25 @Deprecated
25 public static final int LOAD_TYPE_DEFAULT = 0; 26 public static final int LOAD_TYPE_BROWSER_INITIATED_HTTP_POST =
26 public static final int LOAD_TYPE_BROWSER_INITIATED_HTTP_POST = 1; 27 LoadURLType.BROWSER_INITIATED_HTTP_POST;
27 public static final int LOAD_TYPE_DATA = 2;
28
29 // Should match NavigationController::UserAgentOverrideOption exactly.
30 // See comments there for proper usage. initializeConstants() checks that
31 // the values are correct.
32 public static final int UA_OVERRIDE_INHERIT = 0;
33 public static final int UA_OVERRIDE_FALSE = 1;
34 public static final int UA_OVERRIDE_TRUE = 2;
35 28
36 // Fields with counterparts in NavigationController::LoadURLParams. 29 // Fields with counterparts in NavigationController::LoadURLParams.
37 // Package private so that ContentViewCore.loadUrl can pass them down to 30 // Package private so that ContentViewCore.loadUrl can pass them down to
38 // native code. Should not be accessed directly anywhere else outside of 31 // native code. Should not be accessed directly anywhere else outside of
39 // this class. 32 // this class.
40 String mUrl; 33 String mUrl;
41 int mLoadUrlType; 34 int mLoadUrlType;
42 int mTransitionType; 35 int mTransitionType;
43 Referrer mReferrer; 36 Referrer mReferrer;
44 private Map<String, String> mExtraHeaders; 37 private Map<String, String> mExtraHeaders;
(...skipping 17 matching lines...) Expand all
62 * Creates an instance with the given page transition type. 55 * Creates an instance with the given page transition type.
63 * @param url the url to be loaded 56 * @param url the url to be loaded
64 * @param transitionType the PageTransitionType constant corresponding to th e load 57 * @param transitionType the PageTransitionType constant corresponding to th e load
65 */ 58 */
66 public LoadUrlParams(String url, int transitionType) { 59 public LoadUrlParams(String url, int transitionType) {
67 mUrl = url; 60 mUrl = url;
68 mTransitionType = transitionType; 61 mTransitionType = transitionType;
69 62
70 // Initialize other fields to defaults matching defaults of the native 63 // Initialize other fields to defaults matching defaults of the native
71 // NavigationController::LoadUrlParams. 64 // NavigationController::LoadUrlParams.
72 mLoadUrlType = LOAD_TYPE_DEFAULT; 65 mLoadUrlType = LoadURLType.DEFAULT;
73 mUaOverrideOption = UA_OVERRIDE_INHERIT; 66 mUaOverrideOption = UserAgentOverrideOption.INHERIT;
74 mPostData = null; 67 mPostData = null;
75 mBaseUrlForDataUrl = null; 68 mBaseUrlForDataUrl = null;
76 mVirtualUrlForDataUrl = null; 69 mVirtualUrlForDataUrl = null;
77 } 70 }
78 71
79 /** 72 /**
80 * Helper method to create a LoadUrlParams object for data url. 73 * Helper method to create a LoadUrlParams object for data url.
81 * @param data Data to be loaded. 74 * @param data Data to be loaded.
82 * @param mimeType Mime type of the data. 75 * @param mimeType Mime type of the data.
83 * @param isBase64Encoded True if the data is encoded in Base 64 format. 76 * @param isBase64Encoded True if the data is encoded in Base 64 format.
(...skipping 18 matching lines...) Expand all
102 if (charset != null && !charset.isEmpty()) { 95 if (charset != null && !charset.isEmpty()) {
103 dataUrl.append(";charset=" + charset); 96 dataUrl.append(";charset=" + charset);
104 } 97 }
105 if (isBase64Encoded) { 98 if (isBase64Encoded) {
106 dataUrl.append(";base64"); 99 dataUrl.append(";base64");
107 } 100 }
108 dataUrl.append(","); 101 dataUrl.append(",");
109 dataUrl.append(data); 102 dataUrl.append(data);
110 103
111 LoadUrlParams params = new LoadUrlParams(dataUrl.toString()); 104 LoadUrlParams params = new LoadUrlParams(dataUrl.toString());
112 params.setLoadType(LoadUrlParams.LOAD_TYPE_DATA); 105 params.setLoadType(LoadURLType.DATA);
113 params.setTransitionType(PageTransition.TYPED); 106 params.setTransitionType(PageTransition.TYPED);
114 return params; 107 return params;
115 } 108 }
116 109
117 /** 110 /**
118 * Helper method to create a LoadUrlParams object for data url with base 111 * Helper method to create a LoadUrlParams object for data url with base
119 * and virtual url. 112 * and virtual url.
120 * @param data Data to be loaded. 113 * @param data Data to be loaded.
121 * @param mimeType Mime type of the data. 114 * @param mimeType Mime type of the data.
122 * @param isBase64Encoded True if the data is encoded in Base 64 format. 115 * @param isBase64Encoded True if the data is encoded in Base 64 format.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } 159 }
167 160
168 /** 161 /**
169 * Helper method to create a LoadUrlParams object for an HTTP POST load. 162 * Helper method to create a LoadUrlParams object for an HTTP POST load.
170 * @param url URL of the load. 163 * @param url URL of the load.
171 * @param postData Post data of the load. Can be null. 164 * @param postData Post data of the load. Can be null.
172 */ 165 */
173 public static LoadUrlParams createLoadHttpPostParams( 166 public static LoadUrlParams createLoadHttpPostParams(
174 String url, byte[] postData) { 167 String url, byte[] postData) {
175 LoadUrlParams params = new LoadUrlParams(url); 168 LoadUrlParams params = new LoadUrlParams(url);
176 params.setLoadType(LOAD_TYPE_BROWSER_INITIATED_HTTP_POST); 169 params.setLoadType(LoadURLType.BROWSER_INITIATED_HTTP_POST);
177 params.setTransitionType(PageTransition.TYPED); 170 params.setTransitionType(PageTransition.TYPED);
178 params.setPostData(postData); 171 params.setPostData(postData);
179 return params; 172 return params;
180 } 173 }
181 174
182 /** 175 /**
183 * Sets the url. 176 * Sets the url.
184 */ 177 */
185 public void setUrl(String url) { 178 public void setUrl(String url) {
186 mUrl = url; 179 mUrl = url;
187 } 180 }
188 181
189 /** 182 /**
190 * Return the url. 183 * Return the url.
191 */ 184 */
192 public String getUrl() { 185 public String getUrl() {
193 return mUrl; 186 return mUrl;
194 } 187 }
195 188
196 /** 189 /**
197 * Return the base url for a data url, otherwise null. 190 * Return the base url for a data url, otherwise null.
198 */ 191 */
199 public String getBaseUrl() { 192 public String getBaseUrl() {
200 return mBaseUrlForDataUrl; 193 return mBaseUrlForDataUrl;
201 } 194 }
202 195
203 /** 196 /**
204 * Set load type of this load. Defaults to LOAD_TYPE_DEFAULT. 197 * Set load type of this load. Defaults to LoadURLType.DEFAULT.
205 * @param loadType One of LOAD_TYPE static constants above. 198 * @param loadType One of LOAD_TYPE static constants above.
206 */ 199 */
207 public void setLoadType(int loadType) { 200 public void setLoadType(int loadType) {
208 mLoadUrlType = loadType; 201 mLoadUrlType = loadType;
209 } 202 }
210 203
211 /** 204 /**
212 * Set transition type of this load. Defaults to PageTransition.LINK. 205 * Set transition type of this load. Defaults to PageTransition.LINK.
213 * @param transitionType One of PAGE_TRANSITION static constants in ContentV iew. 206 * @param transitionType One of PAGE_TRANSITION static constants in ContentV iew.
214 */ 207 */
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 } 293 }
301 294
302 /** 295 /**
303 * @return the verbatim extra headers string 296 * @return the verbatim extra headers string
304 */ 297 */
305 public String getVerbatimHeaders() { 298 public String getVerbatimHeaders() {
306 return mVerbatimHeaders; 299 return mVerbatimHeaders;
307 } 300 }
308 301
309 /** 302 /**
310 * Set user agent override option of this load. Defaults to UA_OVERRIDE_INHE RIT. 303 * Set user agent override option of this load. Defaults to UserAgentOverrid eOption.INHERIT.
311 * @param uaOption One of UA_OVERRIDE static constants above. 304 * @param uaOption One of UA_OVERRIDE static constants above.
312 */ 305 */
313 public void setOverrideUserAgent(int uaOption) { 306 public void setOverrideUserAgent(int uaOption) {
314 mUaOverrideOption = uaOption; 307 mUaOverrideOption = uaOption;
315 } 308 }
316 309
317 /** 310 /**
318 * Get user agent override option of this load. Defaults to UA_OVERRIDE_INHE RIT. 311 * Get user agent override option of this load. Defaults to UserAgentOverrid eOption.INHERIT.
319 * @param uaOption One of UA_OVERRIDE static constants above. 312 * @param uaOption One of UA_OVERRIDE static constants above.
320 */ 313 */
321 public int getUserAgentOverrideOption() { 314 public int getUserAgentOverrideOption() {
322 return mUaOverrideOption; 315 return mUaOverrideOption;
323 } 316 }
324 317
325 /** 318 /**
326 * Set the post data of this load. This field is ignored unless load type is 319 * Set the post data of this load. This field is ignored unless load type is
327 * LOAD_TYPE_BROWSER_INITIATED_HTTP_POST. 320 * LoadURLType.BROWSER_INITIATED_HTTP_POST.
328 * @param postData Post data for this http post load. 321 * @param postData Post data for this http post load.
329 */ 322 */
330 public void setPostData(byte[] postData) { 323 public void setPostData(byte[] postData) {
331 mPostData = postData; 324 mPostData = postData;
332 } 325 }
333 326
334 /** 327 /**
335 * @return the data to be sent through POST 328 * @return the data to be sent through POST
336 */ 329 */
337 public byte[] getPostData() { 330 public byte[] getPostData() {
338 return mPostData; 331 return mPostData;
339 } 332 }
340 333
341 /** 334 /**
342 * Set the base url for data load. It is used both to resolve relative URLs 335 * Set the base url for data load. It is used both to resolve relative URLs
343 * and when applying JavaScript's same origin policy. It is ignored unless 336 * and when applying JavaScript's same origin policy. It is ignored unless
344 * load type is LOAD_TYPE_DATA. 337 * load type is LoadURLType.DATA.
345 * @param baseUrl The base url for this data load. 338 * @param baseUrl The base url for this data load.
346 */ 339 */
347 public void setBaseUrlForDataUrl(String baseUrl) { 340 public void setBaseUrlForDataUrl(String baseUrl) {
348 mBaseUrlForDataUrl = baseUrl; 341 mBaseUrlForDataUrl = baseUrl;
349 } 342 }
350 343
351 /** 344 /**
352 * Get the virtual url for data load. It is the url displayed to the user. 345 * Get the virtual url for data load. It is the url displayed to the user.
353 * It is ignored unless load type is LOAD_TYPE_DATA. 346 * It is ignored unless load type is LoadURLType.DATA.
354 * @return The virtual url for this data load. 347 * @return The virtual url for this data load.
355 */ 348 */
356 public String getVirtualUrlForDataUrl() { 349 public String getVirtualUrlForDataUrl() {
357 return mVirtualUrlForDataUrl; 350 return mVirtualUrlForDataUrl;
358 } 351 }
359 352
360 /** 353 /**
361 * Set the virtual url for data load. It is the url displayed to the user. 354 * Set the virtual url for data load. It is the url displayed to the user.
362 * It is ignored unless load type is LOAD_TYPE_DATA. 355 * It is ignored unless load type is LoadURLType.DATA.
363 * @param virtualUrl The virtual url for this data load. 356 * @param virtualUrl The virtual url for this data load.
364 */ 357 */
365 public void setVirtualUrlForDataUrl(String virtualUrl) { 358 public void setVirtualUrlForDataUrl(String virtualUrl) {
366 mVirtualUrlForDataUrl = virtualUrl; 359 mVirtualUrlForDataUrl = virtualUrl;
367 } 360 }
368 361
369 /** 362 /**
370 * Set whether the load should be able to access local resources. This 363 * Set whether the load should be able to access local resources. This
371 * defaults to false. 364 * defaults to false.
372 */ 365 */
(...skipping 23 matching lines...) Expand all
396 /** 389 /**
397 * @return Whether or not this load was initiated from a renderer or not. 390 * @return Whether or not this load was initiated from a renderer or not.
398 */ 391 */
399 public boolean getIsRendererInitiated() { 392 public boolean getIsRendererInitiated() {
400 return mIsRendererInitiated; 393 return mIsRendererInitiated;
401 } 394 }
402 395
403 public boolean isBaseUrlDataScheme() { 396 public boolean isBaseUrlDataScheme() {
404 // If there's no base url set, but this is a data load then 397 // If there's no base url set, but this is a data load then
405 // treat the scheme as data:. 398 // treat the scheme as data:.
406 if (mBaseUrlForDataUrl == null && mLoadUrlType == LOAD_TYPE_DATA) { 399 if (mBaseUrlForDataUrl == null && mLoadUrlType == LoadURLType.DATA) {
407 return true; 400 return true;
408 } 401 }
409 return nativeIsDataScheme(mBaseUrlForDataUrl); 402 return nativeIsDataScheme(mBaseUrlForDataUrl);
410 } 403 }
411 404
412 @SuppressWarnings("unused")
413 @CalledByNative
414 private static void initializeConstants(
415 int loadTypeDefault,
416 int loadTypeBrowserInitiatedHttpPost,
417 int loadTypeData,
418 int uaOverrideInherit,
419 int uaOverrideFalse,
420 int uaOverrideTrue) {
421 assert LOAD_TYPE_DEFAULT == loadTypeDefault;
422 assert LOAD_TYPE_BROWSER_INITIATED_HTTP_POST == loadTypeBrowserInitiated HttpPost;
423 assert LOAD_TYPE_DATA == loadTypeData;
424 assert UA_OVERRIDE_INHERIT == uaOverrideInherit;
425 assert UA_OVERRIDE_FALSE == uaOverrideFalse;
426 assert UA_OVERRIDE_TRUE == uaOverrideTrue;
427 }
428
429 /** 405 /**
430 * Parses |url| as a GURL on the native side, and 406 * Parses |url| as a GURL on the native side, and
431 * returns true if it's scheme is data:. 407 * returns true if it's scheme is data:.
432 */ 408 */
433 private static native boolean nativeIsDataScheme(String url); 409 private static native boolean nativeIsDataScheme(String url);
434 } 410 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698