| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 83 |
| 84 /** Host list as it appears to the user. */ | 84 /** Host list as it appears to the user. */ |
| 85 private ListView mHostListView; | 85 private ListView mHostListView; |
| 86 | 86 |
| 87 /** Progress view shown instead of the host list when the host list is loadi
ng. */ | 87 /** Progress view shown instead of the host list when the host list is loadi
ng. */ |
| 88 private View mProgressView; | 88 private View mProgressView; |
| 89 | 89 |
| 90 /** Dialog for reporting connection progress. */ | 90 /** Dialog for reporting connection progress. */ |
| 91 private ProgressDialog mProgressIndicator; | 91 private ProgressDialog mProgressIndicator; |
| 92 | 92 |
| 93 /** Object for fetching OAuth2 access tokens from third party authorization
servers. */ | 93 /** |
| 94 private ThirdPartyTokenFetcher mTokenFetcher; | 94 * Helper used by SessionConnection for session authentication. Receives onN
ewIntent() |
| 95 * notifications to handle third-party authentication. |
| 96 */ |
| 97 private SessionAuthenticator mAuthenticator; |
| 95 | 98 |
| 96 /** | 99 /** |
| 97 * This is set when receiving an authentication error from the HostListLoade
r. If that occurs, | 100 * This is set when receiving an authentication error from the HostListLoade
r. If that occurs, |
| 98 * this flag is set and a fresh authentication token is fetched from the Acc
ountsService, and | 101 * this flag is set and a fresh authentication token is fetched from the Acc
ountsService, and |
| 99 * used to request the host list a second time. | 102 * used to request the host list a second time. |
| 100 */ | 103 */ |
| 101 boolean mTriedNewAuthToken; | 104 boolean mTriedNewAuthToken; |
| 102 | 105 |
| 103 /** | 106 /** |
| 104 * Flag to track whether a call to AccountManager.getAuthToken() is currentl
y pending. | 107 * Flag to track whether a call to AccountManager.getAuthToken() is currentl
y pending. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 210 |
| 208 @Override | 211 @Override |
| 209 protected void onPostCreate(Bundle savedInstanceState) { | 212 protected void onPostCreate(Bundle savedInstanceState) { |
| 210 super.onPostCreate(savedInstanceState); | 213 super.onPostCreate(savedInstanceState); |
| 211 mDrawerToggle.syncState(); | 214 mDrawerToggle.syncState(); |
| 212 } | 215 } |
| 213 | 216 |
| 214 @Override | 217 @Override |
| 215 protected void onNewIntent(Intent intent) { | 218 protected void onNewIntent(Intent intent) { |
| 216 super.onNewIntent(intent); | 219 super.onNewIntent(intent); |
| 217 if (mTokenFetcher != null) { | 220 |
| 218 if (mTokenFetcher.handleTokenFetched(intent)) { | 221 if (mAuthenticator != null) { |
| 219 mTokenFetcher = null; | 222 mAuthenticator.onNewIntent(intent); |
| 220 } | |
| 221 } | 223 } |
| 222 } | 224 } |
| 223 | 225 |
| 224 /** | 226 /** |
| 225 * Called when the activity becomes visible. This happens on initial launch
and whenever the | 227 * Called when the activity becomes visible. This happens on initial launch
and whenever the |
| 226 * user switches to the activity, for example, by using the window-switcher
or when coming from | 228 * user switches to the activity, for example, by using the window-switcher
or when coming from |
| 227 * the device's lock screen. | 229 * the device's lock screen. |
| 228 */ | 230 */ |
| 229 @Override | 231 @Override |
| 230 public void onStart() { | 232 public void onStart() { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 mProgressIndicator = ProgressDialog.show( | 318 mProgressIndicator = ProgressDialog.show( |
| 317 this, | 319 this, |
| 318 host.name, | 320 host.name, |
| 319 getString(R.string.footer_connecting), | 321 getString(R.string.footer_connecting), |
| 320 true, | 322 true, |
| 321 true, | 323 true, |
| 322 new DialogInterface.OnCancelListener() { | 324 new DialogInterface.OnCancelListener() { |
| 323 @Override | 325 @Override |
| 324 public void onCancel(DialogInterface dialog) { | 326 public void onCancel(DialogInterface dialog) { |
| 325 JniInterface.disconnectFromHost(); | 327 JniInterface.disconnectFromHost(); |
| 326 mTokenFetcher = null; | |
| 327 } | 328 } |
| 328 }); | 329 }); |
| 329 SessionConnector connector = new SessionConnector(this, this, mHostListL
oader); | 330 SessionConnector connector = new SessionConnector(this, this, mHostListL
oader); |
| 330 assert mTokenFetcher == null; | 331 mAuthenticator = new SessionAuthenticator(this, host); |
| 331 mTokenFetcher = createTokenFetcher(host); | 332 connector.connectToHost(mAccount.name, mToken, host, mAuthenticator); |
| 332 connector.connectToHost(mAccount.name, mToken, host); | |
| 333 } | 333 } |
| 334 | 334 |
| 335 private void refreshHostList() { | 335 private void refreshHostList() { |
| 336 if (mWaitingForAuthToken) { | 336 if (mWaitingForAuthToken) { |
| 337 return; | 337 return; |
| 338 } | 338 } |
| 339 | 339 |
| 340 mTriedNewAuthToken = false; | 340 mTriedNewAuthToken = false; |
| 341 setHostListProgressVisible(true); | 341 setHostListProgressVisible(true); |
| 342 | 342 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 default: | 503 default: |
| 504 // Unreachable, but required by Google Java style and findbugs. | 504 // Unreachable, but required by Google Java style and findbugs. |
| 505 assert false : "Unreached"; | 505 assert false : "Unreached"; |
| 506 } | 506 } |
| 507 | 507 |
| 508 if (dismissProgress && mProgressIndicator != null) { | 508 if (dismissProgress && mProgressIndicator != null) { |
| 509 mProgressIndicator.dismiss(); | 509 mProgressIndicator.dismiss(); |
| 510 mProgressIndicator = null; | 510 mProgressIndicator = null; |
| 511 } | 511 } |
| 512 } | 512 } |
| 513 | |
| 514 private ThirdPartyTokenFetcher createTokenFetcher(HostInfo host) { | |
| 515 ThirdPartyTokenFetcher.Callback callback = new ThirdPartyTokenFetcher.Ca
llback() { | |
| 516 @Override | |
| 517 public void onTokenFetched(String code, String accessToken) { | |
| 518 // The native client sends the OAuth authorization code to the h
ost as the token so | |
| 519 // that the host can obtain the shared secret from the third par
ty authorization | |
| 520 // server. | |
| 521 String token = code; | |
| 522 | |
| 523 // The native client uses the OAuth access token as the shared s
ecret to | |
| 524 // authenticate itself with the host using spake. | |
| 525 String sharedSecret = accessToken; | |
| 526 | |
| 527 JniInterface.onThirdPartyTokenFetched(token, sharedSecret); | |
| 528 } | |
| 529 }; | |
| 530 return new ThirdPartyTokenFetcher(this, host.getTokenUrlPatterns(), call
back); | |
| 531 } | |
| 532 | |
| 533 public void fetchThirdPartyToken(String tokenUrl, String clientId, String sc
ope) { | |
| 534 assert mTokenFetcher != null; | |
| 535 mTokenFetcher.fetchToken(tokenUrl, clientId, scope); | |
| 536 } | |
| 537 } | 513 } |
| OLD | NEW |