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 * managed: (boolean|undefined), | |
63 * setupCompleted: (boolean|undefined), | |
64 * setupInProgress: (boolean|undefined), | |
65 * signedIn: (boolean|undefined), | |
66 * signinAllowed: (boolean|undefined), | |
67 * signoutAllowed: (boolean|undefined), | |
68 * statusText: (string|undefined), | |
69 * supervisedUser: (boolean|undefined), | |
70 * syncSystemEnabled: (boolean|undefined)}} | |
71 * @see chrome/browser/ui/webui/settings/sync_handler.cc | |
72 */ | |
73 settings.SyncStatus; | |
74 | |
75 /** | |
76 * @enum {string} | |
77 */ | |
78 settings.PageStatus = { | |
79 SPINNER: 'spinner', // Before the page has loaded. | |
80 CONFIGURE: 'configure', // Preferences ready to be configured. | |
81 TIMEOUT: 'timeout', // Preferences loading has timed out. | |
82 DONE: 'done', // Sync subpage can be closed now. | |
83 PASSPHRASE_ERROR: 'passphraseError', // Error in the passphrase. | |
84 }; | |
85 | |
86 cr.define('settings', function() { | |
87 /** | |
88 * API which encapsulates messaging between JS and C++ for the sync page. | |
89 * @constructor | |
90 */ | |
91 function SyncPrivateApi() {} | |
92 | |
93 /** @private {?function(settings.SyncPrefs)} */ | |
94 SyncPrivateApi.syncPrefsCallback_ = null; | |
95 | |
96 /** @private {?function(settings.PageStatus)} */ | |
97 SyncPrivateApi.setPageStatusCallback_ = null; | |
98 | |
99 /** | |
100 * Starts the signin process for the user. Does nothing if the user is | |
101 * already signed in. | |
102 * @private | |
103 */ | |
104 SyncPrivateApi.startSignIn = function() { | |
105 chrome.send('SyncSetupStartSignIn'); | |
106 }; | |
107 | |
108 /** | |
109 * Disconnects the signed in user. | |
110 * @param {!boolean} deleteProfile | |
111 * @private | |
112 */ | |
113 SyncPrivateApi.disconnect = function(deleteProfile) { | |
114 chrome.send('SyncSetupStopSyncing', [deleteProfile]); | |
115 }; | |
116 | |
117 /** | |
118 * Determines the appropriate page to show in the Sync Setup UI based on | |
119 * the state of the Sync backend. Does nothing if the user is not signed in. | |
120 * @private | |
121 */ | |
122 SyncPrivateApi.showSetupUI = function() { | |
123 chrome.send('SyncSetupShowSetupUI'); | |
124 chrome.send('coreOptionsUserMetricsAction', ['Options_ShowSyncAdvanced']); | |
125 }; | |
126 | |
127 /** | |
128 * Function to invoke when the sync page has been navigated to. This registers | |
129 * the UI as the "active" sync UI so that if the user tries to open another | |
130 * sync UI, this one will be shown instead. | |
131 */ | |
132 SyncPrivateApi.didNavigateToSyncPage = function() { | |
133 chrome.send('SyncSetupShowSetupUI'); | |
134 }; | |
135 | |
136 /** | |
137 * Function to invoke when leaving the sync page so that the C++ layer can be | |
138 * notified that the sync UI is no longer open. | |
139 */ | |
140 SyncPrivateApi.didNavigateAwayFromSyncPage = function() { | |
141 SyncPrivateApi.setPageStatusCallback_ = null; | |
142 chrome.send('SyncSetupDidClosePage'); | |
143 }; | |
144 | |
145 /** | |
146 * Sets the callback to be invoked when sync data has been fetched. | |
147 * @param {!function(settings.SyncPrefs)} callback | |
148 */ | |
149 SyncPrivateApi.setSyncPrefsCallback = function(callback) { | |
150 SyncPrivateApi.syncPrefsCallback_ = callback; | |
151 }; | |
152 | |
153 /** | |
154 * Handler for when state has been fetched from C++. | |
155 * @param {!settings.SyncPrefs} syncPrefsFromCpp | |
156 * @private | |
157 */ | |
158 SyncPrivateApi.sendSyncPrefs_ = function(syncPrefsFromCpp) { | |
159 if (SyncPrivateApi.syncPrefsCallback_) | |
160 SyncPrivateApi.syncPrefsCallback_(syncPrefsFromCpp); | |
161 }; | |
162 | |
163 /** | |
164 * Sets the sync state by sending it to the C++ layer. | |
165 * @param {!settings.SyncPrefs} syncPrefs | |
166 * @param {!function(settings.PageStatus)} callback | |
167 */ | |
168 SyncPrivateApi.setSyncPrefs = function(syncPrefs, callback) { | |
169 SyncPrivateApi.setPageStatusCallback_ = callback; | |
170 chrome.send('SyncSetupConfigure', [JSON.stringify(syncPrefs)]); | |
171 }; | |
172 | |
173 /** | |
174 * Handler for when setSyncPrefs() has either succeeded or failed. | |
175 * @param {!settings.PageStatus} status | |
176 * @private | |
177 */ | |
178 SyncPrivateApi.setPageStatus_ = function(status) { | |
179 if (SyncPrivateApi.setPageStatusCallback_) | |
180 SyncPrivateApi.setPageStatusCallback_(status); | |
181 | |
182 SyncPrivateApi.setPageStatusCallback_ = null; | |
183 }; | |
184 | |
185 /** | |
186 * Sends a request from JS to C++ for the current sync status. | |
187 * @param {!function(settings.SyncStatus)} callback | |
188 */ | |
189 SyncPrivateApi.getSyncStatus = function(callback) { | |
190 SyncPrivateApi.syncStatusCallback_ = callback; | |
191 chrome.send('SyncSetupGetSyncStatus'); | |
192 }; | |
193 | |
194 /** | |
195 * Handler for when sync status has been fetched from C++. | |
196 * @param {!settings.SyncStatus} syncStatusFromCpp | |
197 * @private | |
198 */ | |
199 SyncPrivateApi.sendSyncStatus = function(syncStatusFromCpp) { | |
200 if (SyncPrivateApi.syncStatusCallback_) | |
201 SyncPrivateApi.syncStatusCallback_(syncStatusFromCpp); | |
202 }; | |
203 | |
204 /** | |
205 * Sends a request from JS to C++ to open the multi-profile User Manager. | |
206 */ | |
207 SyncPrivateApi.manageOtherPeople = function() { | |
208 chrome.send('SyncSetupManageOtherPeople'); | |
209 }; | |
210 | |
211 /** | |
212 * This function encapsulates the logic that maps from the legacy | |
213 * SyncSettingsHandler to an API natural to the new Polymer implementation. | |
214 * @param {!settings.PageStatus} status | |
215 * @param {!settings.SyncPrefs} prefs | |
216 */ | |
217 SyncPrivateApi.showSyncSetupPage = function(status, prefs) { | |
218 switch (status) { | |
219 case settings.PageStatus.TIMEOUT: | |
220 case settings.PageStatus.DONE: | |
221 SyncPrivateApi.setPageStatus_(status); | |
222 break; | |
223 case settings.PageStatus.CONFIGURE: | |
224 if (prefs.passphraseFailed) { | |
225 SyncPrivateApi.setPageStatus_( | |
226 settings.PageStatus.PASSPHRASE_ERROR); | |
227 return; | |
228 } | |
229 | |
230 SyncPrivateApi.sendSyncPrefs_(prefs); | |
231 break; | |
232 default: | |
233 // Other statuses (i.e. "spinner") are ignored. | |
234 } | |
235 }; | |
236 | |
237 return { | |
238 SyncPrivateApi: SyncPrivateApi, | |
239 }; | |
240 }); | |
OLD | NEW |