Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: chrome/browser/resources/chromeos/mobile_setup.js

Issue 2944703004: Run clang-format on .js files in c/b/r/chromeos (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 cr.define('mobile', function() { 6 cr.define('mobile', function() {
7 7
8 function MobileSetup() { 8 function MobileSetup() {}
9 }
10 9
11 cr.addSingletonGetter(MobileSetup); 10 cr.addSingletonGetter(MobileSetup);
12 11
13 MobileSetup.PLAN_ACTIVATION_UNKNOWN = -2; 12 MobileSetup.PLAN_ACTIVATION_UNKNOWN = -2;
14 MobileSetup.PLAN_ACTIVATION_PAGE_LOADING = -1; 13 MobileSetup.PLAN_ACTIVATION_PAGE_LOADING = -1;
15 MobileSetup.PLAN_ACTIVATION_START = 0; 14 MobileSetup.PLAN_ACTIVATION_START = 0;
16 MobileSetup.PLAN_ACTIVATION_TRYING_OTASP = 1; 15 MobileSetup.PLAN_ACTIVATION_TRYING_OTASP = 1;
17 MobileSetup.PLAN_ACTIVATION_INITIATING_ACTIVATION = 3; 16 MobileSetup.PLAN_ACTIVATION_INITIATING_ACTIVATION = 3;
18 MobileSetup.PLAN_ACTIVATION_RECONNECTING = 4; 17 MobileSetup.PLAN_ACTIVATION_RECONNECTING = 4;
19 MobileSetup.PLAN_ACTIVATION_WAITING_FOR_CONNECTION = 5; 18 MobileSetup.PLAN_ACTIVATION_WAITING_FOR_CONNECTION = 5;
20 MobileSetup.PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING = 6; 19 MobileSetup.PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING = 6;
21 MobileSetup.PLAN_ACTIVATION_SHOWING_PAYMENT = 7; 20 MobileSetup.PLAN_ACTIVATION_SHOWING_PAYMENT = 7;
22 MobileSetup.PLAN_ACTIVATION_RECONNECTING_PAYMENT = 8; 21 MobileSetup.PLAN_ACTIVATION_RECONNECTING_PAYMENT = 8;
23 MobileSetup.PLAN_ACTIVATION_DELAY_OTASP = 9; 22 MobileSetup.PLAN_ACTIVATION_DELAY_OTASP = 9;
24 MobileSetup.PLAN_ACTIVATION_START_OTASP = 10; 23 MobileSetup.PLAN_ACTIVATION_START_OTASP = 10;
25 MobileSetup.PLAN_ACTIVATION_OTASP = 11; 24 MobileSetup.PLAN_ACTIVATION_OTASP = 11;
26 MobileSetup.PLAN_ACTIVATION_DONE = 12; 25 MobileSetup.PLAN_ACTIVATION_DONE = 12;
27 MobileSetup.PLAN_ACTIVATION_ERROR = 0xFF; 26 MobileSetup.PLAN_ACTIVATION_ERROR = 0xFF;
28 27
29 MobileSetup.EXTENSION_PAGE_URL = 28 MobileSetup.EXTENSION_PAGE_URL =
30 'chrome-extension://iadeocfgjdjdmpenejdbfeaocpbikmab'; 29 'chrome-extension://iadeocfgjdjdmpenejdbfeaocpbikmab';
31 MobileSetup.ACTIVATION_PAGE_URL = MobileSetup.EXTENSION_PAGE_URL + 30 MobileSetup.ACTIVATION_PAGE_URL =
32 '/activation.html'; 31 MobileSetup.EXTENSION_PAGE_URL + '/activation.html';
33 MobileSetup.PORTAL_OFFLINE_PAGE_URL = MobileSetup.EXTENSION_PAGE_URL + 32 MobileSetup.PORTAL_OFFLINE_PAGE_URL =
34 '/portal_offline.html'; 33 MobileSetup.EXTENSION_PAGE_URL + '/portal_offline.html';
35 MobileSetup.REDIRECT_POST_PAGE_URL = MobileSetup.EXTENSION_PAGE_URL + 34 MobileSetup.REDIRECT_POST_PAGE_URL =
36 '/redirect.html'; 35 MobileSetup.EXTENSION_PAGE_URL + '/redirect.html';
37 36
38 MobileSetup.prototype = { 37 MobileSetup.prototype = {
39 // Mobile device information. 38 // Mobile device information.
40 deviceInfo_: null, 39 deviceInfo_: null,
41 frameName_: '', 40 frameName_: '',
42 initialized_: false, 41 initialized_: false,
43 fakedTransaction_: false, 42 fakedTransaction_: false,
44 paymentShown_: false, 43 paymentShown_: false,
45 frameLoadError_: 0, 44 frameLoadError_: 0,
46 frameLoadIgnored_: true, 45 frameLoadIgnored_: true,
(...skipping 10 matching lines...) Expand all
57 56
58 initialize: function(frame_name, carrierPage) { 57 initialize: function(frame_name, carrierPage) {
59 if (this.initialized_) { 58 if (this.initialized_) {
60 console.log('calling initialize() again?'); 59 console.log('calling initialize() again?');
61 return; 60 return;
62 } 61 }
63 this.initialized_ = true; 62 this.initialized_ = true;
64 self = this; 63 self = this;
65 this.frameName_ = frame_name; 64 this.frameName_ = frame_name;
66 65
67 cr.ui.dialogs.BaseDialog.OK_LABEL = 66 cr.ui.dialogs.BaseDialog.OK_LABEL = loadTimeData.getString('ok_button');
68 loadTimeData.getString('ok_button');
69 cr.ui.dialogs.BaseDialog.CANCEL_LABEL = 67 cr.ui.dialogs.BaseDialog.CANCEL_LABEL =
70 loadTimeData.getString('cancel_button'); 68 loadTimeData.getString('cancel_button');
71 this.confirm_ = new cr.ui.dialogs.ConfirmDialog(document.body); 69 this.confirm_ = new cr.ui.dialogs.ConfirmDialog(document.body);
72 70
73 window.addEventListener('message', function(e) { 71 window.addEventListener('message', function(e) {
74 self.onMessageReceived_(e); 72 self.onMessageReceived_(e);
75 }); 73 });
76 74
77 $('closeButton').addEventListener('click', function(e) { 75 $('closeButton').addEventListener('click', function(e) {
78 $('finalStatus').classList.add('hidden'); 76 $('finalStatus').classList.add('hidden');
79 }); 77 });
80 78
81 // Kick off activation process. 79 // Kick off activation process.
82 chrome.send('startActivation'); 80 chrome.send('startActivation');
83 }, 81 },
84 82
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 case MobileSetup.PLAN_ACTIVATION_DELAY_OTASP: 152 case MobileSetup.PLAN_ACTIVATION_DELAY_OTASP:
155 case MobileSetup.PLAN_ACTIVATION_START_OTASP: 153 case MobileSetup.PLAN_ACTIVATION_START_OTASP:
156 case MobileSetup.PLAN_ACTIVATION_RECONNECTING: 154 case MobileSetup.PLAN_ACTIVATION_RECONNECTING:
157 case MobileSetup.PLAN_ACTIVATION_RECONNECTING_PAYMENT: 155 case MobileSetup.PLAN_ACTIVATION_RECONNECTING_PAYMENT:
158 // Activation page should not be shown for the simple activation flow. 156 // Activation page should not be shown for the simple activation flow.
159 if (simpleActivationFlow) 157 if (simpleActivationFlow)
160 break; 158 break;
161 159
162 $('statusHeader').textContent = 160 $('statusHeader').textContent =
163 loadTimeData.getString('connecting_header'); 161 loadTimeData.getString('connecting_header');
164 $('auxHeader').textContent = 162 $('auxHeader').textContent = loadTimeData.getString('please_wait');
165 loadTimeData.getString('please_wait');
166 $('paymentForm').classList.add('hidden'); 163 $('paymentForm').classList.add('hidden');
167 $('finalStatus').classList.add('hidden'); 164 $('finalStatus').classList.add('hidden');
168 this.setCarrierPage_(MobileSetup.ACTIVATION_PAGE_URL); 165 this.setCarrierPage_(MobileSetup.ACTIVATION_PAGE_URL);
169 $('systemStatus').classList.remove('hidden'); 166 $('systemStatus').classList.remove('hidden');
170 $('canvas').classList.remove('hidden'); 167 $('canvas').classList.remove('hidden');
171 this.startSpinner_(); 168 this.startSpinner_();
172 break; 169 break;
173 case MobileSetup.PLAN_ACTIVATION_TRYING_OTASP: 170 case MobileSetup.PLAN_ACTIVATION_TRYING_OTASP:
174 case MobileSetup.PLAN_ACTIVATION_INITIATING_ACTIVATION: 171 case MobileSetup.PLAN_ACTIVATION_INITIATING_ACTIVATION:
175 case MobileSetup.PLAN_ACTIVATION_OTASP: 172 case MobileSetup.PLAN_ACTIVATION_OTASP:
176 // Activation page should not be shown for the simple activation flow. 173 // Activation page should not be shown for the simple activation flow.
177 if (simpleActivationFlow) 174 if (simpleActivationFlow)
178 break; 175 break;
179 176
180 $('statusHeader').textContent = 177 $('statusHeader').textContent =
181 loadTimeData.getString('activating_header'); 178 loadTimeData.getString('activating_header');
182 $('auxHeader').textContent = 179 $('auxHeader').textContent = loadTimeData.getString('please_wait');
183 loadTimeData.getString('please_wait');
184 $('paymentForm').classList.add('hidden'); 180 $('paymentForm').classList.add('hidden');
185 $('finalStatus').classList.add('hidden'); 181 $('finalStatus').classList.add('hidden');
186 this.setCarrierPage_(MobileSetup.ACTIVATION_PAGE_URL); 182 this.setCarrierPage_(MobileSetup.ACTIVATION_PAGE_URL);
187 $('systemStatus').classList.remove('hidden'); 183 $('systemStatus').classList.remove('hidden');
188 $('canvas').classList.remove('hidden'); 184 $('canvas').classList.remove('hidden');
189 this.startSpinner_(); 185 this.startSpinner_();
190 break; 186 break;
191 case MobileSetup.PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: 187 case MobileSetup.PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING:
192 // Activation page should not be shown for the simple activation flow. 188 // Activation page should not be shown for the simple activation flow.
193 if (!simpleActivationFlow) { 189 if (!simpleActivationFlow) {
194 $('statusHeader').textContent = 190 $('statusHeader').textContent =
195 loadTimeData.getString('connecting_header'); 191 loadTimeData.getString('connecting_header');
196 $('auxHeader').textContent = ''; 192 $('auxHeader').textContent = '';
197 $('paymentForm').classList.add('hidden'); 193 $('paymentForm').classList.add('hidden');
198 $('finalStatus').classList.add('hidden'); 194 $('finalStatus').classList.add('hidden');
199 this.setCarrierPage_(MobileSetup.ACTIVATION_PAGE_URL); 195 this.setCarrierPage_(MobileSetup.ACTIVATION_PAGE_URL);
200 $('systemStatus').classList.remove('hidden'); 196 $('systemStatus').classList.remove('hidden');
201 $('canvas').classList.remove('hidden'); 197 $('canvas').classList.remove('hidden');
202 } 198 }
203 this.loadPaymentFrame_(deviceInfo); 199 this.loadPaymentFrame_(deviceInfo);
204 break; 200 break;
205 case MobileSetup.PLAN_ACTIVATION_WAITING_FOR_CONNECTION: 201 case MobileSetup.PLAN_ACTIVATION_WAITING_FOR_CONNECTION:
206 var statusHeaderText; 202 var statusHeaderText;
207 var carrierPage; 203 var carrierPage;
208 if (deviceInfo.activation_type == 'NonCellular') { 204 if (deviceInfo.activation_type == 'NonCellular') {
209 statusHeaderText = loadTimeData.getString( 205 statusHeaderText =
210 'portal_unreachable_header'); 206 loadTimeData.getString('portal_unreachable_header');
211 carrierPage = MobileSetup.PORTAL_OFFLINE_PAGE_URL; 207 carrierPage = MobileSetup.PORTAL_OFFLINE_PAGE_URL;
212 } else if (deviceInfo.activation_type == 'OTA') { 208 } else if (deviceInfo.activation_type == 'OTA') {
213 statusHeaderText = 209 statusHeaderText = loadTimeData.getString('connecting_header');
214 loadTimeData.getString('connecting_header');
215 carrierPage = MobileSetup.ACTIVATION_PAGE_URL; 210 carrierPage = MobileSetup.ACTIVATION_PAGE_URL;
216 } 211 }
217 $('statusHeader').textContent = statusHeaderText; 212 $('statusHeader').textContent = statusHeaderText;
218 $('auxHeader').textContent = ''; 213 $('auxHeader').textContent = '';
219 $('auxHeader').classList.add('hidden'); 214 $('auxHeader').classList.add('hidden');
220 $('paymentForm').classList.add('hidden'); 215 $('paymentForm').classList.add('hidden');
221 $('finalStatus').classList.add('hidden'); 216 $('finalStatus').classList.add('hidden');
222 $('systemStatus').classList.remove('hidden'); 217 $('systemStatus').classList.remove('hidden');
223 this.setCarrierPage_(carrierPage); 218 this.setCarrierPage_(carrierPage);
224 $('canvas').classList.remove('hidden'); 219 $('canvas').classList.remove('hidden');
(...skipping 20 matching lines...) Expand all
245 $('closeButton').classList.remove('hidden'); 240 $('closeButton').classList.remove('hidden');
246 $('finalStatus').classList.remove('hidden'); 241 $('finalStatus').classList.remove('hidden');
247 $('canvas').classList.add('hidden'); 242 $('canvas').classList.add('hidden');
248 $('closeButton').classList.toggle('hidden', !this.paymentShown_); 243 $('closeButton').classList.toggle('hidden', !this.paymentShown_);
249 $('paymentForm').classList.toggle('hidden', !this.paymentShown_); 244 $('paymentForm').classList.toggle('hidden', !this.paymentShown_);
250 this.stopSpinner_(); 245 this.stopSpinner_();
251 break; 246 break;
252 case MobileSetup.PLAN_ACTIVATION_ERROR: 247 case MobileSetup.PLAN_ACTIVATION_ERROR:
253 $('statusHeader').textContent = ''; 248 $('statusHeader').textContent = '';
254 $('auxHeader').textContent = ''; 249 $('auxHeader').textContent = '';
255 $('finalHeader').textContent = 250 $('finalHeader').textContent = loadTimeData.getString('error_header');
256 loadTimeData.getString('error_header');
257 $('finalMessage').textContent = deviceInfo.error; 251 $('finalMessage').textContent = deviceInfo.error;
258 $('systemStatus').classList.add('hidden'); 252 $('systemStatus').classList.add('hidden');
259 $('canvas').classList.add('hidden'); 253 $('canvas').classList.add('hidden');
260 $('closeButton').classList.toggle('hidden', !this.paymentShown_); 254 $('closeButton').classList.toggle('hidden', !this.paymentShown_);
261 $('paymentForm').classList.toggle('hidden', !this.paymentShown_); 255 $('paymentForm').classList.toggle('hidden', !this.paymentShown_);
262 $('finalStatus').classList.remove('hidden'); 256 $('finalStatus').classList.remove('hidden');
263 this.stopSpinner_(); 257 this.stopSpinner_();
264 break; 258 break;
265 } 259 }
266 this.state_ = newState; 260 this.state_ = newState;
(...skipping 18 matching lines...) Expand all
285 }, 279 },
286 280
287 portalFrameLoadCompleted_: function() { 281 portalFrameLoadCompleted_: function() {
288 if (this.frameLoadIgnored_) 282 if (this.frameLoadIgnored_)
289 return; 283 return;
290 console.log('Portal frame load completed!'); 284 console.log('Portal frame load completed!');
291 this.onFrameLoaded_(this.frameLoadError_ == 0); 285 this.onFrameLoaded_(this.frameLoadError_ == 0);
292 }, 286 },
293 287
294 sendPostFrame_: function(frameUrl) { 288 sendPostFrame_: function(frameUrl) {
295 var msg = { type: 'postFrame' }; 289 var msg = {type: 'postFrame'};
296 $(this.frameName_).contentWindow.postMessage(msg, frameUrl); 290 $(this.frameName_).contentWindow.postMessage(msg, frameUrl);
297 }, 291 },
298 292
299 sendDeviceInfo_: function() { 293 sendDeviceInfo_: function() {
300 var msg = { 294 var msg = {
301 type: 'deviceInfoMsg', 295 type: 'deviceInfoMsg',
302 domain: document.location, 296 domain: document.location,
303 payload: { 297 payload: {
304 'carrier': this.deviceInfo_.carrier, 298 'carrier': this.deviceInfo_.carrier,
305 'MEID': this.deviceInfo_.MEID, 299 'MEID': this.deviceInfo_.MEID,
306 'IMEI': this.deviceInfo_.IMEI, 300 'IMEI': this.deviceInfo_.IMEI,
307 'MDN': this.deviceInfo_.MDN 301 'MDN': this.deviceInfo_.MDN
308 } 302 }
309 }; 303 };
310 $(this.frameName_).contentWindow.postMessage(msg, 304 $(this.frameName_)
311 this.deviceInfo_.payment_url); 305 .contentWindow.postMessage(msg, this.deviceInfo_.payment_url);
312 } 306 }
313 307
314 }; 308 };
315 309
316 MobileSetup.drawProgress = function() { 310 MobileSetup.drawProgress = function() {
317 var ctx = canvas.getContext('2d'); 311 var ctx = canvas.getContext('2d');
318 ctx.clearRect(0, 0, canvas.width, canvas.height); 312 ctx.clearRect(0, 0, canvas.width, canvas.height);
319 313
320 var segmentCount = Math.min(12, canvas.width / 1.6); // Number of segments 314 var segmentCount = Math.min(12, canvas.width / 1.6); // Number of segments
321 var rotation = 0.75; // Counterclockwise rotation 315 var rotation = 0.75; // Counterclockwise rotation
322 316
323 // Rotate canvas over time 317 // Rotate canvas over time
324 ctx.translate(canvas.width / 2, canvas.height / 2); 318 ctx.translate(canvas.width / 2, canvas.height / 2);
325 ctx.rotate(Math.PI * 2 / (segmentCount + rotation)); 319 ctx.rotate(Math.PI * 2 / (segmentCount + rotation));
326 ctx.translate(-canvas.width / 2, -canvas.height / 2); 320 ctx.translate(-canvas.width / 2, -canvas.height / 2);
327 321
328 var gap = canvas.width / 24; // Gap between segments 322 var gap = canvas.width / 24; // Gap between segments
329 var oRadius = canvas.width / 2; // Outer radius 323 var oRadius = canvas.width / 2; // Outer radius
330 var iRadius = oRadius * 0.618; // Inner radius 324 var iRadius = oRadius * 0.618; // Inner radius
331 var oCircumference = Math.PI * 2 * oRadius; // Outer circumference 325 var oCircumference = Math.PI * 2 * oRadius; // Outer circumference
332 var iCircumference = Math.PI * 2 * iRadius; // Inner circumference 326 var iCircumference = Math.PI * 2 * iRadius; // Inner circumference
333 var oGap = gap / oCircumference; // Gap size as fraction of outer ring 327 var oGap = gap / oCircumference; // Gap size as fraction of outer ring
334 var iGap = gap / iCircumference; // Gap size as fraction of inner ring 328 var iGap = gap / iCircumference; // Gap size as fraction of inner ring
335 var oArc = Math.PI * 2 * (1 / segmentCount - oGap); // Angle of outer arcs 329 var oArc = Math.PI * 2 * (1 / segmentCount - oGap); // Angle of outer arcs
336 var iArc = Math.PI * 2 * (1 / segmentCount - iGap); // Angle of inner arcs 330 var iArc = Math.PI * 2 * (1 / segmentCount - iGap); // Angle of inner arcs
337 331
338 for (i = 0; i < segmentCount; i++) { // Draw each segment 332 for (i = 0; i < segmentCount; i++) { // Draw each segment
339 var opacity = Math.pow(1.0 - i / segmentCount, 3.0); 333 var opacity = Math.pow(1.0 - i / segmentCount, 3.0);
340 opacity = (0.15 + opacity * 0.8); // Vary from 0.15 to 0.95 334 opacity = (0.15 + opacity * 0.8); // Vary from 0.15 to 0.95
341 var angle = - Math.PI * 2 * i / segmentCount; 335 var angle = -Math.PI * 2 * i / segmentCount;
342 336
343 ctx.beginPath(); 337 ctx.beginPath();
344 ctx.arc(canvas.width / 2, canvas.height / 2, oRadius, 338 ctx.arc(
345 angle - oArc / 2, angle + oArc / 2, false); 339 canvas.width / 2, canvas.height / 2, oRadius, angle - oArc / 2,
346 ctx.arc(canvas.width / 2, canvas.height / 2, iRadius, 340 angle + oArc / 2, false);
347 angle + iArc / 2, angle - iArc / 2, true); 341 ctx.arc(
342 canvas.width / 2, canvas.height / 2, iRadius, angle + iArc / 2,
343 angle - iArc / 2, true);
348 ctx.closePath(); 344 ctx.closePath();
349 ctx.fillStyle = 'rgba(240, 30, 29, ' + opacity + ')'; 345 ctx.fillStyle = 'rgba(240, 30, 29, ' + opacity + ')';
350 ctx.fill(); 346 ctx.fill();
351 } 347 }
352 }; 348 };
353 349
354 MobileSetup.deviceStateChanged = function(deviceInfo) { 350 MobileSetup.deviceStateChanged = function(deviceInfo) {
355 MobileSetup.getInstance().updateDeviceStatus_(deviceInfo); 351 MobileSetup.getInstance().updateDeviceStatus_(deviceInfo);
356 }; 352 };
357 353
358 MobileSetup.portalFrameLoadError = function(errorCode) { 354 MobileSetup.portalFrameLoadError = function(errorCode) {
359 MobileSetup.getInstance().portalFrameLoadError_(errorCode); 355 MobileSetup.getInstance().portalFrameLoadError_(errorCode);
360 }; 356 };
361 357
362 MobileSetup.portalFrameLoadCompleted = function() { 358 MobileSetup.portalFrameLoadCompleted = function() {
363 MobileSetup.getInstance().portalFrameLoadCompleted_(); 359 MobileSetup.getInstance().portalFrameLoadCompleted_();
364 }; 360 };
365 361
366 MobileSetup.loadPage = function() { 362 MobileSetup.loadPage = function() {
367 mobile.MobileSetup.getInstance().initialize('paymentForm', 363 mobile.MobileSetup.getInstance().initialize(
368 mobile.MobileSetup.ACTIVATION_PAGE_URL); 364 'paymentForm', mobile.MobileSetup.ACTIVATION_PAGE_URL);
369 }; 365 };
370 366
371 // Export 367 // Export
372 return { 368 return {MobileSetup: MobileSetup};
373 MobileSetup: MobileSetup
374 };
375 }); 369 });
376 370
377 document.addEventListener('DOMContentLoaded', mobile.MobileSetup.loadPage); 371 document.addEventListener('DOMContentLoaded', mobile.MobileSetup.loadPage);
OLDNEW
« no previous file with comments | « chrome/browser/resources/chromeos/login/throbber_notice.js ('k') | chrome/browser/resources/chromeos/mobile_setup_portal.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698