| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 const char kInvalidRedirect[] = "Did not redirect to the right URL."; | 68 const char kInvalidRedirect[] = "Did not redirect to the right URL."; |
| 69 const char kOffTheRecord[] = "Identity API is disabled in incognito windows."; | 69 const char kOffTheRecord[] = "Identity API is disabled in incognito windows."; |
| 70 const char kPageLoadFailure[] = "Authorization page could not be loaded."; | 70 const char kPageLoadFailure[] = "Authorization page could not be loaded."; |
| 71 const char kCanceled[] = "canceled"; | 71 const char kCanceled[] = "canceled"; |
| 72 | 72 |
| 73 const int kCachedIssueAdviceTTLSeconds = 1; | 73 const int kCachedIssueAdviceTTLSeconds = 1; |
| 74 } // namespace identity_constants | 74 } // namespace identity_constants |
| 75 | 75 |
| 76 namespace { | 76 namespace { |
| 77 | 77 |
| 78 static const char kChromiumDomainRedirectUrlPattern[] = | |
| 79 "https://%s.chromiumapp.org/"; | |
| 80 | |
| 81 #if defined(OS_CHROMEOS) | 78 #if defined(OS_CHROMEOS) |
| 82 // The list of apps that are allowed to use the Identity API to retrieve the | 79 // The list of apps that are allowed to use the Identity API to retrieve the |
| 83 // token from the device robot account in a public session. | 80 // token from the device robot account in a public session. |
| 84 const char* const kPublicSessionAllowedOrigins[] = { | 81 const char* const kPublicSessionAllowedOrigins[] = { |
| 85 // Chrome Remote Desktop - Chromium branding. | 82 // Chrome Remote Desktop - Chromium branding. |
| 86 "chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk/", | 83 "chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk/", |
| 87 // Chrome Remote Desktop - Official branding. | 84 // Chrome Remote Desktop - Official branding. |
| 88 "chrome-extension://gbchcmhmhahfdphkhkmpfmihenigjmpp/"}; | 85 "chrome-extension://gbchcmhmhahfdphkhkmpfmihenigjmpp/"}; |
| 89 #endif | 86 #endif |
| 90 | 87 |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 | 932 |
| 936 std::unique_ptr<identity::RemoveCachedAuthToken::Params> params( | 933 std::unique_ptr<identity::RemoveCachedAuthToken::Params> params( |
| 937 identity::RemoveCachedAuthToken::Params::Create(*args_)); | 934 identity::RemoveCachedAuthToken::Params::Create(*args_)); |
| 938 EXTENSION_FUNCTION_VALIDATE(params.get()); | 935 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 939 IdentityAPI::GetFactoryInstance() | 936 IdentityAPI::GetFactoryInstance() |
| 940 ->Get(browser_context()) | 937 ->Get(browser_context()) |
| 941 ->EraseCachedToken(extension()->id(), params->details.token); | 938 ->EraseCachedToken(extension()->id(), params->details.token); |
| 942 return RespondNow(NoArguments()); | 939 return RespondNow(NoArguments()); |
| 943 } | 940 } |
| 944 | 941 |
| 945 IdentityLaunchWebAuthFlowFunction::IdentityLaunchWebAuthFlowFunction() {} | |
| 946 | |
| 947 IdentityLaunchWebAuthFlowFunction::~IdentityLaunchWebAuthFlowFunction() { | |
| 948 if (auth_flow_) | |
| 949 auth_flow_.release()->DetachDelegateAndDelete(); | |
| 950 } | |
| 951 | |
| 952 bool IdentityLaunchWebAuthFlowFunction::RunAsync() { | |
| 953 if (GetProfile()->IsOffTheRecord()) { | |
| 954 error_ = identity_constants::kOffTheRecord; | |
| 955 return false; | |
| 956 } | |
| 957 | |
| 958 std::unique_ptr<identity::LaunchWebAuthFlow::Params> params( | |
| 959 identity::LaunchWebAuthFlow::Params::Create(*args_)); | |
| 960 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 961 | |
| 962 GURL auth_url(params->details.url); | |
| 963 WebAuthFlow::Mode mode = | |
| 964 params->details.interactive && *params->details.interactive ? | |
| 965 WebAuthFlow::INTERACTIVE : WebAuthFlow::SILENT; | |
| 966 | |
| 967 // Set up acceptable target URLs. (Does not include chrome-extension | |
| 968 // scheme for this version of the API.) | |
| 969 InitFinalRedirectURLPrefix(extension()->id()); | |
| 970 | |
| 971 AddRef(); // Balanced in OnAuthFlowSuccess/Failure. | |
| 972 | |
| 973 auth_flow_.reset(new WebAuthFlow(this, GetProfile(), auth_url, mode)); | |
| 974 auth_flow_->Start(); | |
| 975 return true; | |
| 976 } | |
| 977 | |
| 978 void IdentityLaunchWebAuthFlowFunction::InitFinalRedirectURLPrefixForTest( | |
| 979 const std::string& extension_id) { | |
| 980 InitFinalRedirectURLPrefix(extension_id); | |
| 981 } | |
| 982 | |
| 983 void IdentityLaunchWebAuthFlowFunction::InitFinalRedirectURLPrefix( | |
| 984 const std::string& extension_id) { | |
| 985 if (final_url_prefix_.is_empty()) { | |
| 986 final_url_prefix_ = GURL(base::StringPrintf( | |
| 987 kChromiumDomainRedirectUrlPattern, extension_id.c_str())); | |
| 988 } | |
| 989 } | |
| 990 | |
| 991 void IdentityLaunchWebAuthFlowFunction::OnAuthFlowFailure( | |
| 992 WebAuthFlow::Failure failure) { | |
| 993 switch (failure) { | |
| 994 case WebAuthFlow::WINDOW_CLOSED: | |
| 995 error_ = identity_constants::kUserRejected; | |
| 996 break; | |
| 997 case WebAuthFlow::INTERACTION_REQUIRED: | |
| 998 error_ = identity_constants::kInteractionRequired; | |
| 999 break; | |
| 1000 case WebAuthFlow::LOAD_FAILED: | |
| 1001 error_ = identity_constants::kPageLoadFailure; | |
| 1002 break; | |
| 1003 default: | |
| 1004 NOTREACHED() << "Unexpected error from web auth flow: " << failure; | |
| 1005 error_ = identity_constants::kInvalidRedirect; | |
| 1006 break; | |
| 1007 } | |
| 1008 SendResponse(false); | |
| 1009 if (auth_flow_) | |
| 1010 auth_flow_.release()->DetachDelegateAndDelete(); | |
| 1011 Release(); // Balanced in RunAsync. | |
| 1012 } | |
| 1013 | |
| 1014 void IdentityLaunchWebAuthFlowFunction::OnAuthFlowURLChange( | |
| 1015 const GURL& redirect_url) { | |
| 1016 if (redirect_url.GetWithEmptyPath() == final_url_prefix_) { | |
| 1017 SetResult(base::MakeUnique<base::StringValue>(redirect_url.spec())); | |
| 1018 SendResponse(true); | |
| 1019 if (auth_flow_) | |
| 1020 auth_flow_.release()->DetachDelegateAndDelete(); | |
| 1021 Release(); // Balanced in RunAsync. | |
| 1022 } | |
| 1023 } | |
| 1024 | |
| 1025 } // namespace extensions | 942 } // namespace extensions |
| OLD | NEW |