| 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | package org.chromium.net; |
| 6 | |
| 7 | import org.chromium.base.JNINamespace; |
| 8 | |
| 9 | /** |
| 10 | * Class to access the GURL library from java. |
| 11 | */ |
| 12 | @JNINamespace("net") |
| 13 | public final class GURLUtils { |
| 14 | |
| 15 | /** |
| 16 | * Get the origin of an url: Ex getOrigin("http://www.example.com:8080/index.html?bar=foo") |
| 17 | * would return "http://www.example.com:8080". It will return an empty string for an |
| 18 | * invalid url. |
| 19 | * |
| 20 | * @return The origin of the url |
| 21 | */ |
| 22 | public static String getOrigin(String url) { |
| 23 | return nativeGetOrigin(url); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Get the scheme of the url (e.g. http, https, file). The returned string |
| 28 | * contains everything before the "://". |
| 29 | * |
| 30 | * @return The scheme of the url. |
| 31 | */ |
| 32 | public static String getScheme(String url) { |
| 33 | return nativeGetScheme(url); |
| 34 | } |
| 35 | |
| 36 | private static native String nativeGetOrigin(String url); |
| 37 | private static native String nativeGetScheme(String url); |
| 38 | } |