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

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 kDeprecatedError[] = "This function is deprecated";
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 void WebstorePrivateApi::SetTestingProfileSyncService( 96 void WebstorePrivateApi::SetTestingProfileSyncService(
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
106 bool InstallFunction::RunImpl() {
107 error_ = kDeprecatedError;
108 return false;
109 }
110
99 // static 111 // static
100 void InstallFunction::SetTestingInstallBaseUrl( 112 void BeginInstallFunction::SetIgnoreUserGestureForTests(bool ignore) {
113 ignore_user_gesture_for_tests = ignore;
114 }
115
116 bool BeginInstallFunction::RunImpl() {
117 if (!IsWebStoreURL(profile_, source_url()))
118 return false;
119
120 std::string id;
121 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id));
122 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.
123
124 if (!user_gesture() && !ignore_user_gesture_for_tests) {
125 error_ = kUserGestureRequiredError;
126 return false;
127 }
128
129 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.
130 return true;
131 }
132
133 // static
134 void CompleteInstallFunction::SetTestingInstallBaseUrl(
101 const char* testing_install_base_url) { 135 const char* testing_install_base_url) {
102 install_base_url = testing_install_base_url; 136 install_base_url = testing_install_base_url;
103 } 137 }
104 138
105 bool InstallFunction::RunImpl() { 139 bool CompleteInstallFunction::RunImpl() {
106 if (!IsWebStoreURL(profile_, source_url())) 140 if (!IsWebStoreURL(profile_, source_url()))
107 return false; 141 return false;
108 142
109 std::string id; 143 std::string id;
110 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id)); 144 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id));
111 EXTENSION_FUNCTION_VALIDATE(Extension::IdIsValid(id)); 145 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.
112 146
147 if (!CrxInstaller::IsIdWhitelisted(id)) {
148 error_ = ExtensionErrorUtils::FormatErrorMessage(
149 kNoPreviousBeginInstallError, id);
150 return false;
151 }
152
113 std::vector<std::string> params; 153 std::vector<std::string> params;
114 params.push_back("id=" + id); 154 params.push_back("id=" + id);
115 params.push_back("lang=" + g_browser_process->GetApplicationLocale()); 155 params.push_back("lang=" + g_browser_process->GetApplicationLocale());
116 params.push_back("uc"); 156 params.push_back("uc");
117 std::string url_string = install_base_url; 157 std::string url_string = install_base_url;
118 158
119 GURL url(url_string + "?response=redirect&x=" + 159 GURL url(url_string + "?response=redirect&x=" +
120 EscapeQueryParamValue(JoinString(params, '&'), true)); 160 EscapeQueryParamValue(JoinString(params, '&'), true));
121 DCHECK(url.is_valid()); 161 DCHECK(url.is_valid());
122 162
123 // Cleared in ~CrxInstaller().
124 CrxInstaller::SetWhitelistedInstallId(id);
125
126 // The download url for the given |id| is now contained in |url|. We 163 // 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 164 // 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 165 // download starting. Once completed it will go through the normal extension
129 // install flow. The above call to SetWhitelistedInstallId will bypass the 166 // install flow. The above call to SetWhitelistedInstallId will bypass the
130 // normal permissions install dialog. 167 // normal permissions install dialog.
131 NavigationController& controller = 168 NavigationController& controller =
132 dispatcher()->delegate()->associated_tab_contents()->controller(); 169 dispatcher()->delegate()->associated_tab_contents()->controller();
133 controller.LoadURL(url, source_url(), PageTransition::LINK); 170 controller.LoadURL(url, source_url(), PageTransition::LINK);
134 171
135 return true; 172 return true;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 } 312 }
276 313
277 DCHECK(waiting_for_token_); 314 DCHECK(waiting_for_token_);
278 315
279 result_.reset(CreateLoginResult(GetDefaultProfile(profile_))); 316 result_.reset(CreateLoginResult(GetDefaultProfile(profile_)));
280 SendResponse(true); 317 SendResponse(true);
281 318
282 // Matches the AddRef in RunImpl(). 319 // Matches the AddRef in RunImpl().
283 Release(); 320 Release();
284 } 321 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698