| 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 <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/prefs/pref_service.h" | |
| 15 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 17 #include "base/values.h" | 16 #include "base/values.h" |
| 18 #include "chrome/browser/app_mode/app_mode_utils.h" | 17 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 19 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/chrome_notification_types.h" | 19 #include "chrome/browser/chrome_notification_types.h" |
| 21 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 23 #include "chrome/browser/signin/chrome_signin_client_factory.h" | 23 #include "chrome/browser/signin/chrome_signin_client_factory.h" |
| 24 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 24 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 25 #include "chrome/browser/signin/signin_manager_factory.h" | 25 #include "chrome/browser/signin/signin_manager_factory.h" |
| 26 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 26 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 27 #include "chrome/common/extensions/api/identity.h" | 27 #include "chrome/common/extensions/api/identity.h" |
| 28 #include "chrome/common/pref_names.h" | |
| 29 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 29 #include "components/signin/core/browser/account_tracker_service.h" |
| 30 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 30 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 31 #include "components/signin/core/browser/signin_manager.h" | 31 #include "components/signin/core/browser/signin_manager.h" |
| 32 #include "components/signin/core/common/profile_management_switches.h" | 32 #include "components/signin/core/common/profile_management_switches.h" |
| 33 #include "extensions/browser/event_router.h" | 33 #include "extensions/browser/event_router.h" |
| 34 #include "extensions/browser/extension_function_dispatcher.h" | 34 #include "extensions/browser/extension_function_dispatcher.h" |
| 35 #include "extensions/common/extension.h" | 35 #include "extensions/common/extension.h" |
| 36 #include "extensions/common/extension_l10n_util.h" | 36 #include "extensions/common/extension_l10n_util.h" |
| 37 #include "extensions/common/manifest_handlers/oauth2_manifest_handler.h" | 37 #include "extensions/common/manifest_handlers/oauth2_manifest_handler.h" |
| 38 #include "extensions/common/permissions/permission_set.h" | 38 #include "extensions/common/permissions/permission_set.h" |
| 39 #include "extensions/common/permissions/permissions_data.h" | 39 #include "extensions/common/permissions/permissions_data.h" |
| (...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 } | 838 } |
| 839 | 839 |
| 840 IdentityGetProfileUserInfoFunction::~IdentityGetProfileUserInfoFunction() { | 840 IdentityGetProfileUserInfoFunction::~IdentityGetProfileUserInfoFunction() { |
| 841 } | 841 } |
| 842 | 842 |
| 843 ExtensionFunction::ResponseAction IdentityGetProfileUserInfoFunction::Run() { | 843 ExtensionFunction::ResponseAction IdentityGetProfileUserInfoFunction::Run() { |
| 844 if (GetProfile()->IsOffTheRecord()) { | 844 if (GetProfile()->IsOffTheRecord()) { |
| 845 return RespondNow(Error(identity_constants::kOffTheRecord)); | 845 return RespondNow(Error(identity_constants::kOffTheRecord)); |
| 846 } | 846 } |
| 847 | 847 |
| 848 AccountTrackerService::AccountInfo account = |
| 849 AccountTrackerServiceFactory::GetForProfile(GetProfile()) |
| 850 ->GetAccountInfo(GetPrimaryAccountId(GetProfile())); |
| 848 api::identity::ProfileUserInfo profile_user_info; | 851 api::identity::ProfileUserInfo profile_user_info; |
| 849 if (extension()->permissions_data()->HasAPIPermission( | 852 if (extension()->permissions_data()->HasAPIPermission( |
| 850 APIPermission::kIdentityEmail)) { | 853 APIPermission::kIdentityEmail)) { |
| 851 profile_user_info.email = | 854 profile_user_info.email = account.email; |
| 852 GetProfile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername); | |
| 853 } | 855 } |
| 854 profile_user_info.id = | 856 profile_user_info.id = account.gaia; |
| 855 GetProfile()->GetPrefs()->GetString(prefs::kGoogleServicesUserAccountId); | |
| 856 | 857 |
| 857 return RespondNow(OneArgument(profile_user_info.ToValue().release())); | 858 return RespondNow(OneArgument(profile_user_info.ToValue().release())); |
| 858 } | 859 } |
| 859 | 860 |
| 860 IdentityRemoveCachedAuthTokenFunction::IdentityRemoveCachedAuthTokenFunction() { | 861 IdentityRemoveCachedAuthTokenFunction::IdentityRemoveCachedAuthTokenFunction() { |
| 861 } | 862 } |
| 862 | 863 |
| 863 IdentityRemoveCachedAuthTokenFunction:: | 864 IdentityRemoveCachedAuthTokenFunction:: |
| 864 ~IdentityRemoveCachedAuthTokenFunction() { | 865 ~IdentityRemoveCachedAuthTokenFunction() { |
| 865 } | 866 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 void IdentityLaunchWebAuthFlowFunction::OnAuthFlowURLChange( | 949 void IdentityLaunchWebAuthFlowFunction::OnAuthFlowURLChange( |
| 949 const GURL& redirect_url) { | 950 const GURL& redirect_url) { |
| 950 if (redirect_url.GetWithEmptyPath() == final_url_prefix_) { | 951 if (redirect_url.GetWithEmptyPath() == final_url_prefix_) { |
| 951 SetResult(new base::StringValue(redirect_url.spec())); | 952 SetResult(new base::StringValue(redirect_url.spec())); |
| 952 SendResponse(true); | 953 SendResponse(true); |
| 953 Release(); // Balanced in RunAsync. | 954 Release(); // Balanced in RunAsync. |
| 954 } | 955 } |
| 955 } | 956 } |
| 956 | 957 |
| 957 } // namespace extensions | 958 } // namespace extensions |
| OLD | NEW |