Commit 0b108ac1 authored by Christian Dullweber's avatar Christian Dullweber Committed by Commit Bot

Remove ContentSettingExceptionType enum

This enum contains a subset of the values of ContentSettingsType.
As WebsitePermissionFetcher defines which ContentSettingsType are
fetched as ContentSettingsException and which as PermissionInfo, we do
not need this duplicate and the code to convert between types.

Bug: 1103597
Change-Id: I17667e76c5091ed6417795cdba807c78b35a85a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2346425Reviewed-by: default avatarEhimare Okoyomon <eokoyomon@chromium.org>
Reviewed-by: default avatarAndy Paicu <andypaicu@chromium.org>
Commit-Queue: Christian Dullweber <dullweber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798580}
parent 2ecce21d
...@@ -536,20 +536,19 @@ public class WebsitePermissionsFetcherTest { ...@@ -536,20 +536,19 @@ public class WebsitePermissionsFetcherTest {
// Check content setting exception types. // Check content setting exception types.
Assert.assertEquals(Integer.valueOf(ContentSettingValues.DEFAULT), Assert.assertEquals(Integer.valueOf(ContentSettingValues.DEFAULT),
site.getContentSettingPermission(ContentSettingException.Type.COOKIE)); site.getContentSettingPermission(ContentSettingsType.COOKIES));
Assert.assertEquals(Integer.valueOf(ContentSettingValues.DEFAULT), Assert.assertEquals(Integer.valueOf(ContentSettingValues.DEFAULT),
site.getContentSettingPermission(ContentSettingException.Type.POPUP)); site.getContentSettingPermission(ContentSettingsType.POPUPS));
Assert.assertEquals(Integer.valueOf(ContentSettingValues.DEFAULT), Assert.assertEquals(Integer.valueOf(ContentSettingValues.DEFAULT),
site.getContentSettingPermission(ContentSettingException.Type.ADS)); site.getContentSettingPermission(ContentSettingsType.ADS));
Assert.assertEquals(Integer.valueOf(ContentSettingValues.DEFAULT), Assert.assertEquals(Integer.valueOf(ContentSettingValues.DEFAULT),
site.getContentSettingPermission(ContentSettingException.Type.JAVASCRIPT)); site.getContentSettingPermission(ContentSettingsType.JAVASCRIPT));
Assert.assertEquals(Integer.valueOf(ContentSettingValues.DEFAULT), Assert.assertEquals(Integer.valueOf(ContentSettingValues.DEFAULT),
site.getContentSettingPermission(ContentSettingException.Type.SOUND)); site.getContentSettingPermission(ContentSettingsType.SOUND));
Assert.assertEquals(Integer.valueOf(ContentSettingValues.DEFAULT), Assert.assertEquals(Integer.valueOf(ContentSettingValues.DEFAULT),
site.getContentSettingPermission(ContentSettingException.Type.BACKGROUND_SYNC)); site.getContentSettingPermission(ContentSettingsType.BACKGROUND_SYNC));
Assert.assertEquals(Integer.valueOf(ContentSettingValues.DEFAULT), Assert.assertEquals(Integer.valueOf(ContentSettingValues.DEFAULT),
site.getContentSettingPermission( site.getContentSettingPermission(ContentSettingsType.AUTOMATIC_DOWNLOADS));
ContentSettingException.Type.AUTOMATIC_DOWNLOADS));
// Check storage info. // Check storage info.
ArrayList<StorageInfo> storageInfos = new ArrayList<>(site.getStorageInfo()); ArrayList<StorageInfo> storageInfos = new ArrayList<>(site.getStorageInfo());
...@@ -705,26 +704,21 @@ public class WebsitePermissionsFetcherTest { ...@@ -705,26 +704,21 @@ public class WebsitePermissionsFetcherTest {
String googleOrigin = "https://google.com"; String googleOrigin = "https://google.com";
String preferenceSource = "preference"; String preferenceSource = "preference";
ArrayList<Integer> contentSettingExceptionTypes = new ArrayList<>(Arrays.asList( ArrayList<Integer> contentSettingExceptionTypes = new ArrayList<>(
ContentSettingException.Type.ADS, ContentSettingException.Type.AUTOMATIC_DOWNLOADS, Arrays.asList(ContentSettingsType.ADS, ContentSettingsType.AUTOMATIC_DOWNLOADS,
ContentSettingException.Type.BACKGROUND_SYNC, ContentSettingsType.BACKGROUND_SYNC, ContentSettingsType.BLUETOOTH_SCANNING,
ContentSettingException.Type.BLUETOOTH_SCANNING, ContentSettingsType.COOKIES, ContentSettingsType.JAVASCRIPT,
ContentSettingException.Type.COOKIE, ContentSettingException.Type.JAVASCRIPT, ContentSettingsType.POPUPS, ContentSettingsType.SOUND));
ContentSettingException.Type.POPUP, ContentSettingException.Type.SOUND));
Assert.assertEquals(8, ContentSettingException.Type.NUM_ENTRIES);
for (@ContentSettingsType int type : contentSettingExceptionTypes) { for (@ContentSettingsType int type : contentSettingExceptionTypes) {
@ContentSettingsType
int contentSettingsType = ContentSettingException.getContentSettingsType(type);
{ {
ContentSettingException fakeContentSettingException = ContentSettingException fakeContentSettingException = new ContentSettingException(
new ContentSettingException(contentSettingsType, googleOrigin, type, googleOrigin, ContentSettingValues.DEFAULT, preferenceSource);
ContentSettingValues.DEFAULT, preferenceSource);
websitePreferenceBridge.addContentSettingException(fakeContentSettingException); websitePreferenceBridge.addContentSettingException(fakeContentSettingException);
fetcher.fetchPreferencesForCategory( fetcher.fetchPreferencesForCategory(
SiteSettingsCategory.createFromContentSettingsType( SiteSettingsCategory.createFromContentSettingsType(
UNUSED_BROWSER_CONTEXT_HANDLE, contentSettingsType), UNUSED_BROWSER_CONTEXT_HANDLE, type),
(sites) -> { (sites) -> {
Assert.assertEquals(1, sites.size()); Assert.assertEquals(1, sites.size());
...@@ -736,14 +730,13 @@ public class WebsitePermissionsFetcherTest { ...@@ -736,14 +730,13 @@ public class WebsitePermissionsFetcherTest {
// Make sure that the content setting value is updated. // Make sure that the content setting value is updated.
{ {
ContentSettingException fakeContentSettingException = ContentSettingException fakeContentSettingException = new ContentSettingException(
new ContentSettingException(contentSettingsType, googleOrigin, type, googleOrigin, ContentSettingValues.BLOCK, preferenceSource);
ContentSettingValues.BLOCK, preferenceSource);
websitePreferenceBridge.addContentSettingException(fakeContentSettingException); websitePreferenceBridge.addContentSettingException(fakeContentSettingException);
fetcher.fetchPreferencesForCategory( fetcher.fetchPreferencesForCategory(
SiteSettingsCategory.createFromContentSettingsType( SiteSettingsCategory.createFromContentSettingsType(
UNUSED_BROWSER_CONTEXT_HANDLE, contentSettingsType), UNUSED_BROWSER_CONTEXT_HANDLE, type),
(sites) -> { (sites) -> {
Assert.assertEquals(1, sites.size()); Assert.assertEquals(1, sites.size());
...@@ -766,11 +759,8 @@ public class WebsitePermissionsFetcherTest { ...@@ -766,11 +759,8 @@ public class WebsitePermissionsFetcherTest {
String mainSite = "https://a.com"; String mainSite = "https://a.com";
String thirdPartySite = "https://b.com"; String thirdPartySite = "https://b.com";
String preferenceSource = "preference"; String preferenceSource = "preference";
@ContentSettingException.Type
int contentSettingExceptionType = ContentSettingException.Type.COOKIE;
@ContentSettingsType @ContentSettingsType
int contentSettingsType = int contentSettingsType = ContentSettingsType.COOKIES;
ContentSettingException.getContentSettingsType(contentSettingExceptionType);
// Test the advanced exception combinations of: // Test the advanced exception combinations of:
// b.com on a.com // b.com on a.com
...@@ -797,7 +787,7 @@ public class WebsitePermissionsFetcherTest { ...@@ -797,7 +787,7 @@ public class WebsitePermissionsFetcherTest {
Website site = sites.iterator().next(); Website site = sites.iterator().next();
assertContentSettingExceptionEquals(fakeContentSettingException, assertContentSettingExceptionEquals(fakeContentSettingException,
site.getContentSettingException(contentSettingExceptionType)); site.getContentSettingException(contentSettingsType));
}); });
} }
...@@ -816,7 +806,7 @@ public class WebsitePermissionsFetcherTest { ...@@ -816,7 +806,7 @@ public class WebsitePermissionsFetcherTest {
Website site = sites.iterator().next(); Website site = sites.iterator().next();
assertContentSettingExceptionEquals(fakeContentSettingException, assertContentSettingExceptionEquals(fakeContentSettingException,
site.getContentSettingException(contentSettingExceptionType)); site.getContentSettingException(contentSettingsType));
}); });
} }
} }
......
...@@ -73,8 +73,9 @@ public class SingleWebsiteSettingsTest { ...@@ -73,8 +73,9 @@ public class SingleWebsiteSettingsTest {
@Test @Test
@SmallTest @SmallTest
public void testCorrectMapOfPreferenceKeyToContentSettingsType() { public void testCorrectMapOfPreferenceKeyToContentSettingsType() {
SingleWebsiteSettings settings = new SingleWebsiteSettings();
for (String key : SingleWebsiteSettings.PERMISSION_PREFERENCE_KEYS) { for (String key : SingleWebsiteSettings.PERMISSION_PREFERENCE_KEYS) {
Assert.assertEquals(SingleWebsiteSettings.getContentSettingsTypeFromPreferenceKey(key), Assert.assertEquals(settings.getContentSettingsTypeFromPreferenceKey(key),
getCorrectContentSettingsTypeForPreferenceKey(key)); getCorrectContentSettingsTypeForPreferenceKey(key));
} }
} }
......
...@@ -6,42 +6,17 @@ package org.chromium.components.browser_ui.site_settings; ...@@ -6,42 +6,17 @@ package org.chromium.components.browser_ui.site_settings;
import static org.chromium.components.browser_ui.site_settings.WebsitePreferenceBridge.SITE_WILDCARD; import static org.chromium.components.browser_ui.site_settings.WebsitePreferenceBridge.SITE_WILDCARD;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.chromium.components.content_settings.ContentSettingValues; import org.chromium.components.content_settings.ContentSettingValues;
import org.chromium.components.content_settings.ContentSettingsType;
import org.chromium.components.embedder_support.browser_context.BrowserContextHandle; import org.chromium.components.embedder_support.browser_context.BrowserContextHandle;
import java.io.Serializable; import java.io.Serializable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/** /**
* Exception information for a given origin. * Exception information for a given origin.
*/ */
public class ContentSettingException implements Serializable { public class ContentSettingException implements Serializable {
@IntDef({Type.ADS, Type.AUTOMATIC_DOWNLOADS, Type.BACKGROUND_SYNC, Type.BLUETOOTH_SCANNING,
Type.COOKIE, Type.JAVASCRIPT, Type.POPUP, Type.SOUND})
@Retention(RetentionPolicy.SOURCE)
public @interface Type {
// Values used to address array index - should be enumerated from 0 and can't have gaps.
// All updates here must also be reflected in {@link #getContentSettingsType(int)
// getContentSettingsType} and {@link SingleWebsiteSettings.PERMISSION_PREFERENCE_KEYS}.
int ADS = 0;
int AUTOMATIC_DOWNLOADS = 1;
int BACKGROUND_SYNC = 2;
int BLUETOOTH_SCANNING = 3;
int COOKIE = 4;
int JAVASCRIPT = 5;
int POPUP = 6;
int SOUND = 7;
/**
* Number of handled exceptions used for calculating array sizes.
*/
int NUM_ENTRIES = 8;
}
private final int mContentSettingType; private final int mContentSettingType;
private final String mPrimaryPattern; private final String mPrimaryPattern;
private final String mSecondaryPattern; private final String mSecondaryPattern;
...@@ -97,33 +72,9 @@ public class ContentSettingException implements Serializable { ...@@ -97,33 +72,9 @@ public class ContentSettingException implements Serializable {
/** /**
* Sets the content setting value for this exception. * Sets the content setting value for this exception.
*/ */
public void setContentSetting(BrowserContextHandle browserContextHandle, public void setContentSetting(
@ContentSettingValues @Nullable Integer value) { BrowserContextHandle browserContextHandle, @ContentSettingValues int value) {
WebsitePreferenceBridge.setContentSettingForPattern(browserContextHandle, WebsitePreferenceBridge.setContentSettingForPattern(browserContextHandle,
mContentSettingType, mPrimaryPattern, mSecondaryPattern, value); mContentSettingType, mPrimaryPattern, mSecondaryPattern, value);
} }
public static @ContentSettingsType int getContentSettingsType(@Type int type) {
switch (type) {
case Type.ADS:
return ContentSettingsType.ADS;
case Type.AUTOMATIC_DOWNLOADS:
return ContentSettingsType.AUTOMATIC_DOWNLOADS;
case Type.BACKGROUND_SYNC:
return ContentSettingsType.BACKGROUND_SYNC;
case Type.BLUETOOTH_SCANNING:
return ContentSettingsType.BLUETOOTH_SCANNING;
case Type.COOKIE:
return ContentSettingsType.COOKIES;
case Type.JAVASCRIPT:
return ContentSettingsType.JAVASCRIPT;
case Type.POPUP:
return ContentSettingsType.POPUPS;
case Type.SOUND:
return ContentSettingsType.SOUND;
default:
assert false;
return ContentSettingsType.DEFAULT;
}
}
} }
...@@ -210,13 +210,11 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment ...@@ -210,13 +210,11 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment
getSiteSettingsClient().getBrowserContextHandle(); getSiteSettingsClient().getBrowserContextHandle();
for (@SiteSettingsCategory.Type int i = 0; i < SiteSettingsCategory.Type.NUM_ENTRIES; i++) { for (@SiteSettingsCategory.Type int i = 0; i < SiteSettingsCategory.Type.NUM_ENTRIES; i++) {
if (!mCategory.showSites(i)) continue; if (!mCategory.showSites(i)) continue;
for (@ContentSettingException.Type int j = 0; @ContentSettingValues
j < ContentSettingException.Type.NUM_ENTRIES; j++) { Integer contentSettingPermission = website.site().getContentSettingPermission(
if (ContentSettingException.getContentSettingsType(j) SiteSettingsCategory.contentSettingsType(i));
== SiteSettingsCategory.contentSettingsType(i)) { if (contentSettingPermission != null) {
return ContentSettingValues.BLOCK return ContentSettingValues.BLOCK == contentSettingPermission;
== website.site().getContentSettingPermission(j);
}
} }
for (@PermissionInfo.Type int j = 0; j < PermissionInfo.Type.NUM_ENTRIES; j++) { for (@PermissionInfo.Type int j = 0; j < PermissionInfo.Type.NUM_ENTRIES; j++) {
if (PermissionInfo.getContentSettingsType(j) if (PermissionInfo.getContentSettingsType(j)
......
...@@ -35,10 +35,9 @@ import org.chromium.components.content_settings.ContentSettingsType; ...@@ -35,10 +35,9 @@ import org.chromium.components.content_settings.ContentSettingsType;
import org.chromium.components.embedder_support.browser_context.BrowserContextHandle; import org.chromium.components.embedder_support.browser_context.BrowserContextHandle;
import org.chromium.components.embedder_support.util.Origin; import org.chromium.components.embedder_support.util.Origin;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashMap;
import java.util.Set; import java.util.Map;
/** /**
* Shows the permissions and other settings for a particular website. * Shows the permissions and other settings for a particular website.
...@@ -71,19 +70,38 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -71,19 +70,38 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
// Buttons: // Buttons:
public static final String PREF_RESET_SITE = "reset_site_button"; public static final String PREF_RESET_SITE = "reset_site_button";
/**
* Currently only implemented for ContentSettingsType that have a ContentSettingsException.
* TODO(crbug.com/1103597): Replace PermissionInfo.Type enum with ContentSettingsType.
* @param type ContentSettingsType
* @return The preference key of this type
*/
private static @Nullable String getPreferenceKey(@ContentSettingsType int type) {
switch (type) {
case ContentSettingsType.ADS:
return "ads_permission_list";
case ContentSettingsType.AUTOMATIC_DOWNLOADS:
return "automatic_downloads_permission_list";
case ContentSettingsType.BACKGROUND_SYNC:
return "background_sync_permission_list";
case ContentSettingsType.BLUETOOTH_SCANNING:
return "bluetooth_scanning_permission_list";
case ContentSettingsType.COOKIES:
return "cookies_permission_list";
case ContentSettingsType.JAVASCRIPT:
return "javascript_permission_list";
case ContentSettingsType.POPUPS:
return "popup_permission_list";
case ContentSettingsType.SOUND:
return "sound_permission_list";
default:
return null;
}
}
// Website permissions (if adding new, see hasPermissionsPreferences and resetSite below) // Website permissions (if adding new, see hasPermissionsPreferences and resetSite below)
// All permissions from the permissions preference category must be listed here. // All permissions from the permissions preference category must be listed here.
public static final String[] PERMISSION_PREFERENCE_KEYS = { public static final String[] PERMISSION_PREFERENCE_KEYS = {
// Permission keys mapped for next {@link ContentSettingException.Type} values.
"ads_permission_list", // ContentSettingException.Type.ADS
"automatic_downloads_permission_list",
// ContentSettingException.Type.AUTOMATIC_DOWNLOADS
"background_sync_permission_list", // ContentSettingException.Type.BACKGROUND_SYNC
"bluetooth_scanning_permission_list", // ContentSettingException.Type.BLUETOOTH_SCANNING
"cookies_permission_list", // ContentSettingException.Type.COOKIE
"javascript_permission_list", // ContentSettingException.Type.JAVASCRIPT
"popup_permission_list", // ContentSettingException.Type.POPUP
"sound_permission_list", // ContentSettingException.Type.SOUND
// Permission keys mapped for next {@link PermissionInfo.Type} values. // Permission keys mapped for next {@link PermissionInfo.Type} values.
"ar_permission_list", // PermissionInfo.Type.AUGMENTED_REALITY "ar_permission_list", // PermissionInfo.Type.AUGMENTED_REALITY
"camera_permission_list", // PermissionInfo.Type.CAMERA "camera_permission_list", // PermissionInfo.Type.CAMERA
...@@ -123,6 +141,8 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -123,6 +141,8 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
// The Preference key for chooser object permissions. // The Preference key for chooser object permissions.
private static final String CHOOSER_PERMISSION_PREFERENCE_KEY = "chooser_permission_list"; private static final String CHOOSER_PERMISSION_PREFERENCE_KEY = "chooser_permission_list";
// The maximum order of a permission preference.
private int mMaxPermissionOrder;
// The number of user and policy chosen object permissions displayed. // The number of user and policy chosen object permissions displayed.
private int mObjectUserPermissionCount; private int mObjectUserPermissionCount;
private int mObjectPolicyPermissionCount; private int mObjectPolicyPermissionCount;
...@@ -131,6 +151,9 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -131,6 +151,9 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
// revocation within the Android system permission activity. // revocation within the Android system permission activity.
private @ContentSettingValues @Nullable Integer mPreviousNotificationPermission; private @ContentSettingValues @Nullable Integer mPreviousNotificationPermission;
// Map from preference key to ContentSettingsType.
private Map<String, Integer> mPreferenceMap;
private class SingleWebsitePermissionsPopulator private class SingleWebsitePermissionsPopulator
implements WebsitePermissionsFetcher.WebsitePermissionsCallback { implements WebsitePermissionsFetcher.WebsitePermissionsCallback {
private final WebsiteAddress mSiteAddress; private final WebsiteAddress mSiteAddress;
...@@ -260,11 +283,11 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -260,11 +283,11 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
// This loop looks expensive, but the amount of data is likely to be relatively small // This loop looks expensive, but the amount of data is likely to be relatively small
// because most sites have very few permissions. // because most sites have very few permissions.
for (Website other : websites) { for (Website other : websites) {
if (merged.getContentSettingException(ContentSettingException.Type.ADS) == null if (merged.getContentSettingException(ContentSettingsType.ADS) == null
&& other.getContentSettingException(ContentSettingException.Type.ADS) != null && other.getContentSettingException(ContentSettingsType.ADS) != null
&& other.compareByAddressTo(merged) == 0) { && other.compareByAddressTo(merged) == 0) {
merged.setContentSettingException(ContentSettingException.Type.ADS, merged.setContentSettingException(ContentSettingsType.ADS,
other.getContentSettingException(ContentSettingException.Type.ADS)); other.getContentSettingException(ContentSettingsType.ADS));
} }
for (@PermissionInfo.Type int type = 0; type < PermissionInfo.Type.NUM_ENTRIES; for (@PermissionInfo.Type int type = 0; type < PermissionInfo.Type.NUM_ENTRIES;
type++) { type++) {
...@@ -291,15 +314,13 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -291,15 +314,13 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
} }
} }
if (host.equals(other.getAddress().getHost())) { if (host.equals(other.getAddress().getHost())) {
for (@ContentSettingException.Type int type = 0; for (ContentSettingException exception : other.getContentSettingExceptions()) {
type < ContentSettingException.Type.NUM_ENTRIES; type++) { int type = exception.getContentSettingType();
if (type == ContentSettingException.Type.ADS) { if (type == ContentSettingsType.ADS) {
continue; continue;
} }
if (merged.getContentSettingException(type) == null if (merged.getContentSettingException(type) == null) {
&& other.getContentSettingException(type) != null) { merged.setContentSettingException(type, exception);
merged.setContentSettingException(
type, other.getContentSettingException(type));
} }
} }
} }
...@@ -329,22 +350,19 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -329,22 +350,19 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
} }
SettingsUtils.addPreferencesFromResource(this, R.xml.single_website_preferences); SettingsUtils.addPreferencesFromResource(this, R.xml.single_website_preferences);
Set<String> permissionPreferenceKeys = mMaxPermissionOrder = 0;
new HashSet<>(Arrays.asList(PERMISSION_PREFERENCE_KEYS));
int maxPermissionOrder = 0;
PreferenceScreen preferenceScreen = getPreferenceScreen(); PreferenceScreen preferenceScreen = getPreferenceScreen();
// Iterate over preferences in reverse order because some preferences will be removed during // Iterate over preferences in reverse order because some preferences will be removed during
// this setup, causing indices of later preferences to change. // this setup, causing indices of later preferences to change.
for (int i = preferenceScreen.getPreferenceCount() - 1; i >= 0; i--) { for (int i = preferenceScreen.getPreferenceCount() - 1; i >= 0; i--) {
Preference preference = preferenceScreen.getPreference(i); Preference preference = preferenceScreen.getPreference(i);
setUpPreference(preference); setUpPreference(preference);
// Keep track of the maximum 'order' value of permission preferences, to allow correct if (getContentSettingsTypeFromPreferenceKey(preference.getKey())
// positioning of subsequent permission preferences. != ContentSettingsType.DEFAULT) {
if (permissionPreferenceKeys.contains(preference.getKey())) { mMaxPermissionOrder = Math.max(mMaxPermissionOrder, preference.getOrder());
maxPermissionOrder = Math.max(maxPermissionOrder, preference.getOrder());
} }
} }
setUpChosenObjectPreferences(maxPermissionOrder); setUpChosenObjectPreferences(mMaxPermissionOrder);
setUpOsWarningPreferences(); setUpOsWarningPreferences();
setUpAdsInformationalBanner(); setUpAdsInformationalBanner();
...@@ -375,29 +393,9 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -375,29 +393,9 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
} else if (PREF_RESET_SITE.equals(preference.getKey())) { } else if (PREF_RESET_SITE.equals(preference.getKey())) {
setupResetSitePreference(preference); setupResetSitePreference(preference);
} else { } else {
assert PERMISSION_PREFERENCE_KEYS.length assert PERMISSION_PREFERENCE_KEYS.length == PermissionInfo.Type.NUM_ENTRIES;
== ContentSettingException.Type.NUM_ENTRIES + PermissionInfo.Type.NUM_ENTRIES;
for (@ContentSettingException.Type int i = 0;
i < ContentSettingException.Type.NUM_ENTRIES; i++) {
if (!PERMISSION_PREFERENCE_KEYS[i].equals(preference.getKey())) {
continue;
}
if (i == ContentSettingException.Type.ADS) {
setUpAdsPreference(preference);
} else if (i == ContentSettingException.Type.SOUND) {
setUpSoundPreference(preference);
} else if (i == ContentSettingException.Type.JAVASCRIPT) {
setUpJavascriptPreference(preference);
} else {
// ContentSettingException can not be embargoed.
setUpListPreference(preference, mSite.getContentSettingPermission(i),
false /* isEmbargoed */);
}
return;
}
for (@PermissionInfo.Type int i = 0; i < PermissionInfo.Type.NUM_ENTRIES; i++) { for (@PermissionInfo.Type int i = 0; i < PermissionInfo.Type.NUM_ENTRIES; i++) {
if (!PERMISSION_PREFERENCE_KEYS[i + ContentSettingException.Type.NUM_ENTRIES] if (!PERMISSION_PREFERENCE_KEYS[i].equals(preference.getKey())) {
.equals(preference.getKey())) {
continue; continue;
} }
if (i == PermissionInfo.Type.GEOLOCATION) { if (i == PermissionInfo.Type.GEOLOCATION) {
...@@ -413,6 +411,22 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -413,6 +411,22 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
} }
return; return;
} }
@ContentSettingsType
int type = getContentSettingsTypeFromPreferenceKey(preference.getKey());
if (type != ContentSettingsType.DEFAULT) {
if (type == ContentSettingsType.ADS) {
setUpAdsPreference(preference);
} else if (type == ContentSettingsType.SOUND) {
setUpSoundPreference(preference);
} else if (type == ContentSettingsType.JAVASCRIPT) {
setUpJavascriptPreference(preference);
} else {
// ContentSettingException can not be embargoed.
setUpListPreference(preference, mSite.getContentSettingPermission(type),
false /* isEmbargoed */);
}
return;
}
} }
} }
...@@ -613,8 +627,7 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -613,8 +627,7 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
// User has navigated back from system channel settings on O+. Ensure notification // User has navigated back from system channel settings on O+. Ensure notification
// preference is up to date, since they might have toggled it from channel settings. // preference is up to date, since they might have toggled it from channel settings.
Preference notificationsPreference = Preference notificationsPreference =
findPreference(PERMISSION_PREFERENCE_KEYS[PermissionInfo.Type.NOTIFICATION findPreference(PERMISSION_PREFERENCE_KEYS[PermissionInfo.Type.NOTIFICATION]);
+ ContentSettingException.Type.NUM_ENTRIES]);
if (notificationsPreference != null) { if (notificationsPreference != null) {
setUpNotificationsPreference(notificationsPreference, false /* isEmbargoed */); setUpNotificationsPreference(notificationsPreference, false /* isEmbargoed */);
} }
...@@ -722,8 +735,7 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -722,8 +735,7 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
&& WebsitePreferenceBridge.getAdBlockingActivated( && WebsitePreferenceBridge.getAdBlockingActivated(
getSiteSettingsClient().getBrowserContextHandle(), getSiteSettingsClient().getBrowserContextHandle(),
mSite.getAddress().getOrigin()) mSite.getAddress().getOrigin())
&& findPreference(PERMISSION_PREFERENCE_KEYS[ContentSettingException.Type.ADS]) && findPreference(getPreferenceKey(ContentSettingsType.ADS)) != null;
!= null;
if (!adBlockingActivated) { if (!adBlockingActivated) {
removePreferenceSafely(PREF_INTRUSIVE_ADS_INFO); removePreferenceSafely(PREF_INTRUSIVE_ADS_INFO);
...@@ -767,9 +779,8 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -767,9 +779,8 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
for (int i = 0; i < PermissionInfo.Type.NUM_ENTRIES; i++) { for (int i = 0; i < PermissionInfo.Type.NUM_ENTRIES; i++) {
if (PermissionInfo.getContentSettingsType(i) if (PermissionInfo.getContentSettingsType(i)
== SiteSettingsCategory.contentSettingsType(type)) { == SiteSettingsCategory.contentSettingsType(type)) {
return mSite.getPermission(browserContextHandle, i) == null return mSite.getPermission(browserContextHandle, i) != null
? false && SiteSettingsCategory.createFromType(browserContextHandle, type)
: SiteSettingsCategory.createFromType(browserContextHandle, type)
.showPermissionBlockedMessage(getActivity()); .showPermissionBlockedMessage(getActivity());
} }
} }
...@@ -784,9 +795,7 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -784,9 +795,7 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
private boolean hasPermissionsPreferences() { private boolean hasPermissionsPreferences() {
if (mObjectUserPermissionCount > 0 || mObjectPolicyPermissionCount > 0) return true; if (mObjectUserPermissionCount > 0 || mObjectPolicyPermissionCount > 0) return true;
for (String key : PERMISSION_PREFERENCE_KEYS) { if (mMaxPermissionOrder > 0) return true;
if (findPreference(key) != null) return true;
}
return false; return false;
} }
...@@ -868,8 +877,7 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -868,8 +877,7 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
private void setUpSoundPreference(Preference preference) { private void setUpSoundPreference(Preference preference) {
@ContentSettingValues @ContentSettingValues
@Nullable @Nullable
Integer currentValue = Integer currentValue = mSite.getContentSettingPermission(ContentSettingsType.SOUND);
mSite.getContentSettingPermission(ContentSettingException.Type.SOUND);
// In order to always show the sound permission, set it up with the default value if it // In order to always show the sound permission, set it up with the default value if it
// doesn't have a current value. // doesn't have a current value.
if (currentValue == null) { if (currentValue == null) {
...@@ -886,8 +894,7 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -886,8 +894,7 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
private void setUpJavascriptPreference(Preference preference) { private void setUpJavascriptPreference(Preference preference) {
@ContentSettingValues @ContentSettingValues
@Nullable @Nullable
Integer currentValue = Integer currentValue = mSite.getContentSettingPermission(ContentSettingsType.JAVASCRIPT);
mSite.getContentSettingPermission(ContentSettingException.Type.JAVASCRIPT);
// If Javascript is blocked by default, then always show a Javascript permission. // If Javascript is blocked by default, then always show a Javascript permission.
// To do this, set it to the default value (blocked). // To do this, set it to the default value (blocked).
if ((currentValue == null) if ((currentValue == null)
...@@ -919,7 +926,7 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -919,7 +926,7 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
getSiteSettingsClient().getBrowserContextHandle(), mSite.getAddress().getOrigin()); getSiteSettingsClient().getBrowserContextHandle(), mSite.getAddress().getOrigin());
@ContentSettingValues @ContentSettingValues
@Nullable @Nullable
Integer permission = mSite.getContentSettingPermission(ContentSettingException.Type.ADS); Integer permission = mSite.getContentSettingPermission(ContentSettingsType.ADS);
// If |permission| is null, there is no explicit (non-default) permission set for this site. // If |permission| is null, there is no explicit (non-default) permission set for this site.
// If the site is not considered a candidate for blocking, do the standard thing and remove // If the site is not considered a candidate for blocking, do the standard thing and remove
...@@ -972,16 +979,23 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -972,16 +979,23 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
}); });
} }
public static int getContentSettingsTypeFromPreferenceKey(String preferenceKey) { public @ContentSettingsType int getContentSettingsTypeFromPreferenceKey(String preferenceKey) {
if (mPreferenceMap == null) {
mPreferenceMap = new HashMap<>();
for (int i = 0; i < PERMISSION_PREFERENCE_KEYS.length; i++) { for (int i = 0; i < PERMISSION_PREFERENCE_KEYS.length; i++) {
if (PERMISSION_PREFERENCE_KEYS[i].equals(preferenceKey)) { mPreferenceMap.put(
return i < ContentSettingException.Type.NUM_ENTRIES PERMISSION_PREFERENCE_KEYS[i], PermissionInfo.getContentSettingsType(i));
? ContentSettingException.getContentSettingsType(i) }
: PermissionInfo.getContentSettingsType( for (@ContentSettingsType int type = 0; type < ContentSettingsType.NUM_TYPES; type++) {
i - ContentSettingException.Type.NUM_ENTRIES); String key = getPreferenceKey(type);
if (key != null) {
mPreferenceMap.put(key, type);
} }
} }
return 0; }
Integer type = mPreferenceMap.get(preferenceKey);
if (type != null) return type;
return ContentSettingsType.DEFAULT;
} }
private void popBackIfNoSettings() { private void popBackIfNoSettings() {
...@@ -1001,16 +1015,16 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -1001,16 +1015,16 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
getSiteSettingsClient().getBrowserContextHandle(); getSiteSettingsClient().getBrowserContextHandle();
for (int i = 0; i < PERMISSION_PREFERENCE_KEYS.length; i++) { for (int i = 0; i < PERMISSION_PREFERENCE_KEYS.length; i++) {
if (PERMISSION_PREFERENCE_KEYS[i].equals(preference.getKey())) { if (PERMISSION_PREFERENCE_KEYS[i].equals(preference.getKey())) {
if (i < ContentSettingException.Type.NUM_ENTRIES) { mSite.setPermission(browserContextHandle, i, permission);
mSite.setContentSettingPermission(
getSiteSettingsClient().getBrowserContextHandle(), i, permission);
} else {
mSite.setPermission(browserContextHandle,
i - ContentSettingException.Type.NUM_ENTRIES, permission);
}
return true; return true;
} }
} }
int type = getContentSettingsTypeFromPreferenceKey(preference.getKey());
if (type != ContentSettingsType.DEFAULT) {
mSite.setContentSettingPermission(
getSiteSettingsClient().getBrowserContextHandle(), type, permission);
}
return true; return true;
} }
...@@ -1045,6 +1059,12 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -1045,6 +1059,12 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
for (String key : PERMISSION_PREFERENCE_KEYS) { for (String key : PERMISSION_PREFERENCE_KEYS) {
removePreferenceSafely(key); removePreferenceSafely(key);
} }
for (@ContentSettingsType int type = 0; type < ContentSettingsType.NUM_TYPES; type++) {
String key = getPreferenceKey(type);
if (key != null) {
removePreferenceSafely(key);
}
}
// Clearing stored data implies popping back to parent menu if there is nothing left to // Clearing stored data implies popping back to parent menu if there is nothing left to
// show. Therefore, we only need to explicitly close the activity if there's no stored data // show. Therefore, we only need to explicitly close the activity if there's no stored data
......
...@@ -24,10 +24,9 @@ public class SiteDataCleaner { ...@@ -24,10 +24,9 @@ public class SiteDataCleaner {
WebsitePreferenceBridgeJni.get().clearMediaLicenses(browserContextHandle, origin); WebsitePreferenceBridgeJni.get().clearMediaLicenses(browserContextHandle, origin);
// Clear the permissions. // Clear the permissions.
for (@ContentSettingException.Type int type = 0; for (ContentSettingException exception : site.getContentSettingExceptions()) {
type < ContentSettingException.Type.NUM_ENTRIES; type++) { site.setContentSettingPermission(browserContextHandle,
site.setContentSettingPermission( exception.getContentSettingType(), ContentSettingValues.DEFAULT);
browserContextHandle, type, ContentSettingValues.DEFAULT);
} }
for (@PermissionInfo.Type int type = 0; type < PermissionInfo.Type.NUM_ENTRIES; type++) { for (@PermissionInfo.Type int type = 0; type < PermissionInfo.Type.NUM_ENTRIES; type++) {
site.setPermission(browserContextHandle, type, ContentSettingValues.DEFAULT); site.setPermission(browserContextHandle, type, ContentSettingValues.DEFAULT);
......
...@@ -17,34 +17,30 @@ import org.chromium.components.embedder_support.browser_context.BrowserContextHa ...@@ -17,34 +17,30 @@ import org.chromium.components.embedder_support.browser_context.BrowserContextHa
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Website is a class for storing information about a website and its associated permissions. * Website is a class for storing information about a website and its associated permissions.
*/ */
public class Website implements Serializable { public final class Website implements Serializable {
static final int INVALID_CAMERA_OR_MICROPHONE_ACCESS = 0;
static final int CAMERA_ACCESS_ALLOWED = 1;
static final int MICROPHONE_AND_CAMERA_ACCESS_ALLOWED = 2;
static final int MICROPHONE_ACCESS_ALLOWED = 3;
static final int CAMERA_ACCESS_DENIED = 4;
static final int MICROPHONE_AND_CAMERA_ACCESS_DENIED = 5;
static final int MICROPHONE_ACCESS_DENIED = 6;
private final WebsiteAddress mOrigin; private final WebsiteAddress mOrigin;
private final WebsiteAddress mEmbedder; private final WebsiteAddress mEmbedder;
/** /**
* Indexed by ContentSettingException.Type. * Indexed by ContentSettingsType.
*/ */
private ContentSettingException mContentSettingException[]; private Map<Integer, ContentSettingException> mContentSettingExceptions = new HashMap<>();
/** /**
* Indexed by PermissionInfo.Type. * Indexed by PermissionInfo.Type.
*/ */
private PermissionInfo[] mPermissionInfo; private PermissionInfo[] mPermissionInfo;
private LocalStorageInfo mLocalStorageInfo; private LocalStorageInfo mLocalStorageInfo;
private final List<StorageInfo> mStorageInfo = new ArrayList<StorageInfo>(); private final List<StorageInfo> mStorageInfo = new ArrayList<>();
private int mStorageInfoCallbacksLeft; private int mStorageInfoCallbacksLeft;
// The collection of chooser-based permissions (e.g. USB device access) granted to this site. // The collection of chooser-based permissions (e.g. USB device access) granted to this site.
...@@ -56,8 +52,6 @@ public class Website implements Serializable { ...@@ -56,8 +52,6 @@ public class Website implements Serializable {
mOrigin = origin; mOrigin = origin;
mEmbedder = embedder; mEmbedder = embedder;
mPermissionInfo = new PermissionInfo[PermissionInfo.Type.NUM_ENTRIES]; mPermissionInfo = new PermissionInfo[PermissionInfo.Type.NUM_ENTRIES];
mContentSettingException =
new ContentSettingException[ContentSettingException.Type.NUM_ENTRIES];
} }
public WebsiteAddress getAddress() { public WebsiteAddress getAddress() {
...@@ -164,29 +158,34 @@ public class Website implements Serializable { ...@@ -164,29 +158,34 @@ public class Website implements Serializable {
} }
} }
public Collection<ContentSettingException> getContentSettingExceptions() {
return mContentSettingExceptions.values();
}
/** /**
* Returns the exception info for this Website for specified type. * Returns the exception info for this Website for specified type.
*/ */
public ContentSettingException getContentSettingException( public ContentSettingException getContentSettingException(@ContentSettingsType int type) {
@ContentSettingException.Type int type) { return mContentSettingExceptions.get(type);
return mContentSettingException[type];
} }
/** /**
* Sets the exception info for this Website for specified type. * Sets the exception info for this Website for specified type.
*/ */
public void setContentSettingException( public void setContentSettingException(
@ContentSettingException.Type int type, ContentSettingException exception) { @ContentSettingsType int type, ContentSettingException exception) {
mContentSettingException[type] = exception; mContentSettingExceptions.put(type, exception);
} }
/** /**
* Returns what ContentSettingException governs the setting of specified type. * Returns what ContentSettingException governs the setting of specified type.
*/ */
public @ContentSettingValues @Nullable Integer getContentSettingPermission( public @ContentSettingValues @Nullable Integer getContentSettingPermission(
@ContentSettingException.Type int type) { @ContentSettingsType int type) {
return mContentSettingException[type] != null // TODO(crbug.com/1103597): Merge with getPermission() when both are keyed by
? mContentSettingException[type].getContentSetting() // ContentSettingsType.
return getContentSettingException(type) != null
? getContentSettingException(type).getContentSetting()
: null; : null;
} }
...@@ -194,24 +193,28 @@ public class Website implements Serializable { ...@@ -194,24 +193,28 @@ public class Website implements Serializable {
* Sets the permission. * Sets the permission.
*/ */
public void setContentSettingPermission(BrowserContextHandle browserContextHandle, public void setContentSettingPermission(BrowserContextHandle browserContextHandle,
@ContentSettingException.Type int type, @ContentSettingValues int value) { @ContentSettingsType int type, @ContentSettingValues int value) {
if (type == ContentSettingException.Type.ADS) { // TODO(crbug.com/1103597): Merge with setPermission() when both are keyed by
// ContentSettingsType.
ContentSettingException exception = getContentSettingException(type);
if (type == ContentSettingsType.ADS) {
// It is possible to set the permission without having an existing exception, // It is possible to set the permission without having an existing exception,
// because we can show the BLOCK state even when this permission is set to the // because we can show the BLOCK state even when this permission is set to the
// default. In that case, just set an exception now to BLOCK to enable changing the // default. In that case, just set an exception now to BLOCK to enable changing the
// permission. // permission.
if (mContentSettingException[type] == null) { if (exception == null) {
mContentSettingException[type] = exception = new ContentSettingException(ContentSettingsType.ADS,
new ContentSettingException(ContentSettingsType.ADS,
getAddress().getOrigin(), ContentSettingValues.BLOCK, ""); getAddress().getOrigin(), ContentSettingValues.BLOCK, "");
setContentSettingException(type, exception);
} }
} else if (type == ContentSettingException.Type.JAVASCRIPT) { } else if (type == ContentSettingsType.JAVASCRIPT) {
// It is possible to set the permission without having an existing exception, // It is possible to set the permission without having an existing exception,
// because we show the javascript permission in Site Settings if javascript // because we show the javascript permission in Site Settings if javascript
// is blocked by default. // is blocked by default.
if (mContentSettingException[type] == null) { if (exception == null) {
mContentSettingException[type] = new ContentSettingException( exception = new ContentSettingException(
ContentSettingsType.JAVASCRIPT, getAddress().getHost(), value, ""); ContentSettingsType.JAVASCRIPT, getAddress().getHost(), value, "");
setContentSettingException(type, exception);
} }
// It's possible for either action to be emitted. This code path is hit // It's possible for either action to be emitted. This code path is hit
// regardless of whether there was an existing permission or not. // regardless of whether there was an existing permission or not.
...@@ -220,12 +223,13 @@ public class Website implements Serializable { ...@@ -220,12 +223,13 @@ public class Website implements Serializable {
} else { } else {
RecordUserAction.record("JavascriptContentSetting.DisableBy.SiteSettings"); RecordUserAction.record("JavascriptContentSetting.DisableBy.SiteSettings");
} }
} else if (type == ContentSettingException.Type.SOUND) { } else if (type == ContentSettingsType.SOUND) {
// It is possible to set the permission without having an existing exception, // It is possible to set the permission without having an existing exception,
// because we always show the sound permission in Site Settings. // because we always show the sound permission in Site Settings.
if (mContentSettingException[type] == null) { if (exception == null) {
mContentSettingException[type] = new ContentSettingException( exception = new ContentSettingException(
ContentSettingsType.SOUND, getAddress().getHost(), value, ""); ContentSettingsType.SOUND, getAddress().getHost(), value, "");
setContentSettingException(type, exception);
} }
if (value == ContentSettingValues.BLOCK) { if (value == ContentSettingValues.BLOCK) {
RecordUserAction.record("SoundContentSetting.MuteBy.SiteSettings"); RecordUserAction.record("SoundContentSetting.MuteBy.SiteSettings");
...@@ -236,8 +240,8 @@ public class Website implements Serializable { ...@@ -236,8 +240,8 @@ public class Website implements Serializable {
// We want to call setContentSetting even after explicitly setting // We want to call setContentSetting even after explicitly setting
// mContentSettingException above because this will trigger the actual change // mContentSettingException above because this will trigger the actual change
// on the PrefServiceBridge. // on the PrefServiceBridge.
if (mContentSettingException[type] != null) { if (exception != null) {
mContentSettingException[type].setContentSetting(browserContextHandle, value); exception.setContentSetting(browserContextHandle, value);
} }
} }
......
...@@ -285,20 +285,6 @@ public class WebsitePermissionsFetcher { ...@@ -285,20 +285,6 @@ public class WebsitePermissionsFetcher {
} }
private void setException(int contentSettingsType) { private void setException(int contentSettingsType) {
@ContentSettingException.Type
int exceptionType;
for (exceptionType = 0; exceptionType < ContentSettingException.Type.NUM_ENTRIES;
exceptionType++) {
if (contentSettingsType
== ContentSettingException.getContentSettingsType(exceptionType)) {
break;
}
}
assert contentSettingsType
== ContentSettingException.getContentSettingsType(exceptionType)
: "Unexpected content setting type received: "
+ contentSettingsType;
for (ContentSettingException exception : for (ContentSettingException exception :
mWebsitePreferenceBridge.getContentSettingsExceptions( mWebsitePreferenceBridge.getContentSettingsExceptions(
mBrowserContextHandle, contentSettingsType)) { mBrowserContextHandle, contentSettingsType)) {
...@@ -309,7 +295,7 @@ public class WebsitePermissionsFetcher { ...@@ -309,7 +295,7 @@ public class WebsitePermissionsFetcher {
continue; continue;
} }
Website site = findOrCreateSite(address, embedder); Website site = findOrCreateSite(address, embedder);
site.setContentSettingException(exceptionType, exception); site.setContentSettingException(contentSettingsType, exception);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment