Chromium Code Reviews| 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/common/extensions/api/experimental_identity.h" | 9 #include "chrome/common/extensions/api/experimental_identity.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_function_dispatcher.h" | 11 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/permissions_updater.h" | 13 #include "chrome/browser/extensions/permissions_updater.h" |
| 13 #include "chrome/browser/signin/token_service.h" | 14 #include "chrome/browser/signin/token_service.h" |
| 14 #include "chrome/browser/signin/token_service_factory.h" | 15 #include "chrome/browser/signin/token_service_factory.h" |
| 15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_navigator.h" | 17 #include "chrome/browser/ui/browser_navigator.h" |
| 17 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 18 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 18 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 19 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 19 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | 20 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.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" | |
| 21 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 22 #include "content/public/common/page_transition_types.h" | 25 #include "content/public/common/page_transition_types.h" |
| 23 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
| 24 #include "webkit/glue/window_open_disposition.h" | 27 #include "webkit/glue/window_open_disposition.h" |
| 25 | 28 |
| 26 namespace extensions { | 29 namespace extensions { |
| 27 | 30 |
| 28 namespace identity_constants { | 31 namespace identity_constants { |
| 29 const char kInvalidClientId[] = "Invalid OAuth2 Client ID."; | 32 const char kInvalidClientId[] = "Invalid OAuth2 Client ID."; |
| 30 const char kInvalidScopes[] = "Invalid OAuth2 scopes."; | 33 const char kInvalidScopes[] = "Invalid OAuth2 scopes."; |
| 31 const char kAuthFailure[] = "OAuth2 request failed: "; | 34 const char kAuthFailure[] = "OAuth2 request failed: "; |
| 32 const char kNoGrant[] = "OAuth2 not granted or revoked."; | 35 const char kNoGrant[] = "OAuth2 not granted or revoked."; |
| 33 const char kUserRejected[] = "The user did not approve access."; | 36 const char kUserRejected[] = "The user did not approve access."; |
| 34 const char kUserNotSignedIn[] = "The user is not signed in."; | 37 const char kUserNotSignedIn[] = "The user is not signed in."; |
| 35 const char kInvalidRedirect[] = "Did not redirect to the right URL."; | 38 const char kInvalidRedirect[] = "Did not redirect to the right URL."; |
| 36 } | 39 } |
|
Devlin
2013/01/14 20:18:34
since you're in the file, please add a "// namespa
SanjoyPal
2013/01/16 19:10:52
Done.
| |
| 37 | 40 |
| 38 namespace GetAuthToken = extensions::api::experimental_identity::GetAuthToken; | 41 namespace GetAuthToken = extensions::api::experimental_identity::GetAuthToken; |
| 39 namespace LaunchWebAuthFlow = | 42 namespace LaunchWebAuthFlow = |
| 40 extensions::api::experimental_identity::LaunchWebAuthFlow; | 43 extensions::api::experimental_identity::LaunchWebAuthFlow; |
| 41 namespace identity = extensions::api::experimental_identity; | 44 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 extensions::OAuth2Info* oauth2_info = |
|
Devlin
2013/01/14 20:18:34
You're in the extensions namespace - you don't nee
SanjoyPal
2013/01/16 19:10:52
Done.
| |
| 57 OAuth2Info::GetOAuth2Info(GetExtension()); | |
| 54 | 58 |
| 55 // Check that the necessary information is present in the manfist. | 59 // Check that the necessary information is present in the manfist. |
| 56 if (oauth2_info.client_id.empty()) { | 60 if (oauth2_info->client_id.empty()) { |
| 57 error_ = identity_constants::kInvalidClientId; | 61 error_ = identity_constants::kInvalidClientId; |
| 58 return false; | 62 return false; |
| 59 } | 63 } |
| 60 | 64 |
| 61 if (oauth2_info.scopes.size() == 0) { | 65 if (oauth2_info->scopes.size() == 0) { |
| 62 error_ = identity_constants::kInvalidScopes; | 66 error_ = identity_constants::kInvalidScopes; |
| 63 return false; | 67 return false; |
| 64 } | 68 } |
| 65 | 69 |
| 66 // Balanced in OnIssueAdviceSuccess|OnMintTokenSuccess|OnMintTokenFailure| | 70 // Balanced in OnIssueAdviceSuccess|OnMintTokenSuccess|OnMintTokenFailure| |
| 67 // InstallUIAbort|OnLoginUIClosed. | 71 // InstallUIAbort|OnLoginUIClosed. |
| 68 AddRef(); | 72 AddRef(); |
| 69 | 73 |
| 70 if (!HasLoginToken()) { | 74 if (!HasLoginToken()) { |
| 71 if (StartLogin()) { | 75 if (StartLogin()) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 login_ui_service->ShowLoginPopup(); | 180 login_ui_service->ShowLoginPopup(); |
| 177 } | 181 } |
| 178 | 182 |
| 179 void IdentityGetAuthTokenFunction::ShowOAuthApprovalDialog( | 183 void IdentityGetAuthTokenFunction::ShowOAuthApprovalDialog( |
| 180 const IssueAdviceInfo& issue_advice) { | 184 const IssueAdviceInfo& issue_advice) { |
| 181 install_ui_->ConfirmIssueAdvice(this, GetExtension(), issue_advice); | 185 install_ui_->ConfirmIssueAdvice(this, GetExtension(), issue_advice); |
| 182 } | 186 } |
| 183 | 187 |
| 184 OAuth2MintTokenFlow* IdentityGetAuthTokenFunction::CreateMintTokenFlow( | 188 OAuth2MintTokenFlow* IdentityGetAuthTokenFunction::CreateMintTokenFlow( |
| 185 OAuth2MintTokenFlow::Mode mode) { | 189 OAuth2MintTokenFlow::Mode mode) { |
| 186 const Extension::OAuth2Info& oauth2_info = GetExtension()->oauth2_info(); | 190 const extensions::OAuth2Info* oauth2_info = |
| 191 OAuth2Info::GetOAuth2Info(GetExtension()); | |
| 187 TokenService* token_service = TokenServiceFactory::GetForProfile(profile()); | 192 TokenService* token_service = TokenServiceFactory::GetForProfile(profile()); |
| 188 return new OAuth2MintTokenFlow( | 193 return new OAuth2MintTokenFlow( |
| 189 profile()->GetRequestContext(), | 194 profile()->GetRequestContext(), |
| 190 this, | 195 this, |
| 191 OAuth2MintTokenFlow::Parameters( | 196 OAuth2MintTokenFlow::Parameters( |
| 192 token_service->GetOAuth2LoginRefreshToken(), | 197 token_service->GetOAuth2LoginRefreshToken(), |
| 193 GetExtension()->id(), | 198 GetExtension()->id(), |
| 194 oauth2_info.client_id, | 199 oauth2_info->client_id, |
| 195 oauth2_info.scopes, | 200 oauth2_info->scopes, |
| 196 mode)); | 201 mode)); |
| 197 } | 202 } |
| 198 | 203 |
| 199 bool IdentityGetAuthTokenFunction::HasLoginToken() const { | 204 bool IdentityGetAuthTokenFunction::HasLoginToken() const { |
| 200 TokenService* token_service = TokenServiceFactory::GetForProfile(profile()); | 205 TokenService* token_service = TokenServiceFactory::GetForProfile(profile()); |
| 201 return token_service->HasOAuthLoginToken(); | 206 return token_service->HasOAuthLoginToken(); |
| 202 } | 207 } |
| 203 | 208 |
| 204 IdentityLaunchWebAuthFlowFunction::IdentityLaunchWebAuthFlowFunction() {} | 209 IdentityLaunchWebAuthFlowFunction::IdentityLaunchWebAuthFlowFunction() {} |
| 205 IdentityLaunchWebAuthFlowFunction::~IdentityLaunchWebAuthFlowFunction() {} | 210 IdentityLaunchWebAuthFlowFunction::~IdentityLaunchWebAuthFlowFunction() {} |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 SendResponse(true); | 250 SendResponse(true); |
| 246 Release(); // Balanced in RunImpl. | 251 Release(); // Balanced in RunImpl. |
| 247 } | 252 } |
| 248 | 253 |
| 249 void IdentityLaunchWebAuthFlowFunction::OnAuthFlowFailure() { | 254 void IdentityLaunchWebAuthFlowFunction::OnAuthFlowFailure() { |
| 250 error_ = identity_constants::kInvalidRedirect; | 255 error_ = identity_constants::kInvalidRedirect; |
| 251 SendResponse(false); | 256 SendResponse(false); |
| 252 Release(); // Balanced in RunImpl. | 257 Release(); // Balanced in RunImpl. |
| 253 } | 258 } |
| 254 | 259 |
| 260 IdentityAPI::IdentityAPI(Profile* profile) { | |
| 261 ManifestHandler::Register(extension_manifest_keys::kOAuth2, | |
|
Devlin
2013/01/14 20:18:34
Include what you use - c/c/e/manifest_handler.h.
SanjoyPal
2013/01/16 19:10:52
Done.
| |
| 262 new OAuth2ManifestHandler); | |
| 263 } | |
| 264 | |
| 265 IdentityAPI::~IdentityAPI() { | |
| 266 } | |
| 267 | |
| 268 static base::LazyInstance<ProfileKeyedAPIFactory<IdentityAPI> > | |
| 269 g_factory = LAZY_INSTANCE_INITIALIZER; | |
|
Devlin
2013/01/14 20:18:34
Indentation.
SanjoyPal
2013/01/16 19:10:52
Done.
| |
| 270 | |
| 271 // static | |
| 272 ProfileKeyedAPIFactory<IdentityAPI>* IdentityAPI::GetFactoryInstance() { | |
| 273 return &g_factory.Get(); | |
| 274 } | |
| 275 | |
| 255 } // namespace extensions | 276 } // namespace extensions |
| OLD | NEW |