Chromium Code Reviews| 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 * 'settings-date-time-page' is the settings page containing date and time | 7 * 'settings-date-time-page' is the settings page containing date and time |
| 8 * settings. | 8 * settings. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 cr.exportPath('settings'); | 11 cr.exportPath('settings'); |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * Possible values of the system time-zone auto-detection policy. Must stay in | 14 * Describes the status of the auto-detect policy. |
| 15 * sync with AutomaticTimezoneDetectionType in chrome_device_policy.proto. | |
| 16 * @enum {number} | 15 * @enum {number} |
| 17 * @const | |
| 18 */ | 16 */ |
| 19 settings.AutomaticTimezoneDetectionPolicy = { | 17 settings.TimeZoneAutoDetectPolicy = { |
| 20 USERS_DECIDE: 0, | 18 NONE: 0, |
| 21 DISABLED: 1, | 19 FORCED_ON: 1, |
| 22 IP_ONLY: 2, | 20 FORCED_OFF: 2, |
| 23 SEND_WIFI_ACCESS_POINTS: 3, | |
| 24 }; | 21 }; |
| 25 | 22 |
| 26 Polymer({ | 23 Polymer({ |
| 27 is: 'settings-date-time-page', | 24 is: 'settings-date-time-page', |
| 28 | 25 |
| 29 behaviors: [PrefsBehavior], | 26 behaviors: [PrefsBehavior, WebUIListenerBehavior], |
| 30 | 27 |
| 31 properties: { | 28 properties: { |
| 32 /** Preferences state. */ | 29 /** Preferences state. */ |
| 33 prefs: { | 30 prefs: { |
| 34 type: Object, | 31 type: Object, |
| 35 notify: true, | 32 notify: true, |
| 36 }, | 33 }, |
| 37 | 34 |
| 38 /** | 35 /** |
| 39 * If the time zone is managed at the system level, the user cannot control | 36 * The time zone auto-detect policy. |
| 40 * any time zone settings. | 37 * @private {settings.TimeZoneAutoDetectPolicy} |
| 41 * @private | |
| 42 */ | 38 */ |
| 43 systemTimeZoneManaged_: { | 39 timeZoneAutoDetectPolicy_: { |
| 44 type: Boolean, | 40 type: Boolean, |
| 45 value: function() { | 41 value: function() { |
| 46 return loadTimeData.getBoolean('systemTimeZoneManaged'); | 42 if (!loadTimeData.valueExists('timeZoneAutoDetectValueFromPolicy')) |
| 43 return settings.TimeZoneAutoDetectPolicy.NONE; | |
| 44 return loadTimeData.getBoolean('timeZoneAutoDetectValueFromPolicy') ? | |
| 45 settings.TimeZoneAutoDetectPolicy.FORCED_ON : | |
| 46 settings.TimeZoneAutoDetectPolicy.FORCED_OFF; | |
| 47 }, | 47 }, |
| 48 }, | 48 }, |
| 49 | 49 |
| 50 /** | 50 /** |
| 51 * If the time zone auto-detection setting is managed at the system level, | 51 * Whether a policy controls the time zone auto-detect setting. |
| 52 * the user cannot override the setting unless the policy is USERS_DECIDE. | |
| 53 * @private | 52 * @private |
| 54 */ | 53 */ |
| 55 systemTimeZoneDetectionManaged_: { | 54 hasTimeZoneAutoDetectPolicy_: { |
| 56 type: Boolean, | 55 type: Boolean, |
| 57 value: function() { | 56 computed: |
| 58 return loadTimeData.getBoolean( | 57 'computeHasTimeZoneAutoDetectPolicy_(timeZoneAutoDetectPolicy_)', |
| 59 'systemTimeZoneDetectionManaged'); | |
| 60 }, | |
| 61 }, | 58 }, |
| 62 | 59 |
| 63 /** | 60 /** |
| 64 * Value of the system time zone auto-detection policy, or null if system | 61 * The effective time zone auto-detect setting. |
| 65 * time zone auto-detection is not managed. | 62 * @private |
| 66 * @private {?settings.AutomaticTimezoneDetectionPolicy} | |
| 67 */ | 63 */ |
| 68 systemTimeZoneDetectionPolicyValue_: { | 64 timeZoneAutoDetect_: { |
| 69 type: Number, | 65 type: Boolean, |
| 70 value: function() { | 66 computed: 'computeTimeZoneAutoDetect_(' + |
| 71 return loadTimeData.valueExists('systemTimeZoneDetectionPolicyValue') ? | 67 'timeZoneAutoDetectPolicy_,' + |
| 72 /** @type {settings.AutomaticTimezoneDetectionPolicy} */( | 68 'prefs.settings.resolve_timezone_by_geolocation.value,' + |
| 73 loadTimeData.getInteger('systemTimeZoneDetectionPolicyValue')) : | 69 'hideTimeZoneDetection_)', |
| 74 null; | |
| 75 }, | |
| 76 }, | 70 }, |
| 77 | 71 |
| 78 /** | 72 /** |
| 79 * Hides the time zone auto-detection feature when the | 73 * A fake preference to provide cr-policy-pref-indicator with policy info. |
| 74 * @private {!chrome.settingsPrivate.PrefObject} | |
| 75 */ | |
| 76 timeZonePolicyPref_: { | |
| 77 type: Object, | |
| 78 value: function() { | |
| 79 return { | |
| 80 key: 'fakeTimeZonePref', | |
| 81 type: chrome.settingsPrivate.PrefType.NUMBER, | |
| 82 value: 0, | |
| 83 policySource: chrome.settingsPrivate.PolicySource.DEVICE_POLICY, | |
| 84 policyEnforcement: chrome.settingsPrivate.PolicyEnforcement.ENFORCED, | |
| 85 }; | |
|
stevenjb
2016/10/21 20:16:40
nit: Since this is frequently unused, maybe defaul
michaelpg
2016/10/25 00:35:15
Done.
| |
| 86 }, | |
| 87 readOnly: true, | |
| 88 }, | |
| 89 | |
| 90 /** | |
| 91 * Hides the time zone auto-detect feature when the | |
| 80 * --disable-timezone-tracking-option flag is set. | 92 * --disable-timezone-tracking-option flag is set. |
| 81 * @private | 93 * @private |
| 82 */ | 94 */ |
| 83 hideTimeZoneDetection_: { | 95 hideTimeZoneDetection_: { |
| 84 type: Boolean, | 96 type: Boolean, |
| 85 value: function() { | 97 value: function() { |
| 86 return loadTimeData.valueExists('hideTimeZoneDetection') && | 98 return loadTimeData.valueExists('hideTimeZoneDetection') && |
| 87 loadTimeData.getBoolean('hideTimeZoneDetection'); | 99 loadTimeData.getBoolean('hideTimeZoneDetection'); |
| 88 }, | 100 }, |
| 89 readOnly: true, | 101 readOnly: true, |
| 90 }, | 102 }, |
| 103 | |
| 104 /** | |
| 105 * Initialized with the current time zone so the menu displays the | |
| 106 * correct value. The full option list is fetched lazily if necessary by | |
| 107 * maybeGetTimeZoneList_. | |
| 108 * @private {!DropdownMenuOptionList} | |
| 109 */ | |
| 110 timeZoneList_: { | |
| 111 type: Array, | |
| 112 value: function() { | |
| 113 return [{ | |
| 114 name: loadTimeData.getString('timeZoneName'), | |
| 115 value: loadTimeData.getString('timeZoneID'), | |
| 116 }]; | |
| 117 }, | |
| 118 }, | |
| 91 }, | 119 }, |
| 92 | 120 |
| 93 observers: [ | 121 observers: [ |
| 94 // TODO(michaelpg): Implement a BrowserProxy to listen for policy changes. | 122 'maybeGetTimeZoneList_(' + |
| 95 'updateTimeZoneDetectionCheckbox_(' + | 123 'prefs.cros.system.timezone.value, timeZoneAutoDetect_)', |
| 96 'prefs.settings.resolve_timezone_by_geolocation.value,' + | |
| 97 'systemTimeZoneManaged_,' + | |
| 98 'systemTimeZoneDetectionManaged_,' + | |
| 99 'systemTimeZoneDetectionPolicyValue_)', | |
| 100 ], | 124 ], |
| 101 | 125 |
| 126 attached: function() { | |
| 127 this.addWebUIListener( | |
| 128 'time-zone-auto-detect-policy', | |
| 129 this.onTimeZoneAutoDetectPolicyChanged_.bind(this)); | |
| 130 chrome.send('dateTimePageReady'); | |
| 131 | |
| 132 this.maybeGetTimeZoneList_(); | |
| 133 }, | |
| 134 | |
| 102 /** | 135 /** |
| 103 * Processes all the time zone preferences and policy interactions in one | 136 * @param {boolean} managed Whether the auto-detect setting is controlled. |
| 104 * observer function instead of complicating the HTML with computed bindings. | 137 * @param {boolean} valueFromPolicy The value of the auto-detect setting |
| 105 * @param {boolean} userPrefValue | 138 * forced by policy. |
| 106 * @param {boolean} systemTimeZoneManaged | 139 * @private |
| 107 * @param {boolean} systemTimeZoneDetectionManaged | |
| 108 * @param {?settings.AutomaticTimezoneDetectionPolicy} | |
| 109 * systemTimeZoneDetectionPolicyValue | |
| 110 */ | 140 */ |
| 111 updateTimeZoneDetectionCheckbox_(userPrefValue, | 141 onTimeZoneAutoDetectPolicyChanged_: function(managed, valueFromPolicy) { |
| 112 systemTimeZoneManaged, | 142 if (managed) { |
| 113 systemTimeZoneDetectionManaged, | 143 this.timeZoneAutoDetectPolicy_ = valueFromPolicy ? |
| 114 systemTimeZoneDetectionPolicyValue) { | 144 settings.TimeZoneAutoDetectPolicy.FORCED_ON : |
| 115 // Do nothing if the feature is disabled by a flag. | 145 settings.TimeZoneAutoDetectPolicy.FORCED_OFF; |
| 116 if (this.hideTimeZoneDetection_) | 146 } else { |
| 147 this.timeZoneAutoDetectPolicy_ = settings.TimeZoneAutoDetectPolicy.NONE; | |
| 148 } | |
| 149 }, | |
| 150 | |
| 151 /** | |
| 152 * @param {!Event} e | |
| 153 * @private | |
| 154 */ | |
| 155 onTimeZoneAutoDetectCheckboxChange_: function(e) { | |
| 156 this.setPrefValue( | |
| 157 'settings.resolve_timezone_by_geolocation', e.target.checked); | |
| 158 }, | |
| 159 | |
| 160 /** | |
| 161 * @param {settings.TimeZoneAutoDetectPolicy} timeZoneAutoDetectPolicy | |
| 162 * @return {boolean} | |
| 163 * @private | |
| 164 */ | |
| 165 computeHasTimeZoneAutoDetectPolicy_: function(timeZoneAutoDetectPolicy) { | |
| 166 return timeZoneAutoDetectPolicy != settings.TimeZoneAutoDetectPolicy.NONE; | |
| 167 }, | |
| 168 | |
| 169 /** | |
| 170 * @param {settings.TimeZoneAutoDetectPolicy} timeZoneAutoDetectPolicy | |
| 171 * @param {boolean} prefValue Value of the geolocation pref. | |
| 172 * @param {boolean} hidden Whether the auto detect setting is hidden. | |
| 173 * @return {boolean} Whether time zone auto-detect is enabled. | |
| 174 * @private | |
| 175 */ | |
| 176 computeTimeZoneAutoDetect_: function( | |
| 177 timeZoneAutoDetectPolicy, prefValue, hidden) { | |
| 178 if (hidden) | |
| 179 return false; | |
| 180 | |
| 181 switch (timeZoneAutoDetectPolicy) { | |
| 182 case settings.TimeZoneAutoDetectPolicy.NONE: | |
| 183 return prefValue; | |
| 184 case settings.TimeZoneAutoDetectPolicy.FORCED_ON: | |
| 185 return true; | |
| 186 case settings.TimeZoneAutoDetectPolicy.FORCED_OFF: | |
| 187 return false; | |
| 188 default: | |
| 189 assertNotReached(); | |
| 190 } | |
| 191 }, | |
| 192 | |
| 193 /** | |
| 194 * Fetches the list of time zones if necessary. | |
| 195 * @private | |
| 196 */ | |
| 197 maybeGetTimeZoneList_: function() { | |
| 198 // Only fetch the list once. | |
| 199 if (this.timeZoneList_.length > 1 || !CrSettingsPrefs.isInitialized) | |
| 117 return; | 200 return; |
| 118 | 201 |
| 119 var checkbox = this.$.timeZoneDetectionCheckbox; | 202 // If auto-detect is enabled, we only need the current time zone. |
| 120 | 203 if (this.timeZoneAutoDetect_ && |
| 121 // Time zone auto-detection is disabled when the time zone is managed. | 204 this.getPref('cros.system.timezone').value == |
| 122 if (systemTimeZoneManaged) { | 205 this.timeZoneList_[0].value) { |
| 123 checkbox.disabled = true; | |
| 124 checkbox.checked = false; | |
| 125 return; | 206 return; |
| 126 } | 207 } |
| 127 | 208 |
| 128 // The time zone auto-detection policy may force-disable auto-detection. | 209 cr.sendWithPromise('getTimeZones').then(this.setTimeZoneList_.bind(this)); |
| 129 if (systemTimeZoneDetectionManaged && | |
| 130 systemTimeZoneDetectionPolicyValue != | |
| 131 settings.AutomaticTimezoneDetectionPolicy.USERS_DECIDE) { | |
| 132 checkbox.disabled = true; | |
| 133 checkbox.checked = | |
| 134 systemTimeZoneDetectionPolicyValue != | |
| 135 settings.AutomaticTimezoneDetectionPolicy.DISABLED; | |
| 136 return; | |
| 137 } | |
| 138 | |
| 139 // If there is no policy, or the policy is USERS_DECIDE, the pref is used. | |
| 140 checkbox.disabled = false; | |
| 141 checkbox.checked = userPrefValue; | |
| 142 }, | 210 }, |
| 143 | 211 |
| 144 /** @param {!Event} e */ | 212 /** |
| 145 onTimeZoneDetectionCheckboxChange_: function(e) { | 213 * Converts the C++ response into an array of menu options. |
| 146 this.setPrefValue( | 214 * @param {!Array<!Array<string>>} timeZones C++ time zones response. |
| 147 'settings.resolve_timezone_by_geolocation', e.target.checked); | 215 * @private |
| 216 */ | |
| 217 setTimeZoneList_: function(timeZones) { | |
| 218 this.timeZoneList_ = timeZones.map(function(timeZonePair) { | |
| 219 return { | |
| 220 name: timeZonePair[1], | |
| 221 value: timeZonePair[0], | |
| 222 }; | |
| 223 }); | |
| 148 }, | 224 }, |
| 149 }); | 225 }); |
| OLD | NEW |