PageInfo: Reduce memory allocations for discoverability icon
The experiment results show slightly increased memory usage from
the discoverability icon: https://crbug.com/1228739#c1
This CL removes some unnecessary allocations.
The static getHighestPriorityPermission() method in
SingleWebsiteSettings triggers lots of classes to be loaded. To avoid
this, it is moved to a separate util class.
ContentSettingsResources has some static configuration data. Replace
it with a switch statement to avoid permanently allocating memory for
this.
Bug: 1228739
Change-Id: I3d36dc63d41fc8d896a2710ece58e557a5318759
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3026865
Reviewed-by: Ehimare Okoyomon <eokoyomon@chromium.org>
Reviewed-by: Tomasz Wiszkowski <ender@google.com>
Auto-Submit: Christian Dullweber <dullweber@chromium.org>
Commit-Queue: Tomasz Wiszkowski <ender@google.com>
Cr-Commit-Position: refs/heads/master@{#902441}
diff --git a/chrome/browser/ui/android/omnibox/java/src/org/chromium/chrome/browser/omnibox/status/StatusMediator.java b/chrome/browser/ui/android/omnibox/java/src/org/chromium/chrome/browser/omnibox/status/StatusMediator.java
index 940db253..6c7661d 100644
--- a/chrome/browser/ui/android/omnibox/java/src/org/chromium/chrome/browser/omnibox/status/StatusMediator.java
+++ b/chrome/browser/ui/android/omnibox/java/src/org/chromium/chrome/browser/omnibox/status/StatusMediator.java
@@ -30,7 +30,7 @@
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.theme.ThemeUtils;
import org.chromium.components.browser_ui.site_settings.ContentSettingsResources;
-import org.chromium.components.browser_ui.site_settings.SingleWebsiteSettings;
+import org.chromium.components.browser_ui.site_settings.SiteSettingsUtil;
import org.chromium.components.content_settings.ContentSettingValues;
import org.chromium.components.content_settings.ContentSettingsType;
import org.chromium.components.embedder_support.util.UrlUtilities;
@@ -621,7 +621,7 @@
return;
}
@ContentSettingsType
- int permission = SingleWebsiteSettings.getHighestPriorityPermission(permissions);
+ int permission = SiteSettingsUtil.getHighestPriorityPermission(permissions);
// The permission is not available in the settings page. Do not show an icon.
if (permission == ContentSettingsType.DEFAULT) return;
mLastPermission = permission;
diff --git a/components/browser_ui/site_settings/android/BUILD.gn b/components/browser_ui/site_settings/android/BUILD.gn
index 2215eea6..26464cf 100644
--- a/components/browser_ui/site_settings/android/BUILD.gn
+++ b/components/browser_ui/site_settings/android/BUILD.gn
@@ -65,6 +65,7 @@
"java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsDelegate.java",
"java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsFeatureList.java",
"java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsPreferenceFragment.java",
+ "java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsUtil.java",
"java/src/org/chromium/components/browser_ui/site_settings/StorageInfo.java",
"java/src/org/chromium/components/browser_ui/site_settings/TriStateSiteSettingsPreference.java",
"java/src/org/chromium/components/browser_ui/site_settings/Website.java",
diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/ContentSettingsResources.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/ContentSettingsResources.java
index 2a1a7ad..1c6a1c7 100644
--- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/ContentSettingsResources.java
+++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/ContentSettingsResources.java
@@ -21,15 +21,11 @@
import androidx.annotation.Nullable;
import org.chromium.base.FeatureList;
-import org.chromium.base.ThreadUtils;
import org.chromium.components.browser_ui.settings.SettingsUtils;
import org.chromium.components.content_settings.ContentSettingValues;
import org.chromium.components.content_settings.ContentSettingsType;
import org.chromium.device.DeviceFeatureList;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* A class with utility functions that get the appropriate string and icon resources for the
* Android UI that allows managing content settings.
@@ -95,167 +91,177 @@
}
}
- // TODO(lshang): use string for the index of HashMap after we change the type of
- // ContentSettingsType from int to string.
- private static Map<Integer, ResourceItem> sResourceInfo;
-
- /**
- * Initializes and returns the map. Only initializes it the first time it's needed.
- */
- private static Map<Integer, ResourceItem> getResourceInfo() {
- ThreadUtils.assertOnUiThread();
- if (sResourceInfo == null) {
- Map<Integer, ResourceItem> localMap = new HashMap<Integer, ResourceItem>();
- localMap.put(ContentSettingsType.ADS,
- new ResourceItem(R.drawable.web_asset, 0, R.string.ads_permission_title,
- ContentSettingValues.ALLOW, ContentSettingValues.BLOCK, 0,
- R.string.website_settings_category_ads_blocked));
- localMap.put(ContentSettingsType.AR,
- new ResourceItem(R.drawable.gm_filled_cardboard_24,
- R.drawable.gm_filled_cardboard_20, R.string.ar_permission_title,
- ContentSettingValues.ASK, ContentSettingValues.BLOCK,
- R.string.website_settings_category_ar_ask,
- R.string.website_settings_category_ar_blocked));
- localMap.put(ContentSettingsType.AUTOMATIC_DOWNLOADS,
- new ResourceItem(R.drawable.infobar_downloading, 0,
- R.string.automatic_downloads_permission_title, ContentSettingValues.ASK,
- ContentSettingValues.BLOCK, R.string.website_settings_category_ask, 0));
- localMap.put(ContentSettingsType.BACKGROUND_SYNC,
- new ResourceItem(R.drawable.permission_background_sync, 0,
- R.string.background_sync_permission_title, ContentSettingValues.ALLOW,
- ContentSettingValues.BLOCK,
- R.string.website_settings_category_allowed_recommended, 0));
- localMap.put(ContentSettingsType.BLUETOOTH_CHOOSER_DATA,
- new ResourceItem(R.drawable.settings_bluetooth, 0, 0, ContentSettingValues.ASK,
- ContentSettingValues.BLOCK, 0, 0));
- localMap.put(ContentSettingsType.BLUETOOTH_GUARD,
- new ResourceItem(R.drawable.settings_bluetooth, 0,
- R.string.website_settings_bluetooth, ContentSettingValues.ASK,
- ContentSettingValues.BLOCK,
- R.string.website_settings_category_bluetooth_ask,
- R.string.website_settings_category_bluetooth_blocked));
- localMap.put(ContentSettingsType.BLUETOOTH_SCANNING,
- new ResourceItem(R.drawable.gm_filled_bluetooth_searching_24,
- R.drawable.gm_filled_bluetooth_searching_20,
- R.string.website_settings_bluetooth_scanning, ContentSettingValues.ASK,
- ContentSettingValues.BLOCK,
- R.string.website_settings_category_bluetooth_scanning_ask, 0));
- localMap.put(ContentSettingsType.CLIPBOARD_READ_WRITE,
- new ResourceItem(R.drawable.gm_filled_content_paste_24,
- R.drawable.gm_filled_content_paste_20,
- R.string.clipboard_permission_title, ContentSettingValues.ASK,
- ContentSettingValues.BLOCK,
- R.string.website_settings_category_clipboard_ask,
- R.string.website_settings_category_clipboard_blocked));
- localMap.put(ContentSettingsType.COOKIES,
- new ResourceItem(R.drawable.permission_cookie, 0, R.string.cookies_title,
- ContentSettingValues.ALLOW, ContentSettingValues.BLOCK,
- R.string.website_settings_category_cookie_allowed, 0));
- localMap.put(ContentSettingsType.GEOLOCATION,
- new ResourceItem(R.drawable.gm_filled_location_on_24,
- R.drawable.gm_filled_location_on_20,
- R.string.website_settings_device_location, ContentSettingValues.ASK,
- ContentSettingValues.BLOCK,
- R.string.website_settings_category_location_ask, 0));
- localMap.put(ContentSettingsType.IDLE_DETECTION,
- new ResourceItem(R.drawable.gm_filled_devices_24,
- R.drawable.gm_filled_devices_20,
- R.string.website_settings_idle_detection, ContentSettingValues.ASK,
- ContentSettingValues.BLOCK,
- R.string.website_settings_category_idle_detection_ask,
- R.string.website_settings_category_idle_detection_blocked));
- localMap.put(ContentSettingsType.JAVASCRIPT,
- new ResourceItem(R.drawable.permission_javascript, 0,
- R.string.javascript_permission_title, ContentSettingValues.ALLOW,
- ContentSettingValues.BLOCK,
- R.string.website_settings_category_javascript_allowed, 0));
- localMap.put(ContentSettingsType.MEDIASTREAM_CAMERA,
- new ResourceItem(R.drawable.gm_filled_videocam_24,
- R.drawable.gm_filled_videocam_20, R.string.website_settings_use_camera,
- ContentSettingValues.ASK, ContentSettingValues.BLOCK,
- R.string.website_settings_category_camera_ask, 0));
- localMap.put(ContentSettingsType.MEDIASTREAM_MIC,
- new ResourceItem(R.drawable.gm_filled_mic_24, R.drawable.gm_filled_mic_20,
- R.string.website_settings_use_mic, ContentSettingValues.ASK,
- ContentSettingValues.BLOCK, R.string.website_settings_category_mic_ask,
- 0));
- localMap.put(ContentSettingsType.MIDI_SYSEX,
- new ResourceItem(R.drawable.gm_filled_piano_24, R.drawable.gm_filled_piano_20,
- R.string.midi_sysex_permission_title, null, null, 0, 0));
- localMap.put(ContentSettingsType.NFC,
- new ResourceItem(R.drawable.gm_filled_nfc_24, R.drawable.gm_filled_nfc_20,
- R.string.nfc_permission_title, ContentSettingValues.ASK,
- ContentSettingValues.BLOCK, R.string.website_settings_category_nfc_ask,
- R.string.website_settings_category_nfc_blocked));
- localMap.put(ContentSettingsType.NOTIFICATIONS,
- new ResourceItem(R.drawable.gm_filled_notifications_24,
- R.drawable.gm_filled_notifications_20,
- R.string.push_notifications_permission_title, ContentSettingValues.ASK,
- ContentSettingValues.BLOCK,
- R.string.website_settings_category_notifications_ask, 0));
- localMap.put(ContentSettingsType.POPUPS,
- new ResourceItem(R.drawable.permission_popups, 0,
- R.string.popup_permission_title, ContentSettingValues.ALLOW,
- ContentSettingValues.BLOCK, 0,
- R.string.website_settings_category_popups_redirects_blocked));
- // PROTECTED_MEDIA_IDENTIFIER uses 3-state preference so some values are not used.
- // If 3-state becomes more common we should update localMaps to support it better.
- localMap.put(ContentSettingsType.PROTECTED_MEDIA_IDENTIFIER,
- new ResourceItem(R.drawable.permission_protected_media, 0,
- R.string.protected_content, ContentSettingValues.ASK,
- ContentSettingValues.BLOCK, 0, 0));
- int sensorsPermissionTitle = R.string.motion_sensors_permission_title;
- int sensorsAllowedDescription =
- R.string.website_settings_category_motion_sensors_allowed;
- int sensorsBlockedDescription =
- R.string.website_settings_category_motion_sensors_blocked;
- try {
- if (FeatureList.isNativeInitialized()
- && DeviceFeatureList.isEnabled(
- DeviceFeatureList.GENERIC_SENSOR_EXTRA_CLASSES)) {
- sensorsPermissionTitle = R.string.sensors_permission_title;
- sensorsAllowedDescription = R.string.website_settings_category_sensors_allowed;
- sensorsBlockedDescription = R.string.website_settings_category_sensors_blocked;
- }
- } catch (IllegalArgumentException e) {
- // We can hit this in tests that use the @Features annotation, as it calls
- // FeatureList.setTestFeatures() with a map that should not need to contain
- // DeviceFeatureList.GENERIC_SENSOR_EXTRA_CLASSES.
- }
- localMap.put(ContentSettingsType.SENSORS,
- new ResourceItem(R.drawable.settings_sensors, 0, sensorsPermissionTitle,
- ContentSettingValues.ALLOW, ContentSettingValues.BLOCK,
- sensorsAllowedDescription, sensorsBlockedDescription));
- localMap.put(ContentSettingsType.SOUND,
- new ResourceItem(R.drawable.ic_volume_up_grey600_24dp, 0,
- R.string.sound_permission_title, ContentSettingValues.ALLOW,
- ContentSettingValues.BLOCK,
- R.string.website_settings_category_sound_allowed,
- R.string.website_settings_category_sound_blocked));
- localMap.put(ContentSettingsType.USB_CHOOSER_DATA,
- new ResourceItem(R.drawable.gm_filled_usb_24, R.drawable.gm_filled_usb_20, 0,
- ContentSettingValues.ASK, ContentSettingValues.BLOCK, 0, 0));
- localMap.put(ContentSettingsType.USB_GUARD,
- new ResourceItem(R.drawable.gm_filled_usb_24, R.drawable.gm_filled_usb_20,
- R.string.website_settings_usb, ContentSettingValues.ASK,
- ContentSettingValues.BLOCK, R.string.website_settings_category_usb_ask,
- R.string.website_settings_category_usb_blocked));
- localMap.put(ContentSettingsType.VR,
- new ResourceItem(R.drawable.gm_filled_cardboard_24,
- R.drawable.gm_filled_cardboard_20, R.string.vr_permission_title,
- ContentSettingValues.ASK, ContentSettingValues.BLOCK,
- R.string.website_settings_category_vr_ask,
- R.string.website_settings_category_vr_blocked));
- sResourceInfo = localMap;
- }
- return sResourceInfo;
- }
-
/**
* Returns the ResourceItem for a ContentSettingsType.
*/
private static ResourceItem getResourceItem(int contentType) {
- return getResourceInfo().get(contentType);
+ switch (contentType) {
+ case ContentSettingsType.ADS:
+ return new ResourceItem(R.drawable.web_asset, 0, R.string.ads_permission_title,
+ ContentSettingValues.ALLOW, ContentSettingValues.BLOCK, 0,
+ R.string.website_settings_category_ads_blocked);
+
+ case ContentSettingsType.AR:
+ return new ResourceItem(R.drawable.gm_filled_cardboard_24,
+ R.drawable.gm_filled_cardboard_20, R.string.ar_permission_title,
+ ContentSettingValues.ASK, ContentSettingValues.BLOCK,
+ R.string.website_settings_category_ar_ask,
+ R.string.website_settings_category_ar_blocked);
+
+ case ContentSettingsType.AUTOMATIC_DOWNLOADS:
+ return new ResourceItem(R.drawable.infobar_downloading, 0,
+ R.string.automatic_downloads_permission_title, ContentSettingValues.ASK,
+ ContentSettingValues.BLOCK, R.string.website_settings_category_ask, 0);
+
+ case ContentSettingsType.BACKGROUND_SYNC:
+ return new ResourceItem(R.drawable.permission_background_sync, 0,
+ R.string.background_sync_permission_title, ContentSettingValues.ALLOW,
+ ContentSettingValues.BLOCK,
+ R.string.website_settings_category_allowed_recommended, 0);
+
+ case ContentSettingsType.BLUETOOTH_CHOOSER_DATA:
+ return new ResourceItem(R.drawable.settings_bluetooth, 0, 0,
+ ContentSettingValues.ASK, ContentSettingValues.BLOCK, 0, 0);
+
+ case ContentSettingsType.BLUETOOTH_GUARD:
+ return new ResourceItem(R.drawable.settings_bluetooth, 0,
+ R.string.website_settings_bluetooth, ContentSettingValues.ASK,
+ ContentSettingValues.BLOCK,
+ R.string.website_settings_category_bluetooth_ask,
+ R.string.website_settings_category_bluetooth_blocked);
+
+ case ContentSettingsType.BLUETOOTH_SCANNING:
+ return new ResourceItem(R.drawable.gm_filled_bluetooth_searching_24,
+ R.drawable.gm_filled_bluetooth_searching_20,
+ R.string.website_settings_bluetooth_scanning, ContentSettingValues.ASK,
+ ContentSettingValues.BLOCK,
+ R.string.website_settings_category_bluetooth_scanning_ask, 0);
+
+ case ContentSettingsType.CLIPBOARD_READ_WRITE:
+ return new ResourceItem(R.drawable.gm_filled_content_paste_24,
+ R.drawable.gm_filled_content_paste_20, R.string.clipboard_permission_title,
+ ContentSettingValues.ASK, ContentSettingValues.BLOCK,
+ R.string.website_settings_category_clipboard_ask,
+ R.string.website_settings_category_clipboard_blocked);
+
+ case ContentSettingsType.COOKIES:
+ return new ResourceItem(R.drawable.permission_cookie, 0, R.string.cookies_title,
+ ContentSettingValues.ALLOW, ContentSettingValues.BLOCK,
+ R.string.website_settings_category_cookie_allowed, 0);
+
+ case ContentSettingsType.GEOLOCATION:
+ return new ResourceItem(R.drawable.gm_filled_location_on_24,
+ R.drawable.gm_filled_location_on_20,
+ R.string.website_settings_device_location, ContentSettingValues.ASK,
+ ContentSettingValues.BLOCK, R.string.website_settings_category_location_ask,
+ 0);
+
+ case ContentSettingsType.IDLE_DETECTION:
+ return new ResourceItem(R.drawable.gm_filled_devices_24,
+ R.drawable.gm_filled_devices_20, R.string.website_settings_idle_detection,
+ ContentSettingValues.ASK, ContentSettingValues.BLOCK,
+ R.string.website_settings_category_idle_detection_ask,
+ R.string.website_settings_category_idle_detection_blocked);
+
+ case ContentSettingsType.JAVASCRIPT:
+ return new ResourceItem(R.drawable.permission_javascript, 0,
+ R.string.javascript_permission_title, ContentSettingValues.ALLOW,
+ ContentSettingValues.BLOCK,
+ R.string.website_settings_category_javascript_allowed, 0);
+
+ case ContentSettingsType.MEDIASTREAM_CAMERA:
+ return new ResourceItem(R.drawable.gm_filled_videocam_24,
+ R.drawable.gm_filled_videocam_20, R.string.website_settings_use_camera,
+ ContentSettingValues.ASK, ContentSettingValues.BLOCK,
+ R.string.website_settings_category_camera_ask, 0);
+
+ case ContentSettingsType.MEDIASTREAM_MIC:
+ return new ResourceItem(R.drawable.gm_filled_mic_24, R.drawable.gm_filled_mic_20,
+ R.string.website_settings_use_mic, ContentSettingValues.ASK,
+ ContentSettingValues.BLOCK, R.string.website_settings_category_mic_ask, 0);
+
+ case ContentSettingsType.MIDI_SYSEX:
+ return new ResourceItem(R.drawable.gm_filled_piano_24,
+ R.drawable.gm_filled_piano_20, R.string.midi_sysex_permission_title, null,
+ null, 0, 0);
+
+ case ContentSettingsType.NFC:
+ return new ResourceItem(R.drawable.gm_filled_nfc_24, R.drawable.gm_filled_nfc_20,
+ R.string.nfc_permission_title, ContentSettingValues.ASK,
+ ContentSettingValues.BLOCK, R.string.website_settings_category_nfc_ask,
+ R.string.website_settings_category_nfc_blocked);
+
+ case ContentSettingsType.NOTIFICATIONS:
+ return new ResourceItem(R.drawable.gm_filled_notifications_24,
+ R.drawable.gm_filled_notifications_20,
+ R.string.push_notifications_permission_title, ContentSettingValues.ASK,
+ ContentSettingValues.BLOCK,
+ R.string.website_settings_category_notifications_ask, 0);
+
+ case ContentSettingsType.POPUPS:
+ return new ResourceItem(R.drawable.permission_popups, 0,
+ R.string.popup_permission_title, ContentSettingValues.ALLOW,
+ ContentSettingValues.BLOCK, 0,
+ R.string.website_settings_category_popups_redirects_blocked);
+
+ // PROTECTED_MEDIA_IDENTIFIER uses 3-state preference so some values are not used.
+ // If 3-state becomes more common we should update localMaps to support it better.
+ case ContentSettingsType.PROTECTED_MEDIA_IDENTIFIER:
+ return new ResourceItem(R.drawable.permission_protected_media, 0,
+ R.string.protected_content, ContentSettingValues.ASK,
+ ContentSettingValues.BLOCK, 0, 0);
+
+ case ContentSettingsType.SENSORS:
+ int sensorsPermissionTitle = R.string.motion_sensors_permission_title;
+ int sensorsAllowedDescription =
+ R.string.website_settings_category_motion_sensors_allowed;
+ int sensorsBlockedDescription =
+ R.string.website_settings_category_motion_sensors_blocked;
+ try {
+ if (FeatureList.isNativeInitialized()
+ && DeviceFeatureList.isEnabled(
+ DeviceFeatureList.GENERIC_SENSOR_EXTRA_CLASSES)) {
+ sensorsPermissionTitle = R.string.sensors_permission_title;
+ sensorsAllowedDescription =
+ R.string.website_settings_category_sensors_allowed;
+ sensorsBlockedDescription =
+ R.string.website_settings_category_sensors_blocked;
+ }
+ } catch (IllegalArgumentException e) {
+ // We can hit this in tests that use the @Features annotation, as it calls
+ // FeatureList.setTestFeatures() with a map that should not need to contain
+ // DeviceFeatureList.GENERIC_SENSOR_EXTRA_CLASSES.
+ }
+ return new ResourceItem(R.drawable.settings_sensors, 0, sensorsPermissionTitle,
+ ContentSettingValues.ALLOW, ContentSettingValues.BLOCK,
+ sensorsAllowedDescription, sensorsBlockedDescription);
+
+ case ContentSettingsType.SOUND:
+ return new ResourceItem(R.drawable.ic_volume_up_grey600_24dp, 0,
+ R.string.sound_permission_title, ContentSettingValues.ALLOW,
+ ContentSettingValues.BLOCK,
+ R.string.website_settings_category_sound_allowed,
+ R.string.website_settings_category_sound_blocked);
+
+ case ContentSettingsType.USB_CHOOSER_DATA:
+ return new ResourceItem(R.drawable.gm_filled_usb_24, R.drawable.gm_filled_usb_20, 0,
+ ContentSettingValues.ASK, ContentSettingValues.BLOCK, 0, 0);
+
+ case ContentSettingsType.USB_GUARD:
+ return new ResourceItem(R.drawable.gm_filled_usb_24, R.drawable.gm_filled_usb_20,
+ R.string.website_settings_usb, ContentSettingValues.ASK,
+ ContentSettingValues.BLOCK, R.string.website_settings_category_usb_ask,
+ R.string.website_settings_category_usb_blocked);
+
+ case ContentSettingsType.VR:
+ return new ResourceItem(R.drawable.gm_filled_cardboard_24,
+ R.drawable.gm_filled_cardboard_20, R.string.vr_permission_title,
+ ContentSettingValues.ASK, ContentSettingValues.BLOCK,
+ R.string.website_settings_category_vr_ask,
+ R.string.website_settings_category_vr_blocked);
+ }
+ assert false; // NOTREACHED
+ return null;
}
/**
diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SingleWebsiteSettings.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SingleWebsiteSettings.java
index 44c7acc..6a3b320 100644
--- a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SingleWebsiteSettings.java
+++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SingleWebsiteSettings.java
@@ -19,7 +19,6 @@
import android.view.View;
import androidx.annotation.ColorRes;
-import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.annotation.VisibleForTesting;
@@ -38,7 +37,6 @@
import org.chromium.components.content_settings.ContentSettingsType;
import org.chromium.components.embedder_support.browser_context.BrowserContextHandle;
import org.chromium.components.embedder_support.util.Origin;
-import org.chromium.content_public.browser.ContentFeatureList;
import java.util.Collection;
import java.util.HashMap;
@@ -94,36 +92,6 @@
// Buttons:
public static final String PREF_RESET_SITE = "reset_site_button";
- // Defining the order for content settings based on http://crbug.com/610358
- private static final int[] SETTINGS_ORDER = {
- ContentSettingsType.COOKIES,
- ContentSettingsType.GEOLOCATION,
- ContentSettingsType.MEDIASTREAM_CAMERA,
- ContentSettingsType.MEDIASTREAM_MIC,
- ContentSettingsType.NOTIFICATIONS,
- ContentSettingsType.JAVASCRIPT,
- ContentSettingsType.POPUPS,
- ContentSettingsType.ADS,
- ContentSettingsType.BACKGROUND_SYNC,
- ContentSettingsType.AUTOMATIC_DOWNLOADS,
- ContentSettingsType.PROTECTED_MEDIA_IDENTIFIER,
- ContentSettingsType.SOUND,
- ContentSettingsType.MIDI_SYSEX,
- ContentSettingsType.CLIPBOARD_READ_WRITE,
- ContentSettingsType.NFC,
- ContentSettingsType.BLUETOOTH_SCANNING,
- ContentSettingsType.VR,
- ContentSettingsType.AR,
- ContentSettingsType.IDLE_DETECTION,
- ContentSettingsType.SENSORS,
- };
-
- private static final int[] CHOOSER_PERMISSIONS = {
- ContentSettingsType.USB_CHOOSER_DATA,
- // Bluetooth is only shown when WEB_BLUETOOTH_NEW_PERMISSIONS_BACKEND is enabled.
- ContentSettingsType.BLUETOOTH_CHOOSER_DATA,
- };
-
private static boolean arrayContains(int[] array, int element) {
for (int e : array) {
if (e == element) {
@@ -184,34 +152,6 @@
}
}
- /**
- * @param types A list of ContentSettingsTypes
- * @return The highest priority permission that is available in SiteSettings. Returns DEFAULT
- * when called with empty list or only with entries not represented in this UI.
- */
- public static @ContentSettingsType int getHighestPriorityPermission(
- @ContentSettingsType @NonNull int[] types) {
- for (@ContentSettingsType int setting : SETTINGS_ORDER) {
- for (@ContentSettingsType int type : types) {
- if (setting == type) {
- return type;
- }
- }
- }
- for (@ContentSettingsType int setting : CHOOSER_PERMISSIONS) {
- for (@ContentSettingsType int type : types) {
- if (type == ContentSettingsType.BLUETOOTH_CHOOSER_DATA
- && !ContentFeatureList.isEnabled(
- ContentFeatureList.WEB_BLUETOOTH_NEW_PERMISSIONS_BACKEND)) {
- continue;
- }
- if (setting == type) {
- return type;
- }
- }
- }
- return ContentSettingsType.DEFAULT;
- }
/**
* @return The status of the actionable content settings flag
@@ -544,7 +484,7 @@
private void setupContentSettingsPreferences() {
mMaxPermissionOrder = findPreference(PREF_PERMISSIONS_HEADER).getOrder();
- for (@ContentSettingsType int type : SETTINGS_ORDER) {
+ for (@ContentSettingsType int type : SiteSettingsUtil.SETTINGS_ORDER) {
Preference preference = isActionableContentSettingsEnabled()
? new ChromeSwitchPreference(getStyledContext())
: new ListPreference(getStyledContext());
@@ -816,7 +756,8 @@
for (ChosenObjectInfo info : mSite.getChosenObjectInfo()) {
ChromeImageViewPreference preference =
new ChromeImageViewPreference(getStyledContext());
- assert arrayContains(CHOOSER_PERMISSIONS, info.getContentSettingsType());
+ assert arrayContains(
+ SiteSettingsUtil.CHOOSER_PERMISSIONS, info.getContentSettingsType());
preference.setKey(CHOOSER_PERMISSION_PREFERENCE_KEY);
preference.setIcon(getContentSettingsIcon(info.getContentSettingsType(), null));
preference.setTitle(info.getName());
diff --git a/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsUtil.java b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsUtil.java
new file mode 100644
index 0000000..f4a9d3d
--- /dev/null
+++ b/components/browser_ui/site_settings/android/java/src/org/chromium/components/browser_ui/site_settings/SiteSettingsUtil.java
@@ -0,0 +1,74 @@
+// Copyright 2021 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.components.browser_ui.site_settings;
+
+import androidx.annotation.NonNull;
+
+import org.chromium.components.content_settings.ContentSettingsType;
+import org.chromium.content_public.browser.ContentFeatureList;
+
+/**
+ * Util class for site settings UI.
+ */
+public class SiteSettingsUtil {
+ // Defining the order for content settings based on http://crbug.com/610358
+ static final int[] SETTINGS_ORDER = {
+ ContentSettingsType.COOKIES,
+ ContentSettingsType.GEOLOCATION,
+ ContentSettingsType.MEDIASTREAM_CAMERA,
+ ContentSettingsType.MEDIASTREAM_MIC,
+ ContentSettingsType.NOTIFICATIONS,
+ ContentSettingsType.JAVASCRIPT,
+ ContentSettingsType.POPUPS,
+ ContentSettingsType.ADS,
+ ContentSettingsType.BACKGROUND_SYNC,
+ ContentSettingsType.AUTOMATIC_DOWNLOADS,
+ ContentSettingsType.PROTECTED_MEDIA_IDENTIFIER,
+ ContentSettingsType.SOUND,
+ ContentSettingsType.MIDI_SYSEX,
+ ContentSettingsType.CLIPBOARD_READ_WRITE,
+ ContentSettingsType.NFC,
+ ContentSettingsType.BLUETOOTH_SCANNING,
+ ContentSettingsType.VR,
+ ContentSettingsType.AR,
+ ContentSettingsType.IDLE_DETECTION,
+ ContentSettingsType.SENSORS,
+ };
+
+ static final int[] CHOOSER_PERMISSIONS = {
+ ContentSettingsType.USB_CHOOSER_DATA,
+ // Bluetooth is only shown when WEB_BLUETOOTH_NEW_PERMISSIONS_BACKEND is enabled.
+ ContentSettingsType.BLUETOOTH_CHOOSER_DATA,
+ };
+
+ /**
+ * @param types A list of ContentSettingsTypes
+ * @return The highest priority permission that is available in SiteSettings. Returns DEFAULT
+ * when called with empty list or only with entries not represented in this UI.
+ */
+ public static @ContentSettingsType int getHighestPriorityPermission(
+ @ContentSettingsType @NonNull int[] types) {
+ for (@ContentSettingsType int setting : SETTINGS_ORDER) {
+ for (@ContentSettingsType int type : types) {
+ if (setting == type) {
+ return type;
+ }
+ }
+ }
+ for (@ContentSettingsType int setting : CHOOSER_PERMISSIONS) {
+ for (@ContentSettingsType int type : types) {
+ if (type == ContentSettingsType.BLUETOOTH_CHOOSER_DATA
+ && !ContentFeatureList.isEnabled(
+ ContentFeatureList.WEB_BLUETOOTH_NEW_PERMISSIONS_BACKEND)) {
+ continue;
+ }
+ if (setting == type) {
+ return type;
+ }
+ }
+ }
+ return ContentSettingsType.DEFAULT;
+ }
+}