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 #include "chrome/browser/extensions/api/identity/experimental_identity_api.h" | 5 #include "chrome/browser/extensions/api/identity/experimental_identity_api.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/app_mode/app_mode_utils.h" | 13 #include "chrome/browser/app_mode/app_mode_utils.h" |
14 #include "chrome/browser/browser_process.h" | |
14 #include "chrome/browser/extensions/api/identity/identity_api.h" | 15 #include "chrome/browser/extensions/api/identity/identity_api.h" |
15 #include "chrome/browser/extensions/extension_install_prompt.h" | 16 #include "chrome/browser/extensions/extension_install_prompt.h" |
17 #include "chrome/browser/policy/browser_policy_connector.h" | |
16 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/signin/signin_manager.h" | 19 #include "chrome/browser/signin/signin_manager.h" |
18 #include "chrome/browser/signin/signin_manager_factory.h" | 20 #include "chrome/browser/signin/signin_manager_factory.h" |
19 #include "chrome/browser/signin/token_service.h" | 21 #include "chrome/browser/signin/token_service.h" |
20 #include "chrome/browser/signin/token_service_factory.h" | 22 #include "chrome/browser/signin/token_service_factory.h" |
21 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
22 #include "chrome/common/extensions/api/experimental_identity.h" | 24 #include "chrome/common/extensions/api/experimental_identity.h" |
23 #include "chrome/common/extensions/api/identity.h" | 25 #include "chrome/common/extensions/api/identity.h" |
24 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h" | 26 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h" |
25 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
26 #include "chrome/common/extensions/extension_manifest_constants.h" | 28 #include "chrome/common/extensions/extension_manifest_constants.h" |
27 #include "chrome/common/extensions/manifest_handler.h" | 29 #include "chrome/common/extensions/manifest_handler.h" |
28 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
29 #include "content/public/common/page_transition_types.h" | 31 #include "content/public/common/page_transition_types.h" |
30 #include "google_apis/gaia/gaia_constants.h" | 32 #include "google_apis/gaia/gaia_constants.h" |
31 #include "googleurl/src/gurl.h" | 33 #include "googleurl/src/gurl.h" |
32 #include "ui/base/window_open_disposition.h" | 34 #include "ui/base/window_open_disposition.h" |
33 | 35 |
34 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
35 #include "chrome/browser/chromeos/login/user_manager.h" | 37 #include "chrome/browser/chromeos/login/user_manager.h" |
38 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" | |
39 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " | |
36 #endif | 40 #endif |
37 | 41 |
38 namespace extensions { | 42 namespace extensions { |
39 | 43 |
40 namespace { | 44 namespace { |
41 | 45 |
42 static const char kChromiumDomainRedirectUrlPattern[] = | 46 static const char kChromiumDomainRedirectUrlPattern[] = |
43 "https://%s.chromiumapp.org/"; | 47 "https://%s.chromiumapp.org/"; |
44 | 48 |
45 } // namespace | 49 } // namespace |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 } | 82 } |
79 | 83 |
80 if (oauth2_info.scopes.size() == 0) { | 84 if (oauth2_info.scopes.size() == 0) { |
81 error_ = identity_constants::kInvalidScopes; | 85 error_ = identity_constants::kInvalidScopes; |
82 return false; | 86 return false; |
83 } | 87 } |
84 | 88 |
85 // Balanced in CompleteFunctionWithResult|CompleteFunctionWithError | 89 // Balanced in CompleteFunctionWithResult|CompleteFunctionWithError |
86 AddRef(); | 90 AddRef(); |
87 | 91 |
92 #if defined(OS_CHROMEOS) | |
93 if (chromeos::UserManager::Get()->IsLoggedInAsKioskApp() && | |
94 g_browser_process->browser_policy_connector()->IsEnterpriseManaged()) { | |
zel
2013/06/19 03:09:35
do you want to test if DeviceOAuth2TokenServiceFac
Mattias Nissler (ping if slow)
2013/06/19 03:44:40
Since we don't have the intention to send the user
zel
2013/06/19 21:46:25
Actually, we can still let app show sign-in UI on
| |
95 OAuth2TokenService::ScopeSet scope_set(oauth2_info.scopes.begin(), | |
96 oauth2_info.scopes.end()); | |
97 device_token_request_ = | |
98 chromeos::DeviceOAuth2TokenServiceFactory::Get()->StartRequest( | |
99 scope_set, this); | |
100 return true; | |
101 } | |
102 #endif | |
103 | |
88 if (!HasLoginToken()) { | 104 if (!HasLoginToken()) { |
89 if (!should_prompt_for_signin_) { | 105 if (!should_prompt_for_signin_) { |
90 error_ = identity_constants::kUserNotSignedIn; | 106 error_ = identity_constants::kUserNotSignedIn; |
91 Release(); | 107 Release(); |
92 return false; | 108 return false; |
93 } | 109 } |
94 // Display a login prompt. | 110 // Display a login prompt. |
95 StartSigninFlow(); | 111 StartSigninFlow(); |
96 } else { | 112 } else { |
97 TokenService* token_service = TokenServiceFactory::GetForProfile(profile()); | 113 TokenService* token_service = TokenServiceFactory::GetForProfile(profile()); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 // The user has accepted the scopes, so we may now force (recording a grant | 218 // The user has accepted the scopes, so we may now force (recording a grant |
203 // and receiving a token). | 219 // and receiving a token). |
204 StartGaiaRequest(OAuth2MintTokenFlow::MODE_MINT_TOKEN_FORCE); | 220 StartGaiaRequest(OAuth2MintTokenFlow::MODE_MINT_TOKEN_FORCE); |
205 } | 221 } |
206 | 222 |
207 void ExperimentalIdentityGetAuthTokenFunction::InstallUIAbort( | 223 void ExperimentalIdentityGetAuthTokenFunction::InstallUIAbort( |
208 bool user_initiated) { | 224 bool user_initiated) { |
209 CompleteFunctionWithError(identity_constants::kUserRejected); | 225 CompleteFunctionWithError(identity_constants::kUserRejected); |
210 } | 226 } |
211 | 227 |
228 void ExperimentalIdentityGetAuthTokenFunction::OnGetTokenSuccess( | |
229 const OAuth2TokenService::Request* request, | |
230 const std::string& access_token, | |
231 const base::Time& expiration_time) { | |
232 DCHECK_EQ(device_token_request_.get(), request); | |
233 device_token_request_.reset(); | |
234 | |
235 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(GetExtension()); | |
236 IdentityTokenCacheValue token(access_token, | |
237 expiration_time - base::Time::Now()); | |
238 IdentityAPI::GetFactoryInstance()->GetForProfile(profile())->SetCachedToken( | |
239 GetExtension()->id(), oauth2_info.scopes, token); | |
240 | |
241 CompleteFunctionWithResult(access_token); | |
242 } | |
243 | |
244 void ExperimentalIdentityGetAuthTokenFunction::OnGetTokenFailure( | |
245 const OAuth2TokenService::Request* request, | |
246 const GoogleServiceAuthError& error) { | |
247 DCHECK_EQ(device_token_request_.get(), request); | |
248 device_token_request_.reset(); | |
249 | |
250 CompleteFunctionWithError(error.ToString()); | |
251 } | |
252 | |
212 void ExperimentalIdentityGetAuthTokenFunction::StartGaiaRequest( | 253 void ExperimentalIdentityGetAuthTokenFunction::StartGaiaRequest( |
213 OAuth2MintTokenFlow::Mode mode) { | 254 OAuth2MintTokenFlow::Mode mode) { |
214 mint_token_flow_.reset(CreateMintTokenFlow(mode)); | 255 mint_token_flow_.reset(CreateMintTokenFlow(mode)); |
215 mint_token_flow_->Start(); | 256 mint_token_flow_->Start(); |
216 } | 257 } |
217 | 258 |
218 void ExperimentalIdentityGetAuthTokenFunction::ShowLoginPopup() { | 259 void ExperimentalIdentityGetAuthTokenFunction::ShowLoginPopup() { |
219 signin_flow_.reset(new IdentitySigninFlow(this, profile())); | 260 signin_flow_.reset(new IdentitySigninFlow(this, profile())); |
220 signin_flow_->Start(); | 261 signin_flow_->Start(); |
221 } | 262 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 } | 403 } |
363 } | 404 } |
364 | 405 |
365 void ExperimentalIdentityLaunchWebAuthFlowFunction:: | 406 void ExperimentalIdentityLaunchWebAuthFlowFunction:: |
366 InitFinalRedirectURLPrefixesForTest(const std::string& extension_id) { | 407 InitFinalRedirectURLPrefixesForTest(const std::string& extension_id) { |
367 final_prefixes_.clear(); | 408 final_prefixes_.clear(); |
368 InitFinalRedirectURLPrefixes(extension_id); | 409 InitFinalRedirectURLPrefixes(extension_id); |
369 } | 410 } |
370 | 411 |
371 } // namespace extensions | 412 } // namespace extensions |
OLD | NEW |