| 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);
|
| }
|
|
|