OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 * Authenticator class wraps the communications between Gaia and its host. | 6 * Authenticator class wraps the communications between Gaia and its host. |
7 */ | 7 */ |
8 function Authenticator() { | 8 function Authenticator() { |
9 } | 9 } |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 GAIA_URL: 'https://accounts.google.com/', | 41 GAIA_URL: 'https://accounts.google.com/', |
42 GAIA_PAGE_PATH: 'ServiceLogin?skipvpage=true&sarp=1&rm=hide', | 42 GAIA_PAGE_PATH: 'ServiceLogin?skipvpage=true&sarp=1&rm=hide', |
43 PARENT_PAGE: 'chrome://oobe/', | 43 PARENT_PAGE: 'chrome://oobe/', |
44 SERVICE_ID: 'chromeoslogin', | 44 SERVICE_ID: 'chromeoslogin', |
45 CONTINUE_URL: Authenticator.THIS_EXTENSION_ORIGIN + '/success.html', | 45 CONTINUE_URL: Authenticator.THIS_EXTENSION_ORIGIN + '/success.html', |
46 | 46 |
47 initialize: function() { | 47 initialize: function() { |
48 var params = getUrlSearchParams(location.search); | 48 var params = getUrlSearchParams(location.search); |
49 this.parentPage_ = params.parentPage || this.PARENT_PAGE; | 49 this.parentPage_ = params.parentPage || this.PARENT_PAGE; |
50 this.gaiaUrl_ = params.gaiaUrl || this.GAIA_URL; | 50 this.gaiaUrl_ = params.gaiaUrl || this.GAIA_URL; |
| 51 this.gaiaPath_ = params.gaiaPath || this.GAIA_PAGE_PATH; |
51 this.inputLang_ = params.hl; | 52 this.inputLang_ = params.hl; |
52 this.inputEmail_ = params.email; | 53 this.inputEmail_ = params.email; |
53 this.service_ = params.service || this.SERVICE_ID; | 54 this.service_ = params.service || this.SERVICE_ID; |
54 this.continueUrl_ = params.continueUrl || this.CONTINUE_URL; | 55 this.continueUrl_ = params.continueUrl || this.CONTINUE_URL; |
55 this.continueUrlWithoutParams_ = | 56 this.continueUrlWithoutParams_ = |
56 this.continueUrl_.substring(0, this.continueUrl_.indexOf('?')) || | 57 this.continueUrl_.substring(0, this.continueUrl_.indexOf('?')) || |
57 this.continueUrl_; | 58 this.continueUrl_; |
58 this.inlineMode_ = params.inlineMode; | 59 this.inlineMode_ = params.inlineMode; |
59 this.partitionId_ = params.partitionId || ''; | 60 this.partitionId_ = params.partitionId || ''; |
60 | 61 |
61 document.addEventListener('DOMContentLoaded', this.onPageLoad.bind(this)); | 62 document.addEventListener('DOMContentLoaded', this.onPageLoad.bind(this)); |
62 document.addEventListener('enableSAML', this.onEnableSAML_.bind(this)); | 63 document.addEventListener('enableSAML', this.onEnableSAML_.bind(this)); |
63 }, | 64 }, |
64 | 65 |
65 isGaiaMessage_: function(msg) { | 66 isGaiaMessage_: function(msg) { |
66 // Not quite right, but good enough. | 67 // Not quite right, but good enough. |
67 return this.gaiaUrl_.indexOf(msg.origin) == 0 || | 68 return this.gaiaUrl_.indexOf(msg.origin) == 0 || |
68 this.GAIA_URL.indexOf(msg.origin) == 0; | 69 this.GAIA_URL.indexOf(msg.origin) == 0; |
69 }, | 70 }, |
70 | 71 |
71 isInternalMessage_: function(msg) { | 72 isInternalMessage_: function(msg) { |
72 return msg.origin == Authenticator.THIS_EXTENSION_ORIGIN; | 73 return msg.origin == Authenticator.THIS_EXTENSION_ORIGIN; |
73 }, | 74 }, |
74 | 75 |
75 isParentMessage_: function(msg) { | 76 isParentMessage_: function(msg) { |
76 return msg.origin == this.parentPage_; | 77 return msg.origin == this.parentPage_; |
77 }, | 78 }, |
78 | 79 |
79 getFrameUrl_: function() { | 80 getFrameUrl_: function() { |
80 var url = this.gaiaUrl_; | 81 var url = this.gaiaUrl_ + this.gaiaPath_; |
81 | 82 |
82 url += this.GAIA_PAGE_PATH + | 83 url = appendParam(url, 'service', this.service_); |
83 '&service=' + encodeURIComponent(this.service_) + | 84 url = appendParam(url, 'continue', this.continueUrl_); |
84 '&continue=' + encodeURIComponent(this.continueUrl_); | 85 if (this.inputLang_) |
| 86 url = appendParam(url, 'hl', this.inputLang_); |
| 87 if (this.inputEmail_) |
| 88 url = appendParam(url, 'Email', this.inputEmail_); |
85 | 89 |
86 if (this.inputLang_) | |
87 url += '&hl=' + encodeURIComponent(this.inputLang_); | |
88 if (this.inputEmail_) | |
89 url += '&Email=' + encodeURIComponent(this.inputEmail_); | |
90 return url; | 90 return url; |
91 }, | 91 }, |
92 | 92 |
93 /** Callback when all loads in the gaia webview is complete. */ | 93 /** Callback when all loads in the gaia webview is complete. */ |
94 onWebviewLoadstop_: function(gaiaFrame) { | 94 onWebviewLoadstop_: function(gaiaFrame) { |
95 // Report the current state to the parent which will then update the | 95 // Report the current state to the parent which will then update the |
96 // browser history so that later it could respond properly to back/forward. | 96 // browser history so that later it could respond properly to back/forward. |
97 var msg = { | 97 var msg = { |
98 'method': 'reportState', | 98 'method': 'reportState', |
99 'src': gaiaFrame.src | 99 'src': gaiaFrame.src |
100 }; | 100 }; |
101 window.parent.postMessage(msg, this.parentPage_); | 101 window.parent.postMessage(msg, this.parentPage_); |
102 | 102 |
103 if (gaiaFrame.src.lastIndexOf( | 103 if (gaiaFrame.src.lastIndexOf( |
104 this.gaiaUrl_ + this.GAIA_PAGE_PATH, 0) == 0) { | 104 this.gaiaUrl_ + this.gaiaPath_, 0) == 0) { |
105 gaiaFrame.executeScript({file: 'inline_injected.js'}, function() { | 105 gaiaFrame.executeScript({file: 'inline_injected.js'}, function() { |
106 // Send an initial message to gaia so that it has an JavaScript | 106 // Send an initial message to gaia so that it has an JavaScript |
107 // reference to the embedder. | 107 // reference to the embedder. |
108 gaiaFrame.contentWindow.postMessage('', gaiaFrame.src); | 108 gaiaFrame.contentWindow.postMessage('', gaiaFrame.src); |
109 }); | 109 }); |
110 this.onLoginUILoaded(); | 110 this.onLoginUILoaded(); |
111 } else if (gaiaFrame.src.lastIndexOf( | 111 } else if (gaiaFrame.src.lastIndexOf( |
112 this.continueUrlWithoutParams_, 0) == 0) { | 112 this.continueUrlWithoutParams_, 0) == 0) { |
113 // Detect when login is finished by the load stop event of the continue | 113 // Detect when login is finished by the load stop event of the continue |
114 // URL. Cannot reuse the login complete flow in success.html, because | 114 // URL. Cannot reuse the login complete flow in success.html, because |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 } else if (msg.method == 'navigate' && | 253 } else if (msg.method == 'navigate' && |
254 this.isParentMessage_(e)) { | 254 this.isParentMessage_(e)) { |
255 $('gaia-frame').src = msg.src; | 255 $('gaia-frame').src = msg.src; |
256 } else { | 256 } else { |
257 console.error('Authenticator.onMessage: unknown message + origin!?'); | 257 console.error('Authenticator.onMessage: unknown message + origin!?'); |
258 } | 258 } |
259 } | 259 } |
260 }; | 260 }; |
261 | 261 |
262 Authenticator.getInstance().initialize(); | 262 Authenticator.getInstance().initialize(); |
OLD | NEW |