OLD | NEW |
---|---|
(Empty) | |
1 function Authenticator() { | |
csilv
2012/05/25 22:38:39
nit: add chromium copyright header
zel
2012/05/25 23:33:53
Done.
| |
2 } | |
3 | |
4 Authenticator.getInstance = function() { | |
5 if (!Authenticator.instance_) { | |
6 Authenticator.instance_ = new Authenticator(); | |
7 } | |
8 return Authenticator.instance_; | |
9 }; | |
10 | |
11 Authenticator.prototype = { | |
12 email_: null, | |
13 password_: null, | |
14 attemptToken_: null, | |
15 | |
16 // Input params from extension initialization URL. | |
17 inputLang_: undefined, | |
18 intputEmail_: undefined, | |
19 | |
20 GAIA_PAGE_ORIGIN: 'https://accounts.google.com', | |
21 GAIA_PAGE_PATH: '/ServiceLogin?service=chromeoslogin' + | |
22 '&skipvpage=true&sarp=1&rm=hide' + | |
23 '&continue=chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik/' + | |
24 'success.html', | |
25 THIS_EXTENSION_ORIGIN: 'chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik', | |
26 PARENT_PAGE: 'chrome://oobe/', | |
27 | |
28 initialize: function() { | |
29 console.log('### Authenticator.initialize'); | |
csilv
2012/05/25 22:38:39
remove console.log unless there is a good reason t
zel
2012/05/25 23:33:53
Done. Kept those that report real errors.
| |
30 | |
31 var params = getUrlSearchParams(location.search); | |
32 this.gaiaOrigin_ = params['gaiaOrigin'] || this.GAIA_PAGE_ORIGIN; | |
33 this.gaiaUrlPath_ = params['gaiaUrlPath'] || ''; | |
34 this.inputLang_ = params['hl']; | |
35 this.inputEmail_ = params['email']; | |
36 this.testEmail_ = params['test_email']; | |
37 this.testPassword_ = params['test_password']; | |
38 | |
39 document.addEventListener('DOMContentLoaded', this.onPageLoad.bind(this)); | |
40 }, | |
41 | |
42 isGaiaMessage_: function(msg) { | |
43 return msg.origin == this.gaiaOrigin_ || | |
44 msg.origin == this.GAIA_PAGE_ORIGIN; | |
45 }, | |
46 | |
47 isInternalMessage_: function(msg) { | |
48 return msg.origin == this.THIS_EXTENSION_ORIGIN; | |
49 }, | |
50 | |
51 getFrameUrl_: function() { | |
52 var url = this.gaiaOrigin_; | |
53 | |
54 if (this.gaiaOrigin_ == 'https://www.google.com') | |
55 url += '/accounts'; | |
56 | |
57 if (this.gaiaUrlPath_ && this.gaiaUrlPath_ != '') | |
58 url += this.gaiaUrlPath_; | |
59 | |
60 url += this.GAIA_PAGE_PATH; | |
61 | |
62 if (this.inputLang_) | |
63 url += '&hl=' + encodeURIComponent(this.inputLang_); | |
64 if (this.inputEmail_) | |
65 url += '&Email=' + encodeURIComponent(this.inputEmail_); | |
66 if (this.testEmail_) | |
67 url += '&test_email=' + encodeURIComponent(this.testEmail_); | |
68 if (this.testPassword_) | |
69 url += '&test_pwd=' + encodeURIComponent(this.testPassword_); | |
70 return url; | |
71 }, | |
72 | |
73 loadFrame_: function() { | |
74 console.log('Authenticator loading GAIA frame from ' + this.getFrameUrl_()); | |
75 $('gaia-frame').src = this.getFrameUrl_(); | |
76 }, | |
77 | |
78 onPageLoad: function(e) { | |
79 window.addEventListener('message', this.onMessage.bind(this), false); | |
80 this.loadFrame_(); | |
81 }, | |
82 | |
83 onLoginUILoaded: function() { | |
84 var msg = { | |
85 'method': 'loginUILoaded' | |
86 }; | |
87 window.parent.postMessage(msg, this.PARENT_PAGE); | |
88 console.log('### Authenticator.onLoginUILoaded.'); | |
89 }, | |
90 | |
91 onMessage: function(e) { | |
92 var msg = e.data; | |
93 console.log('#### Authenticator.onMessage: method=' + msg.method); | |
94 if (msg.method == 'attemptLogin' && this.isGaiaMessage_(e)) { | |
95 this.email_ = msg.email; | |
96 this.password_ = msg.password; | |
97 this.attemptToken_ = msg.attemptToken; | |
98 } else if (msg.method == 'clearOldAttempts' && this.isGaiaMessage_(e)) { | |
99 this.email_ = null; | |
100 this.password_ = null; | |
101 this.attemptToken_ = null; | |
102 this.onLoginUILoaded(); | |
103 } else if (msg.method == 'confirmLogin' && this.isInternalMessage_(e)) { | |
104 if (this.attemptToken_ == msg.attemptToken) { | |
105 var msg = { | |
106 'method': 'completeLogin', | |
107 'email': this.email_, | |
108 'password': this.password_ | |
109 }; | |
110 window.parent.postMessage(msg, this.PARENT_PAGE); | |
111 } else { | |
112 console.log('#### Authenticator.onMessage: unexpected attemptToken!?'); | |
113 } | |
114 } else { | |
115 console.log('#### Authenticator.onMessage: unknown message + origin!?'); | |
116 } | |
117 } | |
118 }; | |
119 | |
120 console.log('#### main.html start'); | |
121 Authenticator.getInstance().initialize(); | |
122 | |
OLD | NEW |