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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 | 79 |
80 /** Host list as it appears to the user. */ | 80 /** Host list as it appears to the user. */ |
81 private ListView mHostListView; | 81 private ListView mHostListView; |
82 | 82 |
83 /** Progress view shown instead of the host list when the host list is loadi ng. */ | 83 /** Progress view shown instead of the host list when the host list is loadi ng. */ |
84 private View mProgressView; | 84 private View mProgressView; |
85 | 85 |
86 /** Dialog for reporting connection progress. */ | 86 /** Dialog for reporting connection progress. */ |
87 private ProgressDialog mProgressIndicator; | 87 private ProgressDialog mProgressIndicator; |
88 | 88 |
89 /** Object for fetching OAuth2 access tokens from third party authorization servers. */ | |
90 private ThirdPartyTokenFetcher mTokenFetcher; | |
91 | |
89 /** | 92 /** |
90 * This is set when receiving an authentication error from the HostListLoade r. If that occurs, | 93 * This is set when receiving an authentication error from the HostListLoade r. If that occurs, |
91 * this flag is set and a fresh authentication token is fetched from the Acc ountsService, and | 94 * this flag is set and a fresh authentication token is fetched from the Acc ountsService, and |
92 * used to request the host list a second time. | 95 * used to request the host list a second time. |
93 */ | 96 */ |
94 boolean mTriedNewAuthToken; | 97 boolean mTriedNewAuthToken; |
95 | 98 |
96 /** Shows a warning explaining that a Google account is required, then close s the activity. */ | 99 /** Shows a warning explaining that a Google account is required, then close s the activity. */ |
97 private void showNoAccountsDialog() { | 100 private void showNoAccountsDialog() { |
98 AlertDialog.Builder builder = new AlertDialog.Builder(this); | 101 AlertDialog.Builder builder = new AlertDialog.Builder(this); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 mHostListView = (ListView)findViewById(R.id.hostList_chooser); | 158 mHostListView = (ListView)findViewById(R.id.hostList_chooser); |
156 mHostListView.setEmptyView(findViewById(R.id.hostList_empty)); | 159 mHostListView.setEmptyView(findViewById(R.id.hostList_empty)); |
157 mProgressView = findViewById(R.id.hostList_progress); | 160 mProgressView = findViewById(R.id.hostList_progress); |
158 | 161 |
159 findViewById(R.id.host_setup_link_android).setOnClickListener(this); | 162 findViewById(R.id.host_setup_link_android).setOnClickListener(this); |
160 | 163 |
161 // Bring native components online. | 164 // Bring native components online. |
162 JniInterface.loadLibrary(this); | 165 JniInterface.loadLibrary(this); |
163 } | 166 } |
164 | 167 |
168 @Override | |
169 protected void onNewIntent(Intent intent) { | |
170 super.onNewIntent(intent); | |
171 if (mTokenFetcher != null) { | |
172 if (mTokenFetcher.handleTokenFetched(intent)) { | |
173 mTokenFetcher = null; | |
174 } | |
175 } | |
176 } | |
165 /** | 177 /** |
166 * Called when the activity becomes visible. This happens on initial launch and whenever the | 178 * Called when the activity becomes visible. This happens on initial launch and whenever the |
167 * user switches to the activity, for example, by using the window-switcher or when coming from | 179 * user switches to the activity, for example, by using the window-switcher or when coming from |
168 * the device's lock screen. | 180 * the device's lock screen. |
169 */ | 181 */ |
170 @Override | 182 @Override |
171 public void onStart() { | 183 public void onStart() { |
172 super.onStart(); | 184 super.onStart(); |
173 | 185 |
174 mAccounts = AccountManager.get(this).getAccountsByType(ACCOUNT_TYPE); | 186 mAccounts = AccountManager.get(this).getAccountsByType(ACCOUNT_TYPE); |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
439 default: | 451 default: |
440 // Unreachable, but required by Google Java style and findbugs. | 452 // Unreachable, but required by Google Java style and findbugs. |
441 assert false : "Unreached"; | 453 assert false : "Unreached"; |
442 } | 454 } |
443 | 455 |
444 if (dismissProgress && mProgressIndicator != null) { | 456 if (dismissProgress && mProgressIndicator != null) { |
445 mProgressIndicator.dismiss(); | 457 mProgressIndicator.dismiss(); |
446 mProgressIndicator = null; | 458 mProgressIndicator = null; |
447 } | 459 } |
448 } | 460 } |
461 | |
462 public void fetchThirdPartyToken(String tokenUrl, String clientId, String sc ope) { | |
463 assert mTokenFetcher == null; | |
464 | |
465 ThirdPartyTokenFetcher.Callback callback = new ThirdPartyTokenFetcher.Ca llback() { | |
466 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 // that the host can obtains the shared secret from the third pa rty authorization | |
Lambros
2014/06/17 02:01:39
s/obtains/obtain
kelvinp
2014/06/17 03:33:40
Done.
| |
469 // server. | |
470 String token = code; | |
Lambros
2014/06/17 02:01:39
nit: Blank line before comment.
kelvinp
2014/06/17 03:33:40
Done.
| |
471 // The native client uses the OAuth access token as the shared s ecret to | |
472 // authenticate itself with the host using spake. | |
473 String sharedSecret = accessToken; | |
474 | |
475 JniInterface.nativeOnThirdPartyTokenFetched(token, sharedSecret) ; | |
476 } | |
477 }; | |
478 | |
479 mTokenFetcher = new ThirdPartyTokenFetcher(this, tokenUrl, clientId, sco pe, callback); | |
480 mTokenFetcher.fetchToken(); | |
481 } | |
482 | |
483 | |
449 } | 484 } |
OLD | NEW |