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

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

Issue 2156273003: Reuse Website objects in WebsitePermissionFetcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix findbugs warnings. Created 4 years, 5 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/SingleWebsitePreferences.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/SingleWebsitePreferences.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/SingleWebsitePreferences.java
index 0fb403de14258042e56ab52a01fb76218dce4eb3..bca422efd87c0f80d3702fa7b0c8fc3c3a3c887a 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/SingleWebsitePreferences.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/SingleWebsitePreferences.java
@@ -29,10 +29,7 @@ import org.chromium.chrome.browser.util.UrlUtilities;
import org.chromium.content_public.browser.WebContents;
import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.Collection;
/**
* Shows the permissions and other settings for a particular website.
@@ -115,18 +112,13 @@ public class SingleWebsitePreferences extends PreferenceFragment
}
@Override
- public void onWebsitePermissionsAvailable(
- Map<String, Set<Website>> sitesByOrigin, Map<String, Set<Website>> sitesByHost) {
+ public void onWebsitePermissionsAvailable(Collection<Website> sites) {
// This method may be called after the activity has been destroyed.
// In that case, bail out.
if (getActivity() == null) return;
- // TODO(mvanouwerkerk): Do this merge at data retrieval time in C++, instead of now.
- List<Set<Website>> allSites = new ArrayList<>();
- allSites.addAll(sitesByOrigin.values());
- allSites.addAll(sitesByHost.values());
// TODO(mvanouwerkerk): Avoid modifying the outer class from this inner class.
- mSite = mergePermissionInfoForTopLevelOrigin(mSiteAddress, allSites);
+ mSite = mergePermissionInfoForTopLevelOrigin(mSiteAddress, sites);
// Display Keygen Content Setting if Keygen is blocked.
if (mSite.getKeygenInfo() == null && mWebContents != null
@@ -192,78 +184,71 @@ public class SingleWebsitePreferences extends PreferenceFragment
* first place.
*
* @param address The address to search for.
- * @param websiteSets The websites to search in.
+ * @param websites The websites to search in.
* @return The merged website.
*/
private static Website mergePermissionInfoForTopLevelOrigin(
- WebsiteAddress address, List<Set<Website>> websiteSets) {
+ WebsiteAddress address, Collection<Website> websites) {
String origin = address.getOrigin();
String host = Uri.parse(origin).getHost();
- Website merged = new Website(address);
- // This nested loop looks expensive, but the amount of data is likely to be relatively
- // small because most sites have very few permissions.
- for (Set<Website> websiteSet : websiteSets) {
- for (Website other : websiteSet) {
- if (merged.getFullscreenInfo() == null && other.getFullscreenInfo() != null
- && permissionInfoIsForTopLevelOrigin(other.getFullscreenInfo(), origin)) {
- merged.setFullscreenInfo(other.getFullscreenInfo());
- }
- if (merged.getGeolocationInfo() == null && other.getGeolocationInfo() != null
- && permissionInfoIsForTopLevelOrigin(other.getGeolocationInfo(), origin)) {
- merged.setGeolocationInfo(other.getGeolocationInfo());
- }
- if (merged.getKeygenInfo() == null && other.getKeygenInfo() != null
- && permissionInfoIsForTopLevelOrigin(other.getKeygenInfo(), origin)) {
- merged.setKeygenInfo(other.getKeygenInfo());
- }
- if (merged.getMidiInfo() == null && other.getMidiInfo() != null
- && permissionInfoIsForTopLevelOrigin(other.getMidiInfo(), origin)) {
- merged.setMidiInfo(other.getMidiInfo());
- }
- if (merged.getProtectedMediaIdentifierInfo() == null
- && other.getProtectedMediaIdentifierInfo() != null
- && permissionInfoIsForTopLevelOrigin(
- other.getProtectedMediaIdentifierInfo(), origin)) {
- merged.setProtectedMediaIdentifierInfo(other.getProtectedMediaIdentifierInfo());
- }
- if (merged.getNotificationInfo() == null
- && other.getNotificationInfo() != null
- && permissionInfoIsForTopLevelOrigin(
- other.getNotificationInfo(), origin)) {
- merged.setNotificationInfo(other.getNotificationInfo());
- }
- if (merged.getCameraInfo() == null && other.getCameraInfo() != null) {
- if (origin.equals(other.getCameraInfo().getOrigin())
- && (origin.equals(other.getCameraInfo().getEmbedderSafe())
- || "*".equals(other.getCameraInfo().getEmbedderSafe()))) {
- merged.setCameraInfo(other.getCameraInfo());
- }
- }
- if (merged.getMicrophoneInfo() == null && other.getMicrophoneInfo() != null) {
- if (origin.equals(other.getMicrophoneInfo().getOrigin())
- && (origin.equals(other.getMicrophoneInfo().getEmbedderSafe())
- || "*".equals(other.getMicrophoneInfo().getEmbedderSafe()))) {
- merged.setMicrophoneInfo(other.getMicrophoneInfo());
- }
- }
- if (merged.getLocalStorageInfo() == null
- && other.getLocalStorageInfo() != null
- && origin.equals(other.getLocalStorageInfo().getOrigin())) {
- merged.setLocalStorageInfo(other.getLocalStorageInfo());
- }
- for (StorageInfo storageInfo : other.getStorageInfo()) {
- if (host.equals(storageInfo.getHost())) {
- merged.addStorageInfo(storageInfo);
- }
+ Website merged = new Website(address, null);
+ // This loop looks expensive, but the amount of data is likely to be relatively small
+ // because most sites have very few permissions.
+ for (Website other : websites) {
+ if (merged.getFullscreenInfo() == null && other.getFullscreenInfo() != null
+ && permissionInfoIsForTopLevelOrigin(other.getFullscreenInfo(), origin)) {
+ merged.setFullscreenInfo(other.getFullscreenInfo());
+ }
+ if (merged.getGeolocationInfo() == null && other.getGeolocationInfo() != null
+ && permissionInfoIsForTopLevelOrigin(other.getGeolocationInfo(), origin)) {
+ merged.setGeolocationInfo(other.getGeolocationInfo());
+ }
+ if (merged.getKeygenInfo() == null && other.getKeygenInfo() != null
+ && permissionInfoIsForTopLevelOrigin(other.getKeygenInfo(), origin)) {
+ merged.setKeygenInfo(other.getKeygenInfo());
+ }
+ if (merged.getMidiInfo() == null && other.getMidiInfo() != null
+ && permissionInfoIsForTopLevelOrigin(other.getMidiInfo(), origin)) {
+ merged.setMidiInfo(other.getMidiInfo());
+ }
+ if (merged.getProtectedMediaIdentifierInfo() == null
+ && other.getProtectedMediaIdentifierInfo() != null
+ && permissionInfoIsForTopLevelOrigin(
+ other.getProtectedMediaIdentifierInfo(), origin)) {
+ merged.setProtectedMediaIdentifierInfo(other.getProtectedMediaIdentifierInfo());
+ }
+ if (merged.getNotificationInfo() == null
+ && other.getNotificationInfo() != null
+ && permissionInfoIsForTopLevelOrigin(
+ other.getNotificationInfo(), origin)) {
+ merged.setNotificationInfo(other.getNotificationInfo());
+ }
+ if (merged.getCameraInfo() == null && other.getCameraInfo() != null
+ && permissionInfoIsForTopLevelOrigin(
+ other.getCameraInfo(), origin)) {
+ merged.setCameraInfo(other.getCameraInfo());
+ }
+ if (merged.getMicrophoneInfo() == null && other.getMicrophoneInfo() != null
+ && permissionInfoIsForTopLevelOrigin(other.getMicrophoneInfo(), origin)) {
+ merged.setMicrophoneInfo(other.getMicrophoneInfo());
+ }
+ if (merged.getLocalStorageInfo() == null
+ && other.getLocalStorageInfo() != null
+ && origin.equals(other.getLocalStorageInfo().getOrigin())) {
+ merged.setLocalStorageInfo(other.getLocalStorageInfo());
+ }
+ for (StorageInfo storageInfo : other.getStorageInfo()) {
+ if (host.equals(storageInfo.getHost())) {
+ merged.addStorageInfo(storageInfo);
}
-
- // TODO(mvanouwerkerk): Make the various info types share a common interface that
- // supports reading the origin or host.
- // TODO(mvanouwerkerk): Merge in PopupExceptionInfo? It uses a pattern, and is never
- // set on Android.
- // TODO(mvanouwerkerk): Merge in JavaScriptExceptionInfo? It uses a pattern.
- // TODO(lshang): Merge in CookieException? It will use patterns.
}
+
+ // TODO(mvanouwerkerk): Make the various info types share a common interface that
+ // supports reading the origin or host.
+ // TODO(mvanouwerkerk): Merge in PopupExceptionInfo? It uses a pattern, and is never
+ // set on Android.
+ // TODO(mvanouwerkerk): Merge in JavaScriptExceptionInfo? It uses a pattern.
+ // TODO(lshang): Merge in CookieException? It will use patterns.
}
return merged;
}

Powered by Google App Engine
This is Rietveld 408576698