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

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

Issue 3606005: Hooked mobile activation UI with the new libcros additions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 } 9 }
10 10
11 cr.addSingletonGetter(MobileSetup); 11 cr.addSingletonGetter(MobileSetup);
12 12
13 MobileSetup.prototype = { 13 MobileSetup.prototype = {
14 // Mobile device information. 14 // Mobile device information.
15 deviceInfo_: null, 15 deviceInfo_: null,
16 frame_name_ : '', 16 frame_name_ : '',
17 local_strings_: new LocalStrings();
18 // UI states.
19 state_ : 0,
20 STATE_UNKNOWN_: "unknown",
21 STATE_CONNECTING_: "connecting",
22 STATE_ERROR_: "error",
23 STATE_PAYMENT_: "payment",
24 STATE_ACTIVATING_: "activating",
25 STATE_CONNECTED_: "connected",
17 26
18 initialize: function(frame_name) { 27 initialize: function(frame_name) {
19 self = this; 28 self = this;
20 this.frame_name_ = frame_name; 29 this.frame_name_ = frame_name;
21 document.addEventListener('DOMContentLoaded', function(deviceInfo) { 30 document.addEventListener('DOMContentLoaded', function(deviceInfo) {
22 chrome.send('getDeviceInfo', 31 chrome.send('getDeviceInfo',
23 ['mobile.MobileSetup.getDeviceInfoCallback']); 32 ['mobile.MobileSetup.getDeviceInfoCallback']);
24 }); 33 });
25 window.addEventListener('message', function(e) { 34 window.addEventListener('message', function(e) {
26 self.onMessageReceived_(e); 35 self.onMessageReceived_(e);
27 }); 36 });
28 }, 37 },
29 38
30 loadPaymentFrame: function(deviceInfo) { 39 loadPaymentFrame: function(deviceInfo) {
31 if (deviceInfo) { 40 if (deviceInfo) {
32 this.deviceInfo_ = deviceInfo; 41 this.deviceInfo_ = deviceInfo;
33 42
34 // HACK(zelidrag): Remove the next line for real testing. 43 // HACK(zelidrag): Remove the next line for real testing.
35 this.deviceInfo_.payment_url = 'http://link.to/mobile_activation.html'; 44 this.deviceInfo_.payment_url =
36 45 'http://test/mobile/activation.html';
46
37 $(this.frame_name_).contentWindow.location.href = 47 $(this.frame_name_).contentWindow.location.href =
38 this.deviceInfo_.payment_url; 48 this.deviceInfo_.payment_url;
39 } 49 }
40 }, 50 },
41 51
42 onMessageReceived_: function(e) { 52 onMessageReceived_: function(e) {
43 if (e.origin != 53 if (e.origin !=
44 this.deviceInfo_.payment_url.substring(0, e.origin.length)) 54 this.deviceInfo_.payment_url.substring(0, e.origin.length))
45 return; 55 return;
46 56
47 if (e.data.type == 'requestDeviceInfoMsg') { 57 if (e.data.type == 'requestDeviceInfoMsg') {
48 this.sendDeviceInfo_(); 58 this.sendDeviceInfo_();
49 } else if (e.data.type == 'reportTransactionStatusMsg') { 59 } else if (e.data.type == 'reportTransactionStatusMsg') {
50 chrome.send('setTransactionStatus', [e.data.status]); 60 chrome.send('setTransactionStatus', [e.data.status]);
51 } 61 }
52 }, 62 },
53 63
64 changeState: function(new_state, errorText) {
65 if (state_ == new_state)
66 return;
67 if (new_state == STATE_UNKNOWN_)
68 document.body.setAttribute('state', STATE_CONNECTING_);
69 else
70 document.body.setAttribute('state', new_state);
71 switch(new_state) {
72 case STATE_UNKNOWN_:
73 case STATE_CONNECTING_:
74 $('status-header').textContent =
75 local_strings_.getString('connecting_header');
76 $('error-message').textContent = '';
77 break;
78 case STATE_ERROR_:
79 $('status-header').textContent =
80 local_strings_.getString('error_header');
81 $('error-message').textContent = errorText;
82 break;
83 case STATE_ACTIVATING_:
84 $('status-header').textContent =
85 local_strings_.getString('activating_header');
86 $('error-message').textContent = '';
87 break;
88 }
89 state_ = new_state;
90 },
91
92 updateDeviceStatus_: function(deviceInfo) {
93 this.changeState(deviceInfo.state, deviceInfo.error);
94 },
95
54 sendDeviceInfo_ : function() { 96 sendDeviceInfo_ : function() {
55 var msg = { 97 var msg = {
56 type: 'deviceInfoMsg', 98 type: 'deviceInfoMsg',
57 domain: document.location, 99 domain: document.location,
58 payload: { 100 payload: {
59 'carrier': this.deviceInfo_.carrier, 101 'carrier': this.deviceInfo_.carrier,
60 'MEID': this.deviceInfo_.MEID, 102 'MEID': this.deviceInfo_.MEID,
61 'IMEI': this.deviceInfo_.IMEI, 103 'IMEI': this.deviceInfo_.IMEI,
62 'IMSI': this.deviceInfo_.IMSI, 104 'IMSI': this.deviceInfo_.IMSI,
63 'ESN': this.deviceInfo_.ESN, 105 'ESN': this.deviceInfo_.ESN,
64 'MDN': this.deviceInfo_.MDN 106 'MDN': this.deviceInfo_.MDN
65 } 107 }
66 }; 108 };
67 $(this.frame_name_).contentWindow.postMessage(msg, 109 $(this.frame_name_).contentWindow.postMessage(msg,
68 this.deviceInfo_.payment_url); 110 this.deviceInfo_.payment_url);
69 } 111 }
112
113 };
114
115 MobileSetup.drawProgress = function () {
116 var canvas = $('wheel');
117 var ctx = canvas.getContext('2d');
118 ctx.clearRect(0, 0, canvas.width, canvas.height);
119
120 var segmentCount = Math.min(12, canvas.width/1.6) // Number of segments
121 var rotation = 0.75; // Counterclockwise rotation
122
123 // Rotate canvas over time
124 ctx.translate(canvas.width/2, canvas.height/2);
125 ctx.rotate(Math.PI * 2 / (segmentCount + rotation));
126 ctx.translate(-canvas.width/2, -canvas.height/2);
127
128 var gap = canvas.width / 24; // Gap between segments
129 var oRadius = canvas.width/2; // Outer radius
130 var iRadius = oRadius * 0.618; // Inner radius
131 var oCircumference = Math.PI * 2 * oRadius; // Outer circumference
132 var iCircumference = Math.PI * 2 * iRadius; // Inner circumference
133 var oGap = gap / oCircumference; // Gap size as fraction of outer ring
134 var iGap = gap / iCircumference; // Gap size as fraction of inner ring
135 var oArc = Math.PI * 2 * ( 1 / segmentCount - oGap); // Angle of outer arcs
136 var iArc = Math.PI * 2 * ( 1 / segmentCount - iGap); // Angle of inner arcs
137
138 for (i = 0; i < segmentCount; i++){ // Draw each segment
139 var opacity = Math.pow(1.0 - i / segmentCount, 3.0);
140 opacity = (0.15 + opacity * 0.8) // Vary from 0.15 to 0.95
141 var angle = - Math.PI * 2 * i / segmentCount;
142
143 ctx.beginPath();
144 ctx.arc(canvas.width/2, canvas.height/2, oRadius,
145 angle - oArc/2, angle + oArc/2, false);
146 ctx.arc(canvas.width/2, canvas.height/2, iRadius,
147 angle + iArc/2, angle - iArc/2, true);
148 ctx.closePath();
149 ctx.fillStyle = "rgba(240, 30, 29, " + opacity + ")";
150 ctx.fill();
151 }
70 }; 152 };
71 153
72 MobileSetup.getDeviceInfoCallback = function(deviceInfo) { 154 MobileSetup.getDeviceInfoCallback = function(deviceInfo) {
73 MobileSetup.getInstance().loadPaymentFrame(deviceInfo); 155 MobileSetup.getInstance().loadPaymentFrame(deviceInfo);
74 }; 156 };
75 157
158
159 MobileSetup.deviceStateChanged = function(deviceInfo) {
160 MobileSetup.getInstance().updateDeviceStatus_(deviceInfo);
161 };
162
76 // Export 163 // Export
77 return { 164 return {
78 MobileSetup: MobileSetup 165 MobileSetup: MobileSetup
79 }; 166 };
80 167
81 }); 168 });
82 169
OLDNEW
« chrome/app/generated_resources.grd ('K') | « chrome/browser/resources/mobile_setup.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698