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

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: renamed modules 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 site that is passed down to the site list.
25 * @type {SiteException}
26 */
27 selectedSite: {
28 type: Object,
29 notify: true,
30 },
31
32 /**
33 * The description to be shown next to the slider.
34 * @private
35 */
36 sliderDescription_: String,
37
38 /**
39 * Used only for the Flash to persist the Ask First checkbox state.
40 * Defaults to true, as the checkbox should be checked unless the user
41 * has explicitly unchecked it or has the ALLOW setting on Flash.
42 */
43 flashAskFirst_: {
44 type: Boolean,
45 value: true,
46 },
47
48 /**
49 * Used only for Cookies to keep track of the Session Only state.
50 * Defaults to true, as the checkbox should be checked unless the user
51 * has explicitly unchecked it or has the ALLOW setting on Cookies.
52 */
53 cookiesSessionOnly_: {
54 type: Boolean,
55 value: true,
56 },
57 },
58
59 observers: [
60 'onCategoryChanged_(category)',
61 ],
62
63 ready: function() {
64 this.addWebUIListener('contentSettingCategoryChanged',
65 this.defaultValueForCategoryChanged_.bind(this));
66 },
67
68 /**
69 * Called when the default value for a category has been changed.
70 * @param {number} category The category that changed.
71 * @private
72 */
73 defaultValueForCategoryChanged_: function(category) {
74 if (category == this.category)
75 this.onCategoryChanged_();
76 },
77
78 /**
79 * A handler for changing the default permission value for a content type.
80 * @private
81 */
82 onChangePermissionControl_: function() {
83 switch (this.category) {
84 case settings.ContentSettingsTypes.BACKGROUND_SYNC:
85 case settings.ContentSettingsTypes.IMAGES:
86 case settings.ContentSettingsTypes.JAVASCRIPT:
87 case settings.ContentSettingsTypes.KEYGEN:
88 case settings.ContentSettingsTypes.POPUPS:
89 case settings.ContentSettingsTypes.PROTOCOL_HANDLERS:
90 // "Allowed" vs "Blocked".
91 this.browserProxy.setDefaultValueForContentType(
92 this.category,
93 this.categoryEnabled ?
94 settings.PermissionValues.ALLOW :
95 settings.PermissionValues.BLOCK);
96 break;
97 case settings.ContentSettingsTypes.AUTOMATIC_DOWNLOADS:
98 case settings.ContentSettingsTypes.CAMERA:
99 case settings.ContentSettingsTypes.GEOLOCATION:
100 case settings.ContentSettingsTypes.MIC:
101 case settings.ContentSettingsTypes.NOTIFICATIONS:
102 case settings.ContentSettingsTypes.UNSANDBOXED_PLUGINS:
103 // "Ask" vs "Blocked".
104 this.browserProxy.setDefaultValueForContentType(
105 this.category,
106 this.categoryEnabled ?
107 settings.PermissionValues.ASK :
108 settings.PermissionValues.BLOCK);
109 break;
110 case settings.ContentSettingsTypes.COOKIES:
111 // This category is tri-state: "Allow", "Block", "Keep data until
112 // browser quits".
113 var value = settings.PermissionValues.BLOCK;
114 if (this.categoryEnabled) {
115 value = this.cookiesSessionOnly_ ?
116 settings.PermissionValues.SESSION_ONLY :
117 settings.PermissionValues.ALLOW;
118 }
119 this.browserProxy.setDefaultValueForContentType(this.category, value);
120 break;
121 case settings.ContentSettingsTypes.PLUGINS:
122 // This category is tri-state: "Allow", "Block", "Ask before running".
123 var value = settings.PermissionValues.BLOCK;
124 if (this.categoryEnabled) {
125 value = this.flashAskFirst_ ?
126 settings.PermissionValues.IMPORTANT_CONTENT :
127 settings.PermissionValues.ALLOW;
128 }
129 this.browserProxy.setDefaultValueForContentType(this.category, value);
130 break;
131 default:
132 assertNotReached('Invalid category: ' + this.category);
133 }
134 },
135
136 /**
137 * Handles changes to the category pref and the |category| member variable.
138 * @private
139 */
140 onCategoryChanged_: function() {
141 settings.SiteSettingsPrefsBrowserProxyImpl.getInstance()
142 .getDefaultValueForContentType(
143 this.category).then(function(defaultValue) {
144 var setting = defaultValue.setting;
145 this.categoryEnabled = this.computeIsSettingEnabled(setting);
146
147 // Flash only shows ALLOW or BLOCK descriptions on the slider.
148 var sliderSetting = setting;
149 if (this.category == settings.ContentSettingsTypes.PLUGINS &&
150 setting == settings.PermissionValues.IMPORTANT_CONTENT) {
151 sliderSetting = settings.PermissionValues.ALLOW;
152 } else if (
153 this.category == settings.ContentSettingsTypes.COOKIES &&
154 setting == settings.PermissionValues.SESSION_ONLY) {
155 sliderSetting = settings.PermissionValues.ALLOW;
156 }
157 this.sliderDescription_ =
158 this.computeCategoryDesc(this.category, sliderSetting, true);
159
160 if (this.category == settings.ContentSettingsTypes.PLUGINS) {
161 // The checkbox should only be cleared when the Flash setting
162 // is explicitly set to ALLOW.
163 if (setting == settings.PermissionValues.ALLOW)
164 this.flashAskFirst_ = false;
165 if (setting == settings.PermissionValues.IMPORTANT_CONTENT)
166 this.flashAskFirst_ = true;
167 } else if (
168 this.category == settings.ContentSettingsTypes.COOKIES) {
169 if (setting == settings.PermissionValues.ALLOW)
170 this.cookiesSessionOnly_ = false;
171 else if (setting == settings.PermissionValues.SESSION_ONLY)
172 this.cookiesSessionOnly_ = true;
173 }
174 }.bind(this));
175 },
176
177 /** @private */
178 isFlashCategory_: function(category) {
179 return category == settings.ContentSettingsTypes.PLUGINS;
180 },
181
182 /** @private */
183 isCookiesCategory_: function(category) {
184 return category == settings.ContentSettingsTypes.COOKIES;
185 },
186 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698