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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/extension_webstore_private_api.h" 5 #include "chrome/browser/extensions/extension_webstore_private_api.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/extensions/crx_installer.h" 14 #include "chrome/browser/extensions/crx_installer.h"
15 #include "chrome/browser/extensions/extension_prefs.h" 15 #include "chrome/browser/extensions/extension_prefs.h"
16 #include "chrome/browser/extensions/extensions_service.h" 16 #include "chrome/browser/extensions/extensions_service.h"
17 #include "chrome/browser/net/gaia/token_service.h" 17 #include "chrome/browser/net/gaia/token_service.h"
18 #include "chrome/browser/profile_manager.h" 18 #include "chrome/browser/profile_manager.h"
19 #include "chrome/browser/sync/profile_sync_service.h" 19 #include "chrome/browser/sync/profile_sync_service.h"
20 #include "chrome/browser/tab_contents/tab_contents.h" 20 #include "chrome/browser/tab_contents/tab_contents.h"
21 #include "chrome/common/extensions/extension_constants.h" 21 #include "chrome/common/extensions/extension_constants.h"
22 #include "chrome/common/extensions/extension_error_utils.h"
22 #include "chrome/common/net/gaia/gaia_constants.h" 23 #include "chrome/common/net/gaia/gaia_constants.h"
23 #include "chrome/common/notification_service.h" 24 #include "chrome/common/notification_service.h"
24 #include "chrome/common/notification_type.h" 25 #include "chrome/common/notification_type.h"
25 #include "grit/chromium_strings.h" 26 #include "grit/chromium_strings.h"
26 #include "grit/generated_resources.h" 27 #include "grit/generated_resources.h"
27 #include "net/base/escape.h" 28 #include "net/base/escape.h"
28 29
29 namespace { 30 namespace {
30 31
31 const char* install_base_url = extension_urls::kGalleryUpdateHttpsUrl; 32 const char* install_base_url = extension_urls::kGalleryUpdateHttpsUrl;
32 const char kLoginKey[] = "login"; 33 const char kLoginKey[] = "login";
33 const char kTokenKey[] = "token"; 34 const char kTokenKey[] = "token";
35 const char kInvalidIdError[] = "Invalid id";
36 const char kNoPreviousBeginInstallError[] =
37 "* does not match a previous call to beginInstall";
38 const char kUserGestureRequiredError[] =
39 "This function must be called during a user gesture";
34 40
35 ProfileSyncService* test_sync_service = NULL; 41 ProfileSyncService* test_sync_service = NULL;
36 BrowserSignin* test_signin = NULL; 42 BrowserSignin* test_signin = NULL;
43 bool ignore_user_gesture_for_tests = false;
37 44
38 // Returns either the test sync service, or the real one from |profile|. 45 // Returns either the test sync service, or the real one from |profile|.
39 ProfileSyncService* GetSyncService(Profile* profile) { 46 ProfileSyncService* GetSyncService(Profile* profile) {
40 if (test_sync_service) 47 if (test_sync_service)
41 return test_sync_service; 48 return test_sync_service;
42 else 49 else
43 return profile->GetProfileSyncService(); 50 return profile->GetProfileSyncService();
44 } 51 }
45 52
46 BrowserSignin* GetBrowserSignin(Profile* profile) { 53 BrowserSignin* GetBrowserSignin(Profile* profile) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 ProfileSyncService* service) { 97 ProfileSyncService* service) {
91 test_sync_service = service; 98 test_sync_service = service;
92 } 99 }
93 100
94 // static 101 // static
95 void WebstorePrivateApi::SetTestingBrowserSignin(BrowserSignin* signin) { 102 void WebstorePrivateApi::SetTestingBrowserSignin(BrowserSignin* signin) {
96 test_signin = signin; 103 test_signin = signin;
97 } 104 }
98 105
99 // static 106 // static
100 void InstallFunction::SetTestingInstallBaseUrl( 107 void BeginInstallFunction::SetIgnoreUserGestureForTests(bool ignore) {
101 const char* testing_install_base_url) { 108 ignore_user_gesture_for_tests = ignore;
102 install_base_url = testing_install_base_url;
103 } 109 }
104 110
105 bool InstallFunction::RunImpl() { 111 bool BeginInstallFunction::RunImpl() {
106 if (!IsWebStoreURL(profile_, source_url())) 112 if (!IsWebStoreURL(profile_, source_url()))
107 return false; 113 return false;
108 114
109 std::string id; 115 std::string id;
110 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id)); 116 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id));
111 EXTENSION_FUNCTION_VALIDATE(Extension::IdIsValid(id)); 117 if (!Extension::IdIsValid(id)) {
118 error_ = kInvalidIdError;
119 return false;
120 }
121
122 if (!user_gesture() && !ignore_user_gesture_for_tests) {
123 error_ = kUserGestureRequiredError;
124 return false;
125 }
126
127 // This gets cleared in CrxInstaller::ConfirmInstall(). TODO(asargent) - in
128 // the future we may also want to add time-based expiration, where a whitelist
129 // entry is only valid for some number of minutes.
130 CrxInstaller::SetWhitelistedInstallId(id);
131 return true;
132 }
133
134 // static
135 void CompleteInstallFunction::SetTestingInstallBaseUrl(
136 const char* testing_install_base_url) {
137 install_base_url = testing_install_base_url;
138 }
139
140 bool CompleteInstallFunction::RunImpl() {
141 if (!IsWebStoreURL(profile_, source_url()))
142 return false;
143
144 std::string id;
145 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id));
146 if (!Extension::IdIsValid(id)) {
147 error_ = kInvalidIdError;
148 return false;
149 }
150
151 if (!CrxInstaller::IsIdWhitelisted(id)) {
152 error_ = ExtensionErrorUtils::FormatErrorMessage(
153 kNoPreviousBeginInstallError, id);
154 return false;
155 }
112 156
113 std::vector<std::string> params; 157 std::vector<std::string> params;
114 params.push_back("id=" + id); 158 params.push_back("id=" + id);
115 params.push_back("lang=" + g_browser_process->GetApplicationLocale()); 159 params.push_back("lang=" + g_browser_process->GetApplicationLocale());
116 params.push_back("uc"); 160 params.push_back("uc");
117 std::string url_string = install_base_url; 161 std::string url_string = install_base_url;
118 162
119 GURL url(url_string + "?response=redirect&x=" + 163 GURL url(url_string + "?response=redirect&x=" +
120 EscapeQueryParamValue(JoinString(params, '&'), true)); 164 EscapeQueryParamValue(JoinString(params, '&'), true));
121 DCHECK(url.is_valid()); 165 DCHECK(url.is_valid());
122 166
123 // Cleared in ~CrxInstaller().
124 CrxInstaller::SetWhitelistedInstallId(id);
125
126 // The download url for the given |id| is now contained in |url|. We 167 // The download url for the given |id| is now contained in |url|. We
127 // navigate the current (calling) tab to this url which will result in a 168 // navigate the current (calling) tab to this url which will result in a
128 // download starting. Once completed it will go through the normal extension 169 // download starting. Once completed it will go through the normal extension
129 // install flow. The above call to SetWhitelistedInstallId will bypass the 170 // install flow. The above call to SetWhitelistedInstallId will bypass the
130 // normal permissions install dialog. 171 // normal permissions install dialog.
131 NavigationController& controller = 172 NavigationController& controller =
132 dispatcher()->delegate()->associated_tab_contents()->controller(); 173 dispatcher()->delegate()->associated_tab_contents()->controller();
133 controller.LoadURL(url, source_url(), PageTransition::LINK); 174 controller.LoadURL(url, source_url(), PageTransition::LINK);
134 175
135 return true; 176 return true;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 } 316 }
276 317
277 DCHECK(waiting_for_token_); 318 DCHECK(waiting_for_token_);
278 319
279 result_.reset(CreateLoginResult(GetDefaultProfile(profile_))); 320 result_.reset(CreateLoginResult(GetDefaultProfile(profile_)));
280 SendResponse(true); 321 SendResponse(true);
281 322
282 // Matches the AddRef in RunImpl(). 323 // Matches the AddRef in RunImpl().
283 Release(); 324 Release();
284 } 325 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698