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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/webstore_private/webstore_private_api.cc
diff --git a/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc b/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc
index 902011de02e7cf846fd7a2b14de91bb887e666fc..bbe8169c1f6e7c664a4c4f002456902d5b608903 100644
--- a/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc
+++ b/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc
@@ -31,6 +31,7 @@
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_util.h"
#include "extensions/common/extension.h"
+#include "url/gurl.h"
namespace extensions {
@@ -43,6 +44,7 @@ namespace GetEphemeralAppsEnabled =
namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled;
namespace GetStoreLogin = api::webstore_private::GetStoreLogin;
namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus;
+namespace InstallBundle = api::webstore_private::InstallBundle;
namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode;
namespace LaunchEphemeralApp = api::webstore_private::LaunchEphemeralApp;
namespace SetStoreLogin = api::webstore_private::SetStoreLogin;
@@ -155,9 +157,12 @@ static base::LazyInstance<PendingApprovals> g_pending_approvals =
// A preference set by the web store to indicate login information for
// purchased apps.
const char kWebstoreLogin[] = "extensions.webstore_login";
+
+// Error messages that can be returned by the API.
const char kAlreadyInstalledError[] = "This item is already installed";
const char kCannotSpecifyIconDataAndUrlError[] =
"You cannot specify both icon data and an icon url";
+const char kInvalidBundleError[] = "Invalid bundle";
const char kInvalidIconUrlError[] = "Invalid icon url";
const char kInvalidIdError[] = "Invalid id";
const char kInvalidManifestError[] = "Invalid manifest";
@@ -165,7 +170,7 @@ const char kNoPreviousBeginInstallWithManifestError[] =
"* does not match a previous call to beginInstallWithManifest3";
const char kUserCancelledError[] = "User cancelled install";
-WebstoreInstaller::Delegate* test_webstore_installer_delegate = NULL;
+WebstoreInstaller::Delegate* test_webstore_installer_delegate = nullptr;
// We allow the web store to set a string containing login information when a
// purchase is made, so that when a user logs into sync with a different
@@ -269,7 +274,7 @@ WebstorePrivateFunctionWithPermissionPrompt<Params>::Run() {
if (response)
return RespondNow(response.Pass());
- net::URLRequestContextGetter* context_getter = NULL;
+ net::URLRequestContextGetter* context_getter = nullptr;
if (!icon_url.is_empty())
context_getter = browser_context()->GetRequestContext();
@@ -589,6 +594,132 @@ WebstorePrivateShowPermissionPromptForDelegatedInstallFunction::CreateResults(
return ShowPermissionPromptForDelegatedInstall::Results::Create(result);
}
+WebstorePrivateInstallBundleFunction::WebstorePrivateInstallBundleFunction()
+ : chrome_details_(this) {
+}
+
+WebstorePrivateInstallBundleFunction::~WebstorePrivateInstallBundleFunction() {
+}
+
+ExtensionFunction::ResponseAction WebstorePrivateInstallBundleFunction::Run() {
+ params_ = InstallBundle::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params_);
+
+ if (!crx_file::id_util::IdIsValid(params_->details.id))
+ return RespondNow(Error(kInvalidIdError));
+
+ if (params_->details.icon_data && params_->details.icon_url)
+ 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
+
+ GURL icon_url;
+ if (params_->details.icon_url) {
+ icon_url = source_url().Resolve(*params_->details.icon_url);
+ if (!icon_url.is_valid())
+ return RespondNow(Error(kInvalidIconUrlError));
+ }
+
+ if (params_->contents.empty())
+ return RespondNow(Error(kInvalidBundleError));
+
+ std::string icon_data = params_->details.icon_data ?
+ *params_->details.icon_data : std::string();
+
+ net::URLRequestContextGetter* context_getter = nullptr;
+ if (!icon_url.is_empty())
+ context_getter = browser_context()->GetRequestContext();
+
+ scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper(
+ this, params_->details.id, std::string(), icon_data, icon_url,
+ context_getter);
+
+ // The helper will call us back via OnWebstoreParseSuccess or
+ // OnWebstoreParseFailure.
+ helper->Start();
+
+ // Matched with a Release in OnWebstoreParseSuccess, OnWebstoreParseFailure,
+ // OnInstallApproval, or OnInstallComplete.
+ AddRef();
+
+ // The response is sent asynchronously in OnWebstoreParseSuccess,
+ // OnWebstoreParseFailure, OnInstallApproval, or OnInstallComplete.
+ return RespondLater();
+}
+
+void WebstorePrivateInstallBundleFunction::OnWebstoreParseSuccess(
+ const std::string& id,
+ const SkBitmap& icon,
+ base::DictionaryValue* parsed_manifest) {
+ InstallTracker* tracker = InstallTracker::Get(browser_context());
+ DCHECK(tracker);
+
+ std::string authuser;
+ if (params_->details.authuser)
+ authuser = *params_->details.authuser;
+
+ BundleInstaller::ItemList items;
+ for (const auto& entry : params_->contents) {
+ // Skip already-installed items.
+ if (util::IsExtensionInstalledPermanently(entry->id, browser_context()) ||
+ tracker->GetActiveInstall(entry->id)) {
+ continue;
+ }
+ BundleInstaller::Item item;
+ item.id = entry->id;
+ item.manifest = entry->manifest;
+ item.localized_name = entry->localized_name;
+ if (entry->icon_url)
+ item.icon_url = source_url().Resolve(*entry->icon_url);
+ if (entry->icon_data)
+ item.icon_data = *entry->icon_data;
+ items.push_back(item);
+ }
+ if (items.empty()) {
+ Respond(Error(kAlreadyInstalledError));
+ Release();
+ return;
+ }
+ bundle_.reset(new BundleInstaller(chrome_details_.GetCurrentBrowser(),
+ params_->details.localized_name,
+ icon,
+ authuser,
+ items));
+
+ // The bundle installer will call us back via OnInstallApproval.
+ bundle_->PromptForApproval(
+ base::Bind(&WebstorePrivateInstallBundleFunction::OnInstallApproval,
+ base::Unretained(this)));
+}
+
+void WebstorePrivateInstallBundleFunction::OnWebstoreParseFailure(
+ const std::string& id,
+ WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code,
+ const std::string& error_message) {
+ Respond(Error(error_message));
+ Release();
+}
+
+void WebstorePrivateInstallBundleFunction::OnInstallApproval(
+ BundleInstaller::ApprovalState state) {
+ if (state != BundleInstaller::APPROVED) {
+ Respond(Error(state == BundleInstaller::USER_CANCELED
+ ? kUserCancelledError
+ : kInvalidBundleError));
+ Release();
+ return;
+ }
+
+ // The bundle installer will call us back via OnInstallComplete.
+ bundle_->CompleteInstall(
+ chrome_details_.GetAssociatedWebContents(),
+ base::Bind(&WebstorePrivateInstallBundleFunction::OnInstallComplete,
+ base::Unretained(this)));
+}
+
+void WebstorePrivateInstallBundleFunction::OnInstallComplete() {
+ Respond(NoArguments());
+ Release();
+}
+
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
WebstorePrivateEnableAppLauncherFunction::
WebstorePrivateEnableAppLauncherFunction() : chrome_details_(this) {}

Powered by Google App Engine
This is Rietveld 408576698