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

Unified Diff: net/android/java/src/org/chromium/net/GURLUtils.java

Issue 84703003: Allow data URL > 2MB for loadDataWithBaseURL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Bo comments Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: net/android/java/src/org/chromium/net/GURLUtils.java
diff --git a/net/android/java/src/org/chromium/net/GURLUtils.java b/net/android/java/src/org/chromium/net/GURLUtils.java
index 719ddeabb2343a85613fe7daf6db649112fb8cca..a7478870bb5e1a1c8350d42f04d9c22a01ceeda4 100644
--- a/net/android/java/src/org/chromium/net/GURLUtils.java
+++ b/net/android/java/src/org/chromium/net/GURLUtils.java
@@ -33,6 +33,25 @@ public final class GURLUtils {
return nativeGetScheme(url);
}
+ /**
+ * Efficiently determines if the given |url| has the given |scheme|.
+ * The passed scheme must be non-null, and not include the trailing colon.
+ * @return true if the url starts with the supplied scheme (regardless of whether the remainer
+ * of the URL is validly formed for that scheme type).
+ */
+ public static boolean schemeIs(String url, String scheme) {
+ // Avoid using a native method or parsing the full URL as this maybe a very large
+ // data:... URL.
+ if (url == null || scheme.isEmpty()) return false;
+ assert scheme.charAt(scheme.length() - 1) != ':';
+ int start = 0;
+ while (start < url.length() && Character.isWhitespace(url.codePointAt(start))) ++start;
+ final int colonPos = start + scheme.length();
+ return url.length() > colonPos &&
+ url.charAt(colonPos) == ':' &&
+ url.regionMatches(true, start, scheme, 0, scheme.length());
+ }
+
private static native String nativeGetOrigin(String url);
private static native String nativeGetScheme(String url);
}

Powered by Google App Engine
This is Rietveld 408576698