Chromium Code Reviews| 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); | |
|
asargent_no_longer_on_chrome
2015/03/26 18:12:50
FYI, I think the icon_url we're passed is probably
Marc Treib
2015/03/27 11:52:12
Acknowledged.
| |
| 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, | |
| 620 base::Unretained(this)))); | |
| 621 | |
| 622 // Matched with a Release in OnIconFetched, OnInstallApproval, or | |
| 623 // OnInstallComplete. | |
| 624 AddRef(); | |
|
asargent_no_longer_on_chrome
2015/03/26 18:12:50
Instead of doing manual AddRef/Release calls and u
Marc Treib
2015/03/27 11:52:12
Indeed, that's much nicer, thanks! Done.
| |
| 625 | |
| 626 // The response is sent asynchronously in OnIconFetched, OnInstallApproval, or | |
| 627 // OnInstallComplete. | |
| 628 return RespondLater(); | |
| 629 } | |
| 630 | |
| 631 void WebstorePrivateInstallBundleFunction::OnIconFetched(const SkBitmap& icon) { | |
| 632 InstallTracker* tracker = InstallTracker::Get(browser_context()); | |
| 633 DCHECK(tracker); | |
| 634 | |
| 635 std::string authuser; | |
| 636 if (params_->details.authuser) | |
| 637 authuser = *params_->details.authuser; | |
| 638 | |
| 639 BundleInstaller::ItemList items; | |
| 640 for (const auto& entry : params_->contents) { | |
| 641 // Skip already-installed items. | |
| 642 if (util::IsExtensionInstalledPermanently(entry->id, browser_context()) || | |
| 643 tracker->GetActiveInstall(entry->id)) { | |
| 644 continue; | |
| 645 } | |
| 646 BundleInstaller::Item item; | |
| 647 item.id = entry->id; | |
| 648 item.manifest = entry->manifest; | |
| 649 item.localized_name = entry->localized_name; | |
| 650 if (entry->icon_url) | |
| 651 item.icon_url = source_url().Resolve(*entry->icon_url); | |
| 652 items.push_back(item); | |
| 653 } | |
| 654 if (items.empty()) { | |
| 655 Respond(Error(kAlreadyInstalledError)); | |
| 656 Release(); | |
| 657 return; | |
| 658 } | |
| 659 bundle_.reset(new BundleInstaller(chrome_details_.GetCurrentBrowser(), | |
| 660 params_->details.localized_name, | |
| 661 icon, authuser, items)); | |
| 662 | |
| 663 // The bundle installer will call us back via OnInstallApproval. | |
| 664 bundle_->PromptForApproval( | |
| 665 base::Bind(&WebstorePrivateInstallBundleFunction::OnInstallApproval, | |
| 666 base::Unretained(this))); | |
| 667 } | |
| 668 | |
| 669 void WebstorePrivateInstallBundleFunction::OnInstallApproval( | |
| 670 BundleInstaller::ApprovalState state) { | |
| 671 if (state != BundleInstaller::APPROVED) { | |
| 672 Respond(Error(state == BundleInstaller::USER_CANCELED | |
| 673 ? kUserCancelledError | |
| 674 : kInvalidBundleError)); | |
| 675 Release(); | |
| 676 return; | |
| 677 } | |
| 678 | |
| 679 // The bundle installer will call us back via OnInstallComplete. | |
| 680 bundle_->CompleteInstall( | |
| 681 chrome_details_.GetAssociatedWebContents(), | |
| 682 base::Bind(&WebstorePrivateInstallBundleFunction::OnInstallComplete, | |
| 683 base::Unretained(this))); | |
| 684 } | |
| 685 | |
| 686 void WebstorePrivateInstallBundleFunction::OnInstallComplete() { | |
| 687 Respond(NoArguments()); | |
| 688 Release(); | |
| 689 } | |
| 690 | |
| 589 WebstorePrivateEnableAppLauncherFunction:: | 691 WebstorePrivateEnableAppLauncherFunction:: |
| 590 WebstorePrivateEnableAppLauncherFunction() : chrome_details_(this) {} | 692 WebstorePrivateEnableAppLauncherFunction() : chrome_details_(this) {} |
| 591 | 693 |
| 592 WebstorePrivateEnableAppLauncherFunction:: | 694 WebstorePrivateEnableAppLauncherFunction:: |
| 593 ~WebstorePrivateEnableAppLauncherFunction() {} | 695 ~WebstorePrivateEnableAppLauncherFunction() {} |
| 594 | 696 |
| 595 ExtensionFunction::ResponseAction | 697 ExtensionFunction::ResponseAction |
| 596 WebstorePrivateEnableAppLauncherFunction::Run() { | 698 WebstorePrivateEnableAppLauncherFunction::Run() { |
| 597 AppListService* app_list_service = AppListService::Get( | 699 AppListService* app_list_service = AppListService::Get( |
| 598 GetHostDesktopTypeForWebContents( | 700 GetHostDesktopTypeForWebContents( |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 759 WebstorePrivateGetEphemeralAppsEnabledFunction:: | 861 WebstorePrivateGetEphemeralAppsEnabledFunction:: |
| 760 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {} | 862 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {} |
| 761 | 863 |
| 762 ExtensionFunction::ResponseAction | 864 ExtensionFunction::ResponseAction |
| 763 WebstorePrivateGetEphemeralAppsEnabledFunction::Run() { | 865 WebstorePrivateGetEphemeralAppsEnabledFunction::Run() { |
| 764 return RespondNow(ArgumentList(GetEphemeralAppsEnabled::Results::Create( | 866 return RespondNow(ArgumentList(GetEphemeralAppsEnabled::Results::Create( |
| 765 EphemeralAppLauncher::IsFeatureEnabled()))); | 867 EphemeralAppLauncher::IsFeatureEnabled()))); |
| 766 } | 868 } |
| 767 | 869 |
| 768 } // namespace extensions | 870 } // namespace extensions |
| OLD | NEW |