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

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

Issue 8341037: Added logic that will retry to reload+reconnect the mobile payment portal page 5 times before it ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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) 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,
47 spinner_int_: -1,
43 // UI states. 48 // UI states.
44 state_ : -1, 49 state_ : -1,
45 STATE_UNKNOWN_: "unknown", 50 STATE_UNKNOWN_: "unknown",
46 STATE_CONNECTING_: "connecting", 51 STATE_CONNECTING_: "connecting",
47 STATE_ERROR_: "error", 52 STATE_ERROR_: "error",
48 STATE_PAYMENT_: "payment", 53 STATE_PAYMENT_: "payment",
49 STATE_ACTIVATING_: "activating", 54 STATE_ACTIVATING_: "activating",
50 STATE_CONNECTED_: "connected", 55 STATE_CONNECTED_: "connected",
51 56
52 initialize: function(frame_name, carrierPage) { 57 initialize: function(frame_name, carrierPage) {
(...skipping 25 matching lines...) Expand all
78 window.close(); 83 window.close();
79 return; 84 return;
80 } 85 }
81 self.confirm_.show( 86 self.confirm_.show(
82 MobileSetup.localStrings_.getString('cancel_question'), function() { 87 MobileSetup.localStrings_.getString('cancel_question'), function() {
83 window.close(); 88 window.close();
84 }); 89 });
85 }); 90 });
86 91
87 this.changeState_({state: MobileSetup.PLAN_ACTIVATION_PAGE_LOADING}); 92 this.changeState_({state: MobileSetup.PLAN_ACTIVATION_PAGE_LOADING});
88 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 startSpinner_:function() {
94 $(this.frameName_).addEventListener('load', function(e) { 98 this.stopSpinner_();
95 // Flip the visibility of the payment page only after the frame is 99 this.spinner_int_ = setInterval(mobile.MobileSetup.drawProgress, 100);
96 // fully loaded. 100 },
97 if (self.state_ == MobileSetup.PLAN_ACTIVATION_SHOWING_PAYMENT) { 101
98 $('statusHeader').textContent = ''; 102 stopSpinner_:function() {
99 $('auxHeader').textContent = ''; 103 if (this.spinner_int_ != -1) {
100 $('finalStatus').classList.add('hidden'); 104 clearInterval(this.spinner_int_);
101 $('systemStatus').classList.add('hidden'); 105 this.spinner_int_ = -1;
102 $('canvas').classList.add('hidden'); 106 }
103 $('carrierPage').classList.add('hidden'); 107 },
104 $('paymentForm').classList.remove('hidden'); 108
105 } 109 onFrameLoaded_: function(success) {
106 }); 110 chrome.send('paymentPortalLoad', [success ? 'ok' : 'failed']);
107 }, 111 },
108 112
109 loadPaymentFrame_: function(deviceInfo) { 113 loadPaymentFrame_: function(deviceInfo) {
110 if (deviceInfo) { 114 if (deviceInfo) {
115 this.frame_load_error_ = 0;
111 this.deviceInfo_ = deviceInfo; 116 this.deviceInfo_ = deviceInfo;
112 if (deviceInfo.post_data && deviceInfo.post_data.length) { 117 if (deviceInfo.post_data && deviceInfo.post_data.length) {
118 this.frame_load_ignored_ = true;
113 $(this.frameName_).contentWindow.location.href = 119 $(this.frameName_).contentWindow.location.href =
114 MobileSetup.REDIRECT_POST_PAGE_URL + 120 MobileSetup.REDIRECT_POST_PAGE_URL +
115 '?post_data=' + escape(deviceInfo.post_data) + 121 '?post_data=' + escape(deviceInfo.post_data) +
116 '&formUrl=' + escape(deviceInfo.payment_url); 122 '&formUrl=' + escape(deviceInfo.payment_url);
117 } else { 123 } else {
118 this.setupPaymentFrameListener_(); 124 this.frame_load_ignored_ = false;
119 $(this.frameName_).contentWindow.location.href = 125 $(this.frameName_).contentWindow.location.href =
120 deviceInfo.payment_url; 126 deviceInfo.payment_url;
121 } 127 }
122 } 128 }
123 }, 129 },
124 130
125 onMessageReceived_: function(e) { 131 onMessageReceived_: function(e) {
126 if (e.origin != 132 if (e.origin !=
127 this.deviceInfo_.payment_url.substring(0, e.origin.length) && 133 this.deviceInfo_.payment_url.substring(0, e.origin.length) &&
128 e.origin != MobileSetup.EXTENSION_PAGE_URL) 134 e.origin != MobileSetup.EXTENSION_PAGE_URL)
129 return; 135 return;
130 136
131 if (e.data.type == 'requestDeviceInfoMsg') { 137 if (e.data.type == 'requestDeviceInfoMsg') {
132 this.sendDeviceInfo_(); 138 this.sendDeviceInfo_();
133 } else if (e.data.type == 'framePostReady') { 139 } else if (e.data.type == 'framePostReady') {
134 this.setupPaymentFrameListener_(); 140 this.frame_load_ignored_ = false;
135 this.sendPostFrame_(e.origin); 141 this.sendPostFrame_(e.origin);
136 } else if (e.data.type == 'reportTransactionStatusMsg') { 142 } else if (e.data.type == 'reportTransactionStatusMsg') {
137 console.log('calling setTransactionStatus from onMessageReceived_'); 143 console.log('calling setTransactionStatus from onMessageReceived_');
138 $('paymentForm').classList.add('hidden'); 144 $('paymentForm').classList.add('hidden');
139 chrome.send('setTransactionStatus', [e.data.status]); 145 chrome.send('setTransactionStatus', [e.data.status]);
140 } 146 }
141 }, 147 },
142 148
143 changeState_: function(deviceInfo) { 149 changeState_: function(deviceInfo) {
144 var new_state = deviceInfo.state; 150 var new_state = deviceInfo.state;
145 if (this.state_ == new_state) 151 if (this.state_ == new_state)
146 return; 152 return;
147 var main = $('mainbody'); 153 var main = $('mainbody');
148 // Map handler state to UX. 154 // Map handler state to UX.
149 switch(new_state) { 155 switch(new_state) {
150 case MobileSetup.PLAN_ACTIVATION_PAGE_LOADING: 156 case MobileSetup.PLAN_ACTIVATION_PAGE_LOADING:
151 case MobileSetup.PLAN_ACTIVATION_START: 157 case MobileSetup.PLAN_ACTIVATION_START:
152 case MobileSetup.PLAN_ACTIVATION_DELAY_OTASP: 158 case MobileSetup.PLAN_ACTIVATION_DELAY_OTASP:
153 case MobileSetup.PLAN_ACTIVATION_START_OTASP: 159 case MobileSetup.PLAN_ACTIVATION_START_OTASP:
154 case MobileSetup.PLAN_ACTIVATION_RECONNECTING: 160 case MobileSetup.PLAN_ACTIVATION_RECONNECTING:
161 case MobileSetup.PLAN_ACTIVATION_RECONNECTING_PAYMENT:
155 case MobileSetup.PLAN_ACTIVATION_RECONNECTING_OTASP_TRY: 162 case MobileSetup.PLAN_ACTIVATION_RECONNECTING_OTASP_TRY:
156 case MobileSetup.PLAN_ACTIVATION_RECONNECTING_OTASP: 163 case MobileSetup.PLAN_ACTIVATION_RECONNECTING_OTASP:
157 $('statusHeader').textContent = 164 $('statusHeader').textContent =
158 MobileSetup.localStrings_.getString('connecting_header'); 165 MobileSetup.localStrings_.getString('connecting_header');
159 $('auxHeader').textContent = 166 $('auxHeader').textContent =
160 MobileSetup.localStrings_.getString('please_wait'); 167 MobileSetup.localStrings_.getString('please_wait');
161 $('paymentForm').classList.add('hidden'); 168 $('paymentForm').classList.add('hidden');
162 $('finalStatus').classList.add('hidden'); 169 $('finalStatus').classList.add('hidden');
163 $('systemStatus').classList.remove('hidden'); 170 $('systemStatus').classList.remove('hidden');
171 $('carrierPage').classList.remove('hidden');
164 $('canvas').classList.remove('hidden'); 172 $('canvas').classList.remove('hidden');
165 $('carrierPage').classList.remove('hidden'); 173 this.startSpinner_();
166 break; 174 break;
167 case MobileSetup.PLAN_ACTIVATION_TRYING_OTASP: 175 case MobileSetup.PLAN_ACTIVATION_TRYING_OTASP:
168 case MobileSetup.PLAN_ACTIVATION_INITIATING_ACTIVATION: 176 case MobileSetup.PLAN_ACTIVATION_INITIATING_ACTIVATION:
169 case MobileSetup.PLAN_ACTIVATION_OTASP: 177 case MobileSetup.PLAN_ACTIVATION_OTASP:
170 $('statusHeader').textContent = 178 $('statusHeader').textContent =
171 MobileSetup.localStrings_.getString('activating_header'); 179 MobileSetup.localStrings_.getString('activating_header');
172 $('auxHeader').textContent = 180 $('auxHeader').textContent =
173 MobileSetup.localStrings_.getString('please_wait'); 181 MobileSetup.localStrings_.getString('please_wait');
174 $('paymentForm').classList.add('hidden'); 182 $('paymentForm').classList.add('hidden');
175 $('finalStatus').classList.add('hidden'); 183 $('finalStatus').classList.add('hidden');
176 $('systemStatus').classList.remove('hidden'); 184 $('systemStatus').classList.remove('hidden');
185 $('carrierPage').classList.remove('hidden');
177 $('canvas').classList.remove('hidden'); 186 $('canvas').classList.remove('hidden');
178 $('carrierPage').classList.remove('hidden'); 187 this.startSpinner_();
179 break; 188 break;
180 case MobileSetup.PLAN_ACTIVATION_SHOWING_PAYMENT: 189 case MobileSetup.PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING:
181 $('statusHeader').textContent = 190 $('statusHeader').textContent =
182 MobileSetup.localStrings_.getString('connecting_header'); 191 MobileSetup.localStrings_.getString('connecting_header');
183 $('auxHeader').textContent = ''; 192 $('auxHeader').textContent = '';
184 $('paymentForm').classList.add('hidden'); 193 $('paymentForm').classList.add('hidden');
185 $('finalStatus').classList.add('hidden'); 194 $('finalStatus').classList.add('hidden');
186 $('systemStatus').classList.remove('hidden'); 195 $('systemStatus').classList.remove('hidden');
187 $('canvas').classList.remove('hidden'); 196 $('canvas').classList.remove('hidden');
188 this.loadPaymentFrame_(deviceInfo); 197 this.loadPaymentFrame_(deviceInfo);
198 break;
199 case MobileSetup.PLAN_ACTIVATION_SHOWING_PAYMENT:
200 $('statusHeader').textContent = '';
201 $('auxHeader').textContent = '';
202 $('finalStatus').classList.add('hidden');
203 $('systemStatus').classList.add('hidden');
204 $('carrierPage').classList.add('hidden');
205 $('paymentForm').classList.remove('hidden');
206 $('canvas').classList.add('hidden');
207 this.stopSpinner_();
189 this.payment_shown_ = true; 208 this.payment_shown_ = true;
190 break; 209 break;
191 case MobileSetup.PLAN_ACTIVATION_DONE: 210 case MobileSetup.PLAN_ACTIVATION_DONE:
192 $('statusHeader').textContent = ''; 211 $('statusHeader').textContent = '';
193 $('auxHeader').textContent = ''; 212 $('auxHeader').textContent = '';
194 $('finalHeader').textContent = 213 $('finalHeader').textContent =
195 MobileSetup.localStrings_.getString('completed_header'); 214 MobileSetup.localStrings_.getString('completed_header');
196 $('finalMessage').textContent = 215 $('finalMessage').textContent =
197 MobileSetup.localStrings_.getString('completed_text'); 216 MobileSetup.localStrings_.getString('completed_text');
198 $('systemStatus').classList.add('hidden'); 217 $('systemStatus').classList.add('hidden');
199 $('canvas').classList.add('hidden');
200 $('carrierPage').classList.add('hidden'); 218 $('carrierPage').classList.add('hidden');
201 $('paymentForm').classList.remove('hidden'); 219 $('paymentForm').classList.remove('hidden');
202 $('closeButton').classList.remove('hidden'); 220 $('closeButton').classList.remove('hidden');
203 $('finalStatus').classList.remove('hidden'); 221 $('finalStatus').classList.remove('hidden');
222 $('canvas').classList.add('hidden');
223 this.stopSpinner_();
204 if (this.payment_shown_) { 224 if (this.payment_shown_) {
205 $('closeButton').classList.remove('hidden'); 225 $('closeButton').classList.remove('hidden');
206 } else { 226 } else {
207 $('closeButton').classList.add('hidden'); 227 $('closeButton').classList.add('hidden');
208 $('cancelButton').textContent = 228 $('cancelButton').textContent =
209 MobileSetup.localStrings_.getString('close_button'); 229 MobileSetup.localStrings_.getString('close_button');
210 } 230 }
211 break; 231 break;
212 case MobileSetup.PLAN_ACTIVATION_ERROR: 232 case MobileSetup.PLAN_ACTIVATION_ERROR:
213 $('statusHeader').textContent = ''; 233 $('statusHeader').textContent = '';
214 $('auxHeader').textContent = ''; 234 $('auxHeader').textContent = '';
215 $('finalHeader').textContent = 235 $('finalHeader').textContent =
216 MobileSetup.localStrings_.getString('error_header'); 236 MobileSetup.localStrings_.getString('error_header');
217 $('finalMessage').textContent = deviceInfo.error; 237 $('finalMessage').textContent = deviceInfo.error;
218 $('systemStatus').classList.add('hidden'); 238 $('systemStatus').classList.add('hidden');
219 $('canvas').classList.add('hidden');
220 $('carrierPage').classList.add('hidden'); 239 $('carrierPage').classList.add('hidden');
221 $('paymentForm').classList.remove('hidden'); 240 $('paymentForm').classList.remove('hidden');
241 $('canvas').classList.add('hidden');
242 this.stopSpinner_();
222 if (this.payment_shown_) { 243 if (this.payment_shown_) {
223 $('closeButton').classList.remove('hidden'); 244 $('closeButton').classList.remove('hidden');
224 } else { 245 } else {
225 $('closeButton').classList.add('hidden'); 246 $('closeButton').classList.add('hidden');
226 $('cancelButton').textContent = 247 $('cancelButton').textContent =
227 MobileSetup.localStrings_.getString('close_button'); 248 MobileSetup.localStrings_.getString('close_button');
228 } 249 }
229 $('finalStatus').classList.remove('hidden'); 250 $('finalStatus').classList.remove('hidden');
230 break; 251 break;
231 } 252 }
232 this.state_ = new_state; 253 this.state_ = new_state;
233 }, 254 },
234 255
235 updateDeviceStatus_: function(deviceInfo) { 256 updateDeviceStatus_: function(deviceInfo) {
236 this.changeState_(deviceInfo); 257 this.changeState_(deviceInfo);
237 }, 258 },
238 259
260 portalFrameLoadError_: function(errorCode) {
261 if (this.frame_load_ignored_)
262 return;
263 console.log("Portal frame load error detected: " + errorCode);
264 this.frame_load_error_ = errorCode;
265 },
266
267 portalFrameLoadCompleted_: function() {
268 if (this.frame_load_ignored_)
269 return;
270 console.log("Portal frame load completed!");
271 this.onFrameLoaded_(this.frame_load_error_ == 0);
272 },
273
239 sendPostFrame_ : function(frameUrl) { 274 sendPostFrame_ : function(frameUrl) {
240 var msg = { type: 'postFrame' }; 275 var msg = { type: 'postFrame' };
241 $(this.frameName_).contentWindow.postMessage(msg, frameUrl); 276 $(this.frameName_).contentWindow.postMessage(msg, frameUrl);
242 }, 277 },
243 278
244 sendDeviceInfo_ : function() { 279 sendDeviceInfo_ : function() {
245 var msg = { 280 var msg = {
246 type: 'deviceInfoMsg', 281 type: 'deviceInfoMsg',
247 domain: document.location, 282 domain: document.location,
248 payload: { 283 payload: {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 ctx.closePath(); 328 ctx.closePath();
294 ctx.fillStyle = "rgba(240, 30, 29, " + opacity + ")"; 329 ctx.fillStyle = "rgba(240, 30, 29, " + opacity + ")";
295 ctx.fill(); 330 ctx.fill();
296 } 331 }
297 }; 332 };
298 333
299 MobileSetup.deviceStateChanged = function(deviceInfo) { 334 MobileSetup.deviceStateChanged = function(deviceInfo) {
300 MobileSetup.getInstance().updateDeviceStatus_(deviceInfo); 335 MobileSetup.getInstance().updateDeviceStatus_(deviceInfo);
301 }; 336 };
302 337
338 MobileSetup.portalFrameLoadError = function(errorCode) {
339 MobileSetup.getInstance().portalFrameLoadError_(errorCode);
340 };
341
342 MobileSetup.portalFrameLoadCompleted = function() {
343 MobileSetup.getInstance().portalFrameLoadCompleted_();
344 };
345
303 MobileSetup.loadPage = function() { 346 MobileSetup.loadPage = function() {
304 mobile.MobileSetup.getInstance().initialize('paymentForm', 347 mobile.MobileSetup.getInstance().initialize('paymentForm',
305 mobile.MobileSetup.ACTIVATION_PAGE_URL); 348 mobile.MobileSetup.ACTIVATION_PAGE_URL);
306 }; 349 };
307 350
308 // Export 351 // Export
309 return { 352 return {
310 MobileSetup: MobileSetup 353 MobileSetup: MobileSetup
311 }; 354 };
312 355
313 }); 356 });
314 357
OLDNEW
« no previous file with comments | « chrome/browser/resources/mobile_setup.html ('k') | chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698