Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2999)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/preferences/website/WebsiteAddress.java

Issue 927763003: Move website settings fetching from WebsitePreferences to new WebsitePermissionFetcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert changes to WebsiteSettingsPopup. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
}

Powered by Google App Engine
This is Rietveld 408576698