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

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 kInvalidIdError[] = "Invalid id";
+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) {
@@ -97,19 +104,56 @@
}
// 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));
+ if (!Extension::IdIsValid(id)) {
+ error_ = kInvalidIdError;
+ return false;
+ }
+
+ if (!user_gesture() && !ignore_user_gesture_for_tests) {
+ error_ = kUserGestureRequiredError;
+ return false;
+ }
+
+ // This gets cleared in CrxInstaller::ConfirmInstall(). TODO(asargent) - in
+ // the future we may also want to add time-based expiration, where a whitelist
+ // entry is only valid for some number of minutes.
+ CrxInstaller::SetWhitelistedInstallId(id);
+ 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;
std::string id;
EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id));
- EXTENSION_FUNCTION_VALIDATE(Extension::IdIsValid(id));
+ if (!Extension::IdIsValid(id)) {
+ error_ = kInvalidIdError;
+ return false;
+ }
+ 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 +164,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
« no previous file with comments | « chrome/browser/extensions/extension_webstore_private_api.h ('k') | chrome/common/extensions/api/extension_api.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698