OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * 'cr-settings-location-page' is the settings page for location access. | 7 * 'cr-settings-location-page' is the settings page for location access. |
8 * | 8 * |
9 * Example: | 9 * Example: |
10 * | 10 * |
11 * <cr-settings-location-page prefs="{{prefs}}"> | 11 * <cr-settings-location-page prefs="{{prefs}}"> |
12 * </cr-settings-location-page> | 12 * </cr-settings-location-page> |
13 * ... other pages ... | 13 * ... other pages ... |
14 * | 14 * |
15 * @group Chrome Settings Elements | 15 * @group Chrome Settings Elements |
16 * @element cr-settings-location-page | 16 * @element cr-settings-location-page |
17 */ | 17 */ |
18 Polymer({ | 18 Polymer({ |
| 19 /* TODO(finnur): Rename this to cr-settings-site-category. */ |
19 is: 'cr-settings-location-page', | 20 is: 'cr-settings-location-page', |
20 | 21 |
21 properties: { | 22 properties: { |
22 /** | 23 /** |
23 * Preferences state. | 24 * Preferences state. |
24 */ | 25 */ |
25 prefs: { | 26 prefs: { |
26 type: Object, | 27 type: Object, |
27 notify: true, | 28 notify: true, |
28 }, | 29 }, |
(...skipping 23 matching lines...) Expand all Loading... |
52 | 53 |
53 /** | 54 /** |
54 * Title for the page header and navigation menu. | 55 * Title for the page header and navigation menu. |
55 */ | 56 */ |
56 pageTitle: { | 57 pageTitle: { |
57 type: String, | 58 type: String, |
58 value: '', | 59 value: '', |
59 }, | 60 }, |
60 | 61 |
61 /** | 62 /** |
62 * Name of the 'iron-icon' to show. | 63 * What the main toggle for the category is set to (the global default when |
| 64 * no other policy is in effect). |
63 */ | 65 */ |
64 icon: { | 66 toggleState: { |
65 type: String, | 67 type: Boolean, |
66 value: 'communication:location-on', | |
67 readOnly: true, | |
68 }, | 68 }, |
69 | 69 |
70 /** | 70 /** |
71 * Array of objects with url members. | 71 * The ID of the category this widget is displaying data for. |
| 72 * See |categories| for possible values. |
72 */ | 73 */ |
73 block: { | 74 category: { |
74 type: Array, | 75 type: Number, |
75 }, | 76 }, |
76 | 77 |
77 /** | 78 /** |
78 * Array of objects with url members. | 79 * An enum containing all the possible category numbers. Corresponds to |
| 80 * the values found in the ContentSettingsType. |
79 */ | 81 */ |
80 allow: { | 82 categories: { |
81 type: Array, | 83 type: Object, |
| 84 }, |
| 85 |
| 86 /** |
| 87 * An enum containing the two possible values for the site list (allowed |
| 88 * list and blocked list). |
| 89 */ |
| 90 allowOrBlock: { |
| 91 readOnly: true, |
| 92 type: Object, |
| 93 value: { |
| 94 BLOCK: 0, |
| 95 ALLOW: 1, |
| 96 }, |
82 }, | 97 }, |
83 }, | 98 }, |
84 | 99 |
85 ready: function() { | 100 ready: function() { |
86 this.block = []; | 101 chrome.send('fetchToggleState', [this.category]); |
87 this.allow = []; | |
88 }, | 102 }, |
89 | 103 |
90 getTitleAndCount_: function(title, count) { | 104 attached: function() { |
91 return loadTimeData.getStringF( | 105 var self = this; |
92 'titleAndCount', loadTimeData.getString(title), count); | 106 cr.define('Settings', function() { |
| 107 return { |
| 108 receiveToggleState: function() { |
| 109 return self.receiveToggleState_.apply(self, arguments); |
| 110 }, |
| 111 }; |
| 112 }); |
| 113 }, |
| 114 |
| 115 /** |
| 116 * Receive the state of the toggle (from the native level). |
| 117 * @param {boolean} toggleState The initial value of the toggle. |
| 118 * @private |
| 119 */ |
| 120 receiveToggleState_: function(toggleState) { |
| 121 this.toggleState = toggleState; |
| 122 }, |
| 123 |
| 124 /** |
| 125 * A handler for flipping the toggle value. |
| 126 * @private |
| 127 */ |
| 128 handleToggleChange_: function(event) { |
| 129 chrome.send( |
| 130 'toggleChanged', [this.category, this.toggleState]); |
| 131 }, |
| 132 |
| 133 /** |
| 134 * A utility function to compute the icon to use for the category. |
| 135 * @param {number} category The category to show the icon for. |
| 136 * @private |
| 137 */ |
| 138 computeIcon_: function(category) { |
| 139 // Wonder if any of these enum values are directly accessible from .js? |
| 140 switch (category) { |
| 141 case this.categories.COOKIES: |
| 142 return ''; // Haven't found a good cookies icon under iron-icons. |
| 143 case this.categories.JAVASCRIPT: |
| 144 return 'icons:input'; |
| 145 case this.categories.FULLSCREEN: |
| 146 return 'icons:fullscreen'; |
| 147 case this.categories.POPUPS: |
| 148 return 'icons:open-in-new'; |
| 149 case this.categories.GEOLOCATION: |
| 150 return 'communication:location-on'; |
| 151 case this.categories.NOTIFICATION: |
| 152 return 'social:notifications'; |
| 153 case this.categories.CAMERA: |
| 154 return 'av:videocam'; |
| 155 case this.categories.MIC: |
| 156 return 'av:mic'; |
| 157 default: |
| 158 assertNotReached(); |
| 159 return ''; |
| 160 } |
| 161 }, |
| 162 |
| 163 /** |
| 164 * A utility function to compute the title of the category. |
| 165 * @param {number} category The category to show the title for. |
| 166 * @private |
| 167 */ |
| 168 computeTitle_: function(category) { |
| 169 switch (category) { |
| 170 case this.categories.COOKIES: |
| 171 return loadTimeData.getString('siteSettingsCookies'); |
| 172 case this.categories.JAVASCRIPT: |
| 173 return loadTimeData.getString('siteSettingsJavascript'); |
| 174 case this.categories.FULLSCREEN: |
| 175 return loadTimeData.getString('siteSettingsFullscreen'); |
| 176 case this.categories.POPUPS: |
| 177 return loadTimeData.getString('siteSettingsPopups'); |
| 178 case this.categories.GEOLOCATION: |
| 179 return loadTimeData.getString('siteSettingsLocation'); |
| 180 case this.categories.NOTIFICATION: |
| 181 return loadTimeData.getString('siteSettingsNotifications'); |
| 182 case this.categories.CAMERA: |
| 183 return loadTimeData.getString('siteSettingsCamera'); |
| 184 case this.categories.MIC: |
| 185 return loadTimeData.getString('siteSettingsMic'); |
| 186 default: |
| 187 assertNotReached(); |
| 188 return ''; |
| 189 } |
| 190 }, |
| 191 |
| 192 /** |
| 193 * A utility function to compute the description for the category. |
| 194 * @param {number} category The category to show the description for. |
| 195 * @param {boolean} toggleState The state of the global toggle. |
| 196 * @private |
| 197 */ |
| 198 computeDesc_: function(category, toggleState) { |
| 199 switch (category) { |
| 200 case this.categories.JAVASCRIPT: |
| 201 // "Allowed (recommended)" vs "Blocked". |
| 202 return toggleState ? |
| 203 loadTimeData.getString('siteSettingsAllowedRecommended') : |
| 204 loadTimeData.getString('siteSettingsBlocked'); |
| 205 case this.categories.POPUPS: |
| 206 // "Allowed" vs "Blocked (recommended)". |
| 207 return toggleState ? |
| 208 loadTimeData.getString('siteSettingsAllowed') : |
| 209 loadTimeData.getString('siteSettingsBlockedRecommended'); |
| 210 case this.categories.NOTIFICATION: |
| 211 // "Ask before sending (recommended)" vs "Blocked". |
| 212 return toggleState ? |
| 213 loadTimeData.getString('siteSettingsAskBeforeSending') : |
| 214 loadTimeData.getString('siteSettingsBlocked'); |
| 215 case this.categories.GEOLOCATION: |
| 216 case this.categories.CAMERA: |
| 217 case this.categories.MIC: |
| 218 // "Ask before accessing (recommended)" vs "Blocked". |
| 219 return toggleState ? |
| 220 loadTimeData.getString('siteSettingsAskBeforeAccessing') : |
| 221 loadTimeData.getString('siteSettingsBlocked'); |
| 222 case this.categories.FULLSCREEN: |
| 223 // "Allowed" vs. "Ask first (recommended)". |
| 224 return toggleState ? |
| 225 loadTimeData.getString('siteSettingsAllowed') : |
| 226 loadTimeData.getString('siteSettingsAskFirstRecommended'); |
| 227 case this.categories.COOKIES: |
| 228 // "Allow sites to save and read cookie data" vs "Blocked". |
| 229 return toggleState ? |
| 230 loadTimeData.getString('siteSettingsCookiesAllowed') : |
| 231 loadTimeData.getString('siteSettingsBlocked'); |
| 232 default: |
| 233 assertNotReached(); |
| 234 return ''; |
| 235 } |
93 }, | 236 }, |
94 }); | 237 }); |
OLD | NEW |