Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/website/WebsiteAddress.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/WebsiteAddress.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/WebsiteAddress.java |
index 2269cf4001a6b20ce3bc9b10a45e27e858ae27e3..64763a14f4e024d07ff66629f6a17051367fedce 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/WebsiteAddress.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/WebsiteAddress.java |
@@ -10,6 +10,8 @@ |
import java.io.Serializable; |
+import javax.annotation.Nullable; |
+ |
/** |
* WebsiteAddress is a robust class for storing website address, which can be a |
* fully specified origin, or just a host, or a website name pattern. |
@@ -24,25 +26,43 @@ |
private static final String SCHEME_SUFFIX = "://"; |
private static final String ANY_SUBDOMAIN_PATTERN = "[*.]"; |
+ /** |
+ * Creates a new WebsiteAddress from |originOrHostOrPattern|. |
+ * |
+ * @return A new WebsiteAddress, or null if |originOrHostOrPattern| was null or empty. |
+ */ |
+ @Nullable |
public static WebsiteAddress create(String originOrHostOrPattern) { |
+ // TODO(mvanouwerkerk): Define the behavior of this method if a url with path, query, or |
+ // fragment is passed in. |
+ |
if (originOrHostOrPattern == null || originOrHostOrPattern.isEmpty()) { |
return null; |
- } else if (originOrHostOrPattern.startsWith(ANY_SUBDOMAIN_PATTERN)) { |
- // Pattern |
- return new WebsiteAddress(null, null, |
- originOrHostOrPattern.substring(ANY_SUBDOMAIN_PATTERN.length()), true); |
- } else if (originOrHostOrPattern.indexOf(SCHEME_SUFFIX) != -1) { |
- // Origin |
+ } |
+ |
+ // Pattern |
+ if (originOrHostOrPattern.startsWith(ANY_SUBDOMAIN_PATTERN)) { |
+ String origin = null; |
+ String scheme = null; |
+ String host = originOrHostOrPattern.substring(ANY_SUBDOMAIN_PATTERN.length()); |
+ boolean omitProtocolAndPort = true; |
+ return new WebsiteAddress(origin, scheme, host, omitProtocolAndPort); |
+ } |
+ |
+ // Origin |
+ if (originOrHostOrPattern.indexOf(SCHEME_SUFFIX) != -1) { |
Uri uri = Uri.parse(originOrHostOrPattern); |
- return new WebsiteAddress(trimTrailingBackslash(originOrHostOrPattern), |
- uri.getScheme(), |
- uri.getHost(), |
- HTTP_SCHEME.equals(uri.getScheme()) |
- && (uri.getPort() == -1 || uri.getPort() == 80)); |
- } else { |
- // Host |
- return new WebsiteAddress(null, null, originOrHostOrPattern, true); |
+ String origin = trimTrailingBackslash(originOrHostOrPattern); |
+ boolean omitProtocolAndPort = HTTP_SCHEME.equals(uri.getScheme()) |
+ && (uri.getPort() == -1 || uri.getPort() == 80); |
+ return new WebsiteAddress(origin, uri.getScheme(), uri.getHost(), omitProtocolAndPort); |
} |
+ |
+ // Host |
+ String origin = null; |
+ String scheme = null; |
+ boolean omitProtocolAndPort = true; |
+ return new WebsiteAddress(origin, scheme, originOrHostOrPattern, omitProtocolAndPort); |
} |
private WebsiteAddress(String origin, String scheme, String host, boolean omitProtocolAndPort) { |
@@ -118,6 +138,10 @@ public int compareTo(WebsiteAddress to) { |
return position1 - position2; |
} |
+ public boolean hasSameContentSettingsOrigin(WebsiteAddress otherAddress) { |
+ return nativeHasSameContentSettingsOrigin(getOrigin(), otherAddress.getOrigin()); |
+ } |
+ |
private String[] getSubdomainsList() { |
int startIndex; |
String mAddress; |
@@ -139,4 +163,6 @@ public int compareTo(WebsiteAddress to) { |
private static String trimTrailingBackslash(String origin) { |
return (origin.endsWith("/")) ? origin.substring(0, origin.length() - 1) : origin; |
} |
+ |
+ private static native boolean nativeHasSameContentSettingsOrigin(String url1, String url2); |
} |