OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 // TODO(sail): Refactor options_page and remove this include. | |
6 <include src="options/options_page.js"/> | |
7 <include src="sync_setup_overlay.js"/> | |
8 | |
9 cr.define('sync_promo', function() { | |
10 /** | |
11 * SyncPromo class | |
12 * Subclass of options.SyncSetupOverlay that customizes the sync setup | |
13 * overlay for use in the new tab page. | |
14 * @class | |
15 */ | |
16 function SyncPromo() { | |
17 options.SyncSetupOverlay.call(this, 'syncSetup', | |
18 templateData.syncSetupOverlayTitle, | |
19 'sync-setup-overlay'); | |
20 } | |
21 | |
22 // Replicating enum from chrome/common/extensions/extension_constants.h. | |
23 const actions = (function() { | |
24 var i = 0; | |
25 return { | |
26 VIEWED: i++, | |
27 LEARN_MORE_CLICKED: i++, | |
28 ACCOUNT_HELP_CLICKED: i++, | |
29 CREATE_ACCOUNT_CLICKED: i++, | |
30 SKIP_CLICKED: i++, | |
31 SIGN_IN_ATTEMPTED: i++, | |
32 SIGNED_IN_SUCCESSFULLY: i++, | |
33 ADVANCED_CLICKED: i++, | |
34 ENCRYPTION_HELP_CLICKED: i++, | |
35 CANCELLED_AFTER_SIGN_IN: i++, | |
36 CONFIRMED_AFTER_SIGN_IN: i++, | |
37 CLOSED_TAB: i++, | |
38 CLOSED_WINDOW: i++, | |
39 LEFT_DURING_THROBBER: i++, | |
40 }; | |
41 }()); | |
42 | |
43 cr.addSingletonGetter(SyncPromo); | |
44 | |
45 SyncPromo.prototype = { | |
46 __proto__: options.SyncSetupOverlay.prototype, | |
47 | |
48 showOverlay_: function() { | |
49 $('sync-setup-overlay').hidden = false; | |
50 }, | |
51 | |
52 closeOverlay_: function() { | |
53 chrome.send('SyncPromo:Close'); | |
54 }, | |
55 | |
56 // Initializes the page. | |
57 initializePage: function() { | |
58 localStrings = new LocalStrings(); | |
59 | |
60 options.SyncSetupOverlay.prototype.initializePage.call(this); | |
61 | |
62 // Hide parts of the login UI and show the promo UI. | |
63 this.hideOuterLoginUI_(); | |
64 $('sync-setup-login-promo-column').hidden = false; | |
65 $('promo-skip').hidden = false; | |
66 | |
67 this.showSetupUI_(); | |
68 chrome.send('SyncPromo:Initialize'); | |
69 | |
70 var self = this; | |
71 | |
72 $('promo-skip-button').addEventListener('click', function() { | |
73 chrome.send('SyncPromo:UserSkipped'); | |
74 self.closeOverlay_(); | |
75 }); | |
76 | |
77 var learnMoreClickedAlready = false; | |
78 $('promo-learn-more-show').addEventListener('click', function() { | |
79 self.showLearnMore_(true); | |
80 if (!learnMoreClickedAlready) | |
81 chrome.send('SyncPromo:UserFlowAction', [actions.LEARN_MORE_CLICKED]); | |
82 learnMoreClickedAlready = true; | |
83 }); | |
84 | |
85 $('promo-learn-more-hide').addEventListener('click', function() { | |
86 self.showLearnMore_(false); | |
87 }); | |
88 | |
89 $('promo-advanced').addEventListener('click', function() { | |
90 chrome.send('SyncPromo:ShowAdvancedSettings'); | |
91 }); | |
92 | |
93 var accountHelpClickedAlready = false; | |
94 $('cannot-access-account-link').addEventListener('click', function() { | |
95 if (!accountHelpClickedAlready) | |
96 chrome.send('SyncPromo:UserFlowAction', | |
97 [actions.ACCOUNT_HELP_CLICKED]); | |
98 accountHelpClickedAlready = true; | |
99 }); | |
100 | |
101 var createAccountClickedAlready = false; | |
102 $('create-account-link').addEventListener('click', function() { | |
103 if (!createAccountClickedAlready) | |
104 chrome.send('SyncPromo:UserFlowAction', | |
105 [actions.CREATE_ACCOUNT_CLICKED]); | |
106 createAccountClickedAlready = true; | |
107 }); | |
108 | |
109 // We listen to the <form>'s submit vs. the <input type="submit"> click so | |
110 // we also track users that use the keyboard and press enter. | |
111 var signInAttemptedAlready = false; | |
112 $('gaia-login-form').addEventListener('submit', function() { | |
113 ++self.signInAttempts_; | |
114 if (!signInAttemptedAlready) | |
115 chrome.send('SyncPromo:UserFlowAction', [actions.SIGN_IN_ATTEMPTED]); | |
116 signInAttemptedAlready = true; | |
117 }); | |
118 | |
119 var encryptionHelpClickedAlready = false; | |
120 $('encryption-help-link').addEventListener('click', function() { | |
121 if (!encryptionHelpClickedAlready ) | |
122 chrome.send('SyncPromo:UserFlowAction', | |
123 [actions.ENCRYPTION_HELP_CLICKED]); | |
124 encryptionHelpClickedAlready = true; | |
125 }); | |
126 | |
127 var advancedOptionsClickedAlready = false; | |
128 $('customize-link').addEventListener('click', function() { | |
129 if (!advancedOptionsClickedAlready) | |
130 chrome.send('SyncPromo:UserFlowAction', [actions.ADVANCED_CLICKED]); | |
131 advancedOptionsClickedAlready = true; | |
132 }); | |
133 | |
134 // Re-used across both cancel buttons after a successful sign in. | |
135 var cancelFunc = function() { | |
136 chrome.send('SyncPromo:UserFlowAction', | |
137 [actions.CANCELLED_AFTER_SIGN_IN]); | |
138 }; | |
139 $('confirm-everything-cancel').addEventListener('click', cancelFunc); | |
140 $('choose-datatypes-cancel').addEventListener('click', cancelFunc); | |
141 | |
142 this.infographic_ = $('promo-infographic'); | |
143 this.learnMore_ = $('promo-information'); | |
144 | |
145 this.infographic_.addEventListener('webkitTransitionEnd', | |
146 this.toggleHidden_.bind(this)); | |
147 this.learnMore_.addEventListener('webkitTransitionEnd', | |
148 this.toggleHidden_.bind(this)); | |
149 }, | |
150 | |
151 /** | |
152 * Called when the page is unloading to record number of times a user tried | |
153 * to sign in and if they left while a throbber was running. | |
154 * @private | |
155 */ | |
156 recordPageViewActions_: function() { | |
157 chrome.send('SyncPromo:RecordSignInAttempts', [this.signInAttempts_]); | |
158 if (this.throbberStart_) | |
159 chrome.send('SyncPromo:UserFlowAction', [actions.LEFT_DURING_THROBBER]); | |
160 }, | |
161 | |
162 /** | |
163 * Remove the [hidden] attribute from the node that was not previously | |
164 * transitioning. | |
165 * @param {Event} e A -webkit-transition end event. | |
166 * @private | |
167 */ | |
168 toggleHidden_: function(e) { | |
169 // Only show the other element if the target of this event was hidden | |
170 // (showing also triggers a transition end). | |
171 if (e.target.hidden) { | |
172 if (e.target === this.infographic_) | |
173 this.learnMore_.hidden = false; | |
174 else | |
175 this.infographic_.hidden = false; | |
176 } | |
177 }, | |
178 | |
179 /** | |
180 * Shows or hides the sync information. | |
181 * @param {Boolean} show True if sync information should be shown, false | |
182 * otherwise. | |
183 * @private | |
184 */ | |
185 showLearnMore_: function(show) { | |
186 $('promo-learn-more-show').hidden = show; | |
187 $('promo-learn-more-hide').hidden = !show; | |
188 // Setting [hidden] triggers a transition, which (when ended) will trigger | |
189 // this.toggleHidden_. | |
190 (show ? this.infographic_ : this.learnMore_).hidden = true; | |
191 }, | |
192 | |
193 /** @inheritDoc */ | |
194 sendConfiguration_: function() { | |
195 chrome.send('SyncPromo:UserFlowAction', | |
196 [actions.CONFIRMED_AFTER_SIGN_IN]); | |
197 options.SyncSetupOverlay.prototype.sendConfiguration_.apply(this, | |
198 arguments); | |
199 }, | |
200 | |
201 /** | |
202 * Shows or hides the title of the promo page. | |
203 * @param {Boolean} visible true if the title should be visible, false | |
204 * otherwise. | |
205 * @private | |
206 */ | |
207 setPromoTitleVisible_: function(visible) { | |
208 $('promo-title').hidden = !visible; | |
209 }, | |
210 | |
211 /** @inheritDoc */ | |
212 setThrobbersVisible_: function(visible) { | |
213 if (visible) { | |
214 this.throbberStart_ = Date.now(); | |
215 } else { | |
216 if (this.throbberStart_) { | |
217 chrome.send('SyncPromo:RecordThrobberTime', | |
218 [Date.now() - this.throbberStart_]); | |
219 } | |
220 this.throbberStart_ = 0; | |
221 } | |
222 // Pass through to SyncSetupOverlay to handle display logic. | |
223 options.SyncSetupOverlay.prototype.setThrobbersVisible_.apply( | |
224 this, arguments); | |
225 }, | |
226 | |
227 /** | |
228 * Number of times a user attempted to sign in to GAIA during this page | |
229 * view. | |
230 * @private | |
231 */ | |
232 signInAttempts_: 0, | |
233 | |
234 /** | |
235 * The start time of a throbber on the page. | |
236 * @private | |
237 */ | |
238 throbberStart_: 0, | |
239 }; | |
240 | |
241 SyncPromo.showErrorUI = function() { | |
242 SyncPromo.getInstance().showErrorUI_(); | |
243 }; | |
244 | |
245 SyncPromo.showSetupUI = function() { | |
246 SyncPromo.getInstance().showSetupUI_(); | |
247 }; | |
248 | |
249 SyncPromo.showSyncSetupPage = function(page, args) { | |
250 SyncPromo.getInstance().showSyncSetupPage_(page, args); | |
251 }; | |
252 | |
253 SyncPromo.showSuccessAndClose = function() { | |
254 SyncPromo.getInstance().showSuccessAndClose_(); | |
255 }; | |
256 | |
257 SyncPromo.showSuccessAndSettingUp = function() { | |
258 chrome.send('SyncPromo:UserFlowAction', [actions.SIGNED_IN_SUCCESSFULLY]); | |
259 SyncPromo.getInstance().showSuccessAndSettingUp_(); | |
260 }; | |
261 | |
262 SyncPromo.showStopSyncingUI = function() { | |
263 SyncPromo.getInstance().showStopSyncingUI_(); | |
264 }; | |
265 | |
266 SyncPromo.initialize = function() { | |
267 SyncPromo.getInstance().initializePage(); | |
268 }; | |
269 | |
270 SyncPromo.setPromoTitleVisible = function(visible) { | |
271 SyncPromo.getInstance().setPromoTitleVisible_(visible); | |
272 }; | |
273 | |
274 SyncPromo.recordPageViewActions = function() { | |
275 SyncPromo.getInstance().recordPageViewActions_(); | |
276 }; | |
277 | |
278 SyncPromo.populatePromoMessage = function(resName) { | |
279 SyncPromo.getInstance().populatePromoMessage_(resName); | |
280 }; | |
281 | |
282 // Export | |
283 return { | |
284 SyncPromo: SyncPromo | |
285 }; | |
286 }); | |
287 | |
288 var OptionsPage = options.OptionsPage; | |
289 var SyncSetupOverlay = sync_promo.SyncPromo; | |
290 window.addEventListener('DOMContentLoaded', sync_promo.SyncPromo.initialize); | |
291 window.addEventListener('beforeunload', | |
292 sync_promo.SyncPromo.recordPageViewActions.bind(sync_promo.SyncPromo)); | |
OLD | NEW |