| OLD | NEW |
| (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 cr.exportPath('settings'); | |
| 6 | |
| 7 /** | |
| 8 * The state of sync. This is the data structure sent back and forth between | |
| 9 * C++ and JS. Its naming and structure is not optimal, but changing it would | |
| 10 * require changes to the C++ handler, which is already functional. | |
| 11 * @typedef {{ | |
| 12 * appsEnforced: boolean, | |
| 13 * appsRegistered: boolean, | |
| 14 * appsSynced: boolean, | |
| 15 * autofillEnforced: boolean, | |
| 16 * autofillRegistered: boolean, | |
| 17 * autofillSynced: boolean, | |
| 18 * bookmarksEnforced: boolean, | |
| 19 * bookmarksRegistered: boolean, | |
| 20 * bookmarksSynced: boolean, | |
| 21 * encryptAllData: boolean, | |
| 22 * encryptAllDataAllowed: boolean, | |
| 23 * enterGooglePassphraseBody: (string|undefined), | |
| 24 * enterPassphraseBody: (string|undefined), | |
| 25 * extensionsEnforced: boolean, | |
| 26 * extensionsRegistered: boolean, | |
| 27 * extensionsSynced: boolean, | |
| 28 * fullEncryptionBody: string, | |
| 29 * isGooglePassphrase: (boolean|undefined), | |
| 30 * passphrase: (string|undefined), | |
| 31 * passphraseFailed: boolean, | |
| 32 * passwordsEnforced: boolean, | |
| 33 * passwordsRegistered: boolean, | |
| 34 * passwordsSynced: boolean, | |
| 35 * preferencesEnforced: boolean, | |
| 36 * preferencesRegistered: boolean, | |
| 37 * preferencesSynced: boolean, | |
| 38 * showPassphrase: boolean, | |
| 39 * syncAllDataTypes: boolean, | |
| 40 * syncNothing: boolean, | |
| 41 * tabsEnforced: boolean, | |
| 42 * tabsRegistered: boolean, | |
| 43 * tabsSynced: boolean, | |
| 44 * themesEnforced: boolean, | |
| 45 * themesRegistered: boolean, | |
| 46 * themesSynced: boolean, | |
| 47 * typedUrlsEnforced: boolean, | |
| 48 * typedUrlsRegistered: boolean, | |
| 49 * typedUrlsSynced: boolean, | |
| 50 * usePassphrase: boolean, | |
| 51 * wifiCredentialsEnforced: (boolean|undefined), | |
| 52 * wifiCredentialsSynced: (boolean|undefined) | |
| 53 * }} | |
| 54 */ | |
| 55 settings.SyncPrefs; | |
| 56 | |
| 57 /** | |
| 58 * @typedef {{actionLinkText: (string|undefined), | |
| 59 * childUser: (boolean|undefined), | |
| 60 * hasError: (boolean|undefined), | |
| 61 * hasUnrecoverableError: (boolean|undefined), | |
| 62 * iconURL: (string|undefined), | |
| 63 * managed: (boolean|undefined), | |
| 64 * name: (string|undefined), | |
| 65 * setupCompleted: (boolean|undefined), | |
| 66 * setupInProgress: (boolean|undefined), | |
| 67 * signedIn: (boolean|undefined), | |
| 68 * signinAllowed: (boolean|undefined), | |
| 69 * signoutAllowed: (boolean|undefined), | |
| 70 * statusText: (string|undefined), | |
| 71 * supervisedUser: (boolean|undefined), | |
| 72 * syncSystemEnabled: (boolean|undefined)}} | |
| 73 * @see chrome/browser/ui/webui/settings/sync_handler.cc | |
| 74 */ | |
| 75 settings.SyncStatus; | |
| 76 | |
| 77 /** | |
| 78 * @enum {string} | |
| 79 */ | |
| 80 settings.PageStatus = { | |
| 81 SPINNER: 'spinner', // Before the page has loaded. | |
| 82 CONFIGURE: 'configure', // Preferences ready to be configured. | |
| 83 TIMEOUT: 'timeout', // Preferences loading has timed out. | |
| 84 DONE: 'done', // Sync subpage can be closed now. | |
| 85 PASSPHRASE_ERROR: 'passphraseError', // Error in the passphrase. | |
| 86 }; | |
| 87 | |
| 88 cr.define('settings', function() { | |
| 89 /** | |
| 90 * API which encapsulates messaging between JS and C++ for the sync page. | |
| 91 * @constructor | |
| 92 */ | |
| 93 function SyncPrivateApi() {} | |
| 94 | |
| 95 /** @private {?function(settings.SyncPrefs)} */ | |
| 96 SyncPrivateApi.syncPrefsCallback_ = null; | |
| 97 | |
| 98 /** @private {?function(settings.PageStatus)} */ | |
| 99 SyncPrivateApi.setPageStatusCallback_ = null; | |
| 100 | |
| 101 /** | |
| 102 * Starts the signin process for the user. Does nothing if the user is | |
| 103 * already signed in. | |
| 104 * @private | |
| 105 */ | |
| 106 SyncPrivateApi.startSignIn = function() { | |
| 107 chrome.send('SyncSetupStartSignIn'); | |
| 108 }; | |
| 109 | |
| 110 /** | |
| 111 * Disconnects the signed in user. | |
| 112 * @param {!boolean} deleteProfile | |
| 113 * @private | |
| 114 */ | |
| 115 SyncPrivateApi.disconnect = function(deleteProfile) { | |
| 116 chrome.send('SyncSetupStopSyncing', [deleteProfile]); | |
| 117 }; | |
| 118 | |
| 119 /** | |
| 120 * Determines the appropriate page to show in the Sync Setup UI based on | |
| 121 * the state of the Sync backend. Does nothing if the user is not signed in. | |
| 122 * @private | |
| 123 */ | |
| 124 SyncPrivateApi.showSetupUI = function() { | |
| 125 chrome.send('SyncSetupShowSetupUI'); | |
| 126 chrome.send('coreOptionsUserMetricsAction', ['Options_ShowSyncAdvanced']); | |
| 127 }; | |
| 128 | |
| 129 /** | |
| 130 * Function to invoke when the sync page has been navigated to. This registers | |
| 131 * the UI as the "active" sync UI so that if the user tries to open another | |
| 132 * sync UI, this one will be shown instead. | |
| 133 */ | |
| 134 SyncPrivateApi.didNavigateToSyncPage = function() { | |
| 135 chrome.send('SyncSetupShowSetupUI'); | |
| 136 }; | |
| 137 | |
| 138 /** | |
| 139 * Function to invoke when leaving the sync page so that the C++ layer can be | |
| 140 * notified that the sync UI is no longer open. | |
| 141 */ | |
| 142 SyncPrivateApi.didNavigateAwayFromSyncPage = function() { | |
| 143 SyncPrivateApi.setPageStatusCallback_ = null; | |
| 144 chrome.send('SyncSetupDidClosePage'); | |
| 145 }; | |
| 146 | |
| 147 /** | |
| 148 * Sets the callback to be invoked when sync data has been fetched. | |
| 149 * @param {!function(settings.SyncPrefs)} callback | |
| 150 */ | |
| 151 SyncPrivateApi.setSyncPrefsCallback = function(callback) { | |
| 152 SyncPrivateApi.syncPrefsCallback_ = callback; | |
| 153 }; | |
| 154 | |
| 155 /** | |
| 156 * Handler for when state has been fetched from C++. | |
| 157 * @param {!settings.SyncPrefs} syncPrefsFromCpp | |
| 158 * @private | |
| 159 */ | |
| 160 SyncPrivateApi.sendSyncPrefs_ = function(syncPrefsFromCpp) { | |
| 161 if (SyncPrivateApi.syncPrefsCallback_) | |
| 162 SyncPrivateApi.syncPrefsCallback_(syncPrefsFromCpp); | |
| 163 }; | |
| 164 | |
| 165 /** | |
| 166 * Sets the sync state by sending it to the C++ layer. | |
| 167 * @param {!settings.SyncPrefs} syncPrefs | |
| 168 * @param {!function(settings.PageStatus)} callback | |
| 169 */ | |
| 170 SyncPrivateApi.setSyncPrefs = function(syncPrefs, callback) { | |
| 171 SyncPrivateApi.setPageStatusCallback_ = callback; | |
| 172 chrome.send('SyncSetupConfigure', [JSON.stringify(syncPrefs)]); | |
| 173 }; | |
| 174 | |
| 175 /** | |
| 176 * Handler for when setSyncPrefs() has either succeeded or failed. | |
| 177 * @param {!settings.PageStatus} status | |
| 178 * @private | |
| 179 */ | |
| 180 SyncPrivateApi.setPageStatus_ = function(status) { | |
| 181 if (SyncPrivateApi.setPageStatusCallback_) | |
| 182 SyncPrivateApi.setPageStatusCallback_(status); | |
| 183 | |
| 184 SyncPrivateApi.setPageStatusCallback_ = null; | |
| 185 }; | |
| 186 | |
| 187 /** | |
| 188 * Sends a request from JS to C++ for the current sync status. | |
| 189 * @param {!function(settings.SyncStatus)} callback | |
| 190 */ | |
| 191 SyncPrivateApi.getSyncStatus = function(callback) { | |
| 192 SyncPrivateApi.syncStatusCallback_ = callback; | |
| 193 chrome.send('SyncSetupGetSyncStatus'); | |
| 194 }; | |
| 195 | |
| 196 /** | |
| 197 * Handler for when sync status has been fetched from C++. | |
| 198 * @param {!settings.SyncStatus} syncStatusFromCpp | |
| 199 * @private | |
| 200 */ | |
| 201 SyncPrivateApi.sendSyncStatus = function(syncStatusFromCpp) { | |
| 202 if (SyncPrivateApi.syncStatusCallback_) | |
| 203 SyncPrivateApi.syncStatusCallback_(syncStatusFromCpp); | |
| 204 }; | |
| 205 | |
| 206 /** | |
| 207 * Sends a request from JS to C++ to open the multi-profile User Manager. | |
| 208 */ | |
| 209 SyncPrivateApi.manageOtherPeople = function() { | |
| 210 chrome.send('SyncSetupManageOtherPeople'); | |
| 211 }; | |
| 212 | |
| 213 /** | |
| 214 * This function encapsulates the logic that maps from the legacy | |
| 215 * SyncSettingsHandler to an API natural to the new Polymer implementation. | |
| 216 * @param {!settings.PageStatus} status | |
| 217 * @param {!settings.SyncPrefs} prefs | |
| 218 */ | |
| 219 SyncPrivateApi.showSyncSetupPage = function(status, prefs) { | |
| 220 switch (status) { | |
| 221 case settings.PageStatus.TIMEOUT: | |
| 222 case settings.PageStatus.DONE: | |
| 223 SyncPrivateApi.setPageStatus_(status); | |
| 224 break; | |
| 225 case settings.PageStatus.CONFIGURE: | |
| 226 if (prefs.passphraseFailed) { | |
| 227 SyncPrivateApi.setPageStatus_( | |
| 228 settings.PageStatus.PASSPHRASE_ERROR); | |
| 229 return; | |
| 230 } | |
| 231 | |
| 232 SyncPrivateApi.sendSyncPrefs_(prefs); | |
| 233 break; | |
| 234 default: | |
| 235 // Other statuses (i.e. "spinner") are ignored. | |
| 236 } | |
| 237 }; | |
| 238 | |
| 239 return { | |
| 240 SyncPrivateApi: SyncPrivateApi, | |
| 241 }; | |
| 242 }); | |
| OLD | NEW |