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

Unified Diff: chrome/browser/extensions/extension_webstore_private_api.cc

Issue 4727001: Split the private webstore install API into two parts.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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/extension_webstore_private_api.cc
===================================================================
--- chrome/browser/extensions/extension_webstore_private_api.cc (revision 65457)
+++ chrome/browser/extensions/extension_webstore_private_api.cc (working copy)
@@ -19,6 +19,7 @@
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/extensions/extension_constants.h"
+#include "chrome/common/extensions/extension_error_utils.h"
#include "chrome/common/net/gaia/gaia_constants.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/notification_type.h"
@@ -31,9 +32,15 @@
const char* install_base_url = extension_urls::kGalleryUpdateHttpsUrl;
const char kLoginKey[] = "login";
const char kTokenKey[] = "token";
+const char kDeprecatedError[] = "This function is deprecated";
+const char kNoPreviousBeginInstallError[] =
+ "* does not match a previous call to beginInstall";
+const char kUserGestureRequiredError[] =
+ "This function must be called during a user gesture";
ProfileSyncService* test_sync_service = NULL;
BrowserSignin* test_signin = NULL;
+bool ignore_user_gesture_for_tests = false;
// Returns either the test sync service, or the real one from |profile|.
ProfileSyncService* GetSyncService(Profile* profile) {
@@ -96,13 +103,40 @@
test_signin = signin;
}
+bool InstallFunction::RunImpl() {
+ error_ = kDeprecatedError;
+ return false;
+}
+
// static
-void InstallFunction::SetTestingInstallBaseUrl(
+void BeginInstallFunction::SetIgnoreUserGestureForTests(bool ignore) {
+ ignore_user_gesture_for_tests = ignore;
+}
+
+bool BeginInstallFunction::RunImpl() {
+ if (!IsWebStoreURL(profile_, source_url()))
+ return false;
+
+ std::string id;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id));
+ EXTENSION_FUNCTION_VALIDATE(Extension::IdIsValid(id));
Erik does not do reviews 2010/11/09 16:32:21 this shouldn't be EXTENSION_FUNCTION_VALIDATE sinc
asargent_no_longer_on_chrome 2010/11/10 00:23:48 Done.
+
+ if (!user_gesture() && !ignore_user_gesture_for_tests) {
+ error_ = kUserGestureRequiredError;
+ return false;
+ }
+
+ CrxInstaller::SetWhitelistedInstallId(id);
Erik does not do reviews 2010/11/09 16:32:21 add comment saying where this gets cleared, maybe
asargent_no_longer_on_chrome 2010/11/10 00:23:48 Done.
+ return true;
+}
+
+// static
+void CompleteInstallFunction::SetTestingInstallBaseUrl(
const char* testing_install_base_url) {
install_base_url = testing_install_base_url;
}
-bool InstallFunction::RunImpl() {
+bool CompleteInstallFunction::RunImpl() {
if (!IsWebStoreURL(profile_, source_url()))
return false;
@@ -110,6 +144,12 @@
EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id));
EXTENSION_FUNCTION_VALIDATE(Extension::IdIsValid(id));
Erik does not do reviews 2010/11/09 16:32:21 same here
asargent_no_longer_on_chrome 2010/11/10 00:23:48 Done.
+ if (!CrxInstaller::IsIdWhitelisted(id)) {
+ error_ = ExtensionErrorUtils::FormatErrorMessage(
+ kNoPreviousBeginInstallError, id);
+ return false;
+ }
+
std::vector<std::string> params;
params.push_back("id=" + id);
params.push_back("lang=" + g_browser_process->GetApplicationLocale());
@@ -120,9 +160,6 @@
EscapeQueryParamValue(JoinString(params, '&'), true));
DCHECK(url.is_valid());
- // Cleared in ~CrxInstaller().
- CrxInstaller::SetWhitelistedInstallId(id);
-
// The download url for the given |id| is now contained in |url|. We
// navigate the current (calling) tab to this url which will result in a
// download starting. Once completed it will go through the normal extension

Powered by Google App Engine
This is Rietveld 408576698