OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 package org.chromium.chromoting; | 5 package org.chromium.chromoting; |
6 | 6 |
7 import android.accounts.Account; | 7 import android.accounts.Account; |
8 import android.accounts.AccountManager; | 8 import android.accounts.AccountManager; |
9 import android.accounts.AccountManagerCallback; | 9 import android.accounts.AccountManagerCallback; |
10 import android.accounts.AccountManagerFuture; | 10 import android.accounts.AccountManagerFuture; |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 } | 274 } |
275 | 275 |
276 /** Called when the user taps on a host entry. */ | 276 /** Called when the user taps on a host entry. */ |
277 public void connectToHost(HostInfo host) { | 277 public void connectToHost(HostInfo host) { |
278 mProgressIndicator = ProgressDialog.show(this, | 278 mProgressIndicator = ProgressDialog.show(this, |
279 host.name, getString(R.string.footer_connecting), true, true, | 279 host.name, getString(R.string.footer_connecting), true, true, |
280 new DialogInterface.OnCancelListener() { | 280 new DialogInterface.OnCancelListener() { |
281 @Override | 281 @Override |
282 public void onCancel(DialogInterface dialog) { | 282 public void onCancel(DialogInterface dialog) { |
283 JniInterface.disconnectFromHost(); | 283 JniInterface.disconnectFromHost(); |
| 284 mTokenFetcher = null; |
284 } | 285 } |
285 }); | 286 }); |
286 SessionConnector connector = new SessionConnector(this, this, mHostListL
oader); | 287 SessionConnector connector = new SessionConnector(this, this, mHostListL
oader); |
| 288 assert mTokenFetcher == null; |
| 289 mTokenFetcher = createTokenFetcher(host); |
287 connector.connectToHost(mAccount.name, mToken, host); | 290 connector.connectToHost(mAccount.name, mToken, host); |
288 } | 291 } |
289 | 292 |
290 private void refreshHostList() { | 293 private void refreshHostList() { |
291 mTriedNewAuthToken = false; | 294 mTriedNewAuthToken = false; |
292 setHostListProgressVisible(true); | 295 setHostListProgressVisible(true); |
293 | 296 |
294 // The refresh button simply makes use of the currently-chosen account. | 297 // The refresh button simply makes use of the currently-chosen account. |
295 AccountManager.get(this).getAuthToken(mAccount, TOKEN_SCOPE, null, this,
this, null); | 298 AccountManager.get(this).getAuthToken(mAccount, TOKEN_SCOPE, null, this,
this, null); |
296 } | 299 } |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 // Unreachable, but required by Google Java style and findbugs. | 455 // Unreachable, but required by Google Java style and findbugs. |
453 assert false : "Unreached"; | 456 assert false : "Unreached"; |
454 } | 457 } |
455 | 458 |
456 if (dismissProgress && mProgressIndicator != null) { | 459 if (dismissProgress && mProgressIndicator != null) { |
457 mProgressIndicator.dismiss(); | 460 mProgressIndicator.dismiss(); |
458 mProgressIndicator = null; | 461 mProgressIndicator = null; |
459 } | 462 } |
460 } | 463 } |
461 | 464 |
462 public void fetchThirdPartyToken(String tokenUrl, String clientId, String sc
ope) { | 465 private ThirdPartyTokenFetcher createTokenFetcher(HostInfo host) { |
463 assert mTokenFetcher == null; | |
464 | |
465 ThirdPartyTokenFetcher.Callback callback = new ThirdPartyTokenFetcher.Ca
llback() { | 466 ThirdPartyTokenFetcher.Callback callback = new ThirdPartyTokenFetcher.Ca
llback() { |
466 public void onTokenFetched(String code, String accessToken) { | 467 public void onTokenFetched(String code, String accessToken) { |
467 // The native client sends the OAuth authorization code to the h
ost as the token so | 468 // The native client sends the OAuth authorization code to the h
ost as the token so |
468 // that the host can obtain the shared secret from the third par
ty authorization | 469 // that the host can obtain the shared secret from the third par
ty authorization |
469 // server. | 470 // server. |
470 String token = code; | 471 String token = code; |
471 | 472 |
472 // The native client uses the OAuth access token as the shared s
ecret to | 473 // The native client uses the OAuth access token as the shared s
ecret to |
473 // authenticate itself with the host using spake. | 474 // authenticate itself with the host using spake. |
474 String sharedSecret = accessToken; | 475 String sharedSecret = accessToken; |
475 | 476 |
476 JniInterface.nativeOnThirdPartyTokenFetched(token, sharedSecret)
; | 477 JniInterface.nativeOnThirdPartyTokenFetched(token, sharedSecret)
; |
477 } | 478 } |
478 }; | 479 }; |
479 | 480 return new ThirdPartyTokenFetcher(this, host.tokenUrlPatterns, callback)
; |
480 mTokenFetcher = new ThirdPartyTokenFetcher(this, tokenUrl, clientId, sco
pe, callback); | |
481 mTokenFetcher.fetchToken(); | |
482 } | 481 } |
483 | 482 |
484 | 483 public void fetchThirdPartyToken(String tokenUrl, String clientId, String sc
ope) { |
| 484 assert mTokenFetcher != null; |
| 485 mTokenFetcher.fetchToken(tokenUrl, clientId, scope); |
| 486 } |
485 } | 487 } |
OLD | NEW |