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.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "base/version.h" | 15 #include "base/version.h" |
16 #include "chrome/browser/apps/ephemeral_app_launcher.h" | |
17 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" | 16 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" |
18 #include "chrome/browser/extensions/crx_installer.h" | 17 #include "chrome/browser/extensions/crx_installer.h" |
19 #include "chrome/browser/extensions/extension_install_ui_util.h" | 18 #include "chrome/browser/extensions/extension_install_ui_util.h" |
20 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
21 #include "chrome/browser/extensions/install_tracker.h" | 20 #include "chrome/browser/extensions/install_tracker.h" |
22 #include "chrome/browser/gpu/gpu_feature_checker.h" | 21 #include "chrome/browser/gpu/gpu_feature_checker.h" |
23 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/signin/signin_manager_factory.h" | 23 #include "chrome/browser/signin/signin_manager_factory.h" |
25 #include "chrome/browser/ui/app_list/app_list_service.h" | 24 #include "chrome/browser/ui/app_list/app_list_service.h" |
26 #include "chrome/browser/ui/app_list/app_list_util.h" | 25 #include "chrome/browser/ui/app_list/app_list_util.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 91 } |
93 return scoped_ptr<WebstoreInstaller::Approval>(); | 92 return scoped_ptr<WebstoreInstaller::Approval>(); |
94 } | 93 } |
95 | 94 |
96 chrome::HostDesktopType GetHostDesktopTypeForWebContents( | 95 chrome::HostDesktopType GetHostDesktopTypeForWebContents( |
97 content::WebContents* contents) { | 96 content::WebContents* contents) { |
98 return chrome::GetHostDesktopTypeForNativeWindow( | 97 return chrome::GetHostDesktopTypeForNativeWindow( |
99 contents->GetTopLevelNativeWindow()); | 98 contents->GetTopLevelNativeWindow()); |
100 } | 99 } |
101 | 100 |
102 api::webstore_private::Result WebstoreInstallResultToApiResult( | |
103 webstore_install::Result result) { | |
104 switch (result) { | |
105 case webstore_install::SUCCESS: | |
106 return api::webstore_private::RESULT_SUCCESS; | |
107 case webstore_install::OTHER_ERROR: | |
108 return api::webstore_private::RESULT_UNKNOWN_ERROR; | |
109 case webstore_install::INVALID_ID: | |
110 return api::webstore_private::RESULT_INVALID_ID; | |
111 case webstore_install::NOT_PERMITTED: | |
112 case webstore_install::WEBSTORE_REQUEST_ERROR: | |
113 case webstore_install::INVALID_WEBSTORE_RESPONSE: | |
114 return api::webstore_private::RESULT_INSTALL_ERROR; | |
115 case webstore_install::INVALID_MANIFEST: | |
116 return api::webstore_private::RESULT_MANIFEST_ERROR; | |
117 case webstore_install::ICON_ERROR: | |
118 return api::webstore_private::RESULT_ICON_ERROR; | |
119 case webstore_install::ABORTED: | |
120 case webstore_install::USER_CANCELLED: | |
121 return api::webstore_private::RESULT_USER_CANCELLED; | |
122 case webstore_install::BLACKLISTED: | |
123 return api::webstore_private::RESULT_BLACKLISTED; | |
124 case webstore_install::MISSING_DEPENDENCIES: | |
125 case webstore_install::REQUIREMENT_VIOLATIONS: | |
126 return api::webstore_private::RESULT_MISSING_DEPENDENCIES; | |
127 case webstore_install::BLOCKED_BY_POLICY: | |
128 return api::webstore_private::RESULT_BLOCKED_BY_POLICY; | |
129 case webstore_install::LAUNCH_FEATURE_DISABLED: | |
130 return api::webstore_private::RESULT_FEATURE_DISABLED; | |
131 case webstore_install::LAUNCH_UNSUPPORTED_EXTENSION_TYPE: | |
132 return api::webstore_private::RESULT_UNSUPPORTED_EXTENSION_TYPE; | |
133 case webstore_install::INSTALL_IN_PROGRESS: | |
134 return api::webstore_private::RESULT_INSTALL_IN_PROGRESS; | |
135 case webstore_install::LAUNCH_IN_PROGRESS: | |
136 return api::webstore_private::RESULT_LAUNCH_IN_PROGRESS; | |
137 } | |
138 NOTREACHED(); | |
139 return api::webstore_private::RESULT_NONE; | |
140 } | |
141 | |
142 api::webstore_private::Result WebstoreInstallHelperResultToApiResult( | 101 api::webstore_private::Result WebstoreInstallHelperResultToApiResult( |
143 WebstoreInstallHelper::Delegate::InstallHelperResultCode result) { | 102 WebstoreInstallHelper::Delegate::InstallHelperResultCode result) { |
144 switch (result) { | 103 switch (result) { |
145 case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR: | 104 case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR: |
146 return api::webstore_private::RESULT_UNKNOWN_ERROR; | 105 return api::webstore_private::RESULT_UNKNOWN_ERROR; |
147 case WebstoreInstallHelper::Delegate::ICON_ERROR: | 106 case WebstoreInstallHelper::Delegate::ICON_ERROR: |
148 return api::webstore_private::RESULT_ICON_ERROR; | 107 return api::webstore_private::RESULT_ICON_ERROR; |
149 case WebstoreInstallHelper::Delegate::MANIFEST_ERROR: | 108 case WebstoreInstallHelper::Delegate::MANIFEST_ERROR: |
150 return api::webstore_private::RESULT_MANIFEST_ERROR; | 109 return api::webstore_private::RESULT_MANIFEST_ERROR; |
151 } | 110 } |
(...skipping 15 matching lines...) Expand all Loading... |
167 const char kInvalidBundleError[] = "Invalid bundle"; | 126 const char kInvalidBundleError[] = "Invalid bundle"; |
168 const char kInvalidIconUrlError[] = "Invalid icon url"; | 127 const char kInvalidIconUrlError[] = "Invalid icon url"; |
169 const char kInvalidIdError[] = "Invalid id"; | 128 const char kInvalidIdError[] = "Invalid id"; |
170 const char kInvalidManifestError[] = "Invalid manifest"; | 129 const char kInvalidManifestError[] = "Invalid manifest"; |
171 const char kNoPreviousBeginInstallWithManifestError[] = | 130 const char kNoPreviousBeginInstallWithManifestError[] = |
172 "* does not match a previous call to beginInstallWithManifest3"; | 131 "* does not match a previous call to beginInstallWithManifest3"; |
173 const char kBlockedByPolicyError[] = "Blocked by policy"; | 132 const char kBlockedByPolicyError[] = "Blocked by policy"; |
174 const char kUserCancelledError[] = "User cancelled install"; | 133 const char kUserCancelledError[] = "User cancelled install"; |
175 const char kIncognitoError[] = | 134 const char kIncognitoError[] = |
176 "Apps cannot be installed in guest/incognito mode"; | 135 "Apps cannot be installed in guest/incognito mode"; |
| 136 const char kEphemeralAppLaunchingNotSupported[] = |
| 137 "Ephemeral launching of apps is no longer supported."; |
177 | 138 |
178 WebstoreInstaller::Delegate* test_webstore_installer_delegate = nullptr; | 139 WebstoreInstaller::Delegate* test_webstore_installer_delegate = nullptr; |
179 | 140 |
180 // We allow the web store to set a string containing login information when a | 141 // We allow the web store to set a string containing login information when a |
181 // purchase is made, so that when a user logs into sync with a different | 142 // purchase is made, so that when a user logs into sync with a different |
182 // account we can recognize the situation. The Get function returns the login if | 143 // account we can recognize the situation. The Get function returns the login if |
183 // there was previously stored data, or an empty string otherwise. The Set will | 144 // there was previously stored data, or an empty string otherwise. The Set will |
184 // overwrite any previous login. | 145 // overwrite any previous login. |
185 std::string GetWebstoreLogin(Profile* profile) { | 146 std::string GetWebstoreLogin(Profile* profile) { |
186 if (profile->GetPrefs()->HasPrefPath(kWebstoreLogin)) | 147 if (profile->GetPrefs()->HasPrefPath(kWebstoreLogin)) |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 } | 700 } |
740 | 701 |
741 WebstorePrivateLaunchEphemeralAppFunction:: | 702 WebstorePrivateLaunchEphemeralAppFunction:: |
742 WebstorePrivateLaunchEphemeralAppFunction() : chrome_details_(this) {} | 703 WebstorePrivateLaunchEphemeralAppFunction() : chrome_details_(this) {} |
743 | 704 |
744 WebstorePrivateLaunchEphemeralAppFunction:: | 705 WebstorePrivateLaunchEphemeralAppFunction:: |
745 ~WebstorePrivateLaunchEphemeralAppFunction() {} | 706 ~WebstorePrivateLaunchEphemeralAppFunction() {} |
746 | 707 |
747 ExtensionFunction::ResponseAction | 708 ExtensionFunction::ResponseAction |
748 WebstorePrivateLaunchEphemeralAppFunction::Run() { | 709 WebstorePrivateLaunchEphemeralAppFunction::Run() { |
749 // Check whether the browser window still exists. | 710 // Just fail as this is no longer supported. |
750 content::WebContents* web_contents = | 711 return RespondNow(Error(kEphemeralAppLaunchingNotSupported)); |
751 chrome_details_.GetAssociatedWebContents(); | |
752 if (!web_contents) | |
753 return RespondNow(Error("aborted")); | |
754 | |
755 if (!user_gesture()) { | |
756 return RespondNow(BuildResponse( | |
757 api::webstore_private::RESULT_USER_GESTURE_REQUIRED, | |
758 "User gesture is required")); | |
759 } | |
760 | |
761 scoped_ptr<LaunchEphemeralApp::Params> params( | |
762 LaunchEphemeralApp::Params::Create(*args_)); | |
763 EXTENSION_FUNCTION_VALIDATE(params); | |
764 | |
765 AddRef(); // Balanced in OnLaunchComplete() | |
766 | |
767 scoped_refptr<EphemeralAppLauncher> launcher = | |
768 EphemeralAppLauncher::CreateForWebContents( | |
769 params->id, | |
770 web_contents, | |
771 base::Bind( | |
772 &WebstorePrivateLaunchEphemeralAppFunction::OnLaunchComplete, | |
773 base::Unretained(this))); | |
774 launcher->Start(); | |
775 | |
776 return RespondLater(); | |
777 } | |
778 | |
779 void WebstorePrivateLaunchEphemeralAppFunction::OnLaunchComplete( | |
780 webstore_install::Result result, const std::string& error) { | |
781 Respond(BuildResponse(WebstoreInstallResultToApiResult(result), error)); | |
782 Release(); // Matches AddRef() in Run() | |
783 } | |
784 | |
785 ExtensionFunction::ResponseValue | |
786 WebstorePrivateLaunchEphemeralAppFunction::BuildResponse( | |
787 api::webstore_private::Result result, const std::string& error) { | |
788 if (result != api::webstore_private::RESULT_SUCCESS) { | |
789 std::string error_message; | |
790 if (error.empty()) { | |
791 error_message = base::StringPrintf( | |
792 "[%s]", api::webstore_private::ToString(result).c_str()); | |
793 } else { | |
794 error_message = base::StringPrintf( | |
795 "[%s]: %s", | |
796 api::webstore_private::ToString(result).c_str(), | |
797 error.c_str()); | |
798 } | |
799 return ErrorWithArguments(LaunchEphemeralApp::Results::Create(result), | |
800 error_message); | |
801 } | |
802 return ArgumentList(LaunchEphemeralApp::Results::Create(result)); | |
803 } | 712 } |
804 | 713 |
805 WebstorePrivateGetEphemeralAppsEnabledFunction:: | 714 WebstorePrivateGetEphemeralAppsEnabledFunction:: |
806 WebstorePrivateGetEphemeralAppsEnabledFunction() {} | 715 WebstorePrivateGetEphemeralAppsEnabledFunction() {} |
807 | 716 |
808 WebstorePrivateGetEphemeralAppsEnabledFunction:: | 717 WebstorePrivateGetEphemeralAppsEnabledFunction:: |
809 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {} | 718 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {} |
810 | 719 |
811 ExtensionFunction::ResponseAction | 720 ExtensionFunction::ResponseAction |
812 WebstorePrivateGetEphemeralAppsEnabledFunction::Run() { | 721 WebstorePrivateGetEphemeralAppsEnabledFunction::Run() { |
813 return RespondNow(ArgumentList(GetEphemeralAppsEnabled::Results::Create( | 722 return RespondNow(ArgumentList(GetEphemeralAppsEnabled::Results::Create( |
814 EphemeralAppLauncher::IsFeatureEnabled()))); | 723 false))); |
815 } | 724 } |
816 | 725 |
817 } // namespace extensions | 726 } // namespace extensions |
OLD | NEW |