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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/preferences/website/SingleWebsitePreferences.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: Formatting 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/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 d337bfa5cfa160abd38b16dbc86a7d8ce70e987a..b4999c7c1d2e48d4cd051b1a316ae89d935f3c20 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
@@ -20,13 +20,24 @@
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ContentSettingsType;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* Shows a list of HTML5 settings for a single website.
*/
public class SingleWebsitePreferences extends PreferenceFragment
implements DialogInterface.OnClickListener, OnPreferenceChangeListener,
OnPreferenceClickListener {
+ // SingleWebsitePreferences expects either EXTRA_SITE (a Website) or
+ // EXTRA_ADDRESS (a WebsiteAddress) to be present (but not both). If
+ // EXTRA_SITE is present, the fragment will display the permissions in that
+ // Website object. If EXTRA_ADDRESS is present, the fragment will find all
+ // permissions for that website address and display those.
public static final String EXTRA_SITE = "org.chromium.chrome.preferences.site";
+ public static final String EXTRA_ADDRESS = "org.chromium.chrome.preferences.address";
// Preference keys, see single_website_preferences.xml
// Headings:
@@ -51,13 +62,95 @@
// The website this page is displaying details about.
private Website mSite;
+
+ // The address of the site we want to display. Used only if EXTRA_ADDRESS is provided.
+ private WebsiteAddress mSiteAddress;
+
// A list of possible options for each list preference summary.
private String[] mListPreferenceSummaries;
+ private class SingleWebsitePermissionsPopulator
+ implements WebsitePermissionsFetcher.WebsitePermissionsCallback {
+ @Override
+ public void onWebsitePermissionsAvailable(
+ Map<String, Set<Website>> sitesByOrigin, Map<String, Set<Website>> sitesByHost) {
+ // This method may be called after the activity has been destroyed.
+ // In that case, bail out.
+ if (getActivity() == null) return;
+
+ // Find the website (origin or host name) with the URL in mSite.
+ // TODO(mvanouwerkerk): Do this at data retrieval time, instead of now.
+ ArrayList<Set<Website>> allSites = new ArrayList<>();
+ allSites.addAll(sitesByOrigin.values());
+ allSites.addAll(sitesByHost.values());
+ mSite = findOrCreateWebsite(mSiteAddress, allSites);
+ displaySitePermissions();
+ }
+ }
+
+ /**
+ * Creates a Bundle with the correct arguments for opening this fragment for
+ * the website with the given url.
+ *
+ * @param url The URL to open the fragment with.
+ * @return The bundle to attach to the preferences intent.
+ */
+ public static Bundle createFragmentArgsForSite(String url) {
+ Bundle fragmentArgs = new Bundle();
+ fragmentArgs.putSerializable(
+ SingleWebsitePreferences.EXTRA_ADDRESS, WebsiteAddress.create(url));
+ return fragmentArgs;
+ }
+
@Override
public void onActivityCreated(Bundle savedInstanceState) {
getActivity().setTitle(R.string.prefs_content_settings);
- mSite = (Website) getArguments().getSerializable(EXTRA_SITE);
+ Object extraSite = getArguments().getSerializable(EXTRA_SITE);
+ Object extraAddress = getArguments().getSerializable(EXTRA_ADDRESS);
+
+ if (extraSite != null && extraAddress == null) {
+ mSite = (Website) extraSite;
+ displaySitePermissions();
+ } else if (extraAddress != null && extraSite == null) {
+ mSiteAddress = (WebsiteAddress) extraAddress;
+ WebsitePermissionsFetcher fetcher =
+ new WebsitePermissionsFetcher(new SingleWebsitePermissionsPopulator());
+ fetcher.fetchAllPreferences();
Peter Beverloo 2015/02/17 15:06:46 Hm, so we end up fetching *all* data for *all* web
sashab 2015/02/18 05:28:32 +1 to the TODO. Would be great if we could (native
Michael van Ouwerkerk 2015/02/18 19:57:39 Done.
Michael van Ouwerkerk 2015/02/18 19:57:39 Done.
+ } else {
+ assert false : "Exactly one of EXTRA_SITE or EXTRA_SITE_ADDRESS must be provided.";
+ }
+
+ super.onActivityCreated(savedInstanceState);
+ }
+
+ /**
+ * Given an address and a collection of websites
+ * Returns the site from |websiteSets| with the
+ * same origin as |address| (as determined by content settings). If
Peter Beverloo 2015/02/17 15:06:46 nit: Odd line breaks.
Michael van Ouwerkerk 2015/02/18 19:57:39 Done.
+ * no website is found, returns a new website with the given address.
+ *
+ * @param address The address to search for.
+ * @param websiteSets The websites to search in.
+ * @return The first matching website, or a new website with the given
+ * address.
+ */
+ private static Website findOrCreateWebsite(
+ WebsiteAddress address, List<Set<Website>> websiteSets) {
+ for (Set<Website> websiteSet : websiteSets) {
+ for (Website otherWebsite : websiteSet) {
+ if (address.hasSameContentSettingsOrigin(otherWebsite.getAddress())) {
+ return otherWebsite;
+ }
+ }
+ }
+ return new Website(address);
+ }
+
+ /**
+ * Updates the permissions displayed in the UI by fetching them from mSite.
+ * Must only be called once mSite is set.
+ */
+ private void displaySitePermissions() {
addPreferencesFromResource(R.xml.single_website_preferences);
mListPreferenceSummaries = getActivity().getResources().getStringArray(
R.array.website_settings_permission_options);
@@ -91,11 +184,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
} else if (PREF_PROTECTED_MEDIA_IDENTIFIER_PERMISSION.equals(preference.getKey())) {
setUpListPreference(preference, mSite.getProtectedMediaIdentifierPermission());
} else if (PREF_PUSH_NOTIFICATIONS_PERMISSION.equals(preference.getKey())) {
- if (ContentPreferences.pushNotificationsSupported()) {
- setUpListPreference(preference, mSite.getPushNotificationPermission());
- } else {
- getPreferenceScreen().removePreference(preference);
- }
+ setUpListPreference(preference, mSite.getPushNotificationPermission());
} else if (PREF_VOICE_AND_VIDEO_CAPTURE_PERMISSION.equals(preference.getKey())) {
configureVoiceAndVideoPreference(preference);
}
@@ -111,8 +200,6 @@ public void onActivityCreated(Bundle savedInstanceState) {
Preference heading = preferenceScreen.findPreference(PREF_PERMISSIONS);
preferenceScreen.removePreference(heading);
}
-
- super.onActivityCreated(savedInstanceState);
}
private boolean hasUsagePreferences() {

Powered by Google App Engine
This is Rietveld 408576698