| OLD | NEW |
| 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.PLAN_ACTIVATION_LOADING = -1; | 13 MobileSetup.PLAN_ACTIVATION_LOADING = -1; |
| 14 MobileSetup.PLAN_ACTIVATION_START = 0; | 14 MobileSetup.PLAN_ACTIVATION_START = 0; |
| 15 MobileSetup.PLAN_ACTIVATION_INITIATING_ACTIVATION = 1; | 15 MobileSetup.PLAN_ACTIVATION_INITIATING_ACTIVATION = 1; |
| 16 MobileSetup.PLAN_ACTIVATION_ACTIVATING = 2; | 16 MobileSetup.PLAN_ACTIVATION_RECONNECTING = 2; |
| 17 MobileSetup.PLAN_ACTIVATION_SHOWING_PAYMENT = 3; | 17 MobileSetup.PLAN_ACTIVATION_SHOWING_PAYMENT = 3; |
| 18 MobileSetup.PLAN_ACTIVATION_DONE = 4; | 18 MobileSetup.PLAN_ACTIVATION_DONE = 4; |
| 19 MobileSetup.PLAN_ACTIVATION_ERROR = 5; | 19 MobileSetup.PLAN_ACTIVATION_ERROR = 5; |
| 20 | 20 |
| 21 MobileSetup.localStrings_ = new LocalStrings(); | 21 MobileSetup.localStrings_ = new LocalStrings(); |
| 22 | 22 |
| 23 MobileSetup.prototype = { | 23 MobileSetup.prototype = { |
| 24 // Mobile device information. | 24 // Mobile device information. |
| 25 deviceInfo_: null, | 25 deviceInfo_: null, |
| 26 frameName_ : '', | 26 frameName_ : '', |
| 27 // UI states. | 27 // UI states. |
| 28 state_ : -1, | 28 state_ : -1, |
| 29 STATE_UNKNOWN_: "unknown", | 29 STATE_UNKNOWN_: "unknown", |
| 30 STATE_CONNECTING_: "connecting", | 30 STATE_CONNECTING_: "connecting", |
| 31 STATE_ERROR_: "error", | 31 STATE_ERROR_: "error", |
| 32 STATE_PAYMENT_: "payment", | 32 STATE_PAYMENT_: "payment", |
| 33 STATE_ACTIVATING_: "activating", | 33 STATE_ACTIVATING_: "activating", |
| 34 STATE_CONNECTED_: "connected", | 34 STATE_CONNECTED_: "connected", |
| 35 | 35 |
| 36 initialize: function(frame_name) { | 36 initialize: function(frame_name) { |
| 37 self = this; | 37 self = this; |
| 38 this.frameName_ = frame_name; | 38 this.frameName_ = frame_name; |
| 39 window.addEventListener('message', function(e) { | 39 window.addEventListener('message', function(e) { |
| 40 self.onMessageReceived_(e); | 40 self.onMessageReceived_(e); |
| 41 }); | 41 }); |
| 42 $('cheat').addEventListener('click', function(e) { | 42 $('cheat').addEventListener('click', function(e) { |
| 43 $('paymentForm').classList.add('hidden'); |
| 43 chrome.send('setTransactionStatus', ['OK']); | 44 chrome.send('setTransactionStatus', ['OK']); |
| 44 }); | 45 }); |
| 45 $(frame_name).addEventListener('load', function(e) { | 46 $(frame_name).addEventListener('load', function(e) { |
| 46 // Flip the visibility of the payment page only after the frame is | 47 // Flip the visibility of the payment page only after the frame is |
| 47 // fully loaded. | 48 // fully loaded. |
| 48 $('statusHeader').textContent = ''; | 49 $('statusHeader').textContent = ''; |
| 49 $('paymentForm').classList.remove('hidden'); | 50 $('paymentForm').classList.remove('hidden'); |
| 50 $('finalMessage').classList.add('hidden'); | 51 $('finalMessage').classList.add('hidden'); |
| 51 $('errorMessage').classList.add('hidden'); | 52 $('errorMessage').classList.add('hidden'); |
| 52 $('systemStatus').classList.add('hidden'); | 53 $('systemStatus').classList.add('hidden'); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 68 }, | 69 }, |
| 69 | 70 |
| 70 onMessageReceived_: function(e) { | 71 onMessageReceived_: function(e) { |
| 71 if (e.origin != | 72 if (e.origin != |
| 72 this.deviceInfo_.payment_url.substring(0, e.origin.length)) | 73 this.deviceInfo_.payment_url.substring(0, e.origin.length)) |
| 73 return; | 74 return; |
| 74 | 75 |
| 75 if (e.data.type == 'requestDeviceInfoMsg') { | 76 if (e.data.type == 'requestDeviceInfoMsg') { |
| 76 this.sendDeviceInfo_(); | 77 this.sendDeviceInfo_(); |
| 77 } else if (e.data.type == 'reportTransactionStatusMsg') { | 78 } else if (e.data.type == 'reportTransactionStatusMsg') { |
| 79 $('paymentForm').classList.add('hidden'); |
| 78 chrome.send('setTransactionStatus', [e.data.status]); | 80 chrome.send('setTransactionStatus', [e.data.status]); |
| 79 } | 81 } |
| 80 }, | 82 }, |
| 81 | 83 |
| 82 changeState_: function(deviceInfo) { | 84 changeState_: function(deviceInfo) { |
| 83 var new_state = deviceInfo.state; | 85 var new_state = deviceInfo.state; |
| 84 if (this.state_ == new_state) | 86 if (this.state_ == new_state) |
| 85 return; | 87 return; |
| 86 var main = $('mainbody'); | 88 var main = $('mainbody'); |
| 87 // Map handler state to UX. | 89 // Map handler state to UX. |
| 88 switch(new_state) { | 90 switch(new_state) { |
| 89 case MobileSetup.PLAN_ACTIVATION_LOADING: | 91 case MobileSetup.PLAN_ACTIVATION_LOADING: |
| 90 case MobileSetup.PLAN_ACTIVATION_START: | 92 case MobileSetup.PLAN_ACTIVATION_START: |
| 91 $('statusHeader').textContent = | 93 $('statusHeader').textContent = |
| 92 MobileSetup.localStrings_.getString('connecting_header'); | 94 MobileSetup.localStrings_.getString('connecting_header'); |
| 93 $('errorMessage').textContent = ''; | 95 $('errorMessage').textContent = ''; |
| 94 $('paymentForm').classList.add('hidden'); | 96 $('paymentForm').classList.add('hidden'); |
| 95 $('finalMessage').classList.add('hidden'); | 97 $('finalMessage').classList.add('hidden'); |
| 96 $('errorMessage').classList.add('hidden'); | 98 $('errorMessage').classList.add('hidden'); |
| 97 $('systemStatus').classList.remove('hidden'); | 99 $('systemStatus').classList.remove('hidden'); |
| 98 break; | 100 break; |
| 99 case MobileSetup.PLAN_ACTIVATION_INITIATING_ACTIVATION: | 101 case MobileSetup.PLAN_ACTIVATION_INITIATING_ACTIVATION: |
| 100 case MobileSetup.PLAN_ACTIVATION_ACTIVATING: | 102 case MobileSetup.PLAN_ACTIVATION_RECONNECTING: |
| 101 $('statusHeader').textContent = | 103 $('statusHeader').textContent = |
| 102 MobileSetup.localStrings_.getString('activating_header'); | 104 MobileSetup.localStrings_.getString('activating_header'); |
| 103 $('errorMessage').textContent = ''; | 105 $('errorMessage').textContent = ''; |
| 104 $('paymentForm').classList.add('hidden'); | 106 $('paymentForm').classList.add('hidden'); |
| 105 $('finalMessage').classList.add('hidden'); | 107 $('finalMessage').classList.add('hidden'); |
| 106 $('errorMessage').classList.add('hidden'); | 108 $('errorMessage').classList.add('hidden'); |
| 107 $('systemStatus').classList.remove('hidden'); | 109 $('systemStatus').classList.remove('hidden'); |
| 108 break; | 110 break; |
| 109 case MobileSetup.PLAN_ACTIVATION_SHOWING_PAYMENT: | 111 case MobileSetup.PLAN_ACTIVATION_SHOWING_PAYMENT: |
| 110 this.loadPaymentFrame_(deviceInfo); | 112 this.loadPaymentFrame_(deviceInfo); |
| 111 break; | 113 break; |
| 112 case MobileSetup.PLAN_ACTIVATION_DONE: | 114 case MobileSetup.PLAN_ACTIVATION_DONE: |
| 113 $('statusHeader').textContent = ''; | 115 $('statusHeader').textContent = ''; |
| 114 $('paymentForm').classList.add('hidden'); | 116 $('paymentForm').classList.remove('hidden'); |
| 115 $('finalMessage').classList.remove('hidden'); | 117 $('finalMessage').classList.remove('hidden'); |
| 116 $('errorMessage').classList.add('hidden'); | 118 $('errorMessage').classList.add('hidden'); |
| 117 $('systemStatus').classList.add('hidden'); | 119 $('systemStatus').classList.add('hidden'); |
| 118 break; | 120 break; |
| 119 case MobileSetup.PLAN_ACTIVATION_ERROR: | 121 case MobileSetup.PLAN_ACTIVATION_ERROR: |
| 120 $('statusHeader').textContent = | 122 $('statusHeader').textContent = |
| 121 MobileSetup.localStrings_.getString('error_header'); | 123 MobileSetup.localStrings_.getString('error_header'); |
| 122 $('errorMessage').textContent = deviceInfo.error; | 124 $('errorMessage').textContent = deviceInfo.error; |
| 123 $('paymentForm').classList.add('hidden'); | 125 $('paymentForm').classList.add('hidden'); |
| 124 $('finalMessage').classList.add('hidden'); | 126 $('finalMessage').classList.add('hidden'); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 mobile.MobileSetup.getInstance().initialize('paymentForm'); | 198 mobile.MobileSetup.getInstance().initialize('paymentForm'); |
| 197 }; | 199 }; |
| 198 | 200 |
| 199 // Export | 201 // Export |
| 200 return { | 202 return { |
| 201 MobileSetup: MobileSetup | 203 MobileSetup: MobileSetup |
| 202 }; | 204 }; |
| 203 | 205 |
| 204 }); | 206 }); |
| 205 | 207 |
| OLD | NEW |