Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Side by Side Diff: chrome/browser/extensions/api/webstore_private/webstore_private_api.cc

Issue 855513002: Add/resurrect support for bundles of WebStore items. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@testext_bundle
Patch Set: cleanup;rebase Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/browser/ui/app_list/app_list_util.h" 24 #include "chrome/browser/ui/app_list/app_list_util.h"
25 #include "chrome/common/extensions/extension_constants.h" 25 #include "chrome/common/extensions/extension_constants.h"
26 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
27 #include "components/crx_file/id_util.h" 27 #include "components/crx_file/id_util.h"
28 #include "components/signin/core/browser/signin_manager.h" 28 #include "components/signin/core/browser/signin_manager.h"
29 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
30 #include "extensions/browser/extension_registry.h" 30 #include "extensions/browser/extension_registry.h"
31 #include "extensions/browser/extension_system.h" 31 #include "extensions/browser/extension_system.h"
32 #include "extensions/browser/extension_util.h" 32 #include "extensions/browser/extension_util.h"
33 #include "extensions/common/extension.h" 33 #include "extensions/common/extension.h"
34 #include "url/gurl.h"
34 35
35 namespace extensions { 36 namespace extensions {
36 37
37 namespace BeginInstallWithManifest3 = 38 namespace BeginInstallWithManifest3 =
38 api::webstore_private::BeginInstallWithManifest3; 39 api::webstore_private::BeginInstallWithManifest3;
39 namespace CompleteInstall = api::webstore_private::CompleteInstall; 40 namespace CompleteInstall = api::webstore_private::CompleteInstall;
40 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin; 41 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin;
41 namespace GetEphemeralAppsEnabled = 42 namespace GetEphemeralAppsEnabled =
42 api::webstore_private::GetEphemeralAppsEnabled; 43 api::webstore_private::GetEphemeralAppsEnabled;
43 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; 44 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled;
44 namespace GetStoreLogin = api::webstore_private::GetStoreLogin; 45 namespace GetStoreLogin = api::webstore_private::GetStoreLogin;
45 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; 46 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus;
47 namespace InstallBundle = api::webstore_private::InstallBundle;
46 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; 48 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode;
47 namespace LaunchEphemeralApp = api::webstore_private::LaunchEphemeralApp; 49 namespace LaunchEphemeralApp = api::webstore_private::LaunchEphemeralApp;
48 namespace SetStoreLogin = api::webstore_private::SetStoreLogin; 50 namespace SetStoreLogin = api::webstore_private::SetStoreLogin;
49 namespace ShowPermissionPromptForDelegatedInstall = 51 namespace ShowPermissionPromptForDelegatedInstall =
50 api::webstore_private::ShowPermissionPromptForDelegatedInstall; 52 api::webstore_private::ShowPermissionPromptForDelegatedInstall;
51 53
52 namespace { 54 namespace {
53 55
54 // Holds the Approvals between the time we prompt and start the installs. 56 // Holds the Approvals between the time we prompt and start the installs.
55 class PendingApprovals { 57 class PendingApprovals {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 NOTREACHED(); 150 NOTREACHED();
149 return api::webstore_private::RESULT_NONE; 151 return api::webstore_private::RESULT_NONE;
150 } 152 }
151 153
152 static base::LazyInstance<PendingApprovals> g_pending_approvals = 154 static base::LazyInstance<PendingApprovals> g_pending_approvals =
153 LAZY_INSTANCE_INITIALIZER; 155 LAZY_INSTANCE_INITIALIZER;
154 156
155 // A preference set by the web store to indicate login information for 157 // A preference set by the web store to indicate login information for
156 // purchased apps. 158 // purchased apps.
157 const char kWebstoreLogin[] = "extensions.webstore_login"; 159 const char kWebstoreLogin[] = "extensions.webstore_login";
160
161 // Error messages that can be returned by the API.
158 const char kAlreadyInstalledError[] = "This item is already installed"; 162 const char kAlreadyInstalledError[] = "This item is already installed";
159 const char kCannotSpecifyIconDataAndUrlError[] = 163 const char kCannotSpecifyIconDataAndUrlError[] =
160 "You cannot specify both icon data and an icon url"; 164 "You cannot specify both icon data and an icon url";
165 const char kInvalidBundleError[] = "Invalid bundle";
161 const char kInvalidIconUrlError[] = "Invalid icon url"; 166 const char kInvalidIconUrlError[] = "Invalid icon url";
162 const char kInvalidIdError[] = "Invalid id"; 167 const char kInvalidIdError[] = "Invalid id";
163 const char kInvalidManifestError[] = "Invalid manifest"; 168 const char kInvalidManifestError[] = "Invalid manifest";
164 const char kNoPreviousBeginInstallWithManifestError[] = 169 const char kNoPreviousBeginInstallWithManifestError[] =
165 "* does not match a previous call to beginInstallWithManifest3"; 170 "* does not match a previous call to beginInstallWithManifest3";
166 const char kUserCancelledError[] = "User cancelled install"; 171 const char kUserCancelledError[] = "User cancelled install";
167 172
168 WebstoreInstaller::Delegate* test_webstore_installer_delegate = NULL; 173 WebstoreInstaller::Delegate* test_webstore_installer_delegate = nullptr;
169 174
170 // We allow the web store to set a string containing login information when a 175 // 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 176 // 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 177 // 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 178 // there was previously stored data, or an empty string otherwise. The Set will
174 // overwrite any previous login. 179 // overwrite any previous login.
175 std::string GetWebstoreLogin(Profile* profile) { 180 std::string GetWebstoreLogin(Profile* profile) {
176 if (profile->GetPrefs()->HasPrefPath(kWebstoreLogin)) 181 if (profile->GetPrefs()->HasPrefPath(kWebstoreLogin))
177 return profile->GetPrefs()->GetString(kWebstoreLogin); 182 return profile->GetPrefs()->GetString(kWebstoreLogin);
178 return std::string(); 183 return std::string();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } 267 }
263 } 268 }
264 269
265 std::string icon_data = params_->details.icon_data ? 270 std::string icon_data = params_->details.icon_data ?
266 *params_->details.icon_data : std::string(); 271 *params_->details.icon_data : std::string();
267 272
268 ExtensionFunction::ResponseValue response = RunExtraForResponse(); 273 ExtensionFunction::ResponseValue response = RunExtraForResponse();
269 if (response) 274 if (response)
270 return RespondNow(response.Pass()); 275 return RespondNow(response.Pass());
271 276
272 net::URLRequestContextGetter* context_getter = NULL; 277 net::URLRequestContextGetter* context_getter = nullptr;
273 if (!icon_url.is_empty()) 278 if (!icon_url.is_empty())
274 context_getter = browser_context()->GetRequestContext(); 279 context_getter = browser_context()->GetRequestContext();
275 280
276 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( 281 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper(
277 this, params_->details.id, params_->details.manifest, icon_data, icon_url, 282 this, params_->details.id, params_->details.manifest, icon_data, icon_url,
278 context_getter); 283 context_getter);
279 284
280 // The helper will call us back via OnWebstoreParseSuccess or 285 // The helper will call us back via OnWebstoreParseSuccess or
281 // OnWebstoreParseFailure. 286 // OnWebstoreParseFailure.
282 helper->Start(); 287 helper->Start();
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 install_prompt->ConfirmPermissionsForDelegatedInstall( 587 install_prompt->ConfirmPermissionsForDelegatedInstall(
583 this, dummy_extension().get(), params().details.delegated_user, &icon()); 588 this, dummy_extension().get(), params().details.delegated_user, &icon());
584 } 589 }
585 590
586 scoped_ptr<base::ListValue> 591 scoped_ptr<base::ListValue>
587 WebstorePrivateShowPermissionPromptForDelegatedInstallFunction::CreateResults( 592 WebstorePrivateShowPermissionPromptForDelegatedInstallFunction::CreateResults(
588 api::webstore_private::Result result) const { 593 api::webstore_private::Result result) const {
589 return ShowPermissionPromptForDelegatedInstall::Results::Create(result); 594 return ShowPermissionPromptForDelegatedInstall::Results::Create(result);
590 } 595 }
591 596
597 WebstorePrivateInstallBundleFunction::WebstorePrivateInstallBundleFunction()
598 : chrome_details_(this) {
599 }
600
601 WebstorePrivateInstallBundleFunction::~WebstorePrivateInstallBundleFunction() {
602 }
603
604 ExtensionFunction::ResponseAction WebstorePrivateInstallBundleFunction::Run() {
605 params_ = InstallBundle::Params::Create(*args_);
606 EXTENSION_FUNCTION_VALIDATE(params_);
607
608 if (!crx_file::id_util::IdIsValid(params_->details.id))
609 return RespondNow(Error(kInvalidIdError));
610
611 if (params_->details.icon_data && params_->details.icon_url)
612 return RespondNow(Error(kCannotSpecifyIconDataAndUrlError));
asargent_no_longer_on_chrome 2015/03/16 17:48:22 FYI, we're phasing out the icon_data parameter fro
Marc Treib 2015/03/17 12:18:27 Thanks for the heads-up! If you'll be doing a clea
613
614 GURL icon_url;
615 if (params_->details.icon_url) {
616 icon_url = source_url().Resolve(*params_->details.icon_url);
617 if (!icon_url.is_valid())
618 return RespondNow(Error(kInvalidIconUrlError));
619 }
620
621 if (params_->contents.empty())
622 return RespondNow(Error(kInvalidBundleError));
623
624 std::string icon_data = params_->details.icon_data ?
625 *params_->details.icon_data : std::string();
626
627 net::URLRequestContextGetter* context_getter = nullptr;
628 if (!icon_url.is_empty())
629 context_getter = browser_context()->GetRequestContext();
630
631 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper(
632 this, params_->details.id, std::string(), icon_data, icon_url,
633 context_getter);
634
635 // The helper will call us back via OnWebstoreParseSuccess or
636 // OnWebstoreParseFailure.
637 helper->Start();
638
639 // Matched with a Release in OnWebstoreParseSuccess, OnWebstoreParseFailure,
640 // OnInstallApproval, or OnInstallComplete.
641 AddRef();
642
643 // The response is sent asynchronously in OnWebstoreParseSuccess,
644 // OnWebstoreParseFailure, OnInstallApproval, or OnInstallComplete.
645 return RespondLater();
646 }
647
648 void WebstorePrivateInstallBundleFunction::OnWebstoreParseSuccess(
649 const std::string& id,
650 const SkBitmap& icon,
651 base::DictionaryValue* parsed_manifest) {
652 InstallTracker* tracker = InstallTracker::Get(browser_context());
653 DCHECK(tracker);
654
655 std::string authuser;
656 if (params_->details.authuser)
657 authuser = *params_->details.authuser;
658
659 BundleInstaller::ItemList items;
660 for (const auto& entry : params_->contents) {
661 // Skip already-installed items.
662 if (util::IsExtensionInstalledPermanently(entry->id, browser_context()) ||
663 tracker->GetActiveInstall(entry->id)) {
664 continue;
665 }
666 BundleInstaller::Item item;
667 item.id = entry->id;
668 item.manifest = entry->manifest;
669 item.localized_name = entry->localized_name;
670 if (entry->icon_url)
671 item.icon_url = source_url().Resolve(*entry->icon_url);
672 if (entry->icon_data)
673 item.icon_data = *entry->icon_data;
674 items.push_back(item);
675 }
676 if (items.empty()) {
677 Respond(Error(kAlreadyInstalledError));
678 Release();
679 return;
680 }
681 bundle_.reset(new BundleInstaller(chrome_details_.GetCurrentBrowser(),
682 params_->details.localized_name,
683 icon,
684 authuser,
685 items));
686
687 // The bundle installer will call us back via OnInstallApproval.
688 bundle_->PromptForApproval(
689 base::Bind(&WebstorePrivateInstallBundleFunction::OnInstallApproval,
690 base::Unretained(this)));
691 }
692
693 void WebstorePrivateInstallBundleFunction::OnWebstoreParseFailure(
694 const std::string& id,
695 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code,
696 const std::string& error_message) {
697 Respond(Error(error_message));
698 Release();
699 }
700
701 void WebstorePrivateInstallBundleFunction::OnInstallApproval(
702 BundleInstaller::ApprovalState state) {
703 if (state != BundleInstaller::APPROVED) {
704 Respond(Error(state == BundleInstaller::USER_CANCELED
705 ? kUserCancelledError
706 : kInvalidBundleError));
707 Release();
708 return;
709 }
710
711 // The bundle installer will call us back via OnInstallComplete.
712 bundle_->CompleteInstall(
713 chrome_details_.GetAssociatedWebContents(),
714 base::Bind(&WebstorePrivateInstallBundleFunction::OnInstallComplete,
715 base::Unretained(this)));
716 }
717
718 void WebstorePrivateInstallBundleFunction::OnInstallComplete() {
719 Respond(NoArguments());
720 Release();
721 }
722
asargent_no_longer_on_chrome 2015/03/16 17:48:22 Quite a bit of the code here looks similar to what
Marc Treib 2015/03/17 12:18:26 I've looked at that, but the code is actually not
asargent_no_longer_on_chrome 2015/03/24 23:34:00 Sorry, I guess I was referring to the ::Run method
Marc Treib 2015/03/25 11:21:59 I just removed the bundle ID (since it wasn't used
592 WebstorePrivateEnableAppLauncherFunction:: 723 WebstorePrivateEnableAppLauncherFunction::
593 WebstorePrivateEnableAppLauncherFunction() : chrome_details_(this) {} 724 WebstorePrivateEnableAppLauncherFunction() : chrome_details_(this) {}
594 725
595 WebstorePrivateEnableAppLauncherFunction:: 726 WebstorePrivateEnableAppLauncherFunction::
596 ~WebstorePrivateEnableAppLauncherFunction() {} 727 ~WebstorePrivateEnableAppLauncherFunction() {}
597 728
598 ExtensionFunction::ResponseAction 729 ExtensionFunction::ResponseAction
599 WebstorePrivateEnableAppLauncherFunction::Run() { 730 WebstorePrivateEnableAppLauncherFunction::Run() {
600 AppListService* app_list_service = AppListService::Get( 731 AppListService* app_list_service = AppListService::Get(
601 GetHostDesktopTypeForWebContents( 732 GetHostDesktopTypeForWebContents(
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 WebstorePrivateGetEphemeralAppsEnabledFunction:: 893 WebstorePrivateGetEphemeralAppsEnabledFunction::
763 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {} 894 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {}
764 895
765 ExtensionFunction::ResponseAction 896 ExtensionFunction::ResponseAction
766 WebstorePrivateGetEphemeralAppsEnabledFunction::Run() { 897 WebstorePrivateGetEphemeralAppsEnabledFunction::Run() {
767 return RespondNow(ArgumentList(GetEphemeralAppsEnabled::Results::Create( 898 return RespondNow(ArgumentList(GetEphemeralAppsEnabled::Results::Create(
768 EphemeralAppLauncher::IsFeatureEnabled()))); 899 EphemeralAppLauncher::IsFeatureEnabled())));
769 } 900 }
770 901
771 } // namespace extensions 902 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698