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.h" | 25 #include "chrome/browser/signin/signin_manager.h" |
26 #include "chrome/browser/signin/signin_manager_factory.h" | 26 #include "chrome/browser/signin/signin_promo.h" |
27 #include "chrome/browser/sync/profile_sync_service.h" | 27 #include "chrome/browser/sync/profile_sync_service.h" |
28 #include "chrome/browser/sync/profile_sync_service_factory.h" | 28 #include "chrome/browser/sync/profile_sync_service_factory.h" |
29 #include "chrome/browser/ui/app_list/app_list_service.h" | 29 #include "chrome/browser/ui/app_list/app_list_service.h" |
30 #include "chrome/browser/ui/app_list/app_list_util.h" | 30 #include "chrome/browser/ui/app_list/app_list_util.h" |
31 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
32 #include "chrome/common/extensions/extension_constants.h" | 32 #include "chrome/common/extensions/extension_constants.h" |
33 #include "chrome/common/extensions/extension_l10n_util.h" | 33 #include "chrome/common/extensions/extension_l10n_util.h" |
34 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
| 35 #include "chrome/common/profile_management_switches.h" |
35 #include "content/public/browser/gpu_data_manager.h" | 36 #include "content/public/browser/gpu_data_manager.h" |
36 #include "content/public/browser/notification_details.h" | 37 #include "content/public/browser/notification_details.h" |
37 #include "content/public/browser/notification_source.h" | 38 #include "content/public/browser/notification_source.h" |
38 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
| 40 #include "content/public/common/page_transition_types.h" |
| 41 #include "content/public/common/referrer.h" |
39 #include "extensions/browser/extension_function_dispatcher.h" | 42 #include "extensions/browser/extension_function_dispatcher.h" |
40 #include "extensions/browser/extension_prefs.h" | 43 #include "extensions/browser/extension_prefs.h" |
41 #include "extensions/browser/extension_system.h" | 44 #include "extensions/browser/extension_system.h" |
42 #include "extensions/common/error_utils.h" | 45 #include "extensions/common/error_utils.h" |
43 #include "extensions/common/extension.h" | 46 #include "extensions/common/extension.h" |
| 47 #include "google_apis/gaia/google_service_auth_error.h" |
44 #include "grit/chromium_strings.h" | 48 #include "grit/chromium_strings.h" |
45 #include "grit/generated_resources.h" | 49 #include "grit/generated_resources.h" |
46 #include "ui/base/l10n/l10n_util.h" | 50 #include "ui/base/l10n/l10n_util.h" |
| 51 #include "url/gurl.h" |
47 | 52 |
48 using content::GpuDataManager; | 53 using content::GpuDataManager; |
49 | 54 |
50 namespace extensions { | 55 namespace extensions { |
51 | 56 |
52 namespace BeginInstallWithManifest3 = | 57 namespace BeginInstallWithManifest3 = |
53 api::webstore_private::BeginInstallWithManifest3; | 58 api::webstore_private::BeginInstallWithManifest3; |
54 namespace CompleteInstall = api::webstore_private::CompleteInstall; | 59 namespace CompleteInstall = api::webstore_private::CompleteInstall; |
55 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin; | 60 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin; |
56 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; | 61 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; |
57 namespace GetStoreLogin = api::webstore_private::GetStoreLogin; | 62 namespace GetStoreLogin = api::webstore_private::GetStoreLogin; |
58 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; | 63 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; |
59 namespace InstallBundle = api::webstore_private::InstallBundle; | 64 namespace InstallBundle = api::webstore_private::InstallBundle; |
60 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; | 65 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; |
| 66 namespace SignIn = api::webstore_private::SignIn; |
61 namespace SetStoreLogin = api::webstore_private::SetStoreLogin; | 67 namespace SetStoreLogin = api::webstore_private::SetStoreLogin; |
62 | 68 |
63 namespace { | 69 namespace { |
64 | 70 |
65 // Holds the Approvals between the time we prompt and start the installs. | 71 // Holds the Approvals between the time we prompt and start the installs. |
66 class PendingApprovals { | 72 class PendingApprovals { |
67 public: | 73 public: |
68 PendingApprovals(); | 74 PendingApprovals(); |
69 ~PendingApprovals(); | 75 ~PendingApprovals(); |
70 | 76 |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 results_ = GetIsLauncherEnabled::Results::Create(IsAppLauncherEnabled()); | 685 results_ = GetIsLauncherEnabled::Results::Create(IsAppLauncherEnabled()); |
680 return true; | 686 return true; |
681 } | 687 } |
682 | 688 |
683 bool WebstorePrivateIsInIncognitoModeFunction::RunImpl() { | 689 bool WebstorePrivateIsInIncognitoModeFunction::RunImpl() { |
684 results_ = IsInIncognitoMode::Results::Create( | 690 results_ = IsInIncognitoMode::Results::Create( |
685 GetProfile() != GetProfile()->GetOriginalProfile()); | 691 GetProfile() != GetProfile()->GetOriginalProfile()); |
686 return true; | 692 return true; |
687 } | 693 } |
688 | 694 |
| 695 WebstorePrivateSignInFunction::WebstorePrivateSignInFunction() |
| 696 : signin_manager_(NULL) {} |
| 697 WebstorePrivateSignInFunction::~WebstorePrivateSignInFunction() {} |
| 698 |
| 699 bool WebstorePrivateSignInFunction::RunImpl() { |
| 700 scoped_ptr<SignIn::Params> params = SignIn::Params::Create(*args_); |
| 701 EXTENSION_FUNCTION_VALIDATE(params); |
| 702 |
| 703 // The |continue_url| is required, and must be hosted on the same origin as |
| 704 // the calling page. |
| 705 GURL continue_url(params->continue_url); |
| 706 content::WebContents* web_contents = GetAssociatedWebContents(); |
| 707 if (!continue_url.is_valid() || |
| 708 continue_url.GetOrigin() != |
| 709 web_contents->GetLastCommittedURL().GetOrigin()) { |
| 710 error_ = "invalid_continue_url"; |
| 711 SendResponse(false); |
| 712 return false; |
| 713 } |
| 714 |
| 715 // If sign-in is disallowed, give up. |
| 716 signin_manager_ = SigninManagerFactory::GetForProfile(GetProfile()); |
| 717 if (!signin_manager_ || !signin_manager_->IsSigninAllowed() || |
| 718 switches::IsEnableWebBasedSignin()) { |
| 719 error_ = "signin_is_disallowed"; |
| 720 SendResponse(false); |
| 721 return false; |
| 722 } |
| 723 |
| 724 // If the user is already signed in, there's nothing else to do. |
| 725 if (!signin_manager_->GetAuthenticatedUsername().empty()) { |
| 726 // TODO(isherman): Hui suggests returning |true| below, because the user is |
| 727 // successfully signed in after this call. Is it ever appropriate to set an |
| 728 // |error_| and also return |true|? In general, what's the guideline for |
| 729 // when to return |true| vs. |false|? How is the return value used? Note |
| 730 // that this comment also applies to the MergeSessionComplete() case below. |
| 731 error_ = "user_is_already_signed_in"; |
| 732 SendResponse(false); |
| 733 return false; |
| 734 } |
| 735 |
| 736 // If an authentication is currently in progress, wait for it to complete. |
| 737 if (signin_manager_->AuthInProgress()) { |
| 738 SigninManagerFactory::GetInstance()->AddObserver(this); |
| 739 signin_tracker_.reset(new SigninTracker(GetProfile(), this)); |
| 740 AddRef(); // Balanced in the sign-in observer methods below. |
| 741 return true; |
| 742 } |
| 743 |
| 744 GURL signin_url = |
| 745 signin::GetPromoURLWithContinueURL(signin::SOURCE_WEBSTORE_INSTALL, |
| 746 false /* auto_close */, |
| 747 false /* is_constrained */, |
| 748 continue_url); |
| 749 web_contents->GetController().LoadURL(signin_url, |
| 750 content::Referrer(), |
| 751 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 752 std::string()); |
| 753 |
| 754 SendResponse(true); |
| 755 return true; |
| 756 } |
| 757 |
| 758 void WebstorePrivateSignInFunction::SigninManagerShutdown( |
| 759 SigninManagerBase* manager) { |
| 760 if (manager == signin_manager_) |
| 761 SigninFailed(GoogleServiceAuthError::AuthErrorNone()); |
| 762 } |
| 763 |
| 764 void WebstorePrivateSignInFunction::SigninFailed( |
| 765 const GoogleServiceAuthError& error) { |
| 766 error_ = "signin_failed"; |
| 767 SendResponse(false); |
| 768 |
| 769 SigninManagerFactory::GetInstance()->RemoveObserver(this); |
| 770 Release(); // Balanced in RunImpl(). |
| 771 } |
| 772 |
| 773 void WebstorePrivateSignInFunction::SigninSuccess() { |
| 774 // Nothing to do yet. Keep waiting until MergeSessionComplete() is called. |
| 775 } |
| 776 |
| 777 void WebstorePrivateSignInFunction::MergeSessionComplete( |
| 778 const GoogleServiceAuthError& error) { |
| 779 if (error.state() == GoogleServiceAuthError::NONE) |
| 780 error_ = "user_is_already_signed_in"; |
| 781 else |
| 782 error_ = "merge_session_failed"; |
| 783 |
| 784 SigninManagerFactory::GetInstance()->RemoveObserver(this); |
| 785 SendResponse(false); |
| 786 Release(); // Balanced in RunImpl(). |
| 787 } |
| 788 |
689 } // namespace extensions | 789 } // namespace extensions |
OLD | NEW |