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/webstore_private/webstore_private_api.h" | 5 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" |
6 | 6 |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/about_flags.h" | 16 #include "chrome/browser/about_flags.h" |
17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
19 #include "chrome/browser/extensions/crx_installer.h" | 19 #include "chrome/browser/extensions/crx_installer.h" |
20 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
21 #include "chrome/browser/extensions/extension_util.h" | 21 #include "chrome/browser/extensions/extension_util.h" |
22 #include "chrome/browser/extensions/webstore_installer.h" | 22 #include "chrome/browser/extensions/webstore_installer.h" |
23 #include "chrome/browser/gpu/gpu_feature_checker.h" | 23 #include "chrome/browser/gpu/gpu_feature_checker.h" |
24 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" |
25 #include "chrome/browser/signin/signin_manager_factory.h" | 25 #include "chrome/browser/signin/signin_manager_factory.h" |
| 26 #include "chrome/browser/signin/signin_promo.h" |
26 #include "chrome/browser/signin/signin_tracker_factory.h" | 27 #include "chrome/browser/signin/signin_tracker_factory.h" |
27 #include "chrome/browser/sync/profile_sync_service.h" | 28 #include "chrome/browser/sync/profile_sync_service.h" |
28 #include "chrome/browser/sync/profile_sync_service_factory.h" | 29 #include "chrome/browser/sync/profile_sync_service_factory.h" |
29 #include "chrome/browser/ui/app_list/app_list_service.h" | 30 #include "chrome/browser/ui/app_list/app_list_service.h" |
30 #include "chrome/browser/ui/app_list/app_list_util.h" | 31 #include "chrome/browser/ui/app_list/app_list_util.h" |
31 #include "chrome/browser/ui/browser.h" | 32 #include "chrome/browser/ui/browser.h" |
32 #include "chrome/common/extensions/extension_constants.h" | 33 #include "chrome/common/extensions/extension_constants.h" |
33 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
34 #include "components/signin/core/browser/signin_manager.h" | 35 #include "components/signin/core/browser/signin_manager.h" |
| 36 #include "components/signin/core/common/profile_management_switches.h" |
35 #include "content/public/browser/gpu_data_manager.h" | 37 #include "content/public/browser/gpu_data_manager.h" |
36 #include "content/public/browser/notification_details.h" | 38 #include "content/public/browser/notification_details.h" |
37 #include "content/public/browser/notification_source.h" | 39 #include "content/public/browser/notification_source.h" |
38 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 41 #include "content/public/common/page_transition_types.h" |
| 42 #include "content/public/common/referrer.h" |
39 #include "extensions/browser/extension_function_dispatcher.h" | 43 #include "extensions/browser/extension_function_dispatcher.h" |
40 #include "extensions/browser/extension_prefs.h" | 44 #include "extensions/browser/extension_prefs.h" |
41 #include "extensions/browser/extension_system.h" | 45 #include "extensions/browser/extension_system.h" |
42 #include "extensions/common/error_utils.h" | 46 #include "extensions/common/error_utils.h" |
43 #include "extensions/common/extension.h" | 47 #include "extensions/common/extension.h" |
44 #include "extensions/common/extension_l10n_util.h" | 48 #include "extensions/common/extension_l10n_util.h" |
| 49 #include "google_apis/gaia/google_service_auth_error.h" |
45 #include "grit/chromium_strings.h" | 50 #include "grit/chromium_strings.h" |
46 #include "grit/generated_resources.h" | 51 #include "grit/generated_resources.h" |
47 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
| 53 #include "url/gurl.h" |
48 | 54 |
49 using content::GpuDataManager; | 55 using content::GpuDataManager; |
50 | 56 |
51 namespace extensions { | 57 namespace extensions { |
52 | 58 |
53 namespace BeginInstallWithManifest3 = | 59 namespace BeginInstallWithManifest3 = |
54 api::webstore_private::BeginInstallWithManifest3; | 60 api::webstore_private::BeginInstallWithManifest3; |
55 namespace CompleteInstall = api::webstore_private::CompleteInstall; | 61 namespace CompleteInstall = api::webstore_private::CompleteInstall; |
56 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin; | 62 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin; |
57 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; | 63 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; |
58 namespace GetStoreLogin = api::webstore_private::GetStoreLogin; | 64 namespace GetStoreLogin = api::webstore_private::GetStoreLogin; |
59 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; | 65 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; |
60 namespace InstallBundle = api::webstore_private::InstallBundle; | 66 namespace InstallBundle = api::webstore_private::InstallBundle; |
61 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; | 67 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; |
| 68 namespace SignIn = api::webstore_private::SignIn; |
62 namespace SetStoreLogin = api::webstore_private::SetStoreLogin; | 69 namespace SetStoreLogin = api::webstore_private::SetStoreLogin; |
63 | 70 |
64 namespace { | 71 namespace { |
65 | 72 |
66 // Holds the Approvals between the time we prompt and start the installs. | 73 // Holds the Approvals between the time we prompt and start the installs. |
67 class PendingApprovals { | 74 class PendingApprovals { |
68 public: | 75 public: |
69 PendingApprovals(); | 76 PendingApprovals(); |
70 ~PendingApprovals(); | 77 ~PendingApprovals(); |
71 | 78 |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 results_ = GetIsLauncherEnabled::Results::Create(IsAppLauncherEnabled()); | 688 results_ = GetIsLauncherEnabled::Results::Create(IsAppLauncherEnabled()); |
682 return true; | 689 return true; |
683 } | 690 } |
684 | 691 |
685 bool WebstorePrivateIsInIncognitoModeFunction::RunImpl() { | 692 bool WebstorePrivateIsInIncognitoModeFunction::RunImpl() { |
686 results_ = IsInIncognitoMode::Results::Create( | 693 results_ = IsInIncognitoMode::Results::Create( |
687 GetProfile() != GetProfile()->GetOriginalProfile()); | 694 GetProfile() != GetProfile()->GetOriginalProfile()); |
688 return true; | 695 return true; |
689 } | 696 } |
690 | 697 |
| 698 WebstorePrivateSignInFunction::WebstorePrivateSignInFunction() |
| 699 : signin_manager_(NULL) {} |
| 700 WebstorePrivateSignInFunction::~WebstorePrivateSignInFunction() {} |
| 701 |
| 702 bool WebstorePrivateSignInFunction::RunImpl() { |
| 703 scoped_ptr<SignIn::Params> params = SignIn::Params::Create(*args_); |
| 704 EXTENSION_FUNCTION_VALIDATE(params); |
| 705 |
| 706 // This API must be called only in response to a user gesture. |
| 707 if (!user_gesture()) { |
| 708 error_ = "user_gesture_required"; |
| 709 SendResponse(false); |
| 710 return false; |
| 711 } |
| 712 |
| 713 // The |continue_url| is required, and must be hosted on the same origin as |
| 714 // the calling page. |
| 715 GURL continue_url(params->continue_url); |
| 716 content::WebContents* web_contents = GetAssociatedWebContents(); |
| 717 if (!continue_url.is_valid() || |
| 718 continue_url.GetOrigin() != |
| 719 web_contents->GetLastCommittedURL().GetOrigin()) { |
| 720 error_ = "invalid_continue_url"; |
| 721 SendResponse(false); |
| 722 return false; |
| 723 } |
| 724 |
| 725 // If sign-in is disallowed, give up. |
| 726 signin_manager_ = SigninManagerFactory::GetForProfile(GetProfile()); |
| 727 if (!signin_manager_ || !signin_manager_->IsSigninAllowed() || |
| 728 switches::IsEnableWebBasedSignin()) { |
| 729 error_ = "signin_is_disallowed"; |
| 730 SendResponse(false); |
| 731 return false; |
| 732 } |
| 733 |
| 734 // If the user is already signed in, there's nothing else to do. |
| 735 if (!signin_manager_->GetAuthenticatedUsername().empty()) { |
| 736 SendResponse(true); |
| 737 return true; |
| 738 } |
| 739 |
| 740 // If an authentication is currently in progress, wait for it to complete. |
| 741 if (signin_manager_->AuthInProgress()) { |
| 742 SigninManagerFactory::GetInstance()->AddObserver(this); |
| 743 signin_tracker_ = |
| 744 SigninTrackerFactory::CreateForProfile(GetProfile(), this).Pass(); |
| 745 AddRef(); // Balanced in the sign-in observer methods below. |
| 746 return true; |
| 747 } |
| 748 |
| 749 GURL signin_url = |
| 750 signin::GetPromoURLWithContinueURL(signin::SOURCE_WEBSTORE_INSTALL, |
| 751 false /* auto_close */, |
| 752 false /* is_constrained */, |
| 753 continue_url); |
| 754 web_contents->GetController().LoadURL(signin_url, |
| 755 content::Referrer(), |
| 756 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 757 std::string()); |
| 758 |
| 759 SendResponse(true); |
| 760 return true; |
| 761 } |
| 762 |
| 763 void WebstorePrivateSignInFunction::SigninManagerShutdown( |
| 764 SigninManagerBase* manager) { |
| 765 if (manager == signin_manager_) |
| 766 SigninFailed(GoogleServiceAuthError::AuthErrorNone()); |
| 767 } |
| 768 |
| 769 void WebstorePrivateSignInFunction::SigninFailed( |
| 770 const GoogleServiceAuthError& error) { |
| 771 error_ = "signin_failed"; |
| 772 SendResponse(false); |
| 773 |
| 774 SigninManagerFactory::GetInstance()->RemoveObserver(this); |
| 775 Release(); // Balanced in RunImpl(). |
| 776 } |
| 777 |
| 778 void WebstorePrivateSignInFunction::SigninSuccess() { |
| 779 // Nothing to do yet. Keep waiting until MergeSessionComplete() is called. |
| 780 } |
| 781 |
| 782 void WebstorePrivateSignInFunction::MergeSessionComplete( |
| 783 const GoogleServiceAuthError& error) { |
| 784 if (error.state() == GoogleServiceAuthError::NONE) { |
| 785 SendResponse(true); |
| 786 } else { |
| 787 error_ = "merge_session_failed"; |
| 788 SendResponse(false); |
| 789 } |
| 790 |
| 791 SigninManagerFactory::GetInstance()->RemoveObserver(this); |
| 792 Release(); // Balanced in RunImpl(). |
| 793 } |
| 794 |
691 } // namespace extensions | 795 } // namespace extensions |
OLD | NEW |