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/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/values.h" | 13 #include "base/values.h" |
14 #include "base/version.h" | 14 #include "base/version.h" |
15 #include "chrome/browser/apps/ephemeral_app_launcher.h" | 15 #include "chrome/browser/apps/ephemeral_app_launcher.h" |
16 #include "chrome/browser/extensions/crx_installer.h" | 16 #include "chrome/browser/extensions/crx_installer.h" |
17 #include "chrome/browser/extensions/extension_install_ui_util.h" | 17 #include "chrome/browser/extensions/extension_install_ui_util.h" |
18 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
19 #include "chrome/browser/extensions/install_tracker.h" | 19 #include "chrome/browser/extensions/install_tracker.h" |
20 #include "chrome/browser/gpu/gpu_feature_checker.h" | 20 #include "chrome/browser/gpu/gpu_feature_checker.h" |
21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/safe_image_fetcher.h" |
22 #include "chrome/browser/signin/signin_manager_factory.h" | 23 #include "chrome/browser/signin/signin_manager_factory.h" |
23 #include "chrome/browser/ui/app_list/app_list_service.h" | 24 #include "chrome/browser/ui/app_list/app_list_service.h" |
24 #include "chrome/browser/ui/app_list/app_list_util.h" | 25 #include "chrome/browser/ui/app_list/app_list_util.h" |
25 #include "chrome/common/extensions/extension_constants.h" | 26 #include "chrome/common/extensions/extension_constants.h" |
26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
27 #include "components/crx_file/id_util.h" | 28 #include "components/crx_file/id_util.h" |
28 #include "components/signin/core/browser/signin_manager.h" | 29 #include "components/signin/core/browser/signin_manager.h" |
29 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
30 #include "extensions/browser/extension_registry.h" | 31 #include "extensions/browser/extension_registry.h" |
31 #include "extensions/browser/extension_system.h" | 32 #include "extensions/browser/extension_system.h" |
32 #include "extensions/browser/extension_util.h" | 33 #include "extensions/browser/extension_util.h" |
33 #include "extensions/common/extension.h" | 34 #include "extensions/common/extension.h" |
| 35 #include "url/gurl.h" |
34 | 36 |
35 namespace extensions { | 37 namespace extensions { |
36 | 38 |
37 namespace BeginInstallWithManifest3 = | 39 namespace BeginInstallWithManifest3 = |
38 api::webstore_private::BeginInstallWithManifest3; | 40 api::webstore_private::BeginInstallWithManifest3; |
39 namespace CompleteInstall = api::webstore_private::CompleteInstall; | 41 namespace CompleteInstall = api::webstore_private::CompleteInstall; |
40 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin; | 42 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin; |
41 namespace GetEphemeralAppsEnabled = | 43 namespace GetEphemeralAppsEnabled = |
42 api::webstore_private::GetEphemeralAppsEnabled; | 44 api::webstore_private::GetEphemeralAppsEnabled; |
43 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; | 45 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; |
44 namespace GetStoreLogin = api::webstore_private::GetStoreLogin; | 46 namespace GetStoreLogin = api::webstore_private::GetStoreLogin; |
45 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; | 47 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; |
| 48 namespace InstallBundle = api::webstore_private::InstallBundle; |
46 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; | 49 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; |
47 namespace LaunchEphemeralApp = api::webstore_private::LaunchEphemeralApp; | 50 namespace LaunchEphemeralApp = api::webstore_private::LaunchEphemeralApp; |
48 namespace SetStoreLogin = api::webstore_private::SetStoreLogin; | 51 namespace SetStoreLogin = api::webstore_private::SetStoreLogin; |
49 namespace ShowPermissionPromptForDelegatedInstall = | 52 namespace ShowPermissionPromptForDelegatedInstall = |
50 api::webstore_private::ShowPermissionPromptForDelegatedInstall; | 53 api::webstore_private::ShowPermissionPromptForDelegatedInstall; |
51 | 54 |
52 namespace { | 55 namespace { |
53 | 56 |
54 // Holds the Approvals between the time we prompt and start the installs. | 57 // Holds the Approvals between the time we prompt and start the installs. |
55 class PendingApprovals { | 58 class PendingApprovals { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 NOTREACHED(); | 151 NOTREACHED(); |
149 return api::webstore_private::RESULT_NONE; | 152 return api::webstore_private::RESULT_NONE; |
150 } | 153 } |
151 | 154 |
152 static base::LazyInstance<PendingApprovals> g_pending_approvals = | 155 static base::LazyInstance<PendingApprovals> g_pending_approvals = |
153 LAZY_INSTANCE_INITIALIZER; | 156 LAZY_INSTANCE_INITIALIZER; |
154 | 157 |
155 // A preference set by the web store to indicate login information for | 158 // A preference set by the web store to indicate login information for |
156 // purchased apps. | 159 // purchased apps. |
157 const char kWebstoreLogin[] = "extensions.webstore_login"; | 160 const char kWebstoreLogin[] = "extensions.webstore_login"; |
| 161 |
| 162 // Error messages that can be returned by the API. |
158 const char kAlreadyInstalledError[] = "This item is already installed"; | 163 const char kAlreadyInstalledError[] = "This item is already installed"; |
159 const char kCannotSpecifyIconDataAndUrlError[] = | 164 const char kCannotSpecifyIconDataAndUrlError[] = |
160 "You cannot specify both icon data and an icon url"; | 165 "You cannot specify both icon data and an icon url"; |
| 166 const char kInvalidBundleError[] = "Invalid bundle"; |
161 const char kInvalidIconUrlError[] = "Invalid icon url"; | 167 const char kInvalidIconUrlError[] = "Invalid icon url"; |
162 const char kInvalidIdError[] = "Invalid id"; | 168 const char kInvalidIdError[] = "Invalid id"; |
163 const char kInvalidManifestError[] = "Invalid manifest"; | 169 const char kInvalidManifestError[] = "Invalid manifest"; |
164 const char kNoPreviousBeginInstallWithManifestError[] = | 170 const char kNoPreviousBeginInstallWithManifestError[] = |
165 "* does not match a previous call to beginInstallWithManifest3"; | 171 "* does not match a previous call to beginInstallWithManifest3"; |
166 const char kUserCancelledError[] = "User cancelled install"; | 172 const char kUserCancelledError[] = "User cancelled install"; |
167 | 173 |
168 WebstoreInstaller::Delegate* test_webstore_installer_delegate = NULL; | 174 WebstoreInstaller::Delegate* test_webstore_installer_delegate = nullptr; |
169 | 175 |
170 // We allow the web store to set a string containing login information when a | 176 // We allow the web store to set a string containing login information when a |
171 // purchase is made, so that when a user logs into sync with a different | 177 // purchase is made, so that when a user logs into sync with a different |
172 // account we can recognize the situation. The Get function returns the login if | 178 // account we can recognize the situation. The Get function returns the login if |
173 // there was previously stored data, or an empty string otherwise. The Set will | 179 // there was previously stored data, or an empty string otherwise. The Set will |
174 // overwrite any previous login. | 180 // overwrite any previous login. |
175 std::string GetWebstoreLogin(Profile* profile) { | 181 std::string GetWebstoreLogin(Profile* profile) { |
176 if (profile->GetPrefs()->HasPrefPath(kWebstoreLogin)) | 182 if (profile->GetPrefs()->HasPrefPath(kWebstoreLogin)) |
177 return profile->GetPrefs()->GetString(kWebstoreLogin); | 183 return profile->GetPrefs()->GetString(kWebstoreLogin); |
178 return std::string(); | 184 return std::string(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 return RespondNow(BuildResponse( | 265 return RespondNow(BuildResponse( |
260 api::webstore_private::RESULT_INVALID_ICON_URL, | 266 api::webstore_private::RESULT_INVALID_ICON_URL, |
261 kInvalidIconUrlError)); | 267 kInvalidIconUrlError)); |
262 } | 268 } |
263 } | 269 } |
264 | 270 |
265 ExtensionFunction::ResponseValue response = RunExtraForResponse(); | 271 ExtensionFunction::ResponseValue response = RunExtraForResponse(); |
266 if (response) | 272 if (response) |
267 return RespondNow(response.Pass()); | 273 return RespondNow(response.Pass()); |
268 | 274 |
269 net::URLRequestContextGetter* context_getter = NULL; | 275 net::URLRequestContextGetter* context_getter = nullptr; |
270 if (!icon_url.is_empty()) | 276 if (!icon_url.is_empty()) |
271 context_getter = browser_context()->GetRequestContext(); | 277 context_getter = browser_context()->GetRequestContext(); |
272 | 278 |
273 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( | 279 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( |
274 this, params_->details.id, params_->details.manifest, icon_url, | 280 this, params_->details.id, params_->details.manifest, icon_url, |
275 context_getter); | 281 context_getter); |
276 | 282 |
277 // The helper will call us back via OnWebstoreParseSuccess or | 283 // The helper will call us back via OnWebstoreParseSuccess or |
278 // OnWebstoreParseFailure. | 284 // OnWebstoreParseFailure. |
279 helper->Start(); | 285 helper->Start(); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 install_prompt->ConfirmPermissionsForDelegatedInstall( | 585 install_prompt->ConfirmPermissionsForDelegatedInstall( |
580 this, dummy_extension().get(), params().details.delegated_user, &icon()); | 586 this, dummy_extension().get(), params().details.delegated_user, &icon()); |
581 } | 587 } |
582 | 588 |
583 scoped_ptr<base::ListValue> | 589 scoped_ptr<base::ListValue> |
584 WebstorePrivateShowPermissionPromptForDelegatedInstallFunction::CreateResults( | 590 WebstorePrivateShowPermissionPromptForDelegatedInstallFunction::CreateResults( |
585 api::webstore_private::Result result) const { | 591 api::webstore_private::Result result) const { |
586 return ShowPermissionPromptForDelegatedInstall::Results::Create(result); | 592 return ShowPermissionPromptForDelegatedInstall::Results::Create(result); |
587 } | 593 } |
588 | 594 |
| 595 WebstorePrivateInstallBundleFunction::WebstorePrivateInstallBundleFunction() |
| 596 : chrome_details_(this) { |
| 597 } |
| 598 |
| 599 WebstorePrivateInstallBundleFunction::~WebstorePrivateInstallBundleFunction() { |
| 600 } |
| 601 |
| 602 ExtensionFunction::ResponseAction WebstorePrivateInstallBundleFunction::Run() { |
| 603 params_ = InstallBundle::Params::Create(*args_); |
| 604 EXTENSION_FUNCTION_VALIDATE(params_); |
| 605 |
| 606 GURL icon_url; |
| 607 if (params_->details.icon_url) { |
| 608 icon_url = source_url().Resolve(*params_->details.icon_url); |
| 609 if (!icon_url.is_valid()) |
| 610 return RespondNow(Error(kInvalidIconUrlError)); |
| 611 } |
| 612 |
| 613 if (params_->contents.empty()) |
| 614 return RespondNow(Error(kInvalidBundleError)); |
| 615 |
| 616 // The image fetcher will call us back via OnIconFetched. |
| 617 icon_fetcher_.reset(new SafeImageFetcher( |
| 618 icon_url, browser_context()->GetRequestContext(), |
| 619 base::Bind(&WebstorePrivateInstallBundleFunction::OnIconFetched, this))); |
| 620 |
| 621 // The response is sent asynchronously in OnIconFetched, OnInstallApproval, or |
| 622 // OnInstallComplete. |
| 623 return RespondLater(); |
| 624 } |
| 625 |
| 626 void WebstorePrivateInstallBundleFunction::OnIconFetched(const SkBitmap& icon) { |
| 627 InstallTracker* tracker = InstallTracker::Get(browser_context()); |
| 628 DCHECK(tracker); |
| 629 |
| 630 std::string authuser; |
| 631 if (params_->details.authuser) |
| 632 authuser = *params_->details.authuser; |
| 633 |
| 634 BundleInstaller::ItemList items; |
| 635 for (const auto& entry : params_->contents) { |
| 636 // Skip already-installed items. |
| 637 if (util::IsExtensionInstalledPermanently(entry->id, browser_context()) || |
| 638 tracker->GetActiveInstall(entry->id)) { |
| 639 continue; |
| 640 } |
| 641 BundleInstaller::Item item; |
| 642 item.id = entry->id; |
| 643 item.manifest = entry->manifest; |
| 644 item.localized_name = entry->localized_name; |
| 645 if (entry->icon_url) |
| 646 item.icon_url = source_url().Resolve(*entry->icon_url); |
| 647 items.push_back(item); |
| 648 } |
| 649 if (items.empty()) { |
| 650 Respond(Error(kAlreadyInstalledError)); |
| 651 return; |
| 652 } |
| 653 bundle_.reset(new BundleInstaller(chrome_details_.GetCurrentBrowser(), |
| 654 params_->details.localized_name, |
| 655 icon, authuser, items)); |
| 656 |
| 657 // The bundle installer will call us back via OnInstallApproval. |
| 658 bundle_->PromptForApproval( |
| 659 base::Bind(&WebstorePrivateInstallBundleFunction::OnInstallApproval, |
| 660 this)); |
| 661 } |
| 662 |
| 663 void WebstorePrivateInstallBundleFunction::OnInstallApproval( |
| 664 BundleInstaller::ApprovalState state) { |
| 665 if (state != BundleInstaller::APPROVED) { |
| 666 Respond(Error(state == BundleInstaller::USER_CANCELED |
| 667 ? kUserCancelledError |
| 668 : kInvalidBundleError)); |
| 669 return; |
| 670 } |
| 671 |
| 672 // The bundle installer will call us back via OnInstallComplete. |
| 673 bundle_->CompleteInstall( |
| 674 chrome_details_.GetAssociatedWebContents(), |
| 675 base::Bind(&WebstorePrivateInstallBundleFunction::OnInstallComplete, |
| 676 this)); |
| 677 } |
| 678 |
| 679 void WebstorePrivateInstallBundleFunction::OnInstallComplete() { |
| 680 Respond(NoArguments()); |
| 681 } |
| 682 |
589 WebstorePrivateEnableAppLauncherFunction:: | 683 WebstorePrivateEnableAppLauncherFunction:: |
590 WebstorePrivateEnableAppLauncherFunction() : chrome_details_(this) {} | 684 WebstorePrivateEnableAppLauncherFunction() : chrome_details_(this) {} |
591 | 685 |
592 WebstorePrivateEnableAppLauncherFunction:: | 686 WebstorePrivateEnableAppLauncherFunction:: |
593 ~WebstorePrivateEnableAppLauncherFunction() {} | 687 ~WebstorePrivateEnableAppLauncherFunction() {} |
594 | 688 |
595 ExtensionFunction::ResponseAction | 689 ExtensionFunction::ResponseAction |
596 WebstorePrivateEnableAppLauncherFunction::Run() { | 690 WebstorePrivateEnableAppLauncherFunction::Run() { |
597 AppListService* app_list_service = AppListService::Get( | 691 AppListService* app_list_service = AppListService::Get( |
598 GetHostDesktopTypeForWebContents( | 692 GetHostDesktopTypeForWebContents( |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 WebstorePrivateGetEphemeralAppsEnabledFunction:: | 853 WebstorePrivateGetEphemeralAppsEnabledFunction:: |
760 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {} | 854 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {} |
761 | 855 |
762 ExtensionFunction::ResponseAction | 856 ExtensionFunction::ResponseAction |
763 WebstorePrivateGetEphemeralAppsEnabledFunction::Run() { | 857 WebstorePrivateGetEphemeralAppsEnabledFunction::Run() { |
764 return RespondNow(ArgumentList(GetEphemeralAppsEnabled::Results::Create( | 858 return RespondNow(ArgumentList(GetEphemeralAppsEnabled::Results::Create( |
765 EphemeralAppLauncher::IsFeatureEnabled()))); | 859 EphemeralAppLauncher::IsFeatureEnabled()))); |
766 } | 860 } |
767 | 861 |
768 } // namespace extensions | 862 } // namespace extensions |
OLD | NEW |