Chromium Code Reviews| 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 5c660be98775f72527417ead0ab6daca461a93d8..f24815aaa8383cb26c7fb5531139597d70a511d8 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 |
| @@ -64,6 +64,10 @@ public class SingleWebsitePreferences extends PreferenceFragment |
| public static final String PREF_OS_PERMISSIONS_WARNING_EXTRA = "os_permissions_warning_extra"; |
| public static final String PREF_OS_PERMISSIONS_WARNING_DIVIDER = |
| "os_permissions_warning_divider"; |
| + public static final String PREF_SUBRESOURCE_FILTER_EXTRA_INFO = |
| + "subresource_filter_permission_extra_info"; |
| + public static final String PREF_SUBRESOURCE_FILTER_EXTRA_INFO_DIVIDER = |
| + "subresource_filter_permission_extra_info_divider"; |
| // Actions at the top (if adding new, see hasUsagePreferences below): |
| public static final String PREF_CLEAR_DATA = "clear_data"; |
| // Buttons: |
| @@ -269,6 +273,15 @@ public class SingleWebsitePreferences extends PreferenceFragment |
| private void displaySitePermissions() { |
| addPreferencesFromResource(R.xml.single_website_preferences); |
| + // If the subresource filter is activated, then this site will have resources filtered |
| + // unless there is an explicit permission disallowing the filtering. |
| + // |
| + // This activation is encoded in |subresourceFilterActivated|, which controls how the |
| + // subresource filter list preference behaves. If it is true, there is also an additional |
| + // extra informational banner which shows at the top of the UI. |
| + boolean subresourceFilterActivated = WebsitePreferenceBridge.getSubresourceFilterActivated( |
| + mSite.getAddress().getOrigin()); |
| + |
| Set<String> permissionPreferenceKeys = |
| new HashSet<>(Arrays.asList(PERMISSION_PREFERENCE_KEYS)); |
| int maxPermissionOrder = 0; |
| @@ -313,7 +326,7 @@ public class SingleWebsitePreferences extends PreferenceFragment |
| } else if (PREF_PROTECTED_MEDIA_IDENTIFIER_PERMISSION.equals(preference.getKey())) { |
| setUpListPreference(preference, mSite.getProtectedMediaIdentifierPermission()); |
| } else if (PREF_SUBRESOURCE_FILTER_PERMISSION.equals(preference.getKey())) { |
| - setUpListPreference(preference, mSite.getSubresourceFilterPermission()); |
| + setUpSubresourceFilterPreference(preference, subresourceFilterActivated); |
| } |
| if (permissionPreferenceKeys.contains(preference.getKey())) { |
| @@ -358,6 +371,20 @@ public class SingleWebsitePreferences extends PreferenceFragment |
| } |
| } |
| + // The subresource filter permission includes a header with some additional information, if |
| + // it is being displayed on a site that is activated. |
| + Preference subresourceFilterExtraInfo = |
| + preferenceScreen.findPreference(PREF_SUBRESOURCE_FILTER_EXTRA_INFO); |
| + Preference subresourceFilterExtraInfoDivider = |
| + preferenceScreen.findPreference(PREF_SUBRESOURCE_FILTER_EXTRA_INFO_DIVIDER); |
| + if (getPreferenceScreen().findPreference(PREF_SUBRESOURCE_FILTER_PERMISSION) != null |
| + && subresourceFilterActivated) { |
| + subresourceFilterExtraInfo.setTitle(R.string.subresource_filter_permission_extra_info); |
| + } else { |
| + getPreferenceScreen().removePreference(subresourceFilterExtraInfo); |
| + getPreferenceScreen().removePreference(subresourceFilterExtraInfoDivider); |
| + } |
| + |
| // Remove categories if no sub-items. |
| if (!hasUsagePreferences()) { |
| Preference heading = preferenceScreen.findPreference(PREF_USAGE); |
| @@ -497,6 +524,49 @@ public class SingleWebsitePreferences extends PreferenceFragment |
| } |
| /** |
| + * Updates the subresource filter list preference based on subresource filter activation. This |
| + * has some custom behavior. |
| + * 1. If the site is activated, the permission should show up even if it is set as the default |
|
Finnur
2017/05/24 10:37:22
s/site/filtering/ ?
Charlie Harrison
2017/05/25 15:57:19
Done.
|
| + * (e.g. |preference| is null). |
| + * 2. The BLOCK string is custom. |
| + * @param activated Whether the subresource filter is activated for this site (i.e. whether or |
| + * not the site is a candidate for resource filtering). |
| + */ |
| + private void setUpSubresourceFilterPreference(Preference preference, boolean activated) { |
| + ContentSetting permission = mSite.getSubresourceFilterPermission(); |
| + |
| + // If |permission| is null, there is no explicit (non-default) permission set for this site. |
| + // If the site is activated, we still want to show the permission as BLOCK. |
| + if (permission == null) { |
| + if (activated) { |
| + permission = ContentSetting.BLOCK; |
| + |
| + // Set the subresource filter exception on the associated website. This is necessary |
| + // because we require an exception to be set in order to change content setting |
| + // (see setSubresourceFilterPermission). Otherwise the UI will change but the |
| + // underlying data will remain unchanged. |
| + String origin = mSite.getAddress().getOrigin(); |
| + mSite.setSubresourceFilterException(new ContentSettingException( |
| + ContentSettingsType.CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER, origin, |
| + permission, "")); |
| + } else { |
| + setUpListPreference(preference, null); |
| + return; |
| + } |
| + } |
| + assert permission != null; |
| + setUpListPreference(preference, permission); |
| + |
| + // The subresource filter permission has a custom BLOCK string. |
| + ListPreference listPreference = (ListPreference) preference; |
| + Resources res = getResources(); |
| + listPreference.setEntries( |
| + new String[] {res.getString(R.string.website_settings_permissions_allow), |
| + res.getString(R.string.subresource_filter_permission_block)}); |
| + listPreference.setValueIndex(permission == ContentSetting.ALLOW ? 0 : 1); |
| + } |
| + |
| + /** |
| * Returns true if the current host matches the default search engine host and location for the |
| * default search engine is being granted via x-geo. |
| * @param context The current context. |