This source file includes following definitions.
- isAcceptedScheme
- isAcceptedScheme
- isDownloadableScheme
- isDownloadableScheme
- fixUrl
- fixupUrl
- getOriginForDisplay
- sameDomainOrHost
- getDomainAndRegistry
- nativeSameDomainOrHost
- nativeGetDomainAndRegistry
- nativeIsGoogleSearchUrl
- nativeIsGoogleHomePageUrl
- nativeFixupUrl
package org.chromium.chrome.browser;
import android.text.TextUtils;
import org.chromium.base.CollectionUtil;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashSet;
public class UrlUtilities {
private static final HashSet<String> ACCEPTED_SCHEMES = CollectionUtil.newHashSet(
"about", "data", "file", "http", "https", "inline", "javascript");
private static final HashSet<String> DOWNLOADABLE_SCHEMES = CollectionUtil.newHashSet(
"data", "filesystem", "http", "https");
public static boolean isAcceptedScheme(URI uri) {
return ACCEPTED_SCHEMES.contains(uri.getScheme());
}
public static boolean isAcceptedScheme(String uri) {
try {
return isAcceptedScheme(new URI(uri));
} catch (URISyntaxException e) {
return false;
}
}
public static boolean isDownloadableScheme(URI uri) {
return DOWNLOADABLE_SCHEMES.contains(uri.getScheme());
}
public static boolean isDownloadableScheme(String uri) {
try {
return isDownloadableScheme(new URI(uri));
} catch (URISyntaxException e) {
return false;
}
}
public static String fixUrl(String uri) {
if (uri == null) return null;
try {
String fixedUri = uri.trim();
if (fixedUri.indexOf("://") == 0) {
return "http" + fixedUri;
}
if (fixedUri.indexOf(":") == -1) {
return "http://" + fixedUri;
}
URI parsed = new URI(fixedUri);
if (parsed.getScheme() == null) {
parsed = new URI(
"http",
null,
parsed.getHost(),
parsed.getPort(),
parsed.getRawPath(),
parsed.getRawQuery(),
parsed.getRawFragment());
}
return parsed.toString();
} catch (URISyntaxException e) {
return uri;
}
}
public static String fixupUrl(String uri) {
return nativeFixupUrl(uri, null);
}
public static String getOriginForDisplay(URI uri, boolean showScheme) {
String scheme = uri.getScheme();
String host = uri.getHost();
int port = uri.getPort();
String displayUrl;
if (TextUtils.isEmpty(scheme) || TextUtils.isEmpty(host)) {
displayUrl = uri.toString();
} else {
if (showScheme) {
scheme += "://";
} else {
scheme = "";
}
if (port == -1 || (port == 80 && "http".equals(scheme))
|| (port == 443 && "https".equals(scheme))) {
displayUrl = scheme + host;
} else {
displayUrl = scheme + host + ":" + port;
}
}
return displayUrl;
}
public static boolean sameDomainOrHost(String primaryUrl, String secondaryUrl,
boolean includePrivateRegistries) {
return nativeSameDomainOrHost(primaryUrl, secondaryUrl, includePrivateRegistries);
}
public static String getDomainAndRegistry(String uri, boolean includePrivateRegistries) {
return nativeGetDomainAndRegistry(uri, includePrivateRegistries);
}
private static native boolean nativeSameDomainOrHost(String primaryUrl, String secondaryUrl,
boolean includePrivateRegistries);
private static native String nativeGetDomainAndRegistry(String url,
boolean includePrivateRegistries);
public static native boolean nativeIsGoogleSearchUrl(String url);
public static native boolean nativeIsGoogleHomePageUrl(String url);
public static native String nativeFixupUrl(String url, String desiredTld);
}