Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1382)

Side by Side Diff: chrome/browser/extensions/api/identity/identity_api.cc

Issue 11882025: Move "oauth2" manifest key parsing out of Extension class. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Move "oauth2" manifest key parsing out of Extension class. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #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"
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 "webkit/glue/window_open_disposition.h" 28 #include "webkit/glue/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 = extensions::api::experimental_identity::GetAuthToken;
Devlin 2013/01/16 19:36:12 Remove all extensions:: prefixes, please.
SanjoyPal 2013/01/16 20:11:28 Done.
39 namespace LaunchWebAuthFlow = 43 namespace LaunchWebAuthFlow =
40 extensions::api::experimental_identity::LaunchWebAuthFlow; 44 extensions::api::experimental_identity::LaunchWebAuthFlow;
41 namespace identity = extensions::api::experimental_identity; 45 namespace identity = extensions::api::experimental_identity;
42 46
43 IdentityGetAuthTokenFunction::IdentityGetAuthTokenFunction() 47 IdentityGetAuthTokenFunction::IdentityGetAuthTokenFunction()
44 : interactive_(false) {} 48 : interactive_(false) {}
45 IdentityGetAuthTokenFunction::~IdentityGetAuthTokenFunction() {} 49 IdentityGetAuthTokenFunction::~IdentityGetAuthTokenFunction() {}
46 50
47 bool IdentityGetAuthTokenFunction::RunImpl() { 51 bool IdentityGetAuthTokenFunction::RunImpl() {
48 scoped_ptr<GetAuthToken::Params> params(GetAuthToken::Params::Create(*args_)); 52 scoped_ptr<GetAuthToken::Params> params(GetAuthToken::Params::Create(*args_));
49 EXTENSION_FUNCTION_VALIDATE(params.get()); 53 EXTENSION_FUNCTION_VALIDATE(params.get());
50 if (params->details.get() && params->details->interactive.get()) 54 if (params->details.get() && params->details->interactive.get())
51 interactive_ = *params->details->interactive; 55 interactive_ = *params->details->interactive;
52 56
53 const Extension::OAuth2Info& oauth2_info = GetExtension()->oauth2_info(); 57 const OAuth2Info& oauth2_info = 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;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(GetExtension());
187 TokenService* token_service = TokenServiceFactory::GetForProfile(profile()); 191 TokenService* token_service = TokenServiceFactory::GetForProfile(profile());
188 return new OAuth2MintTokenFlow( 192 return new OAuth2MintTokenFlow(
189 profile()->GetRequestContext(), 193 profile()->GetRequestContext(),
190 this, 194 this,
191 OAuth2MintTokenFlow::Parameters( 195 OAuth2MintTokenFlow::Parameters(
192 token_service->GetOAuth2LoginRefreshToken(), 196 token_service->GetOAuth2LoginRefreshToken(),
193 GetExtension()->id(), 197 GetExtension()->id(),
194 oauth2_info.client_id, 198 oauth2_info.client_id,
195 oauth2_info.scopes, 199 oauth2_info.scopes,
196 mode)); 200 mode));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 SendResponse(true); 249 SendResponse(true);
246 Release(); // Balanced in RunImpl. 250 Release(); // Balanced in RunImpl.
247 } 251 }
248 252
249 void IdentityLaunchWebAuthFlowFunction::OnAuthFlowFailure() { 253 void IdentityLaunchWebAuthFlowFunction::OnAuthFlowFailure() {
250 error_ = identity_constants::kInvalidRedirect; 254 error_ = identity_constants::kInvalidRedirect;
251 SendResponse(false); 255 SendResponse(false);
252 Release(); // Balanced in RunImpl. 256 Release(); // Balanced in RunImpl.
253 } 257 }
254 258
259 IdentityAPI::IdentityAPI(Profile* profile) {
260 ManifestHandler::Register(extension_manifest_keys::kOAuth2,
261 new OAuth2ManifestHandler);
262 }
263
264 IdentityAPI::~IdentityAPI() {
265 }
266
267 static base::LazyInstance<ProfileKeyedAPIFactory<IdentityAPI> >
268 g_factory = LAZY_INSTANCE_INITIALIZER;
269
270 // static
271 ProfileKeyedAPIFactory<IdentityAPI>* IdentityAPI::GetFactoryInstance() {
272 return &g_factory.Get();
273 }
274
255 } // namespace extensions 275 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698