Commit 64779c79 authored by Mugdha Lakhani's avatar Mugdha Lakhani Committed by Commit Bot

Add site setting for Automatic Downloads on Android.

Bug: 616321
Change-Id: I6a9f570f7f100fa8e1515f7736b6294644483f83
Reviewed-on: https://chromium-review.googlesource.com/1234475
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarFinnur Thorarinsson <finnur@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595864}
parent cd5fa3ff
...@@ -60,6 +60,8 @@ ...@@ -60,6 +60,8 @@
android:key="ads_permission_list" /> android:key="ads_permission_list" />
<org.chromium.chrome.browser.preferences.ChromeBaseListPreference <org.chromium.chrome.browser.preferences.ChromeBaseListPreference
android:key="background_sync_permission_list" /> android:key="background_sync_permission_list" />
<org.chromium.chrome.browser.preferences.ChromeBaseListPreference
android:key="automatic_downloads_permission_list" />
<org.chromium.chrome.browser.preferences.ChromeBaseListPreference <org.chromium.chrome.browser.preferences.ChromeBaseListPreference
android:key="protected_media_identifier_permission_list" /> android:key="protected_media_identifier_permission_list" />
<org.chromium.chrome.browser.preferences.ChromeBaseListPreference <org.chromium.chrome.browser.preferences.ChromeBaseListPreference
......
...@@ -53,6 +53,10 @@ ...@@ -53,6 +53,10 @@
<org.chromium.chrome.browser.preferences.website.SiteSettingsPreference <org.chromium.chrome.browser.preferences.website.SiteSettingsPreference
android:fragment="org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences" android:fragment="org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences"
android:key="background_sync" /> android:key="background_sync" />
<!-- Automatic Downloads -->
<org.chromium.chrome.browser.preferences.website.SiteSettingsPreference
android:fragment="org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences"
android:key="automatic_downloads" />
<!-- Protected content --> <!-- Protected content -->
<org.chromium.chrome.browser.preferences.website.SiteSettingsPreference <org.chromium.chrome.browser.preferences.website.SiteSettingsPreference
android:fragment="org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences" android:fragment="org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences"
......
...@@ -339,6 +339,14 @@ public class PrefServiceBridge { ...@@ -339,6 +339,14 @@ public class PrefServiceBridge {
return isContentSettingManaged(ContentSettingsType.CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC); return isContentSettingManaged(ContentSettingsType.CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC);
} }
/**
* @return true if automatic downloads is managed by policy.
*/
public boolean isAutomaticDownloadsManaged() {
return isContentSettingManaged(
ContentSettingsType.CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS);
}
/** /**
* Sets the preference that controls translate * Sets the preference that controls translate
*/ */
...@@ -682,15 +690,15 @@ public class PrefServiceBridge { ...@@ -682,15 +690,15 @@ public class PrefServiceBridge {
case ContentSettingsType.CONTENT_SETTINGS_TYPE_USB_GUARD: case ContentSettingsType.CONTENT_SETTINGS_TYPE_USB_GUARD:
setContentSettingEnabled(contentSettingsType, allow); setContentSettingEnabled(contentSettingsType, allow);
break; break;
case ContentSettingsType.CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS:
nativeSetAutomaticDownloadsEnabled(allow);
break;
case ContentSettingsType.CONTENT_SETTINGS_TYPE_AUTOPLAY: case ContentSettingsType.CONTENT_SETTINGS_TYPE_AUTOPLAY:
nativeSetAutoplayEnabled(allow); nativeSetAutoplayEnabled(allow);
break; break;
case ContentSettingsType.CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC: case ContentSettingsType.CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC:
nativeSetBackgroundSyncEnabled(allow); nativeSetBackgroundSyncEnabled(allow);
break; break;
case ContentSettingsType.CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
nativeSetCameraEnabled(allow);
break;
case ContentSettingsType.CONTENT_SETTINGS_TYPE_CLIPBOARD_READ: case ContentSettingsType.CONTENT_SETTINGS_TYPE_CLIPBOARD_READ:
nativeSetClipboardEnabled(allow); nativeSetClipboardEnabled(allow);
break; break;
...@@ -700,6 +708,9 @@ public class PrefServiceBridge { ...@@ -700,6 +708,9 @@ public class PrefServiceBridge {
case ContentSettingsType.CONTENT_SETTINGS_TYPE_GEOLOCATION: case ContentSettingsType.CONTENT_SETTINGS_TYPE_GEOLOCATION:
nativeSetAllowLocationEnabled(allow); nativeSetAllowLocationEnabled(allow);
break; break;
case ContentSettingsType.CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
nativeSetCameraEnabled(allow);
break;
case ContentSettingsType.CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: case ContentSettingsType.CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
nativeSetMicEnabled(allow); nativeSetMicEnabled(allow);
break; break;
...@@ -730,14 +741,16 @@ public class PrefServiceBridge { ...@@ -730,14 +741,16 @@ public class PrefServiceBridge {
// Returns true if websites are allowed to request permission to access USB devices. // Returns true if websites are allowed to request permission to access USB devices.
case ContentSettingsType.CONTENT_SETTINGS_TYPE_USB_GUARD: case ContentSettingsType.CONTENT_SETTINGS_TYPE_USB_GUARD:
return isContentSettingEnabled(contentSettingsType); return isContentSettingEnabled(contentSettingsType);
case ContentSettingsType.CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS:
return nativeGetAutomaticDownloadsEnabled();
case ContentSettingsType.CONTENT_SETTINGS_TYPE_AUTOPLAY: case ContentSettingsType.CONTENT_SETTINGS_TYPE_AUTOPLAY:
return nativeGetAutoplayEnabled(); return nativeGetAutoplayEnabled();
case ContentSettingsType.CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC: case ContentSettingsType.CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC:
return nativeGetBackgroundSyncEnabled(); return nativeGetBackgroundSyncEnabled();
case ContentSettingsType.CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
return nativeGetCameraEnabled();
case ContentSettingsType.CONTENT_SETTINGS_TYPE_COOKIES: case ContentSettingsType.CONTENT_SETTINGS_TYPE_COOKIES:
return nativeGetAcceptCookiesEnabled(); return nativeGetAcceptCookiesEnabled();
case ContentSettingsType.CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
return nativeGetCameraEnabled();
case ContentSettingsType.CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: case ContentSettingsType.CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
return nativeGetMicEnabled(); return nativeGetMicEnabled();
case ContentSettingsType.CONTENT_SETTINGS_TYPE_NOTIFICATIONS: case ContentSettingsType.CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
...@@ -1069,6 +1082,7 @@ public class PrefServiceBridge { ...@@ -1069,6 +1082,7 @@ public class PrefServiceBridge {
private native boolean nativeGetAcceptCookiesEnabled(); private native boolean nativeGetAcceptCookiesEnabled();
private native boolean nativeGetAcceptCookiesUserModifiable(); private native boolean nativeGetAcceptCookiesUserModifiable();
private native boolean nativeGetAcceptCookiesManagedByCustodian(); private native boolean nativeGetAcceptCookiesManagedByCustodian();
private native boolean nativeGetAutomaticDownloadsEnabled();
private native boolean nativeGetAutoplayEnabled(); private native boolean nativeGetAutoplayEnabled();
private native boolean nativeGetBackgroundSyncEnabled(); private native boolean nativeGetBackgroundSyncEnabled();
private native boolean nativeGetBlockThirdPartyCookiesEnabled(); private native boolean nativeGetBlockThirdPartyCookiesEnabled();
...@@ -1084,11 +1098,11 @@ public class PrefServiceBridge { ...@@ -1084,11 +1098,11 @@ public class PrefServiceBridge {
private native boolean nativeGetPasswordEchoEnabled(); private native boolean nativeGetPasswordEchoEnabled();
private native boolean nativeGetFirstRunEulaAccepted(); private native boolean nativeGetFirstRunEulaAccepted();
private native boolean nativeGetCameraEnabled(); private native boolean nativeGetCameraEnabled();
private native void nativeSetCameraEnabled(boolean allow); private native void nativeSetCameraEnabled(boolean enabled);
private native boolean nativeGetCameraUserModifiable(); private native boolean nativeGetCameraUserModifiable();
private native boolean nativeGetCameraManagedByCustodian(); private native boolean nativeGetCameraManagedByCustodian();
private native boolean nativeGetMicEnabled(); private native boolean nativeGetMicEnabled();
private native void nativeSetMicEnabled(boolean allow); private native void nativeSetMicEnabled(boolean enabled);
private native boolean nativeGetMicUserModifiable(); private native boolean nativeGetMicUserModifiable();
private native boolean nativeGetMicManagedByCustodian(); private native boolean nativeGetMicManagedByCustodian();
private native boolean nativeGetTranslateEnabled(); private native boolean nativeGetTranslateEnabled();
...@@ -1114,23 +1128,24 @@ public class PrefServiceBridge { ...@@ -1114,23 +1128,24 @@ public class PrefServiceBridge {
int clearBrowsingDataTab, int timePeriod); int clearBrowsingDataTab, int timePeriod);
private native int nativeGetLastClearBrowsingDataTab(); private native int nativeGetLastClearBrowsingDataTab();
private native void nativeSetLastClearBrowsingDataTab(int lastTab); private native void nativeSetLastClearBrowsingDataTab(int lastTab);
private native void nativeSetAutoplayEnabled(boolean allow); private native void nativeSetAutomaticDownloadsEnabled(boolean enabled);
private native void nativeSetAllowCookiesEnabled(boolean allow); private native void nativeSetAutoplayEnabled(boolean enabled);
private native void nativeSetBackgroundSyncEnabled(boolean allow); private native void nativeSetAllowCookiesEnabled(boolean enabled);
private native void nativeSetBackgroundSyncEnabled(boolean enabled);
private native void nativeSetBlockThirdPartyCookiesEnabled(boolean enabled); private native void nativeSetBlockThirdPartyCookiesEnabled(boolean enabled);
private native void nativeSetClipboardEnabled(boolean allow); private native void nativeSetClipboardEnabled(boolean enabled);
private native void nativeSetDoNotTrackEnabled(boolean enabled); private native void nativeSetDoNotTrackEnabled(boolean enabled);
private native void nativeSetRememberPasswordsEnabled(boolean allow); private native void nativeSetRememberPasswordsEnabled(boolean allow);
private native void nativeSetPasswordManagerAutoSigninEnabled(boolean enabled); private native void nativeSetPasswordManagerAutoSigninEnabled(boolean enabled);
private native boolean nativeGetAllowLocationEnabled(); private native boolean nativeGetAllowLocationEnabled();
private native boolean nativeGetNotificationsEnabled(); private native boolean nativeGetNotificationsEnabled();
private native boolean nativeGetNotificationsVibrateEnabled(); private native boolean nativeGetNotificationsVibrateEnabled();
private native void nativeSetAllowLocationEnabled(boolean allow); private native void nativeSetAllowLocationEnabled(boolean enabled);
private native void nativeSetNotificationsEnabled(boolean allow); private native void nativeSetNotificationsEnabled(boolean enabled);
private native void nativeSetNotificationsVibrateEnabled(boolean enabled); private native void nativeSetNotificationsVibrateEnabled(boolean enabled);
private native void nativeSetPasswordEchoEnabled(boolean enabled); private native void nativeSetPasswordEchoEnabled(boolean enabled);
private native void nativeSetSensorsEnabled(boolean allow); private native void nativeSetSensorsEnabled(boolean enabled);
private native void nativeSetSoundEnabled(boolean allow); private native void nativeSetSoundEnabled(boolean enabled);
private native boolean nativeCanPrefetchAndPrerender(); private native boolean nativeCanPrefetchAndPrerender();
private native AboutVersionStrings nativeGetAboutVersionStrings(); private native AboutVersionStrings nativeGetAboutVersionStrings();
private native void nativeSetContextualSearchPreference(String preference); private native void nativeSetContextualSearchPreference(String preference);
......
...@@ -17,8 +17,9 @@ import java.lang.annotation.RetentionPolicy; ...@@ -17,8 +17,9 @@ 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.AUTOPLAY, Type.BACKGROUND_SYNC, Type.COOKIE, Type.JAVASCRIPT, @IntDef({Type.ADS, Type.AUTOMATIC_DOWNLOADS, Type.AUTOPLAY,
Type.POPUP, Type.SOUND}) Type.BACKGROUND_SYNC, Type.COOKIE, Type.JAVASCRIPT, Type.POPUP,
Type.SOUND})
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface Type { public @interface Type {
// Values used to address array index below, inside Website and SingleWebsitePreferences. // Values used to address array index below, inside Website and SingleWebsitePreferences.
...@@ -30,13 +31,16 @@ public class ContentSettingException implements Serializable { ...@@ -30,13 +31,16 @@ public class ContentSettingException implements Serializable {
int JAVASCRIPT = 4; int JAVASCRIPT = 4;
int POPUP = 5; int POPUP = 5;
int SOUND = 6; int SOUND = 6;
int AUTOMATIC_DOWNLOADS = 7;
/** /**
* Number of handled exceptions used for calculating array sizes. * Number of handled exceptions used for calculating array sizes.
*/ */
int NUM_ENTRIES = 7; int NUM_ENTRIES = 8;
} }
// Mapping from {@link Type} to ContentSettingType. // Mapping from {@link Type} to ContentSettingType.
// TODO(https://crbug.com/616321) Add a unit test to verify that Type and
// CONTENT_TYPES are in sync.
final static int[] CONTENT_TYPES = { final static int[] CONTENT_TYPES = {
ContentSettingsType.CONTENT_SETTINGS_TYPE_ADS, ContentSettingsType.CONTENT_SETTINGS_TYPE_ADS,
ContentSettingsType.CONTENT_SETTINGS_TYPE_AUTOPLAY, ContentSettingsType.CONTENT_SETTINGS_TYPE_AUTOPLAY,
...@@ -45,7 +49,7 @@ public class ContentSettingException implements Serializable { ...@@ -45,7 +49,7 @@ public class ContentSettingException implements Serializable {
ContentSettingsType.CONTENT_SETTINGS_TYPE_JAVASCRIPT, ContentSettingsType.CONTENT_SETTINGS_TYPE_JAVASCRIPT,
ContentSettingsType.CONTENT_SETTINGS_TYPE_POPUPS, ContentSettingsType.CONTENT_SETTINGS_TYPE_POPUPS,
ContentSettingsType.CONTENT_SETTINGS_TYPE_SOUND, ContentSettingsType.CONTENT_SETTINGS_TYPE_SOUND,
}; ContentSettingsType.CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS};
private final int mContentSettingType; private final int mContentSettingType;
private final String mPattern; private final String mPattern;
......
...@@ -96,6 +96,11 @@ public class ContentSettingsResources { ...@@ -96,6 +96,11 @@ public class ContentSettingsResources {
R.string.ads_permission_title, ContentSetting.ALLOW, R.string.ads_permission_title, ContentSetting.ALLOW,
ContentSetting.BLOCK, 0, ContentSetting.BLOCK, 0,
R.string.website_settings_category_ads_blocked)); R.string.website_settings_category_ads_blocked));
localMap.put(ContentSettingsType.CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
new ResourceItem(R.drawable.infobar_downloading,
R.string.automatic_downloads_permission_title,
R.string.automatic_downloads_permission_title, ContentSetting.ASK,
ContentSetting.BLOCK, R.string.website_settings_category_ask, 0));
localMap.put(ContentSettingsType.CONTENT_SETTINGS_TYPE_AUTOPLAY, localMap.put(ContentSettingsType.CONTENT_SETTINGS_TYPE_AUTOPLAY,
new ResourceItem(R.drawable.settings_autoplay, R.string.autoplay_title, new ResourceItem(R.drawable.settings_autoplay, R.string.autoplay_title,
R.string.autoplay_title, ContentSetting.ALLOW, R.string.autoplay_title, ContentSetting.ALLOW,
......
...@@ -484,7 +484,9 @@ public class SingleCategoryPreferences extends PreferenceFragment ...@@ -484,7 +484,9 @@ public class SingleCategoryPreferences extends PreferenceFragment
private String getAddExceptionDialogMessage() { private String getAddExceptionDialogMessage() {
int resource = 0; int resource = 0;
if (mCategory.showSites(SiteSettingsCategory.Type.AUTOPLAY)) { if (mCategory.showSites(SiteSettingsCategory.Type.AUTOMATIC_DOWNLOADS)) {
resource = R.string.website_settings_add_site_description_automatic_downloads;
} else if (mCategory.showSites(SiteSettingsCategory.Type.AUTOPLAY)) {
resource = R.string.website_settings_add_site_description_autoplay; resource = R.string.website_settings_add_site_description_autoplay;
} else if (mCategory.showSites(SiteSettingsCategory.Type.BACKGROUND_SYNC)) { } else if (mCategory.showSites(SiteSettingsCategory.Type.BACKGROUND_SYNC)) {
resource = R.string.website_settings_add_site_description_background_sync; resource = R.string.website_settings_add_site_description_background_sync;
...@@ -580,6 +582,10 @@ public class SingleCategoryPreferences extends PreferenceFragment ...@@ -580,6 +582,10 @@ public class SingleCategoryPreferences extends PreferenceFragment
&& !PrefServiceBridge.getInstance().isCategoryEnabled( && !PrefServiceBridge.getInstance().isCategoryEnabled(
ContentSettingsType.CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC)) { ContentSettingsType.CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC)) {
exception = true; exception = true;
} else if (mCategory.showSites(SiteSettingsCategory.Type.AUTOMATIC_DOWNLOADS)
&& !PrefServiceBridge.getInstance().isCategoryEnabled(
ContentSettingsType.CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS)) {
exception = true;
} }
if (exception) { if (exception) {
getPreferenceScreen().addPreference(new AddExceptionPreference( getPreferenceScreen().addPreference(new AddExceptionPreference(
......
...@@ -73,6 +73,8 @@ public class SingleWebsitePreferences extends PreferenceFragment ...@@ -73,6 +73,8 @@ public class SingleWebsitePreferences extends PreferenceFragment
"ads_permission_list", // ContentSettingException.Type.ADS "ads_permission_list", // ContentSettingException.Type.ADS
"autoplay_permission_list", // ContentSettingException.Type.AUTOPLAY "autoplay_permission_list", // ContentSettingException.Type.AUTOPLAY
"background_sync_permission_list", // ContentSettingException.Type.BACKGROUND_SYNC "background_sync_permission_list", // ContentSettingException.Type.BACKGROUND_SYNC
"automatic_downloads_permission_list",
// ContentSettingException.Type.AUTOMATIC_DOWNLOADS
"cookies_permission_list", // ContentSettingException.Type.COOKIE "cookies_permission_list", // ContentSettingException.Type.COOKIE
"javascript_permission_list", // ContentSettingException.Type.JAVASCRIPT "javascript_permission_list", // ContentSettingException.Type.JAVASCRIPT
"popup_permission_list", // ContentSettingException.Type.POPUP "popup_permission_list", // ContentSettingException.Type.POPUP
...@@ -84,7 +86,8 @@ public class SingleWebsitePreferences extends PreferenceFragment ...@@ -84,7 +86,8 @@ public class SingleWebsitePreferences extends PreferenceFragment
"microphone_permission_list", // PermissionInfo.Type.MICROPHONE "microphone_permission_list", // PermissionInfo.Type.MICROPHONE
"midi_sysex_permission_list", // PermissionInfo.Type.MIDI "midi_sysex_permission_list", // PermissionInfo.Type.MIDI
"push_notifications_list", // PermissionInfo.Type.NOTIFICATION "push_notifications_list", // PermissionInfo.Type.NOTIFICATION
"protected_media_identifier_permission_list", // PermissionInfo.Type.PROTECTED_MEDIA_IDENTIFIER "protected_media_identifier_permission_list",
// PermissionInfo.Type.PROTECTED_MEDIA_IDENTIFIER
"sensors_permission_list", // PermissionInfo.Type.SENSORS "sensors_permission_list", // PermissionInfo.Type.SENSORS
}; };
......
...@@ -37,10 +37,10 @@ import java.lang.annotation.RetentionPolicy; ...@@ -37,10 +37,10 @@ import java.lang.annotation.RetentionPolicy;
* A base class for dealing with website settings categories. * A base class for dealing with website settings categories.
*/ */
public class SiteSettingsCategory { public class SiteSettingsCategory {
@IntDef({Type.ALL_SITES, Type.ADS, Type.AUTOPLAY, Type.BACKGROUND_SYNC, Type.CAMERA, @IntDef({Type.ALL_SITES, Type.ADS, Type.AUTOMATIC_DOWNLOADS, Type.AUTOPLAY,
Type.CLIPBOARD, Type.COOKIES, Type.DEVICE_LOCATION, Type.JAVASCRIPT, Type.MICROPHONE, Type.BACKGROUND_SYNC, Type.CAMERA, Type.CLIPBOARD, Type.COOKIES, Type.DEVICE_LOCATION,
Type.NOTIFICATIONS, Type.POPUPS, Type.PROTECTED_MEDIA, Type.SENSORS, Type.SOUND, Type.JAVASCRIPT, Type.MICROPHONE, Type.NOTIFICATIONS, Type.POPUPS, Type.PROTECTED_MEDIA,
Type.USE_STORAGE, Type.USB}) Type.SENSORS, Type.SOUND, Type.USE_STORAGE, Type.USB})
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface Type { public @interface Type {
// Values used to address array index. Should be enumerated from 0 and // Values used to address array index. Should be enumerated from 0 and
...@@ -63,15 +63,18 @@ public class SiteSettingsCategory { ...@@ -63,15 +63,18 @@ public class SiteSettingsCategory {
int SOUND = 14; int SOUND = 14;
int USE_STORAGE = 15; int USE_STORAGE = 15;
int USB = 16; int USB = 16;
int AUTOMATIC_DOWNLOADS = 17;
/** /**
* Number of handled categories used for calculating array sizes. * Number of handled categories used for calculating array sizes.
*/ */
int NUM_ENTRIES = 17; int NUM_ENTRIES = 18;
} }
/** /**
* Mapping from Type to String used in preferences. Values are sorted like * Mapping from Type to String used in preferences. Values are sorted like
* Type constants. * Type constants.
* TODO(https://crbug.com:/616321) Add a unit test to verify that Type and
* PREFERENCE_KEYS are in sync.
*/ */
private static final String[] PREFERENCE_KEYS = { private static final String[] PREFERENCE_KEYS = {
"all_sites", // Type.ALL_SITES "all_sites", // Type.ALL_SITES
...@@ -91,6 +94,7 @@ public class SiteSettingsCategory { ...@@ -91,6 +94,7 @@ public class SiteSettingsCategory {
"sound", // Type.SOUND "sound", // Type.SOUND
"use_storage", // Type.USE_STORAGE "use_storage", // Type.USE_STORAGE
"usb", // Type.USB "usb", // Type.USB
"automatic_downloads", // Type.AUTOMATIC_DOWNLOADS
}; };
/** /**
...@@ -117,6 +121,8 @@ public class SiteSettingsCategory { ...@@ -117,6 +121,8 @@ public class SiteSettingsCategory {
ContentSettingsType.CONTENT_SETTINGS_TYPE_SOUND, // Type.SOUND ContentSettingsType.CONTENT_SETTINGS_TYPE_SOUND, // Type.SOUND
-1, // Type.USE_STORAGE -1, // Type.USE_STORAGE
ContentSettingsType.CONTENT_SETTINGS_TYPE_USB_GUARD, // Type.USB ContentSettingsType.CONTENT_SETTINGS_TYPE_USB_GUARD, // Type.USB
ContentSettingsType
.CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, // Type.AUTOMATIC_DOWNLOADS,
}; };
// The id of this category. // The id of this category.
...@@ -217,7 +223,9 @@ public class SiteSettingsCategory { ...@@ -217,7 +223,9 @@ public class SiteSettingsCategory {
*/ */
public boolean isManaged() { public boolean isManaged() {
PrefServiceBridge prefs = PrefServiceBridge.getInstance(); PrefServiceBridge prefs = PrefServiceBridge.getInstance();
if (showSites(Type.BACKGROUND_SYNC)) { if (showSites(Type.AUTOMATIC_DOWNLOADS)) {
return prefs.isAutomaticDownloadsManaged();
} else if (showSites(Type.BACKGROUND_SYNC)) {
return prefs.isBackgroundSyncManaged(); return prefs.isBackgroundSyncManaged();
} else if (showSites(Type.COOKIES)) { } else if (showSites(Type.COOKIES)) {
return !prefs.isAcceptCookiesUserModifiable(); return !prefs.isAcceptCookiesUserModifiable();
......
...@@ -136,6 +136,8 @@ public class SiteSettingsPreferences extends PreferenceFragment ...@@ -136,6 +136,8 @@ public class SiteSettingsPreferences extends PreferenceFragment
if (SiteSettingsCategory.adsCategoryEnabled()) { if (SiteSettingsCategory.adsCategoryEnabled()) {
websitePrefs.add(Type.ADS); websitePrefs.add(Type.ADS);
} }
websitePrefs.add(Type.AUTOMATIC_DOWNLOADS);
// When showing the main menu, if Protected Content is not available, only Autoplay // When showing the main menu, if Protected Content is not available, only Autoplay
// will be visible. // will be visible.
if (!mProtectedContentMenuAvailable) { if (!mProtectedContentMenuAvailable) {
......
...@@ -131,6 +131,9 @@ public class WebsitePermissionsFetcher { ...@@ -131,6 +131,9 @@ public class WebsitePermissionsFetcher {
// Background sync permission is per-origin. // Background sync permission is per-origin.
queue.add(new ExceptionInfoFetcher( queue.add(new ExceptionInfoFetcher(
ContentSettingsType.CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC)); ContentSettingsType.CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC));
// Automatic Downloads permission is per-origin.
queue.add(new ExceptionInfoFetcher(
ContentSettingsType.CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS));
// Autoplay permission is per-origin. // Autoplay permission is per-origin.
queue.add(new ExceptionInfoFetcher(ContentSettingsType.CONTENT_SETTINGS_TYPE_AUTOPLAY)); queue.add(new ExceptionInfoFetcher(ContentSettingsType.CONTENT_SETTINGS_TYPE_AUTOPLAY));
// USB device permission is per-origin and per-embedder. // USB device permission is per-origin and per-embedder.
...@@ -196,6 +199,10 @@ public class WebsitePermissionsFetcher { ...@@ -196,6 +199,10 @@ public class WebsitePermissionsFetcher {
// Background sync info is per-origin. // Background sync info is per-origin.
queue.add(new ExceptionInfoFetcher( queue.add(new ExceptionInfoFetcher(
ContentSettingsType.CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC)); ContentSettingsType.CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC));
} else if (category.showSites(SiteSettingsCategory.Type.AUTOMATIC_DOWNLOADS)) {
// Automatic downloads info is per-origin.
queue.add(new ExceptionInfoFetcher(
ContentSettingsType.CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS));
} else if (category.showSites(SiteSettingsCategory.Type.PROTECTED_MEDIA)) { } else if (category.showSites(SiteSettingsCategory.Type.PROTECTED_MEDIA)) {
// Protected media identifier permission is per-origin and per-embedder. // Protected media identifier permission is per-origin and per-embedder.
queue.add(new PermissionInfoFetcher(PermissionInfo.Type.PROTECTED_MEDIA_IDENTIFIER)); queue.add(new PermissionInfoFetcher(PermissionInfo.Type.PROTECTED_MEDIA_IDENTIFIER));
......
...@@ -915,6 +915,9 @@ Your Google account may have other forms of browsing history like searches and a ...@@ -915,6 +915,9 @@ Your Google account may have other forms of browsing history like searches and a
<message name="IDS_BACKGROUND_SYNC_PERMISSION_TITLE" desc="Title of the permission that allows websites to queue an operation for the next time the device is online[CHAR-LIMIT=32]"> <message name="IDS_BACKGROUND_SYNC_PERMISSION_TITLE" desc="Title of the permission that allows websites to queue an operation for the next time the device is online[CHAR-LIMIT=32]">
Background sync Background sync
</message> </message>
<message name="IDS_AUTOMATIC_DOWNLOADS_PERMISSION_TITLE" desc="Title of the permission that allows websites to download multiple files automatically.">
Automatic downloads
</message>
<message name="IDS_WEBSITE_SETTINGS_ADD_SITE" desc="The label for the button to add a new website to the exception list."> <message name="IDS_WEBSITE_SETTINGS_ADD_SITE" desc="The label for the button to add a new website to the exception list.">
Add site exception Add site exception
</message> </message>
...@@ -936,6 +939,9 @@ Your Google account may have other forms of browsing history like searches and a ...@@ -936,6 +939,9 @@ Your Google account may have other forms of browsing history like searches and a
<message name="IDS_WEBSITE_SETTINGS_ADD_SITE_DESCRIPTION_BACKGROUND_SYNC" desc="The description for the allow Background Sync for website dialog."> <message name="IDS_WEBSITE_SETTINGS_ADD_SITE_DESCRIPTION_BACKGROUND_SYNC" desc="The description for the allow Background Sync for website dialog.">
Allow Background Sync for a specific site. Allow Background Sync for a specific site.
</message> </message>
<message name="IDS_WEBSITE_SETTINGS_ADD_SITE_DESCRIPTION_AUTOMATIC_DOWNLOADS" desc="The description for the allow Automatic Downloads for website dialog.">
Allow a site to download multiple files automatically.
</message>
<message name="IDS_WEBSITE_SETTINGS_ADD_SITE_DESCRIPTION_SOUND_ALLOW" desc="The description for the allow sound for website dialog."> <message name="IDS_WEBSITE_SETTINGS_ADD_SITE_DESCRIPTION_SOUND_ALLOW" desc="The description for the allow sound for website dialog.">
Allow sound for a specific site. Allow sound for a specific site.
</message> </message>
......
...@@ -667,6 +667,39 @@ public class SiteSettingsPreferencesTest { ...@@ -667,6 +667,39 @@ public class SiteSettingsPreferencesTest {
doTestUsbGuardPermission(false); doTestUsbGuardPermission(false);
} }
/**
* Helper function to test allowing and blocking automatic downloads.
* @param enabled true to test enabling automatic downloads, false to test disabling the
* feature.
*/
private void doTestAutomaticDownloadsPermission(final boolean enabled) {
setGlobalToggleForCategory(SiteSettingsCategory.Type.AUTOMATIC_DOWNLOADS, enabled);
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
Assert.assertEquals(
"Automatic Downloads should be " + (enabled ? "enabled" : "disabled"),
PrefServiceBridge.getInstance().isCategoryEnabled(
ContentSettingsType.CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS),
enabled);
}
});
}
@Test
@SmallTest
@Feature({"Preferences"})
public void testAllowAutomaticDownloads() {
doTestAutomaticDownloadsPermission(true);
}
@Test
@SmallTest
@Feature({"Preferences"})
public void testBlockAutomaticDownloads() {
doTestAutomaticDownloadsPermission(false);
}
private int getTabCount() { private int getTabCount() {
return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Integer>() { return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Integer>() {
@Override @Override
......
...@@ -298,6 +298,12 @@ static jboolean JNI_PrefServiceBridge_GetBackgroundSyncEnabled( ...@@ -298,6 +298,12 @@ static jboolean JNI_PrefServiceBridge_GetBackgroundSyncEnabled(
return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC); return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC);
} }
static jboolean JNI_PrefServiceBridge_GetAutomaticDownloadsEnabled(
JNIEnv* env,
const JavaParamRef<jobject>& obj) {
return GetBooleanForContentSetting(CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS);
}
static jboolean JNI_PrefServiceBridge_GetBlockThirdPartyCookiesEnabled( static jboolean JNI_PrefServiceBridge_GetBlockThirdPartyCookiesEnabled(
JNIEnv* env, JNIEnv* env,
const JavaParamRef<jobject>& obj) { const JavaParamRef<jobject>& obj) {
...@@ -749,6 +755,17 @@ static void JNI_PrefServiceBridge_SetBackgroundSyncEnabled( ...@@ -749,6 +755,17 @@ static void JNI_PrefServiceBridge_SetBackgroundSyncEnabled(
allow ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); allow ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK);
} }
static void JNI_PrefServiceBridge_SetAutomaticDownloadsEnabled(
JNIEnv* env,
const JavaParamRef<jobject>& obj,
jboolean allow) {
HostContentSettingsMap* host_content_settings_map =
HostContentSettingsMapFactory::GetForProfile(GetOriginalProfile());
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
allow ? CONTENT_SETTING_ASK : CONTENT_SETTING_BLOCK);
}
static void JNI_PrefServiceBridge_SetBlockThirdPartyCookiesEnabled( static void JNI_PrefServiceBridge_SetBlockThirdPartyCookiesEnabled(
JNIEnv* env, JNIEnv* env,
const JavaParamRef<jobject>& obj, const JavaParamRef<jobject>& obj,
......
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