Commit d00c9171 authored by changwan's avatar changwan Committed by Commit bot

[Android] Add a check function for intent fallback navigation

BUG=440178

Review URL: https://codereview.chromium.org/785163002

Cr-Commit-Position: refs/heads/master@{#308480}
parent 6f6c4e61
......@@ -36,6 +36,12 @@ public class UrlUtilities {
private static final HashSet<String> INTERNAL_SCHEMES = CollectionUtil.newHashSet(
"chrome", "chrome-native", "about");
/**
* URI schemes that can be handled in Intent fallback navigation.
*/
private static final HashSet<String> FALLBACK_VALID_SCHEMES = CollectionUtil.newHashSet(
"http", "https");
/**
* @param uri A URI.
*
......@@ -58,6 +64,28 @@ public class UrlUtilities {
}
}
/**
* @param uri A URI.
*
* @return True if the URI is valid for Intent fallback navigation.
*/
public static boolean isValidForIntentFallbackNavigation(URI uri) {
return FALLBACK_VALID_SCHEMES.contains(uri.getScheme());
}
/**
* @param uri A URI.
*
* @return True if the URI is valid for Intent fallback navigation.
*/
public static boolean isValidForIntentFallbackNavigation(String uri) {
try {
return isValidForIntentFallbackNavigation(new URI(uri));
} catch (URISyntaxException e) {
return false;
}
}
/**
* @param uri A URI.
*
......
......@@ -61,6 +61,16 @@ public class UrlUtilitiesTest extends InstrumentationTestCase {
assertFalse(UrlUtilities.isDownloadableScheme("ht\ntp://awesome.example.com/"));
}
@SmallTest
public void testIsValidForIntentFallbackUrl() {
assertTrue(UrlUtilities.isValidForIntentFallbackNavigation(
"https://user:pass@:awesome.com:9000/bad-scheme:#fake:"));
assertTrue(UrlUtilities.isValidForIntentFallbackNavigation("http://awesome.example.com/"));
assertFalse(UrlUtilities.isValidForIntentFallbackNavigation("inline:skates.co.uk"));
assertFalse(UrlUtilities.isValidForIntentFallbackNavigation("javascript:alert(1)"));
assertFalse(UrlUtilities.isValidForIntentFallbackNavigation(""));
}
@SmallTest
public void testFixUrl() throws URISyntaxException {
try {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment