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

Unified Diff: chrome/browser/resources/settings/site_settings/site_settings_category.js

Issue 2509163004: [MD settings] content category policy (Closed)
Patch Set: browser_tests; review changes Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/settings/site_settings/site_settings_category.js
diff --git a/chrome/browser/resources/settings/site_settings/site_settings_category.js b/chrome/browser/resources/settings/site_settings/site_settings_category.js
index 63cc5ace2c53df64ad00e0278f10d3d4eb37921d..b600fc91ca59b21b17f1f79cafa55f640e8e528c 100644
--- a/chrome/browser/resources/settings/site_settings/site_settings_category.js
+++ b/chrome/browser/resources/settings/site_settings/site_settings_category.js
@@ -13,15 +13,16 @@ Polymer({
behaviors: [SiteSettingsBehavior, WebUIListenerBehavior],
properties: {
- /**
- * Represents the state of the main toggle shown for the category. For
- * example, the Location category can be set to Block/Ask so false, in that
- * case, represents Block and true represents Ask.
- */
- categoryEnabled: Boolean,
+ /** @private */
Dan Beam 2016/11/22 02:57:40 can this be @private {settings_private.PrefObject}
dschuyler 2016/11/24 01:25:48 Done.
+ fakePref_: {
+ type: Object,
+ value: function() {
+ return {};
+ },
+ },
/**
- * The site that was selected by the user in the dropdown list.
+ * The site that is passed down to the site list.
* @type {SiteException}
*/
selectedSite: {
@@ -31,6 +32,7 @@ Polymer({
/**
* The description to be shown next to the slider.
+ * @private
*/
sliderDescription_: String,
@@ -38,6 +40,7 @@ Polymer({
* Used only for the Flash to persist the Ask First checkbox state.
* Defaults to true, as the checkbox should be checked unless the user
* has explicitly unchecked it or has the ALLOW setting on Flash.
+ * @private
*/
flashAskFirst_: {
type: Boolean,
@@ -48,6 +51,7 @@ Polymer({
* Used only for Cookies to keep track of the Session Only state.
* Defaults to true, as the checkbox should be checked unless the user
* has explicitly unchecked it or has the ALLOW setting on Cookies.
+ * @private
*/
cookiesSessionOnly_: {
type: Boolean,
@@ -57,6 +61,7 @@ Polymer({
observers: [
'onCategoryChanged_(category)',
+ 'onChangePermissionControl_(fakePref_.value)',
],
ready: function() {
@@ -70,6 +75,8 @@ Polymer({
* @private
*/
defaultValueForCategoryChanged_: function(category) {
+ // We will get notification if a category setting changes in another tab
+ // or if we re-populate |this| with a different category.
if (category == this.category)
this.onCategoryChanged_();
},
@@ -78,7 +85,10 @@ Polymer({
* A handler for changing the default permission value for a content type.
* @private
*/
- onChangePermissionControl_: function(event) {
+ onChangePermissionControl_: function() {
+ if (!this.category)
Dan Beam 2016/11/22 02:57:40 why can't we just add category to the observer? a
dschuyler 2016/11/24 01:25:48 Nice, that allows for removing the on-change in th
+ return;
+
switch (this.category) {
case settings.ContentSettingsTypes.BACKGROUND_SYNC:
case settings.ContentSettingsTypes.IMAGES:
@@ -89,7 +99,7 @@ Polymer({
// "Allowed" vs "Blocked".
this.browserProxy.setDefaultValueForContentType(
this.category,
- this.categoryEnabled ?
+ this.fakePref_.value ?
settings.PermissionValues.ALLOW :
settings.PermissionValues.BLOCK);
break;
@@ -102,7 +112,7 @@ Polymer({
// "Ask" vs "Blocked".
this.browserProxy.setDefaultValueForContentType(
this.category,
- this.categoryEnabled ?
+ this.fakePref_.value ?
settings.PermissionValues.ASK :
settings.PermissionValues.BLOCK);
break;
@@ -110,7 +120,7 @@ Polymer({
// This category is tri-state: "Allow", "Block", "Keep data until
// browser quits".
var value = settings.PermissionValues.BLOCK;
- if (this.categoryEnabled) {
+ if (this.fakePref_.value) {
value = this.cookiesSessionOnly_ ?
settings.PermissionValues.SESSION_ONLY :
settings.PermissionValues.ALLOW;
@@ -120,7 +130,7 @@ Polymer({
case settings.ContentSettingsTypes.PLUGINS:
// This category is tri-state: "Allow", "Block", "Ask before running".
var value = settings.PermissionValues.BLOCK;
- if (this.categoryEnabled) {
+ if (this.fakePref_.value) {
value = this.flashAskFirst_ ?
settings.PermissionValues.IMPORTANT_CONTENT :
settings.PermissionValues.ALLOW;
@@ -133,14 +143,46 @@ Polymer({
},
/**
+ * Set the fake pref value from the content settings.
+ * @param {!ContentCategorySetting} category
+ * @private
+ */
+ setFakePref_: function(category) {
+ // TODO(dschuyler): The concept of using fake prefs (here and elsewhere)
+ // should be rethought. This is considered okay in a pinch, but not a great
+ // way to get the policy controls. See http://crbug.com/666164
+ var pref = {
+ 'key': 'fakeContentSettingsCategoryPref',
+ 'type': 'BOOLEAN',
+ 'value': this.computeIsSettingEnabled(category.setting),
+ };
+ if (category.source != PolicySource.DEFAULT &&
+ category.source != PolicySource.PREFERENCE) {
+ pref.enforcement = chrome.settingsPrivate.Enforcement.ENFORCED;
+ pref.controlledBy = category.source == PolicySource.EXTENSION ?
+ chrome.settingsPrivate.ControlledBy.EXTENSION :
+ chrome.settingsPrivate.ControlledBy.USER_POLICY;
+ }
+ // The fakePref_ must be replaced (rather than just value changes) so that
+ // observers will be notified of the change.
+ this.fakePref_ = pref;
+ },
+
+ /**
* Handles changes to the category pref and the |category| member variable.
* @private
*/
onCategoryChanged_: function() {
settings.SiteSettingsPrefsBrowserProxyImpl.getInstance()
.getDefaultValueForContentType(
- this.category).then(function(setting) {
- this.categoryEnabled = this.computeIsSettingEnabled(setting);
+ this.category).then(function(categorySetting) {
+ // Early out if there is no actual change.
Dan Beam 2016/11/22 02:57:40 can we do this inside of setFakePref_ instead?
dschuyler 2016/11/24 01:25:48 Done.
+ if (this.computeIsSettingEnabled(categorySetting.setting) ==
+ this.fakePref_.value) {
+ return;
+ }
+ this.setFakePref_(categorySetting);
+ var setting = categorySetting.setting;
// Flash only shows ALLOW or BLOCK descriptions on the slider.
var sliderSetting = setting;

Powered by Google App Engine
This is Rietveld 408576698