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

Side by Side Diff: chrome/browser/resources/settings/site_settings/site_settings_category.js

Issue 2554403005: [MD settings] move extra options in category settings (Closed)
Patch Set: merge with master; review changes Created 4 years 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @fileoverview
7 * 'site-settings-category' is the polymer element for showing a certain
8 * category under Site Settings.
9 */
10 Polymer({
11 is: 'site-settings-category',
12
13 behaviors: [SiteSettingsBehavior, WebUIListenerBehavior],
14
15 properties: {
16 /**
17 * Represents the state of the main toggle shown for the category. For
18 * example, the Location category can be set to Block/Ask so false, in that
19 * case, represents Block and true represents Ask.
20 */
21 categoryEnabled: Boolean,
22
23 /**
24 * The description to be shown next to the slider.
25 * @private
26 */
27 sliderDescription_: String,
28
29 /**
30 * Used only for the Flash to persist the Ask First checkbox state.
31 * Defaults to true, as the checkbox should be checked unless the user
32 * has explicitly unchecked it or has the ALLOW setting on Flash.
33 */
34 flashAskFirst_: {
35 type: Boolean,
36 value: true,
37 },
38
39 /**
40 * Used only for Cookies to keep track of the Session Only state.
41 * Defaults to true, as the checkbox should be checked unless the user
42 * has explicitly unchecked it or has the ALLOW setting on Cookies.
43 */
44 cookiesSessionOnly_: {
45 type: Boolean,
46 value: true,
47 },
48 },
49
50 observers: [
51 'onCategoryChanged_(category)',
52 ],
53
54 ready: function() {
55 this.addWebUIListener('contentSettingCategoryChanged',
56 this.defaultValueForCategoryChanged_.bind(this));
57 },
58
59 /**
60 * Called when the default value for a category has been changed.
61 * @param {number} category The category that changed.
62 * @private
63 */
64 defaultValueForCategoryChanged_: function(category) {
65 if (category == this.category)
66 this.onCategoryChanged_();
67 },
68
69 /**
70 * A handler for changing the default permission value for a content type.
71 * @private
72 */
73 onChangePermissionControl_: function() {
74 switch (this.category) {
75 case settings.ContentSettingsTypes.BACKGROUND_SYNC:
76 case settings.ContentSettingsTypes.IMAGES:
77 case settings.ContentSettingsTypes.JAVASCRIPT:
78 case settings.ContentSettingsTypes.KEYGEN:
79 case settings.ContentSettingsTypes.POPUPS:
80 case settings.ContentSettingsTypes.PROTOCOL_HANDLERS:
81 // "Allowed" vs "Blocked".
82 this.browserProxy.setDefaultValueForContentType(
83 this.category,
84 this.categoryEnabled ?
85 settings.PermissionValues.ALLOW :
86 settings.PermissionValues.BLOCK);
87 break;
88 case settings.ContentSettingsTypes.AUTOMATIC_DOWNLOADS:
89 case settings.ContentSettingsTypes.CAMERA:
90 case settings.ContentSettingsTypes.GEOLOCATION:
91 case settings.ContentSettingsTypes.MIC:
92 case settings.ContentSettingsTypes.NOTIFICATIONS:
93 case settings.ContentSettingsTypes.UNSANDBOXED_PLUGINS:
94 // "Ask" vs "Blocked".
95 this.browserProxy.setDefaultValueForContentType(
96 this.category,
97 this.categoryEnabled ?
98 settings.PermissionValues.ASK :
99 settings.PermissionValues.BLOCK);
100 break;
101 case settings.ContentSettingsTypes.COOKIES:
102 // This category is tri-state: "Allow", "Block", "Keep data until
103 // browser quits".
104 var value = settings.PermissionValues.BLOCK;
105 if (this.categoryEnabled) {
106 value = this.cookiesSessionOnly_ ?
107 settings.PermissionValues.SESSION_ONLY :
108 settings.PermissionValues.ALLOW;
109 }
110 this.browserProxy.setDefaultValueForContentType(this.category, value);
111 break;
112 case settings.ContentSettingsTypes.PLUGINS:
113 // This category is tri-state: "Allow", "Block", "Ask before running".
114 var value = settings.PermissionValues.BLOCK;
115 if (this.categoryEnabled) {
116 value = this.flashAskFirst_ ?
117 settings.PermissionValues.IMPORTANT_CONTENT :
118 settings.PermissionValues.ALLOW;
119 }
120 this.browserProxy.setDefaultValueForContentType(this.category, value);
121 break;
122 default:
123 assertNotReached('Invalid category: ' + this.category);
124 }
125 },
126
127 /**
128 * Handles changes to the category pref and the |category| member variable.
129 * @private
130 */
131 onCategoryChanged_: function() {
132 settings.SiteSettingsPrefsBrowserProxyImpl.getInstance()
133 .getDefaultValueForContentType(
134 this.category).then(function(defaultValue) {
135 var setting = defaultValue.setting;
136 this.categoryEnabled = this.computeIsSettingEnabled(setting);
137
138 // Flash only shows ALLOW or BLOCK descriptions on the slider.
139 var sliderSetting = setting;
140 if (this.category == settings.ContentSettingsTypes.PLUGINS &&
141 setting == settings.PermissionValues.IMPORTANT_CONTENT) {
142 sliderSetting = settings.PermissionValues.ALLOW;
143 } else if (
144 this.category == settings.ContentSettingsTypes.COOKIES &&
145 setting == settings.PermissionValues.SESSION_ONLY) {
146 sliderSetting = settings.PermissionValues.ALLOW;
147 }
148 this.sliderDescription_ =
149 this.computeCategoryDesc(this.category, sliderSetting, true);
150
151 if (this.category == settings.ContentSettingsTypes.PLUGINS) {
152 // The checkbox should only be cleared when the Flash setting
153 // is explicitly set to ALLOW.
154 if (setting == settings.PermissionValues.ALLOW)
155 this.flashAskFirst_ = false;
156 if (setting == settings.PermissionValues.IMPORTANT_CONTENT)
157 this.flashAskFirst_ = true;
158 } else if (
159 this.category == settings.ContentSettingsTypes.COOKIES) {
160 if (setting == settings.PermissionValues.ALLOW)
161 this.cookiesSessionOnly_ = false;
162 else if (setting == settings.PermissionValues.SESSION_ONLY)
163 this.cookiesSessionOnly_ = true;
164 }
165 }.bind(this));
166 },
167
168 /** @private */
169 isFlashCategory_: function(category) {
170 return category == settings.ContentSettingsTypes.PLUGINS;
171 },
172
173 /** @private */
174 isCookiesCategory_: function(category) {
175 return category == settings.ContentSettingsTypes.COOKIES;
176 },
177 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698