Chromium Code Reviews| 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 // TODO(ajwong): This seems like a bad idea to share the exact same object | 5 // TODO(ajwong): This seems like a bad idea to share the exact same object |
| 6 // with the background page. Why are we doing it like this? | 6 // with the background page. Why are we doing it like this? |
| 7 var remoting = chrome.extension.getBackgroundPage().remoting; | 7 var remoting = chrome.extension.getBackgroundPage().remoting; |
| 8 | 8 |
| 9 XMPP_LOGIN_NAME = 'xmpp_login'; | 9 XMPP_LOGIN_NAME = 'xmpp_login'; |
| 10 XMPP_TOKEN_NAME = 'xmpp_token'; | 10 XMPP_TOKEN_NAME = 'xmpp_token'; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 document.getElementById('oauth2_code_button').style.display = 'inline'; | 24 document.getElementById('oauth2_code_button').style.display = 'inline'; |
| 25 document.getElementById('oauth2_clear_button').style.display = 'none'; | 25 document.getElementById('oauth2_clear_button').style.display = 'none'; |
| 26 document.getElementById('oauth2_form').style.display = 'inline'; | 26 document.getElementById('oauth2_form').style.display = 'inline'; |
| 27 } | 27 } |
| 28 var xmpp_status = document.getElementById('xmpp_status'); | 28 var xmpp_status = document.getElementById('xmpp_status'); |
| 29 if (remoting.getItem(XMPP_TOKEN_NAME) && remoting.getItem(XMPP_LOGIN_NAME)) { | 29 if (remoting.getItem(XMPP_TOKEN_NAME) && remoting.getItem(XMPP_LOGIN_NAME)) { |
| 30 document.getElementById('xmpp_clear').style.display = 'inline'; | 30 document.getElementById('xmpp_clear').style.display = 'inline'; |
| 31 document.getElementById('xmpp_form').style.display = 'none'; | 31 document.getElementById('xmpp_form').style.display = 'none'; |
| 32 xmpp_status.innerText = 'OK'; | 32 xmpp_status.innerText = 'OK'; |
| 33 xmpp_status.style.color = 'green'; | 33 xmpp_status.style.color = 'green'; |
| 34 remoting.xmppAuthToken = remoting.getItem(XMPP_TOKEN_NAME); | |
| 35 } else { | 34 } else { |
| 36 document.getElementById('xmpp_clear').style.display = 'none'; | 35 document.getElementById('xmpp_clear').style.display = 'none'; |
| 37 document.getElementById('xmpp_form').style.display = 'inline'; | 36 document.getElementById('xmpp_form').style.display = 'inline'; |
| 38 xmpp_status.innerText = 'Unauthorized'; | 37 xmpp_status.innerText = 'Unauthorized'; |
| 39 xmpp_status.style.color = 'red'; | 38 xmpp_status.style.color = 'red'; |
| 40 } | 39 } |
| 40 var current_email = document.getElementById('current_email'); | |
| 41 if (remoting.getItem(XMPP_LOGIN_NAME)) { | |
|
Wez
2011/05/25 03:57:46
It's a bit confusing that XMPP_LOGIN_NAME contains
awong
2011/05/25 16:56:56
Yes...I'm not going to change this for now. We're
| |
| 42 oauth2_status.style.color = 'green'; | |
| 43 current_email.innerText = remoting.getItem(XMPP_LOGIN_NAME); | |
| 44 } else { | |
| 45 oauth2_status.style.color = 'red'; | |
| 46 current_email.innerText = 'missing e-mail'; | |
| 47 } | |
| 41 } | 48 } |
| 42 | 49 |
| 43 function clientLoginError_(xhr) { | 50 function clientLoginError_(xhr) { |
| 44 // If there's an error URL, load it into an iframe. | 51 // If there's an error URL, load it into an iframe. |
| 45 var url_line = xhr.responseText.match('Url=.*'); | 52 var url_line = xhr.responseText.match('Url=.*'); |
| 46 if (url_line) { | 53 if (url_line) { |
| 47 url = url_line[0].substr(4); | 54 url = url_line[0].substr(4); |
| 48 var error_frame = document.getElementById('xmpp_error'); | 55 var error_frame = document.getElementById('xmpp_error'); |
| 49 error_frame.src = url; | 56 error_frame.src = url; |
| 50 error_frame.style.display = 'block'; | 57 error_frame.style.display = 'block'; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 '&Email=' + encodeURIComponent(form['xmpp_username'].value) + | 139 '&Email=' + encodeURIComponent(form['xmpp_username'].value) + |
| 133 '&Passwd=' + encodeURIComponent(form['xmpp_password'].value); | 140 '&Passwd=' + encodeURIComponent(form['xmpp_password'].value); |
| 134 | 141 |
| 135 if (captcha_result[0]) { | 142 if (captcha_result[0]) { |
| 136 post_data += '&logintoken=' + encodeURIComponent(captcha_result[0]) + | 143 post_data += '&logintoken=' + encodeURIComponent(captcha_result[0]) + |
| 137 '&logincaptcha=' + encodeURIComponent(captcha_result[1]); | 144 '&logincaptcha=' + encodeURIComponent(captcha_result[1]); |
| 138 } | 145 } |
| 139 xhr.send(post_data); | 146 xhr.send(post_data); |
| 140 } | 147 } |
| 141 | 148 |
| 149 function setEmail(form) { | |
| 150 remoting.setItem(XMPP_LOGIN_NAME, form['new_email'].value); | |
| 151 updateAuthStatus_(); | |
| 152 } | |
| 153 | |
| 142 function authorizeOAuth2(code) { | 154 function authorizeOAuth2(code) { |
| 143 remoting.oauth2.exchangeCodeForToken(code, updateAuthStatus_); | 155 remoting.oauth2.exchangeCodeForToken(code, updateAuthStatus_); |
| 144 } | 156 } |
| 145 | 157 |
| 146 function clearOAuth2() { | 158 function clearOAuth2() { |
| 147 remoting.oauth2.clear(); | 159 remoting.oauth2.clear(); |
| 148 updateAuthStatus_(); | 160 updateAuthStatus_(); |
| 149 } | 161 } |
| 150 | 162 |
| 151 function clearXmpp() { | 163 function clearXmpp() { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 'preparing_to_share', | 199 'preparing_to_share', |
| 188 'ready_to_share', | 200 'ready_to_share', |
| 189 'shared']); | 201 'shared']); |
| 190 } | 202 } |
| 191 | 203 |
| 192 function setClientMode(mode) { | 204 function setClientMode(mode) { |
| 193 setMode_(mode, ['unconnected', 'connecting', 'connect_failed']); | 205 setMode_(mode, ['unconnected', 'connecting', 'connect_failed']); |
| 194 } | 206 } |
| 195 | 207 |
| 196 function tryShare() { | 208 function tryShare() { |
| 209 if (remoting.oauth2.needsNewAccessToken()) { | |
| 210 remoting.oauth2.refreshAccessToken(tryShare); | |
| 211 return; | |
| 212 } | |
| 213 | |
| 197 var div = document.getElementById('plugin_wrapper'); | 214 var div = document.getElementById('plugin_wrapper'); |
| 198 var plugin = document.createElement('embed'); | 215 var plugin = document.createElement('embed'); |
| 199 plugin.setAttribute('type', 'HOST_PLUGIN_MIMETYPE'); | 216 plugin.setAttribute('type', 'HOST_PLUGIN_MIMETYPE'); |
| 200 plugin.setAttribute('hidden', 'true'); | 217 plugin.setAttribute('hidden', 'true'); |
| 201 plugin.setAttribute('id', HOST_PLUGIN_ID); | 218 plugin.setAttribute('id', HOST_PLUGIN_ID); |
| 202 div.appendChild(plugin); | 219 div.appendChild(plugin); |
| 203 plugin.onStateChanged = onStateChanged_; | 220 plugin.onStateChanged = onStateChanged_; |
| 204 plugin.connect(remoting.getItem(XMPP_LOGIN_NAME), | 221 plugin.connect(remoting.getItem(XMPP_LOGIN_NAME), |
| 205 remoting.getItem(XMPP_TOKEN_NAME)); | 222 'oauth2:' + remoting.oauth2.getAccessToken()); |
| 206 } | 223 } |
| 207 | 224 |
| 208 function onStateChanged_() { | 225 function onStateChanged_() { |
| 209 var plugin = document.getElementById(HOST_PLUGIN_ID); | 226 var plugin = document.getElementById(HOST_PLUGIN_ID); |
| 210 var state = plugin.state; | 227 var state = plugin.state; |
| 211 if (state == plugin.REQUESTED_ACCESS_CODE) { | 228 if (state == plugin.REQUESTED_ACCESS_CODE) { |
| 212 setHostMode('preparing_to_share'); | 229 setHostMode('preparing_to_share'); |
| 213 } else if (state == plugin.RECEIVED_ACCESS_CODE) { | 230 } else if (state == plugin.RECEIVED_ACCESS_CODE) { |
| 214 var access_code = plugin.accessCode; | 231 var access_code = plugin.accessCode; |
| 215 var access_code_display = document.getElementById('access_code_display'); | 232 var access_code_display = document.getElementById('access_code_display'); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 | 297 |
| 281 xhr.open('GET', | 298 xhr.open('GET', |
| 282 'https://www.googleapis.com/chromoting/v1/support-hosts/' + | 299 'https://www.googleapis.com/chromoting/v1/support-hosts/' + |
| 283 encodeURIComponent(support_id), | 300 encodeURIComponent(support_id), |
| 284 true); | 301 true); |
| 285 xhr.setRequestHeader('Authorization', | 302 xhr.setRequestHeader('Authorization', |
| 286 'OAuth ' + remoting.oauth2.getAccessToken()); | 303 'OAuth ' + remoting.oauth2.getAccessToken()); |
| 287 xhr.send(null); | 304 xhr.send(null); |
| 288 } | 305 } |
| 289 | 306 |
| 290 function tryConnect(form) { | 307 function tryConnect(accessCode) { |
| 291 remoting.accessCode = normalizeAccessCode(form['access_code_entry'].value); | 308 if (remoting.oauth2.needsNewAccessToken()) { |
| 309 remoting.oauth2.refreshAccessToken(function() { | |
| 310 tryConnect(accessCode); | |
|
Wez
2011/05/25 03:57:46
Is there any possibility of this getting stuck in
awong
2011/05/25 17:07:31
Good point. Added simple break for now.
| |
| 311 }); | |
| 312 return; | |
| 313 } | |
| 314 | |
| 315 remoting.accessCode = accessCode; | |
| 292 // TODO(jamiewalch): Since the mapping from (SupportId, HostSecret) to | 316 // TODO(jamiewalch): Since the mapping from (SupportId, HostSecret) to |
| 293 // AccessCode is not yet defined, assume it's hyphen-separated for now. | 317 // AccessCode is not yet defined, assume it's hyphen-separated for now. |
| 294 var parts = remoting.accessCode.split('-'); | 318 var parts = remoting.accessCode.split('-'); |
| 295 if (parts.length != 2) { | 319 if (parts.length != 2) { |
| 296 showConnectError_(404); | 320 showConnectError_(404); |
| 297 } else { | 321 } else { |
| 298 setClientMode('connecting'); | 322 setClientMode('connecting'); |
| 299 if (remoting.oauth2.needsNewAccessToken()) { | 323 resolveSupportId(parts[0]); |
| 300 remoting.oauth2.refreshAccessToken(function() { | |
| 301 resolveSupportId(parts[0]); | |
| 302 }); | |
| 303 return; | |
| 304 } else { | |
| 305 resolveSupportId(parts[0]); | |
| 306 } | |
| 307 } | 324 } |
| 308 } | 325 } |
| 309 | 326 |
| 310 function cancelConnect() { | 327 function cancelConnect() { |
| 311 remoting.accessCode = ''; | 328 remoting.accessCode = ''; |
| 312 setClientMode('unconnected'); | 329 setClientMode('unconnected'); |
| 313 } | 330 } |
| OLD | NEW |