| 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/identity_api.h" | 5 #include "chrome/browser/extensions/api/identity/identity_api.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" |
| 7 #include "base/values.h" | 8 #include "base/values.h" |
| 8 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 9 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 9 #include "chrome/browser/extensions/extension_install_prompt.h" | 10 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/permissions_updater.h" | 12 #include "chrome/browser/extensions/permissions_updater.h" |
| 12 #include "chrome/browser/signin/token_service.h" | 13 #include "chrome/browser/signin/token_service.h" |
| 13 #include "chrome/browser/signin/token_service_factory.h" | 14 #include "chrome/browser/signin/token_service_factory.h" |
| 14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_navigator.h" | 16 #include "chrome/browser/ui/browser_navigator.h" |
| 16 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 17 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 17 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 18 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 18 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | 19 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
| 19 #include "chrome/common/extensions/api/experimental_identity.h" | 20 #include "chrome/common/extensions/api/experimental_identity.h" |
| 21 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h" |
| 20 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
| 23 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 24 #include "chrome/common/extensions/manifest_handler.h" |
| 21 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 22 #include "content/public/common/page_transition_types.h" | 26 #include "content/public/common/page_transition_types.h" |
| 23 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
| 24 #include "ui/base/window_open_disposition.h" | 28 #include "ui/base/window_open_disposition.h" |
| 25 | 29 |
| 26 namespace extensions { | 30 namespace extensions { |
| 27 | 31 |
| 28 namespace identity_constants { | 32 namespace identity_constants { |
| 29 const char kInvalidClientId[] = "Invalid OAuth2 Client ID."; | 33 const char kInvalidClientId[] = "Invalid OAuth2 Client ID."; |
| 30 const char kInvalidScopes[] = "Invalid OAuth2 scopes."; | 34 const char kInvalidScopes[] = "Invalid OAuth2 scopes."; |
| 31 const char kAuthFailure[] = "OAuth2 request failed: "; | 35 const char kAuthFailure[] = "OAuth2 request failed: "; |
| 32 const char kNoGrant[] = "OAuth2 not granted or revoked."; | 36 const char kNoGrant[] = "OAuth2 not granted or revoked."; |
| 33 const char kUserRejected[] = "The user did not approve access."; | 37 const char kUserRejected[] = "The user did not approve access."; |
| 34 const char kUserNotSignedIn[] = "The user is not signed in."; | 38 const char kUserNotSignedIn[] = "The user is not signed in."; |
| 35 const char kInvalidRedirect[] = "Did not redirect to the right URL."; | 39 const char kInvalidRedirect[] = "Did not redirect to the right URL."; |
| 36 } | 40 } // namespace identity_constants |
| 37 | 41 |
| 38 namespace GetAuthToken = extensions::api::experimental_identity::GetAuthToken; | 42 namespace GetAuthToken = api::experimental_identity::GetAuthToken; |
| 39 namespace LaunchWebAuthFlow = | 43 namespace LaunchWebAuthFlow = api::experimental_identity::LaunchWebAuthFlow; |
| 40 extensions::api::experimental_identity::LaunchWebAuthFlow; | 44 namespace identity = api::experimental_identity; |
| 41 namespace identity = extensions::api::experimental_identity; | |
| 42 | 45 |
| 43 IdentityGetAuthTokenFunction::IdentityGetAuthTokenFunction() | 46 IdentityGetAuthTokenFunction::IdentityGetAuthTokenFunction() |
| 44 : interactive_(false) {} | 47 : interactive_(false) {} |
| 45 IdentityGetAuthTokenFunction::~IdentityGetAuthTokenFunction() {} | 48 IdentityGetAuthTokenFunction::~IdentityGetAuthTokenFunction() {} |
| 46 | 49 |
| 47 bool IdentityGetAuthTokenFunction::RunImpl() { | 50 bool IdentityGetAuthTokenFunction::RunImpl() { |
| 48 scoped_ptr<GetAuthToken::Params> params(GetAuthToken::Params::Create(*args_)); | 51 scoped_ptr<GetAuthToken::Params> params(GetAuthToken::Params::Create(*args_)); |
| 49 EXTENSION_FUNCTION_VALIDATE(params.get()); | 52 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 50 if (params->details.get() && params->details->interactive.get()) | 53 if (params->details.get() && params->details->interactive.get()) |
| 51 interactive_ = *params->details->interactive; | 54 interactive_ = *params->details->interactive; |
| 52 | 55 |
| 53 const Extension::OAuth2Info& oauth2_info = GetExtension()->oauth2_info(); | 56 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(GetExtension()); |
| 54 | 57 |
| 55 // Check that the necessary information is present in the manfist. | 58 // Check that the necessary information is present in the manfist. |
| 56 if (oauth2_info.client_id.empty()) { | 59 if (oauth2_info.client_id.empty()) { |
| 57 error_ = identity_constants::kInvalidClientId; | 60 error_ = identity_constants::kInvalidClientId; |
| 58 return false; | 61 return false; |
| 59 } | 62 } |
| 60 | 63 |
| 61 if (oauth2_info.scopes.size() == 0) { | 64 if (oauth2_info.scopes.size() == 0) { |
| 62 error_ = identity_constants::kInvalidScopes; | 65 error_ = identity_constants::kInvalidScopes; |
| 63 return false; | 66 return false; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 login_ui_service->ShowLoginPopup(); | 179 login_ui_service->ShowLoginPopup(); |
| 177 } | 180 } |
| 178 | 181 |
| 179 void IdentityGetAuthTokenFunction::ShowOAuthApprovalDialog( | 182 void IdentityGetAuthTokenFunction::ShowOAuthApprovalDialog( |
| 180 const IssueAdviceInfo& issue_advice) { | 183 const IssueAdviceInfo& issue_advice) { |
| 181 install_ui_->ConfirmIssueAdvice(this, GetExtension(), issue_advice); | 184 install_ui_->ConfirmIssueAdvice(this, GetExtension(), issue_advice); |
| 182 } | 185 } |
| 183 | 186 |
| 184 OAuth2MintTokenFlow* IdentityGetAuthTokenFunction::CreateMintTokenFlow( | 187 OAuth2MintTokenFlow* IdentityGetAuthTokenFunction::CreateMintTokenFlow( |
| 185 OAuth2MintTokenFlow::Mode mode) { | 188 OAuth2MintTokenFlow::Mode mode) { |
| 186 const Extension::OAuth2Info& oauth2_info = GetExtension()->oauth2_info(); | 189 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(GetExtension()); |
| 187 TokenService* token_service = TokenServiceFactory::GetForProfile(profile()); | 190 TokenService* token_service = TokenServiceFactory::GetForProfile(profile()); |
| 188 return new OAuth2MintTokenFlow( | 191 return new OAuth2MintTokenFlow( |
| 189 profile()->GetRequestContext(), | 192 profile()->GetRequestContext(), |
| 190 this, | 193 this, |
| 191 OAuth2MintTokenFlow::Parameters( | 194 OAuth2MintTokenFlow::Parameters( |
| 192 token_service->GetOAuth2LoginRefreshToken(), | 195 token_service->GetOAuth2LoginRefreshToken(), |
| 193 GetExtension()->id(), | 196 GetExtension()->id(), |
| 194 oauth2_info.client_id, | 197 oauth2_info.client_id, |
| 195 oauth2_info.scopes, | 198 oauth2_info.scopes, |
| 196 mode)); | 199 mode)); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 SendResponse(true); | 248 SendResponse(true); |
| 246 Release(); // Balanced in RunImpl. | 249 Release(); // Balanced in RunImpl. |
| 247 } | 250 } |
| 248 | 251 |
| 249 void IdentityLaunchWebAuthFlowFunction::OnAuthFlowFailure() { | 252 void IdentityLaunchWebAuthFlowFunction::OnAuthFlowFailure() { |
| 250 error_ = identity_constants::kInvalidRedirect; | 253 error_ = identity_constants::kInvalidRedirect; |
| 251 SendResponse(false); | 254 SendResponse(false); |
| 252 Release(); // Balanced in RunImpl. | 255 Release(); // Balanced in RunImpl. |
| 253 } | 256 } |
| 254 | 257 |
| 258 IdentityAPI::IdentityAPI(Profile* profile) { |
| 259 ManifestHandler::Register(extension_manifest_keys::kOAuth2, |
| 260 new OAuth2ManifestHandler); |
| 261 } |
| 262 |
| 263 IdentityAPI::~IdentityAPI() { |
| 264 } |
| 265 |
| 266 static base::LazyInstance<ProfileKeyedAPIFactory<IdentityAPI> > |
| 267 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 268 |
| 269 // static |
| 270 ProfileKeyedAPIFactory<IdentityAPI>* IdentityAPI::GetFactoryInstance() { |
| 271 return &g_factory.Get(); |
| 272 } |
| 273 |
| 255 } // namespace extensions | 274 } // namespace extensions |
| OLD | NEW |