OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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.PLAN_ACTIVATION_PAGE_LOADING = -1; | 13 MobileSetup.PLAN_ACTIVATION_PAGE_LOADING = -1; |
14 MobileSetup.PLAN_ACTIVATION_START = 0; | 14 MobileSetup.PLAN_ACTIVATION_START = 0; |
15 MobileSetup.PLAN_ACTIVATION_TRYING_OTASP = 1; | 15 MobileSetup.PLAN_ACTIVATION_TRYING_OTASP = 1; |
16 MobileSetup.PLAN_ACTIVATION_RECONNECTING_OTASP_TRY = 2; | 16 MobileSetup.PLAN_ACTIVATION_RECONNECTING_OTASP_TRY = 2; |
17 MobileSetup.PLAN_ACTIVATION_INITIATING_ACTIVATION = 3; | 17 MobileSetup.PLAN_ACTIVATION_INITIATING_ACTIVATION = 3; |
18 MobileSetup.PLAN_ACTIVATION_RECONNECTING = 4; | 18 MobileSetup.PLAN_ACTIVATION_RECONNECTING = 4; |
19 MobileSetup.PLAN_ACTIVATION_SHOWING_PAYMENT = 5; | 19 MobileSetup.PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING = 5; |
20 MobileSetup.PLAN_ACTIVATION_DELAY_OTASP = 6; | 20 MobileSetup.PLAN_ACTIVATION_SHOWING_PAYMENT = 6; |
21 MobileSetup.PLAN_ACTIVATION_START_OTASP = 7; | 21 MobileSetup.PLAN_ACTIVATION_RECONNECTING_PAYMENT = 7; |
22 MobileSetup.PLAN_ACTIVATION_OTASP = 8; | 22 MobileSetup.PLAN_ACTIVATION_DELAY_OTASP = 8; |
23 MobileSetup.PLAN_ACTIVATION_RECONNECTING_OTASP = 9; | 23 MobileSetup.PLAN_ACTIVATION_START_OTASP = 9; |
24 MobileSetup.PLAN_ACTIVATION_DONE = 10; | 24 MobileSetup.PLAN_ACTIVATION_OTASP = 10; |
25 MobileSetup.PLAN_ACTIVATION_RECONNECTING_OTASP = 11; | |
26 MobileSetup.PLAN_ACTIVATION_DONE = 12; | |
25 MobileSetup.PLAN_ACTIVATION_ERROR = 0xFF; | 27 MobileSetup.PLAN_ACTIVATION_ERROR = 0xFF; |
26 | 28 |
27 MobileSetup.EXTENSION_PAGE_URL = | 29 MobileSetup.EXTENSION_PAGE_URL = |
28 'chrome-extension://iadeocfgjdjdmpenejdbfeaocpbikmab'; | 30 'chrome-extension://iadeocfgjdjdmpenejdbfeaocpbikmab'; |
29 MobileSetup.ACTIVATION_PAGE_URL = MobileSetup.EXTENSION_PAGE_URL + | 31 MobileSetup.ACTIVATION_PAGE_URL = MobileSetup.EXTENSION_PAGE_URL + |
30 '/activation.html'; | 32 '/activation.html'; |
31 MobileSetup.REDIRECT_POST_PAGE_URL = MobileSetup.EXTENSION_PAGE_URL + | 33 MobileSetup.REDIRECT_POST_PAGE_URL = MobileSetup.EXTENSION_PAGE_URL + |
32 '/redirect.html'; | 34 '/redirect.html'; |
33 | 35 |
34 MobileSetup.localStrings_ = new LocalStrings(); | 36 MobileSetup.localStrings_ = new LocalStrings(); |
35 | 37 |
36 MobileSetup.prototype = { | 38 MobileSetup.prototype = { |
37 // Mobile device information. | 39 // Mobile device information. |
38 deviceInfo_: null, | 40 deviceInfo_: null, |
39 frameName_ : '', | 41 frameName_ : '', |
40 initialized_ : false, | 42 initialized_ : false, |
41 faked_transaction_ : false, | 43 faked_transaction_ : false, |
42 payment_shown_ : false, | 44 payment_shown_ : false, |
45 frame_load_error_ : 0, | |
46 frame_load_ignored_ : true, | |
43 // UI states. | 47 // UI states. |
44 state_ : -1, | 48 state_ : -1, |
45 STATE_UNKNOWN_: "unknown", | 49 STATE_UNKNOWN_: "unknown", |
46 STATE_CONNECTING_: "connecting", | 50 STATE_CONNECTING_: "connecting", |
47 STATE_ERROR_: "error", | 51 STATE_ERROR_: "error", |
48 STATE_PAYMENT_: "payment", | 52 STATE_PAYMENT_: "payment", |
49 STATE_ACTIVATING_: "activating", | 53 STATE_ACTIVATING_: "activating", |
50 STATE_CONNECTED_: "connected", | 54 STATE_CONNECTED_: "connected", |
51 | 55 |
52 initialize: function(frame_name, carrierPage) { | 56 initialize: function(frame_name, carrierPage) { |
(...skipping 30 matching lines...) Expand all Loading... | |
83 window.close(); | 87 window.close(); |
84 }); | 88 }); |
85 }); | 89 }); |
86 | 90 |
87 this.changeState_({state: MobileSetup.PLAN_ACTIVATION_PAGE_LOADING}); | 91 this.changeState_({state: MobileSetup.PLAN_ACTIVATION_PAGE_LOADING}); |
88 setInterval(mobile.MobileSetup.drawProgress, 100); | 92 setInterval(mobile.MobileSetup.drawProgress, 100); |
89 // Kick off activation process. | 93 // Kick off activation process. |
90 chrome.send('startActivation', []); | 94 chrome.send('startActivation', []); |
91 }, | 95 }, |
92 | 96 |
93 setupPaymentFrameListener_: function() { | 97 onFrameLoaded_: function(success) { |
94 $(this.frameName_).addEventListener('load', function(e) { | 98 chrome.send('paymentPortalLoad', [success ? 'ok' : 'failed']); |
95 // Flip the visibility of the payment page only after the frame is | |
96 // fully loaded. | |
97 if (self.state_ == MobileSetup.PLAN_ACTIVATION_SHOWING_PAYMENT) { | |
98 $('statusHeader').textContent = ''; | |
99 $('auxHeader').textContent = ''; | |
100 $('finalStatus').classList.add('hidden'); | |
101 $('systemStatus').classList.add('hidden'); | |
102 $('canvas').classList.add('hidden'); | |
103 $('carrierPage').classList.add('hidden'); | |
104 $('paymentForm').classList.remove('hidden'); | |
105 } | |
106 }); | |
107 }, | 99 }, |
108 | 100 |
109 loadPaymentFrame_: function(deviceInfo) { | 101 loadPaymentFrame_: function(deviceInfo) { |
110 if (deviceInfo) { | 102 if (deviceInfo) { |
103 this.frame_load_error_ = 0; | |
111 this.deviceInfo_ = deviceInfo; | 104 this.deviceInfo_ = deviceInfo; |
112 if (deviceInfo.post_data && deviceInfo.post_data.length) { | 105 if (deviceInfo.post_data && deviceInfo.post_data.length) { |
106 this.frame_load_ignored_ = true; | |
113 $(this.frameName_).contentWindow.location.href = | 107 $(this.frameName_).contentWindow.location.href = |
xiyuan
2011/10/26 23:17:03
nit: $(this.frameName_).src = ...
| |
114 MobileSetup.REDIRECT_POST_PAGE_URL + | 108 MobileSetup.REDIRECT_POST_PAGE_URL + |
115 '?post_data=' + escape(deviceInfo.post_data) + | 109 '?post_data=' + escape(deviceInfo.post_data) + |
116 '&formUrl=' + escape(deviceInfo.payment_url); | 110 '&formUrl=' + escape(deviceInfo.payment_url); |
117 } else { | 111 } else { |
118 this.setupPaymentFrameListener_(); | 112 this.frame_load_ignored_ = false; |
119 $(this.frameName_).contentWindow.location.href = | 113 $(this.frameName_).contentWindow.location.href = |
120 deviceInfo.payment_url; | 114 deviceInfo.payment_url; |
121 } | 115 } |
122 } | 116 } |
123 }, | 117 }, |
124 | 118 |
125 onMessageReceived_: function(e) { | 119 onMessageReceived_: function(e) { |
126 if (e.origin != | 120 if (e.origin != |
127 this.deviceInfo_.payment_url.substring(0, e.origin.length) && | 121 this.deviceInfo_.payment_url.substring(0, e.origin.length) && |
128 e.origin != MobileSetup.EXTENSION_PAGE_URL) | 122 e.origin != MobileSetup.EXTENSION_PAGE_URL) |
129 return; | 123 return; |
130 | 124 |
131 if (e.data.type == 'requestDeviceInfoMsg') { | 125 if (e.data.type == 'requestDeviceInfoMsg') { |
132 this.sendDeviceInfo_(); | 126 this.sendDeviceInfo_(); |
133 } else if (e.data.type == 'framePostReady') { | 127 } else if (e.data.type == 'framePostReady') { |
134 this.setupPaymentFrameListener_(); | 128 this.frame_load_ignored_ = false; |
135 this.sendPostFrame_(e.origin); | 129 this.sendPostFrame_(e.origin); |
136 } else if (e.data.type == 'reportTransactionStatusMsg') { | 130 } else if (e.data.type == 'reportTransactionStatusMsg') { |
137 console.log('calling setTransactionStatus from onMessageReceived_'); | 131 console.log('calling setTransactionStatus from onMessageReceived_'); |
138 $('paymentForm').classList.add('hidden'); | 132 $('paymentForm').classList.add('hidden'); |
139 chrome.send('setTransactionStatus', [e.data.status]); | 133 chrome.send('setTransactionStatus', [e.data.status]); |
140 } | 134 } |
141 }, | 135 }, |
142 | 136 |
143 changeState_: function(deviceInfo) { | 137 changeState_: function(deviceInfo) { |
144 var new_state = deviceInfo.state; | 138 var new_state = deviceInfo.state; |
145 if (this.state_ == new_state) | 139 if (this.state_ == new_state) |
146 return; | 140 return; |
147 var main = $('mainbody'); | 141 var main = $('mainbody'); |
148 // Map handler state to UX. | 142 // Map handler state to UX. |
149 switch(new_state) { | 143 switch(new_state) { |
150 case MobileSetup.PLAN_ACTIVATION_PAGE_LOADING: | 144 case MobileSetup.PLAN_ACTIVATION_PAGE_LOADING: |
151 case MobileSetup.PLAN_ACTIVATION_START: | 145 case MobileSetup.PLAN_ACTIVATION_START: |
152 case MobileSetup.PLAN_ACTIVATION_DELAY_OTASP: | 146 case MobileSetup.PLAN_ACTIVATION_DELAY_OTASP: |
153 case MobileSetup.PLAN_ACTIVATION_START_OTASP: | 147 case MobileSetup.PLAN_ACTIVATION_START_OTASP: |
154 case MobileSetup.PLAN_ACTIVATION_RECONNECTING: | 148 case MobileSetup.PLAN_ACTIVATION_RECONNECTING: |
149 case MobileSetup.PLAN_ACTIVATION_RECONNECTING_PAYMENT: | |
155 case MobileSetup.PLAN_ACTIVATION_RECONNECTING_OTASP_TRY: | 150 case MobileSetup.PLAN_ACTIVATION_RECONNECTING_OTASP_TRY: |
156 case MobileSetup.PLAN_ACTIVATION_RECONNECTING_OTASP: | 151 case MobileSetup.PLAN_ACTIVATION_RECONNECTING_OTASP: |
157 $('statusHeader').textContent = | 152 $('statusHeader').textContent = |
158 MobileSetup.localStrings_.getString('connecting_header'); | 153 MobileSetup.localStrings_.getString('connecting_header'); |
159 $('auxHeader').textContent = | 154 $('auxHeader').textContent = |
160 MobileSetup.localStrings_.getString('please_wait'); | 155 MobileSetup.localStrings_.getString('please_wait'); |
161 $('paymentForm').classList.add('hidden'); | 156 $('paymentForm').classList.add('hidden'); |
162 $('finalStatus').classList.add('hidden'); | 157 $('finalStatus').classList.add('hidden'); |
163 $('systemStatus').classList.remove('hidden'); | 158 $('systemStatus').classList.remove('hidden'); |
164 $('canvas').classList.remove('hidden'); | 159 $('canvas').classList.remove('hidden'); |
165 $('carrierPage').classList.remove('hidden'); | 160 $('carrierPage').classList.remove('hidden'); |
166 break; | 161 break; |
167 case MobileSetup.PLAN_ACTIVATION_TRYING_OTASP: | 162 case MobileSetup.PLAN_ACTIVATION_TRYING_OTASP: |
168 case MobileSetup.PLAN_ACTIVATION_INITIATING_ACTIVATION: | 163 case MobileSetup.PLAN_ACTIVATION_INITIATING_ACTIVATION: |
169 case MobileSetup.PLAN_ACTIVATION_OTASP: | 164 case MobileSetup.PLAN_ACTIVATION_OTASP: |
170 $('statusHeader').textContent = | 165 $('statusHeader').textContent = |
171 MobileSetup.localStrings_.getString('activating_header'); | 166 MobileSetup.localStrings_.getString('activating_header'); |
172 $('auxHeader').textContent = | 167 $('auxHeader').textContent = |
173 MobileSetup.localStrings_.getString('please_wait'); | 168 MobileSetup.localStrings_.getString('please_wait'); |
174 $('paymentForm').classList.add('hidden'); | 169 $('paymentForm').classList.add('hidden'); |
175 $('finalStatus').classList.add('hidden'); | 170 $('finalStatus').classList.add('hidden'); |
176 $('systemStatus').classList.remove('hidden'); | 171 $('systemStatus').classList.remove('hidden'); |
177 $('canvas').classList.remove('hidden'); | 172 $('canvas').classList.remove('hidden'); |
178 $('carrierPage').classList.remove('hidden'); | 173 $('carrierPage').classList.remove('hidden'); |
179 break; | 174 break; |
180 case MobileSetup.PLAN_ACTIVATION_SHOWING_PAYMENT: | 175 case MobileSetup.PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: |
181 $('statusHeader').textContent = | 176 $('statusHeader').textContent = |
182 MobileSetup.localStrings_.getString('connecting_header'); | 177 MobileSetup.localStrings_.getString('connecting_header'); |
183 $('auxHeader').textContent = ''; | 178 $('auxHeader').textContent = ''; |
184 $('paymentForm').classList.add('hidden'); | 179 $('paymentForm').classList.add('hidden'); |
185 $('finalStatus').classList.add('hidden'); | 180 $('finalStatus').classList.add('hidden'); |
186 $('systemStatus').classList.remove('hidden'); | 181 $('systemStatus').classList.remove('hidden'); |
187 $('canvas').classList.remove('hidden'); | 182 $('canvas').classList.remove('hidden'); |
188 this.loadPaymentFrame_(deviceInfo); | 183 this.loadPaymentFrame_(deviceInfo); |
184 break; | |
185 case MobileSetup.PLAN_ACTIVATION_SHOWING_PAYMENT: | |
186 $('statusHeader').textContent = ''; | |
187 $('auxHeader').textContent = ''; | |
188 $('finalStatus').classList.add('hidden'); | |
189 $('systemStatus').classList.add('hidden'); | |
190 $('canvas').classList.add('hidden'); | |
191 $('carrierPage').classList.add('hidden'); | |
192 $('paymentForm').classList.remove('hidden'); | |
189 this.payment_shown_ = true; | 193 this.payment_shown_ = true; |
190 break; | 194 break; |
191 case MobileSetup.PLAN_ACTIVATION_DONE: | 195 case MobileSetup.PLAN_ACTIVATION_DONE: |
192 $('statusHeader').textContent = ''; | 196 $('statusHeader').textContent = ''; |
193 $('auxHeader').textContent = ''; | 197 $('auxHeader').textContent = ''; |
194 $('finalHeader').textContent = | 198 $('finalHeader').textContent = |
195 MobileSetup.localStrings_.getString('completed_header'); | 199 MobileSetup.localStrings_.getString('completed_header'); |
196 $('finalMessage').textContent = | 200 $('finalMessage').textContent = |
197 MobileSetup.localStrings_.getString('completed_text'); | 201 MobileSetup.localStrings_.getString('completed_text'); |
198 $('systemStatus').classList.add('hidden'); | 202 $('systemStatus').classList.add('hidden'); |
(...skipping 30 matching lines...) Expand all Loading... | |
229 $('finalStatus').classList.remove('hidden'); | 233 $('finalStatus').classList.remove('hidden'); |
230 break; | 234 break; |
231 } | 235 } |
232 this.state_ = new_state; | 236 this.state_ = new_state; |
233 }, | 237 }, |
234 | 238 |
235 updateDeviceStatus_: function(deviceInfo) { | 239 updateDeviceStatus_: function(deviceInfo) { |
236 this.changeState_(deviceInfo); | 240 this.changeState_(deviceInfo); |
237 }, | 241 }, |
238 | 242 |
243 portalFrameLoadError_: function(errorCode) { | |
244 if (this.frame_load_ignored_) | |
245 return; | |
246 console.log("Portal frame load error detected: " + errorCode); | |
247 this.frame_load_error_ = errorCode; | |
248 }, | |
249 | |
250 portalFrameLoadCompleted_: function() { | |
251 if (this.frame_load_ignored_) | |
252 return; | |
253 console.log("Portal frame load completed!"); | |
254 this.onFrameLoaded_(this.frame_load_error_ == 0); | |
255 }, | |
256 | |
239 sendPostFrame_ : function(frameUrl) { | 257 sendPostFrame_ : function(frameUrl) { |
240 var msg = { type: 'postFrame' }; | 258 var msg = { type: 'postFrame' }; |
241 $(this.frameName_).contentWindow.postMessage(msg, frameUrl); | 259 $(this.frameName_).contentWindow.postMessage(msg, frameUrl); |
242 }, | 260 }, |
243 | 261 |
244 sendDeviceInfo_ : function() { | 262 sendDeviceInfo_ : function() { |
245 var msg = { | 263 var msg = { |
246 type: 'deviceInfoMsg', | 264 type: 'deviceInfoMsg', |
247 domain: document.location, | 265 domain: document.location, |
248 payload: { | 266 payload: { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 ctx.closePath(); | 311 ctx.closePath(); |
294 ctx.fillStyle = "rgba(240, 30, 29, " + opacity + ")"; | 312 ctx.fillStyle = "rgba(240, 30, 29, " + opacity + ")"; |
295 ctx.fill(); | 313 ctx.fill(); |
296 } | 314 } |
297 }; | 315 }; |
298 | 316 |
299 MobileSetup.deviceStateChanged = function(deviceInfo) { | 317 MobileSetup.deviceStateChanged = function(deviceInfo) { |
300 MobileSetup.getInstance().updateDeviceStatus_(deviceInfo); | 318 MobileSetup.getInstance().updateDeviceStatus_(deviceInfo); |
301 }; | 319 }; |
302 | 320 |
321 MobileSetup.portalFrameLoadError = function(errorCode) { | |
322 MobileSetup.getInstance().portalFrameLoadError_(errorCode); | |
323 }; | |
324 | |
325 MobileSetup.portalFrameLoadCompleted = function() { | |
326 MobileSetup.getInstance().portalFrameLoadCompleted_(); | |
327 }; | |
328 | |
303 MobileSetup.loadPage = function() { | 329 MobileSetup.loadPage = function() { |
304 mobile.MobileSetup.getInstance().initialize('paymentForm', | 330 mobile.MobileSetup.getInstance().initialize('paymentForm', |
305 mobile.MobileSetup.ACTIVATION_PAGE_URL); | 331 mobile.MobileSetup.ACTIVATION_PAGE_URL); |
306 }; | 332 }; |
307 | 333 |
308 // Export | 334 // Export |
309 return { | 335 return { |
310 MobileSetup: MobileSetup | 336 MobileSetup: MobileSetup |
311 }; | 337 }; |
312 | 338 |
313 }); | 339 }); |
314 | 340 |
OLD | NEW |