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 <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/app_mode/app_mode_utils.h" | 14 #include "chrome/browser/app_mode/app_mode_utils.h" |
15 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 15 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
16 #include "chrome/browser/extensions/extension_install_prompt.h" | 16 #include "chrome/browser/extensions/extension_install_prompt.h" |
17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
18 #include "chrome/browser/extensions/permissions_updater.h" | 18 #include "chrome/browser/extensions/permissions_updater.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/signin/signin_manager.h" | 20 #include "chrome/browser/signin/signin_manager.h" |
21 #include "chrome/browser/signin/signin_manager_factory.h" | 21 #include "chrome/browser/signin/signin_manager_factory.h" |
22 #include "chrome/browser/signin/token_service.h" | 22 #include "chrome/browser/signin/token_service.h" |
23 #include "chrome/browser/signin/token_service_factory.h" | 23 #include "chrome/browser/signin/token_service_factory.h" |
24 #include "chrome/browser/ui/browser.h" | |
25 #include "chrome/common/extensions/api/identity.h" | 24 #include "chrome/common/extensions/api/identity.h" |
26 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h" | 25 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h" |
27 #include "chrome/common/extensions/extension.h" | 26 #include "chrome/common/extensions/extension.h" |
28 #include "chrome/common/extensions/extension_manifest_constants.h" | 27 #include "chrome/common/extensions/extension_manifest_constants.h" |
29 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
30 #include "content/public/common/page_transition_types.h" | 29 #include "content/public/common/page_transition_types.h" |
31 #include "google_apis/gaia/gaia_constants.h" | 30 #include "google_apis/gaia/gaia_constants.h" |
32 #include "googleurl/src/gurl.h" | 31 #include "googleurl/src/gurl.h" |
33 #include "ui/base/window_open_disposition.h" | 32 #include "ui/base/window_open_disposition.h" |
34 | 33 |
35 #if defined(OS_CHROMEOS) | 34 #if defined(OS_CHROMEOS) |
36 #include "chrome/browser/chromeos/login/user_manager.h" | 35 #include "chrome/browser/chromeos/login/user_manager.h" |
37 #endif | 36 #endif |
38 | 37 |
39 namespace extensions { | 38 namespace extensions { |
40 | 39 |
41 namespace identity_constants { | 40 namespace identity_constants { |
42 const char kInvalidClientId[] = "Invalid OAuth2 Client ID."; | 41 const char kInvalidClientId[] = "Invalid OAuth2 Client ID."; |
43 const char kInvalidScopes[] = "Invalid OAuth2 scopes."; | 42 const char kInvalidScopes[] = "Invalid OAuth2 scopes."; |
44 const char kAuthFailure[] = "OAuth2 request failed: "; | 43 const char kAuthFailure[] = "OAuth2 request failed: "; |
45 const char kNoGrant[] = "OAuth2 not granted or revoked."; | 44 const char kNoGrant[] = "OAuth2 not granted or revoked."; |
46 const char kUserRejected[] = "The user did not approve access."; | 45 const char kUserRejected[] = "The user did not approve access."; |
47 const char kUserNotSignedIn[] = "The user is not signed in."; | 46 const char kUserNotSignedIn[] = "The user is not signed in."; |
48 const char kInteractionRequired[] = "User interaction required."; | 47 const char kInteractionRequired[] = "User interaction required."; |
49 const char kInvalidRedirect[] = "Did not redirect to the right URL."; | 48 const char kInvalidRedirect[] = "Did not redirect to the right URL."; |
50 const char kOffTheRecord[] = "Identity API is disabled in incognito windows."; | 49 const char kOffTheRecord[] = "Identity API is disabled in incognito windows."; |
| 50 const char kPageLoadFailure[] = "Authorization page could not be loaded."; |
51 | 51 |
52 const int kCachedIssueAdviceTTLSeconds = 1; | 52 const int kCachedIssueAdviceTTLSeconds = 1; |
53 } // namespace identity_constants | 53 } // namespace identity_constants |
54 | 54 |
55 namespace { | 55 namespace { |
56 | 56 |
57 static const char kChromiumDomainRedirectUrlPattern[] = | 57 static const char kChromiumDomainRedirectUrlPattern[] = |
58 "https://%s.chromiumapp.org/"; | 58 "https://%s.chromiumapp.org/"; |
59 | 59 |
60 } // namespace | 60 } // namespace |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 | 386 |
387 GURL auth_url(params->details.url); | 387 GURL auth_url(params->details.url); |
388 WebAuthFlow::Mode mode = | 388 WebAuthFlow::Mode mode = |
389 params->details.interactive && *params->details.interactive ? | 389 params->details.interactive && *params->details.interactive ? |
390 WebAuthFlow::INTERACTIVE : WebAuthFlow::SILENT; | 390 WebAuthFlow::INTERACTIVE : WebAuthFlow::SILENT; |
391 | 391 |
392 // Set up acceptable target URLs. (Does not include chrome-extension | 392 // Set up acceptable target URLs. (Does not include chrome-extension |
393 // scheme for this version of the API.) | 393 // scheme for this version of the API.) |
394 InitFinalRedirectURLPrefixes(GetExtension()->id()); | 394 InitFinalRedirectURLPrefixes(GetExtension()->id()); |
395 | 395 |
396 gfx::Rect initial_bounds; | 396 AddRef(); // Balanced in OnAuthFlowClosed |
397 | 397 |
398 AddRef(); // Balanced in OnAuthFlowSuccess/Failure. | 398 auth_flow_.reset(new WebAuthFlow(this, profile(), auth_url, mode)); |
399 | |
400 Browser* current_browser = this->GetCurrentBrowser(); | |
401 chrome::HostDesktopType host_desktop_type = current_browser ? | |
402 current_browser->host_desktop_type() : chrome::GetActiveDesktop(); | |
403 auth_flow_.reset(new WebAuthFlow( | |
404 this, profile(), auth_url, mode, initial_bounds, | |
405 host_desktop_type)); | |
406 auth_flow_->Start(); | 399 auth_flow_->Start(); |
407 return true; | 400 return true; |
408 } | 401 } |
409 | 402 |
410 bool IdentityLaunchWebAuthFlowFunction::IsFinalRedirectURL( | 403 bool IdentityLaunchWebAuthFlowFunction::IsFinalRedirectURL( |
411 const GURL& url) const { | 404 const GURL& url) const { |
412 std::vector<GURL>::const_iterator iter; | 405 std::vector<GURL>::const_iterator iter; |
413 for (iter = final_prefixes_.begin(); iter != final_prefixes_.end(); ++iter) { | 406 for (iter = final_prefixes_.begin(); iter != final_prefixes_.end(); ++iter) { |
414 if (url.GetWithEmptyPath() == *iter) { | 407 if (url.GetWithEmptyPath() == *iter) { |
415 return true; | 408 return true; |
(...skipping 16 matching lines...) Expand all Loading... |
432 | 425 |
433 void IdentityLaunchWebAuthFlowFunction::OnAuthFlowFailure( | 426 void IdentityLaunchWebAuthFlowFunction::OnAuthFlowFailure( |
434 WebAuthFlow::Failure failure) { | 427 WebAuthFlow::Failure failure) { |
435 switch (failure) { | 428 switch (failure) { |
436 case WebAuthFlow::WINDOW_CLOSED: | 429 case WebAuthFlow::WINDOW_CLOSED: |
437 error_ = identity_constants::kUserRejected; | 430 error_ = identity_constants::kUserRejected; |
438 break; | 431 break; |
439 case WebAuthFlow::INTERACTION_REQUIRED: | 432 case WebAuthFlow::INTERACTION_REQUIRED: |
440 error_ = identity_constants::kInteractionRequired; | 433 error_ = identity_constants::kInteractionRequired; |
441 break; | 434 break; |
| 435 case WebAuthFlow::LOAD_FAILED: |
| 436 error_ = std::string(identity_constants::kPageLoadFailure); |
| 437 break; |
442 default: | 438 default: |
443 NOTREACHED() << "Unexpected error from web auth flow: " << failure; | 439 NOTREACHED() << "Unexpected error from web auth flow: " << failure; |
444 error_ = identity_constants::kInvalidRedirect; | 440 error_ = identity_constants::kInvalidRedirect; |
445 break; | 441 break; |
446 } | 442 } |
447 SendResponse(false); | 443 SendResponse(false); |
448 Release(); // Balanced in RunImpl. | 444 auth_flow_->Close(); |
449 } | 445 } |
450 | 446 |
451 void IdentityLaunchWebAuthFlowFunction::OnAuthFlowURLChange( | 447 void IdentityLaunchWebAuthFlowFunction::OnAuthFlowURLChange( |
452 const GURL& redirect_url) { | 448 const GURL& redirect_url) { |
453 if (IsFinalRedirectURL(redirect_url)) { | 449 if (IsFinalRedirectURL(redirect_url)) { |
454 SetResult(Value::CreateStringValue(redirect_url.spec())); | 450 SetResult(Value::CreateStringValue(redirect_url.spec())); |
455 SendResponse(true); | 451 SendResponse(true); |
456 Release(); // Balanced in RunImpl. | 452 auth_flow_->Close(); |
457 } | 453 } |
458 } | 454 } |
459 | 455 |
| 456 void IdentityLaunchWebAuthFlowFunction::OnAuthFlowClosed() { |
| 457 Release(); // Balanced in RunImpl. |
| 458 } |
| 459 |
460 IdentityTokenCacheValue::IdentityTokenCacheValue() | 460 IdentityTokenCacheValue::IdentityTokenCacheValue() |
461 : status_(CACHE_STATUS_NOTFOUND) { | 461 : status_(CACHE_STATUS_NOTFOUND) { |
462 } | 462 } |
463 | 463 |
464 IdentityTokenCacheValue::IdentityTokenCacheValue( | 464 IdentityTokenCacheValue::IdentityTokenCacheValue( |
465 const IssueAdviceInfo& issue_advice) : status_(CACHE_STATUS_ADVICE), | 465 const IssueAdviceInfo& issue_advice) : status_(CACHE_STATUS_ADVICE), |
466 issue_advice_(issue_advice) { | 466 issue_advice_(issue_advice) { |
467 expiration_time_ = base::Time::Now() + base::TimeDelta::FromSeconds( | 467 expiration_time_ = base::Time::Now() + base::TimeDelta::FromSeconds( |
468 identity_constants::kCachedIssueAdviceTTLSeconds); | 468 identity_constants::kCachedIssueAdviceTTLSeconds); |
469 } | 469 } |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 const IdentityAPI::TokenCacheKey& rhs) const { | 622 const IdentityAPI::TokenCacheKey& rhs) const { |
623 if (extension_id < rhs.extension_id) | 623 if (extension_id < rhs.extension_id) |
624 return true; | 624 return true; |
625 else if (rhs.extension_id < extension_id) | 625 else if (rhs.extension_id < extension_id) |
626 return false; | 626 return false; |
627 | 627 |
628 return scopes < rhs.scopes; | 628 return scopes < rhs.scopes; |
629 } | 629 } |
630 | 630 |
631 } // namespace extensions | 631 } // namespace extensions |
OLD | NEW |