| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 A dialog allowing the user to turn off the Easy Unlock feature. | 6 * @fileoverview A dialog allowing the user to turn off the Easy Unlock feature. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 (function() { | 9 cr.exportPath('settings'); |
| 10 | 10 |
| 11 /** | 11 /** |
| 12 * Possible UI statuses for the EasyUnlockTurnOffDialogElement. | 12 * Possible UI statuses for the EasyUnlockTurnOffDialogElement. |
| 13 * See easy_unlock_settings_handler.cc. | 13 * See easy_unlock_settings_handler.cc. |
| 14 * @enum {string} | 14 * @enum {string} |
| 15 */ | 15 */ |
| 16 var EasyUnlockTurnOffStatus = { | 16 settings.EasyUnlockTurnOffStatus = { |
| 17 UNKNOWN: 'unknown', | 17 UNKNOWN: 'unknown', |
| 18 OFFLINE: 'offline', | 18 OFFLINE: 'offline', |
| 19 IDLE: 'idle', | 19 IDLE: 'idle', |
| 20 PENDING: 'pending', | 20 PENDING: 'pending', |
| 21 SERVER_ERROR: 'server-error', | 21 SERVER_ERROR: 'server-error', |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 (function() { |
| 25 |
| 24 Polymer({ | 26 Polymer({ |
| 25 is: 'easy-unlock-turn-off-dialog', | 27 is: 'easy-unlock-turn-off-dialog', |
| 26 | 28 |
| 27 behaviors: [I18nBehavior, WebUIListenerBehavior], | 29 behaviors: [I18nBehavior, WebUIListenerBehavior], |
| 28 | 30 |
| 29 properties: { | 31 properties: { |
| 30 /** @private {!EasyUnlockTurnOffStatus} */ | 32 /** @private {!settings.EasyUnlockTurnOffStatus} */ |
| 31 status_: { | 33 status_: { |
| 32 type: String, | 34 type: String, |
| 33 value: EasyUnlockTurnOffStatus.UNKNOWN, | 35 value: settings.EasyUnlockTurnOffStatus.UNKNOWN, |
| 34 }, | 36 }, |
| 35 }, | 37 }, |
| 36 | 38 |
| 37 /** @private {settings.EasyUnlockBrowserProxy} */ | 39 /** @private {settings.EasyUnlockBrowserProxy} */ |
| 38 browserProxy_: null, | 40 browserProxy_: null, |
| 39 | 41 |
| 40 /** @override */ | 42 /** @override */ |
| 41 attached: function() { | 43 attached: function() { |
| 42 this.browserProxy_ = settings.EasyUnlockBrowserProxyImpl.getInstance(); | 44 this.browserProxy_ = settings.EasyUnlockBrowserProxyImpl.getInstance(); |
| 43 | 45 |
| 44 this.addWebUIListener( | 46 this.addWebUIListener( |
| 45 'easy-unlock-enabled-status', | 47 'easy-unlock-enabled-status', |
| 46 this.handleEasyUnlockEnabledStatusChanged_.bind(this)); | 48 this.handleEasyUnlockEnabledStatusChanged_.bind(this)); |
| 47 | 49 |
| 48 this.addWebUIListener( | 50 this.addWebUIListener( |
| 49 'easy-unlock-turn-off-flow-status', | 51 'easy-unlock-turn-off-flow-status', |
| 50 function(status) { this.status_ = status; }.bind(this)); | 52 function(status) { this.status_ = status; }.bind(this)); |
| 51 | 53 |
| 52 // Since the dialog text depends on the status, defer opening until we have | 54 // Since the dialog text depends on the status, defer opening until we have |
| 53 // retrieved the turn off status to prevent UI flicker. | 55 // retrieved the turn off status to prevent UI flicker. |
| 54 this.getTurnOffStatus_().then(function(status) { | 56 this.getTurnOffStatus_().then(function(status) { |
| 55 this.status_ = status; | 57 this.status_ = status; |
| 56 this.$.dialog.showModal(); | 58 this.$.dialog.showModal(); |
| 57 }.bind(this)); | 59 }.bind(this)); |
| 58 }, | 60 }, |
| 59 | 61 |
| 60 /** | 62 /** |
| 61 * @return {!Promise<!EasyUnlockTurnOffStatus>} | 63 * @return {!Promise<!settings.EasyUnlockTurnOffStatus>} |
| 62 * @private | 64 * @private |
| 63 */ | 65 */ |
| 64 getTurnOffStatus_: function() { | 66 getTurnOffStatus_: function() { |
| 65 return navigator.onLine ? | 67 return navigator.onLine ? |
| 66 this.browserProxy_.getTurnOffFlowStatus() : | 68 this.browserProxy_.getTurnOffFlowStatus() : |
| 67 Promise.resolve(EasyUnlockTurnOffStatus.OFFLINE); | 69 Promise.resolve(settings.EasyUnlockTurnOffStatus.OFFLINE); |
| 68 }, | 70 }, |
| 69 | 71 |
| 70 /** | 72 /** |
| 71 * This dialog listens for Easy Unlock to become disabled. This signals | 73 * This dialog listens for Easy Unlock to become disabled. This signals |
| 72 * that the turnoff process has succeeded. Regardless of whether the turnoff | 74 * that the turnoff process has succeeded. Regardless of whether the turnoff |
| 73 * was initiated from this tab or another, this closes the dialog. | 75 * was initiated from this tab or another, this closes the dialog. |
| 74 * @param {boolean} easyUnlockEnabled | 76 * @param {boolean} easyUnlockEnabled |
| 75 * @private | 77 * @private |
| 76 */ | 78 */ |
| 77 handleEasyUnlockEnabledStatusChanged_: function(easyUnlockEnabled) { | 79 handleEasyUnlockEnabledStatusChanged_: function(easyUnlockEnabled) { |
| 78 var dialog = /** @type {!CrDialogElement} */ this.$.dialog; | 80 var dialog = /** @type {!CrDialogElement} */ this.$.dialog; |
| 79 if (!easyUnlockEnabled && dialog.open) | 81 if (!easyUnlockEnabled && dialog.open) |
| 80 this.onCancelTap_(); | 82 this.onCancelTap_(); |
| 81 }, | 83 }, |
| 82 | 84 |
| 83 /** @private */ | 85 /** @private */ |
| 84 onCancelTap_: function() { | 86 onCancelTap_: function() { |
| 85 this.browserProxy_.cancelTurnOffFlow(); | 87 this.browserProxy_.cancelTurnOffFlow(); |
| 86 this.$.dialog.close(); | 88 this.$.dialog.close(); |
| 87 }, | 89 }, |
| 88 | 90 |
| 89 /** @private */ | 91 /** @private */ |
| 90 onTurnOffTap_: function() { | 92 onTurnOffTap_: function() { |
| 91 this.browserProxy_.startTurnOffFlow(); | 93 this.browserProxy_.startTurnOffFlow(); |
| 92 }, | 94 }, |
| 93 | 95 |
| 94 /** | 96 /** |
| 95 * @param {!EasyUnlockTurnOffStatus} status | 97 * @param {!settings.EasyUnlockTurnOffStatus} status |
| 96 * @return {string} | 98 * @return {string} |
| 97 * @private | 99 * @private |
| 98 */ | 100 */ |
| 99 getTitleText_: function(status) { | 101 getTitleText_: function(status) { |
| 100 switch (status) { | 102 switch (status) { |
| 101 case EasyUnlockTurnOffStatus.OFFLINE: | 103 case settings.EasyUnlockTurnOffStatus.OFFLINE: |
| 102 return this.i18n('easyUnlockTurnOffOfflineTitle'); | 104 return this.i18n('easyUnlockTurnOffOfflineTitle'); |
| 103 case EasyUnlockTurnOffStatus.UNKNOWN: | 105 case settings.EasyUnlockTurnOffStatus.UNKNOWN: |
| 104 case EasyUnlockTurnOffStatus.IDLE: | 106 case settings.EasyUnlockTurnOffStatus.IDLE: |
| 105 case EasyUnlockTurnOffStatus.PENDING: | 107 case settings.EasyUnlockTurnOffStatus.PENDING: |
| 106 return this.i18n('easyUnlockTurnOffTitle'); | 108 return this.i18n('easyUnlockTurnOffTitle'); |
| 107 case EasyUnlockTurnOffStatus.SERVER_ERROR: | 109 case settings.EasyUnlockTurnOffStatus.SERVER_ERROR: |
| 108 return this.i18n('easyUnlockTurnOffErrorTitle'); | 110 return this.i18n('easyUnlockTurnOffErrorTitle'); |
| 109 } | 111 } |
| 110 assertNotReached(); | 112 assertNotReached(); |
| 111 }, | 113 }, |
| 112 | 114 |
| 113 /** | 115 /** |
| 114 * @param {!EasyUnlockTurnOffStatus} status | 116 * @param {!settings.EasyUnlockTurnOffStatus} status |
| 115 * @return {string} | 117 * @return {string} |
| 116 * @private | 118 * @private |
| 117 */ | 119 */ |
| 118 getDescriptionText_: function(status) { | 120 getDescriptionText_: function(status) { |
| 119 switch (status) { | 121 switch (status) { |
| 120 case EasyUnlockTurnOffStatus.OFFLINE: | 122 case settings.EasyUnlockTurnOffStatus.OFFLINE: |
| 121 return this.i18n('easyUnlockTurnOffOfflineMessage'); | 123 return this.i18n('easyUnlockTurnOffOfflineMessage'); |
| 122 case EasyUnlockTurnOffStatus.UNKNOWN: | 124 case settings.EasyUnlockTurnOffStatus.UNKNOWN: |
| 123 case EasyUnlockTurnOffStatus.IDLE: | 125 case settings.EasyUnlockTurnOffStatus.IDLE: |
| 124 case EasyUnlockTurnOffStatus.PENDING: | 126 case settings.EasyUnlockTurnOffStatus.PENDING: |
| 125 return this.i18n('easyUnlockTurnOffDescription'); | 127 return this.i18n('easyUnlockTurnOffDescription'); |
| 126 case EasyUnlockTurnOffStatus.SERVER_ERROR: | 128 case settings.EasyUnlockTurnOffStatus.SERVER_ERROR: |
| 127 return this.i18n('easyUnlockTurnOffErrorMessage'); | 129 return this.i18n('easyUnlockTurnOffErrorMessage'); |
| 128 } | 130 } |
| 129 assertNotReached(); | 131 assertNotReached(); |
| 130 }, | 132 }, |
| 131 | 133 |
| 132 /** | 134 /** |
| 133 * @param {!EasyUnlockTurnOffStatus} status | 135 * @param {!settings.EasyUnlockTurnOffStatus} status |
| 134 * @return {string} | 136 * @return {string} |
| 135 * @private | 137 * @private |
| 136 */ | 138 */ |
| 137 getTurnOffButtonText_: function(status) { | 139 getTurnOffButtonText_: function(status) { |
| 138 switch (status) { | 140 switch (status) { |
| 139 case EasyUnlockTurnOffStatus.OFFLINE: | 141 case settings.EasyUnlockTurnOffStatus.OFFLINE: |
| 140 return ''; | 142 return ''; |
| 141 case EasyUnlockTurnOffStatus.UNKNOWN: | 143 case settings.EasyUnlockTurnOffStatus.UNKNOWN: |
| 142 case EasyUnlockTurnOffStatus.IDLE: | 144 case settings.EasyUnlockTurnOffStatus.IDLE: |
| 143 case EasyUnlockTurnOffStatus.PENDING: | 145 case settings.EasyUnlockTurnOffStatus.PENDING: |
| 144 return this.i18n('easyUnlockTurnOffButton'); | 146 return this.i18n('easyUnlockTurnOffButton'); |
| 145 case EasyUnlockTurnOffStatus.SERVER_ERROR: | 147 case settings.EasyUnlockTurnOffStatus.SERVER_ERROR: |
| 146 return this.i18n('easyUnlockTurnOffRetryButton'); | 148 return this.i18n('easyUnlockTurnOffRetryButton'); |
| 147 } | 149 } |
| 148 assertNotReached(); | 150 assertNotReached(); |
| 149 }, | 151 }, |
| 150 | 152 |
| 151 /** | 153 /** |
| 152 * @param {!EasyUnlockTurnOffStatus} status | 154 * @param {!settings.EasyUnlockTurnOffStatus} status |
| 153 * @return {boolean} | 155 * @return {boolean} |
| 154 * @private | 156 * @private |
| 155 */ | 157 */ |
| 156 isButtonBarHidden_: function(status) { | 158 isButtonBarHidden_: function(status) { |
| 157 return status == EasyUnlockTurnOffStatus.OFFLINE; | 159 return status == settings.EasyUnlockTurnOffStatus.OFFLINE; |
| 158 }, | 160 }, |
| 159 | 161 |
| 160 /** | 162 /** |
| 161 * @param {!EasyUnlockTurnOffStatus} status | 163 * @param {!settings.EasyUnlockTurnOffStatus} status |
| 162 * @return {boolean} | 164 * @return {boolean} |
| 163 * @private | 165 * @private |
| 164 */ | 166 */ |
| 165 isSpinnerActive_: function(status) { | 167 isSpinnerActive_: function(status) { |
| 166 return status == EasyUnlockTurnOffStatus.PENDING; | 168 return status == settings.EasyUnlockTurnOffStatus.PENDING; |
| 167 }, | 169 }, |
| 168 | 170 |
| 169 /** | 171 /** |
| 170 * @param {!EasyUnlockTurnOffStatus} status | 172 * @param {!settings.EasyUnlockTurnOffStatus} status |
| 171 * @return {boolean} | 173 * @return {boolean} |
| 172 * @private | 174 * @private |
| 173 */ | 175 */ |
| 174 isCancelButtonHidden_: function(status) { | 176 isCancelButtonHidden_: function(status) { |
| 175 return status == EasyUnlockTurnOffStatus.SERVER_ERROR; | 177 return status == settings.EasyUnlockTurnOffStatus.SERVER_ERROR; |
| 176 }, | 178 }, |
| 177 | 179 |
| 178 /** | 180 /** |
| 179 * @param {!EasyUnlockTurnOffStatus} status | 181 * @param {!settings.EasyUnlockTurnOffStatus} status |
| 180 * @return {boolean} | 182 * @return {boolean} |
| 181 * @private | 183 * @private |
| 182 */ | 184 */ |
| 183 isTurnOffButtonEnabled_: function(status) { | 185 isTurnOffButtonEnabled_: function(status) { |
| 184 return status == EasyUnlockTurnOffStatus.IDLE || | 186 return status == settings.EasyUnlockTurnOffStatus.IDLE || |
| 185 status == EasyUnlockTurnOffStatus.SERVER_ERROR; | 187 status == settings.EasyUnlockTurnOffStatus.SERVER_ERROR; |
| 186 }, | 188 }, |
| 187 }); | 189 }); |
| 188 | 190 |
| 189 })(); | 191 })(); |
| OLD | NEW |