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

Side by Side Diff: chrome/browser/extensions/api/webstore_private/webstore_private_api.cc

Issue 22815002: webstore_private API implementations now uses JSON compiler generated code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed review comments Created 7 years, 4 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/extensions/api/webstore_private/webstore_private_api.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/api/webstore_private/webstore_private_api.h" 5 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h"
6 6
7 #include "apps/app_launcher.h" 7 #include "apps/app_launcher.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 29 matching lines...) Expand all
40 #include "content/public/browser/web_contents.h" 40 #include "content/public/browser/web_contents.h"
41 #include "extensions/common/error_utils.h" 41 #include "extensions/common/error_utils.h"
42 #include "grit/chromium_strings.h" 42 #include "grit/chromium_strings.h"
43 #include "grit/generated_resources.h" 43 #include "grit/generated_resources.h"
44 #include "ui/base/l10n/l10n_util.h" 44 #include "ui/base/l10n/l10n_util.h"
45 45
46 using content::GpuDataManager; 46 using content::GpuDataManager;
47 47
48 namespace extensions { 48 namespace extensions {
49 49
50 namespace BeginInstallWithManifest3 =
51 api::webstore_private::BeginInstallWithManifest3;
52 namespace CompleteInstall = api::webstore_private::CompleteInstall;
53 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin;
54 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled;
55 namespace GetStoreLogin = api::webstore_private::GetStoreLogin;
56 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus;
57 namespace InstallBundle = api::webstore_private::InstallBundle;
58 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode;
59 namespace SetStoreLogin = api::webstore_private::SetStoreLogin;
60
50 namespace { 61 namespace {
51 62
52 // Holds the Approvals between the time we prompt and start the installs. 63 // Holds the Approvals between the time we prompt and start the installs.
53 class PendingApprovals { 64 class PendingApprovals {
54 public: 65 public:
55 PendingApprovals(); 66 PendingApprovals();
56 ~PendingApprovals(); 67 ~PendingApprovals();
57 68
58 void PushApproval(scoped_ptr<WebstoreInstaller::Approval> approval); 69 void PushApproval(scoped_ptr<WebstoreInstaller::Approval> approval);
59 scoped_ptr<WebstoreInstaller::Approval> PopApproval( 70 scoped_ptr<WebstoreInstaller::Approval> PopApproval(
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 return (installs_.begin() + i); 146 return (installs_.begin() + i);
136 } 147 }
137 return installs_.end(); 148 return installs_.end();
138 } 149 }
139 150
140 static base::LazyInstance<PendingApprovals> g_pending_approvals = 151 static base::LazyInstance<PendingApprovals> g_pending_approvals =
141 LAZY_INSTANCE_INITIALIZER; 152 LAZY_INSTANCE_INITIALIZER;
142 static base::LazyInstance<PendingInstalls> g_pending_installs = 153 static base::LazyInstance<PendingInstalls> g_pending_installs =
143 LAZY_INSTANCE_INITIALIZER; 154 LAZY_INSTANCE_INITIALIZER;
144 155
145 const char kAppInstallBubbleKey[] = "appInstallBubble";
146 const char kEnableLauncherKey[] = "enableLauncher";
147 const char kIconDataKey[] = "iconData";
148 const char kIconUrlKey[] = "iconUrl";
149 const char kIdKey[] = "id";
150 const char kLocalizedNameKey[] = "localizedName";
151 const char kLoginKey[] = "login";
152 const char kManifestKey[] = "manifest";
153
154 // A preference set by the web store to indicate login information for 156 // A preference set by the web store to indicate login information for
155 // purchased apps. 157 // purchased apps.
156 const char kWebstoreLogin[] = "extensions.webstore_login"; 158 const char kWebstoreLogin[] = "extensions.webstore_login";
157 const char kAlreadyInstalledError[] = "This item is already installed"; 159 const char kAlreadyInstalledError[] = "This item is already installed";
158 const char kCannotSpecifyIconDataAndUrlError[] = 160 const char kCannotSpecifyIconDataAndUrlError[] =
159 "You cannot specify both icon data and an icon url"; 161 "You cannot specify both icon data and an icon url";
160 const char kInvalidIconUrlError[] = "Invalid icon url"; 162 const char kInvalidIconUrlError[] = "Invalid icon url";
161 const char kInvalidIdError[] = "Invalid id"; 163 const char kInvalidIdError[] = "Invalid id";
162 const char kInvalidManifestError[] = "Invalid manifest"; 164 const char kInvalidManifestError[] = "Invalid manifest";
163 const char kNoPreviousBeginInstallWithManifestError[] = 165 const char kNoPreviousBeginInstallWithManifestError[] =
164 "* does not match a previous call to beginInstallWithManifest3"; 166 "* does not match a previous call to beginInstallWithManifest3";
165 const char kUserCancelledError[] = "User cancelled install"; 167 const char kUserCancelledError[] = "User cancelled install";
166 168
167 // Helper to create a dictionary with login properties set from the appropriate
168 // values in the passed-in |profile|.
169 base::DictionaryValue* CreateLoginResult(Profile* profile) {
170 base::DictionaryValue* dictionary = new base::DictionaryValue();
171 std::string username = profile->GetPrefs()->GetString(
172 prefs::kGoogleServicesUsername);
173 dictionary->SetString(kLoginKey, username);
174 return dictionary;
175 }
176
177 WebstoreInstaller::Delegate* test_webstore_installer_delegate = NULL; 169 WebstoreInstaller::Delegate* test_webstore_installer_delegate = NULL;
178 170
179 // We allow the web store to set a string containing login information when a 171 // We allow the web store to set a string containing login information when a
180 // purchase is made, so that when a user logs into sync with a different 172 // purchase is made, so that when a user logs into sync with a different
181 // account we can recognize the situation. The Get function returns the login if 173 // account we can recognize the situation. The Get function returns the login if
182 // there was previously stored data, or an empty string otherwise. The Set will 174 // there was previously stored data, or an empty string otherwise. The Set will
183 // overwrite any previous login. 175 // overwrite any previous login.
184 std::string GetWebstoreLogin(Profile* profile) { 176 std::string GetWebstoreLogin(Profile* profile) {
185 if (profile->GetPrefs()->HasPrefPath(kWebstoreLogin)) 177 if (profile->GetPrefs()->HasPrefPath(kWebstoreLogin))
186 return profile->GetPrefs()->GetString(kWebstoreLogin); 178 return profile->GetPrefs()->GetString(kWebstoreLogin);
(...skipping 16 matching lines...) Expand all
203 scoped_ptr<WebstoreInstaller::Approval> 195 scoped_ptr<WebstoreInstaller::Approval>
204 WebstorePrivateApi::PopApprovalForTesting( 196 WebstorePrivateApi::PopApprovalForTesting(
205 Profile* profile, const std::string& extension_id) { 197 Profile* profile, const std::string& extension_id) {
206 return g_pending_approvals.Get().PopApproval(profile, extension_id); 198 return g_pending_approvals.Get().PopApproval(profile, extension_id);
207 } 199 }
208 200
209 WebstorePrivateInstallBundleFunction::WebstorePrivateInstallBundleFunction() {} 201 WebstorePrivateInstallBundleFunction::WebstorePrivateInstallBundleFunction() {}
210 WebstorePrivateInstallBundleFunction::~WebstorePrivateInstallBundleFunction() {} 202 WebstorePrivateInstallBundleFunction::~WebstorePrivateInstallBundleFunction() {}
211 203
212 bool WebstorePrivateInstallBundleFunction::RunImpl() { 204 bool WebstorePrivateInstallBundleFunction::RunImpl() {
213 base::ListValue* extensions = NULL; 205 scoped_ptr<InstallBundle::Params> params(
214 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &extensions)); 206 InstallBundle::Params::Create(*args_));
207 EXTENSION_FUNCTION_VALIDATE(params);
215 208
216 BundleInstaller::ItemList items; 209 BundleInstaller::ItemList items;
217 if (!ReadBundleInfo(extensions, &items)) 210 if (!ReadBundleInfo(*params, &items))
218 return false; 211 return false;
219 212
220 bundle_ = new BundleInstaller(GetCurrentBrowser(), items); 213 bundle_ = new BundleInstaller(GetCurrentBrowser(), items);
221 214
222 AddRef(); // Balanced in OnBundleInstallCompleted / OnBundleInstallCanceled. 215 AddRef(); // Balanced in OnBundleInstallCompleted / OnBundleInstallCanceled.
223 216
224 bundle_->PromptForApproval(this); 217 bundle_->PromptForApproval(this);
225 return true; 218 return true;
226 } 219 }
227 220
228 bool WebstorePrivateInstallBundleFunction:: 221 bool WebstorePrivateInstallBundleFunction::
229 ReadBundleInfo(base::ListValue* extensions, 222 ReadBundleInfo(const InstallBundle::Params& params,
230 BundleInstaller::ItemList* items) { 223 BundleInstaller::ItemList* items) {
231 for (size_t i = 0; i < extensions->GetSize(); ++i) { 224 for (size_t i = 0; i < params.details.size(); ++i) {
232 base::DictionaryValue* details = NULL;
233 EXTENSION_FUNCTION_VALIDATE(extensions->GetDictionary(i, &details));
234
235 BundleInstaller::Item item; 225 BundleInstaller::Item item;
236 EXTENSION_FUNCTION_VALIDATE(details->GetString( 226 item.id = params.details[i]->id;
237 kIdKey, &item.id)); 227 item.manifest = params.details[i]->manifest;
238 EXTENSION_FUNCTION_VALIDATE(details->GetString( 228 item.localized_name = params.details[i]->localized_name;
239 kManifestKey, &item.manifest));
240 EXTENSION_FUNCTION_VALIDATE(details->GetString(
241 kLocalizedNameKey, &item.localized_name));
242
243 items->push_back(item); 229 items->push_back(item);
244 } 230 }
245 231
246 return true; 232 return true;
247 } 233 }
248 234
249 void WebstorePrivateInstallBundleFunction::OnBundleInstallApproved() { 235 void WebstorePrivateInstallBundleFunction::OnBundleInstallApproved() {
250 bundle_->CompleteInstall( 236 bundle_->CompleteInstall(
251 &(dispatcher()->delegate()->GetAssociatedWebContents()->GetController()), 237 &(dispatcher()->delegate()->GetAssociatedWebContents()->GetController()),
252 this); 238 this);
(...skipping 11 matching lines...) Expand all
264 Release(); // Balanced in RunImpl(). 250 Release(); // Balanced in RunImpl().
265 } 251 }
266 252
267 void WebstorePrivateInstallBundleFunction::OnBundleInstallCompleted() { 253 void WebstorePrivateInstallBundleFunction::OnBundleInstallCompleted() {
268 SendResponse(true); 254 SendResponse(true);
269 255
270 Release(); // Balanced in RunImpl(). 256 Release(); // Balanced in RunImpl().
271 } 257 }
272 258
273 WebstorePrivateBeginInstallWithManifest3Function:: 259 WebstorePrivateBeginInstallWithManifest3Function::
274 WebstorePrivateBeginInstallWithManifest3Function() 260 WebstorePrivateBeginInstallWithManifest3Function() {}
275 : use_app_installed_bubble_(false), enable_launcher_(false) {}
276 261
277 WebstorePrivateBeginInstallWithManifest3Function:: 262 WebstorePrivateBeginInstallWithManifest3Function::
278 ~WebstorePrivateBeginInstallWithManifest3Function() {} 263 ~WebstorePrivateBeginInstallWithManifest3Function() {}
279 264
280 bool WebstorePrivateBeginInstallWithManifest3Function::RunImpl() { 265 bool WebstorePrivateBeginInstallWithManifest3Function::RunImpl() {
281 base::DictionaryValue* details = NULL; 266 params_.reset(BeginInstallWithManifest3::Params::Create(*args_).release());
not at google - send to devlin 2013/08/14 14:58:13 better: params_ = BeginInstallWithManifest3::Para
pals 2013/08/16 08:17:24 Done.
282 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); 267 EXTENSION_FUNCTION_VALIDATE(params_);
283 CHECK(details);
284 268
285 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIdKey, &id_)); 269 if (!extensions::Extension::IdIsValid(params_->details.id)) {
286 if (!extensions::Extension::IdIsValid(id_)) {
287 SetResultCode(INVALID_ID); 270 SetResultCode(INVALID_ID);
288 error_ = kInvalidIdError; 271 error_ = kInvalidIdError;
289 return false; 272 return false;
290 } 273 }
291 274
292 EXTENSION_FUNCTION_VALIDATE(details->GetString(kManifestKey, &manifest_)); 275 if (params_->details.icon_data && params_->details.icon_url) {
293
294 if (details->HasKey(kIconDataKey) && details->HasKey(kIconUrlKey)) {
295 SetResultCode(ICON_ERROR); 276 SetResultCode(ICON_ERROR);
296 error_ = kCannotSpecifyIconDataAndUrlError; 277 error_ = kCannotSpecifyIconDataAndUrlError;
297 return false; 278 return false;
298 } 279 }
299 280
300 if (details->HasKey(kIconDataKey))
301 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIconDataKey, &icon_data_));
302
303 GURL icon_url; 281 GURL icon_url;
304 if (details->HasKey(kIconUrlKey)) { 282 if (params_->details.icon_url) {
305 std::string tmp_url; 283 std::string tmp_url;
306 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIconUrlKey, &tmp_url)); 284 icon_url = source_url().Resolve(*params_->details.icon_url);
307 icon_url = source_url().Resolve(tmp_url);
308 if (!icon_url.is_valid()) { 285 if (!icon_url.is_valid()) {
309 SetResultCode(INVALID_ICON_URL); 286 SetResultCode(INVALID_ICON_URL);
310 error_ = kInvalidIconUrlError; 287 error_ = kInvalidIconUrlError;
311 return false; 288 return false;
312 } 289 }
313 } 290 }
314 291
315 if (details->HasKey(kLocalizedNameKey))
316 EXTENSION_FUNCTION_VALIDATE(details->GetString(kLocalizedNameKey,
317 &localized_name_));
318
319 if (details->HasKey(kAppInstallBubbleKey))
320 EXTENSION_FUNCTION_VALIDATE(details->GetBoolean(
321 kAppInstallBubbleKey, &use_app_installed_bubble_));
322
323 if (details->HasKey(kEnableLauncherKey))
324 EXTENSION_FUNCTION_VALIDATE(details->GetBoolean(
325 kEnableLauncherKey, &enable_launcher_));
326
327 ExtensionService* service = 292 ExtensionService* service =
328 extensions::ExtensionSystem::Get(profile_)->extension_service(); 293 extensions::ExtensionSystem::Get(profile_)->extension_service();
329 if (service->GetInstalledExtension(id_) || 294 if (service->GetInstalledExtension(params_->details.id) ||
330 !g_pending_installs.Get().InsertInstall(profile_, id_)) { 295 !g_pending_installs.Get().InsertInstall(profile_, params_->details.id)) {
331 SetResultCode(ALREADY_INSTALLED); 296 SetResultCode(ALREADY_INSTALLED);
332 error_ = kAlreadyInstalledError; 297 error_ = kAlreadyInstalledError;
333 return false; 298 return false;
334 } 299 }
335 300
336 net::URLRequestContextGetter* context_getter = NULL; 301 net::URLRequestContextGetter* context_getter = NULL;
337 if (!icon_url.is_empty()) 302 if (!icon_url.is_empty())
338 context_getter = profile()->GetRequestContext(); 303 context_getter = profile()->GetRequestContext();
339 304
340 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( 305 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper(
341 this, id_, manifest_, icon_data_, icon_url, context_getter); 306 this, params_->details.id, params_->details.manifest,
307 *params_->details.icon_data, icon_url, context_getter);
not at google - send to devlin 2013/08/14 14:58:13 icon_data is optional and might be null here. I su
pals 2013/08/16 08:17:24 Done. Defaulted to std::string().
342 308
343 // The helper will call us back via OnWebstoreParseSuccess or 309 // The helper will call us back via OnWebstoreParseSuccess or
344 // OnWebstoreParseFailure. 310 // OnWebstoreParseFailure.
345 helper->Start(); 311 helper->Start();
346 312
347 // Matched with a Release in OnWebstoreParseSuccess/OnWebstoreParseFailure. 313 // Matched with a Release in OnWebstoreParseSuccess/OnWebstoreParseFailure.
348 AddRef(); 314 AddRef();
349 315
350 // The response is sent asynchronously in OnWebstoreParseSuccess/ 316 // The response is sent asynchronously in OnWebstoreParseSuccess/
351 // OnWebstoreParseFailure. 317 // OnWebstoreParseFailure.
352 return true; 318 return true;
353 } 319 }
354 320
321 const char* WebstorePrivateBeginInstallWithManifest3Function::
322 ResultCodeToString(ResultCode code) {
323 switch (code) {
324 case ERROR_NONE:
325 return "";
326 case UNKNOWN_ERROR:
327 return "unknown_error";
328 case USER_CANCELLED:
329 return "user_cancelled";
330 case MANIFEST_ERROR:
331 return "manifest_error";
332 case ICON_ERROR:
333 return "icon_error";
334 case INVALID_ID:
335 return "invalid_id";
336 case PERMISSION_DENIED:
337 return "permission_denied";
338 case INVALID_ICON_URL:
339 return "invalid_icon_url";
340 case SIGNIN_FAILED:
341 return "signin_failed";
342 case ALREADY_INSTALLED:
343 return "already_installed";
344 }
345 NOTREACHED();
346 return "";
347 }
355 348
356 void WebstorePrivateBeginInstallWithManifest3Function::SetResultCode( 349 void WebstorePrivateBeginInstallWithManifest3Function::SetResultCode(
357 ResultCode code) { 350 ResultCode code) {
358 switch (code) { 351 results_ = BeginInstallWithManifest3::Results::Create(
359 case ERROR_NONE: 352 ResultCodeToString(code));
360 SetResult(Value::CreateStringValue(std::string()));
361 break;
362 case UNKNOWN_ERROR:
363 SetResult(Value::CreateStringValue("unknown_error"));
364 break;
365 case USER_CANCELLED:
366 SetResult(Value::CreateStringValue("user_cancelled"));
367 break;
368 case MANIFEST_ERROR:
369 SetResult(Value::CreateStringValue("manifest_error"));
370 break;
371 case ICON_ERROR:
372 SetResult(Value::CreateStringValue("icon_error"));
373 break;
374 case INVALID_ID:
375 SetResult(Value::CreateStringValue("invalid_id"));
376 break;
377 case PERMISSION_DENIED:
378 SetResult(Value::CreateStringValue("permission_denied"));
379 break;
380 case INVALID_ICON_URL:
381 SetResult(Value::CreateStringValue("invalid_icon_url"));
382 break;
383 case SIGNIN_FAILED:
384 SetResult(Value::CreateStringValue("signin_failed"));
385 break;
386 case ALREADY_INSTALLED:
387 SetResult(Value::CreateStringValue("already_installed"));
388 break;
389 default:
390 CHECK(false);
391 }
392 } 353 }
393 354
394 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseSuccess( 355 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseSuccess(
395 const std::string& id, 356 const std::string& id,
396 const SkBitmap& icon, 357 const SkBitmap& icon,
397 base::DictionaryValue* parsed_manifest) { 358 base::DictionaryValue* parsed_manifest) {
398 CHECK_EQ(id_, id); 359 CHECK_EQ(params_->details.id, id);
399 CHECK(parsed_manifest); 360 CHECK(parsed_manifest);
400 icon_ = icon; 361 icon_ = icon;
401 parsed_manifest_.reset(parsed_manifest); 362 parsed_manifest_.reset(parsed_manifest);
402 363
403 std::string error; 364 std::string error;
404 dummy_extension_ = ExtensionInstallPrompt::GetLocalizedExtensionForDisplay( 365 dummy_extension_ = ExtensionInstallPrompt::GetLocalizedExtensionForDisplay(
405 parsed_manifest_.get(), 366 parsed_manifest_.get(),
406 Extension::FROM_WEBSTORE, 367 Extension::FROM_WEBSTORE,
407 id, 368 id,
408 localized_name_, 369 *params_->details.localized_name,
not at google - send to devlin 2013/08/14 14:58:13 this can also be null, needs to default to "".
pals 2013/08/16 08:17:24 Done.
409 std::string(), 370 std::string(),
410 &error); 371 &error);
411 372
412 if (!dummy_extension_.get()) { 373 if (!dummy_extension_.get()) {
413 OnWebstoreParseFailure(id_, 374 OnWebstoreParseFailure(params_->details.id,
414 WebstoreInstallHelper::Delegate::MANIFEST_ERROR, 375 WebstoreInstallHelper::Delegate::MANIFEST_ERROR,
415 kInvalidManifestError); 376 kInvalidManifestError);
416 return; 377 return;
417 } 378 }
418 379
419 SigninManagerBase* signin_manager = 380 SigninManagerBase* signin_manager =
420 SigninManagerFactory::GetForProfile(profile()); 381 SigninManagerFactory::GetForProfile(profile());
421 if (dummy_extension_->is_platform_app() && 382 if (dummy_extension_->is_platform_app() &&
422 signin_manager && 383 signin_manager &&
423 signin_manager->GetAuthenticatedUsername().empty() && 384 signin_manager->GetAuthenticatedUsername().empty() &&
424 signin_manager->AuthInProgress()) { 385 signin_manager->AuthInProgress()) {
425 signin_tracker_.reset(new SigninTracker(profile(), this)); 386 signin_tracker_.reset(new SigninTracker(profile(), this));
426 return; 387 return;
427 } 388 }
428 389
429 SigninCompletedOrNotNeeded(); 390 SigninCompletedOrNotNeeded();
430 } 391 }
431 392
432 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseFailure( 393 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseFailure(
433 const std::string& id, 394 const std::string& id,
434 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code, 395 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code,
435 const std::string& error_message) { 396 const std::string& error_message) {
436 CHECK_EQ(id_, id); 397 CHECK_EQ(params_->details.id, id);
437 398
438 // Map from WebstoreInstallHelper's result codes to ours. 399 // Map from WebstoreInstallHelper's result codes to ours.
439 switch (result_code) { 400 switch (result_code) {
440 case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR: 401 case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR:
441 SetResultCode(UNKNOWN_ERROR); 402 SetResultCode(UNKNOWN_ERROR);
442 break; 403 break;
443 case WebstoreInstallHelper::Delegate::ICON_ERROR: 404 case WebstoreInstallHelper::Delegate::ICON_ERROR:
444 SetResultCode(ICON_ERROR); 405 SetResultCode(ICON_ERROR);
445 break; 406 break;
446 case WebstoreInstallHelper::Delegate::MANIFEST_ERROR: 407 case WebstoreInstallHelper::Delegate::MANIFEST_ERROR:
447 SetResultCode(MANIFEST_ERROR); 408 SetResultCode(MANIFEST_ERROR);
448 break; 409 break;
449 default: 410 default:
450 CHECK(false); 411 CHECK(false);
451 } 412 }
452 error_ = error_message; 413 error_ = error_message;
453 g_pending_installs.Get().EraseInstall(profile_, id); 414 g_pending_installs.Get().EraseInstall(profile_, id);
454 SendResponse(false); 415 SendResponse(false);
455 416
456 // Matches the AddRef in RunImpl(). 417 // Matches the AddRef in RunImpl().
457 Release(); 418 Release();
458 } 419 }
459 420
460 void WebstorePrivateBeginInstallWithManifest3Function::SigninFailed( 421 void WebstorePrivateBeginInstallWithManifest3Function::SigninFailed(
461 const GoogleServiceAuthError& error) { 422 const GoogleServiceAuthError& error) {
462 signin_tracker_.reset(); 423 signin_tracker_.reset();
463 424
464 SetResultCode(SIGNIN_FAILED); 425 SetResultCode(SIGNIN_FAILED);
465 error_ = error.ToString(); 426 error_ = error.ToString();
466 g_pending_installs.Get().EraseInstall(profile_, id_); 427 g_pending_installs.Get().EraseInstall(profile_, params_->details.id);
467 SendResponse(false); 428 SendResponse(false);
468 429
469 // Matches the AddRef in RunImpl(). 430 // Matches the AddRef in RunImpl().
470 Release(); 431 Release();
471 } 432 }
472 433
473 void WebstorePrivateBeginInstallWithManifest3Function::SigninSuccess() { 434 void WebstorePrivateBeginInstallWithManifest3Function::SigninSuccess() {
474 signin_tracker_.reset(); 435 signin_tracker_.reset();
475 436
476 SigninCompletedOrNotNeeded(); 437 SigninCompletedOrNotNeeded();
(...skipping 12 matching lines...) Expand all
489 ExtensionInstallPrompt::GetDefaultShowDialogCallback()); 450 ExtensionInstallPrompt::GetDefaultShowDialogCallback());
490 // Control flow finishes up in InstallUIProceed or InstallUIAbort. 451 // Control flow finishes up in InstallUIProceed or InstallUIAbort.
491 } 452 }
492 453
493 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIProceed() { 454 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIProceed() {
494 // This gets cleared in CrxInstaller::ConfirmInstall(). TODO(asargent) - in 455 // This gets cleared in CrxInstaller::ConfirmInstall(). TODO(asargent) - in
495 // the future we may also want to add time-based expiration, where a whitelist 456 // the future we may also want to add time-based expiration, where a whitelist
496 // entry is only valid for some number of minutes. 457 // entry is only valid for some number of minutes.
497 scoped_ptr<WebstoreInstaller::Approval> approval( 458 scoped_ptr<WebstoreInstaller::Approval> approval(
498 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( 459 WebstoreInstaller::Approval::CreateWithNoInstallPrompt(
499 profile(), id_, parsed_manifest_.Pass())); 460 profile(), params_->details.id, parsed_manifest_.Pass()));
500 approval->use_app_installed_bubble = use_app_installed_bubble_; 461 approval->use_app_installed_bubble = params_->details.app_install_bubble;
501 approval->enable_launcher = enable_launcher_; 462 approval->enable_launcher = params_->details.enable_launcher;
502 // If we are enabling the launcher, we should not show the app list in order 463 // If we are enabling the launcher, we should not show the app list in order
503 // to train the user to open it themselves at least once. 464 // to train the user to open it themselves at least once.
504 approval->skip_post_install_ui = enable_launcher_; 465 approval->skip_post_install_ui = params_->details.enable_launcher;
505 approval->installing_icon = gfx::ImageSkia::CreateFrom1xBitmap(icon_); 466 approval->installing_icon = gfx::ImageSkia::CreateFrom1xBitmap(icon_);
506 g_pending_approvals.Get().PushApproval(approval.Pass()); 467 g_pending_approvals.Get().PushApproval(approval.Pass());
507 468
508 SetResultCode(ERROR_NONE); 469 SetResultCode(ERROR_NONE);
509 SendResponse(true); 470 SendResponse(true);
510 471
511 // The Permissions_Install histogram is recorded from the ExtensionService 472 // The Permissions_Install histogram is recorded from the ExtensionService
512 // for all extension installs, so we only need to record the web store 473 // for all extension installs, so we only need to record the web store
513 // specific histogram here. 474 // specific histogram here.
514 ExtensionService::RecordPermissionMessagesHistogram( 475 ExtensionService::RecordPermissionMessagesHistogram(
515 dummy_extension_.get(), "Extensions.Permissions_WebStoreInstall"); 476 dummy_extension_.get(), "Extensions.Permissions_WebStoreInstall");
516 477
517 // Matches the AddRef in RunImpl(). 478 // Matches the AddRef in RunImpl().
518 Release(); 479 Release();
519 } 480 }
520 481
521 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIAbort( 482 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIAbort(
522 bool user_initiated) { 483 bool user_initiated) {
523 error_ = kUserCancelledError; 484 error_ = kUserCancelledError;
524 SetResultCode(USER_CANCELLED); 485 SetResultCode(USER_CANCELLED);
525 g_pending_installs.Get().EraseInstall(profile_, id_); 486 g_pending_installs.Get().EraseInstall(profile_, params_->details.id);
526 SendResponse(false); 487 SendResponse(false);
527 488
528 // The web store install histograms are a subset of the install histograms. 489 // The web store install histograms are a subset of the install histograms.
529 // We need to record both histograms here since CrxInstaller::InstallUIAbort 490 // We need to record both histograms here since CrxInstaller::InstallUIAbort
530 // is never called for web store install cancellations. 491 // is never called for web store install cancellations.
531 std::string histogram_name = user_initiated ? 492 std::string histogram_name = user_initiated ?
532 "Extensions.Permissions_WebStoreInstallCancel" : 493 "Extensions.Permissions_WebStoreInstallCancel" :
533 "Extensions.Permissions_WebStoreInstallAbort"; 494 "Extensions.Permissions_WebStoreInstallAbort";
534 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(), 495 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(),
535 histogram_name.c_str()); 496 histogram_name.c_str());
536 497
537 histogram_name = user_initiated ? 498 histogram_name = user_initiated ?
538 "Extensions.Permissions_InstallCancel" : 499 "Extensions.Permissions_InstallCancel" :
539 "Extensions.Permissions_InstallAbort"; 500 "Extensions.Permissions_InstallAbort";
540 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(), 501 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(),
541 histogram_name.c_str()); 502 histogram_name.c_str());
542 503
543 // Matches the AddRef in RunImpl(). 504 // Matches the AddRef in RunImpl().
544 Release(); 505 Release();
545 } 506 }
546 507
547 WebstorePrivateCompleteInstallFunction:: 508 WebstorePrivateCompleteInstallFunction::
548 WebstorePrivateCompleteInstallFunction() {} 509 WebstorePrivateCompleteInstallFunction() {}
549 510
550 WebstorePrivateCompleteInstallFunction:: 511 WebstorePrivateCompleteInstallFunction::
551 ~WebstorePrivateCompleteInstallFunction() {} 512 ~WebstorePrivateCompleteInstallFunction() {}
552 513
553 bool WebstorePrivateCompleteInstallFunction::RunImpl() { 514 bool WebstorePrivateCompleteInstallFunction::RunImpl() {
554 std::string id; 515 scoped_ptr<CompleteInstall::Params> params(
555 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id)); 516 CompleteInstall::Params::Create(*args_));
556 if (!extensions::Extension::IdIsValid(id)) { 517 EXTENSION_FUNCTION_VALIDATE(params);
518 if (!extensions::Extension::IdIsValid(params->expected_id)) {
557 error_ = kInvalidIdError; 519 error_ = kInvalidIdError;
558 return false; 520 return false;
559 } 521 }
560 522
561 approval_ = g_pending_approvals.Get().PopApproval(profile(), id).Pass(); 523 approval_ = g_pending_approvals.Get().PopApproval(profile(),
524 params->expected_id).Pass();
562 if (!approval_) { 525 if (!approval_) {
563 error_ = ErrorUtils::FormatErrorMessage( 526 error_ = ErrorUtils::FormatErrorMessage(
564 kNoPreviousBeginInstallWithManifestError, id); 527 kNoPreviousBeginInstallWithManifestError, params->expected_id);
565 return false; 528 return false;
566 } 529 }
567 530
568 // Balanced in OnExtensionInstallSuccess() or OnExtensionInstallFailure(). 531 // Balanced in OnExtensionInstallSuccess() or OnExtensionInstallFailure().
569 AddRef(); 532 AddRef();
570 533
571 if (approval_->enable_launcher) 534 if (approval_->enable_launcher)
572 AppListService::Get()->EnableAppList(profile()); 535 AppListService::Get()->EnableAppList(profile());
573 536
574 if (apps::IsAppLauncherEnabled()) { 537 if (apps::IsAppLauncherEnabled()) {
575 // Show the app list to show download is progressing. Don't show the app 538 // Show the app list to show download is progressing. Don't show the app
576 // list on first app install so users can be trained to open it themselves. 539 // list on first app install so users can be trained to open it themselves.
577 if (approval_->manifest->is_app() && !approval_->enable_launcher) 540 if (approval_->manifest->is_app() && !approval_->enable_launcher)
578 AppListService::Get()->ShowForProfile(profile()); 541 AppListService::Get()->ShowForProfile(profile());
579 } 542 }
580 543
581 // The extension will install through the normal extension install flow, but 544 // The extension will install through the normal extension install flow, but
582 // the whitelist entry will bypass the normal permissions install dialog. 545 // the whitelist entry will bypass the normal permissions install dialog.
583 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( 546 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller(
584 profile(), this, 547 profile(), this,
585 &(dispatcher()->delegate()->GetAssociatedWebContents()->GetController()), 548 &(dispatcher()->delegate()->GetAssociatedWebContents()->GetController()),
586 id, approval_.Pass(), WebstoreInstaller::FLAG_NONE); 549 params->expected_id, approval_.Pass(), WebstoreInstaller::FLAG_NONE);
587 installer->Start(); 550 installer->Start();
588 551
589 return true; 552 return true;
590 } 553 }
591 554
592 void WebstorePrivateCompleteInstallFunction::OnExtensionInstallSuccess( 555 void WebstorePrivateCompleteInstallFunction::OnExtensionInstallSuccess(
593 const std::string& id) { 556 const std::string& id) {
594 if (test_webstore_installer_delegate) 557 if (test_webstore_installer_delegate)
595 test_webstore_installer_delegate->OnExtensionInstallSuccess(id); 558 test_webstore_installer_delegate->OnExtensionInstallSuccess(id);
596 559
(...skipping 24 matching lines...) Expand all
621 } 584 }
622 585
623 WebstorePrivateEnableAppLauncherFunction:: 586 WebstorePrivateEnableAppLauncherFunction::
624 WebstorePrivateEnableAppLauncherFunction() {} 587 WebstorePrivateEnableAppLauncherFunction() {}
625 588
626 WebstorePrivateEnableAppLauncherFunction:: 589 WebstorePrivateEnableAppLauncherFunction::
627 ~WebstorePrivateEnableAppLauncherFunction() {} 590 ~WebstorePrivateEnableAppLauncherFunction() {}
628 591
629 bool WebstorePrivateEnableAppLauncherFunction::RunImpl() { 592 bool WebstorePrivateEnableAppLauncherFunction::RunImpl() {
630 AppListService::Get()->EnableAppList(profile()); 593 AppListService::Get()->EnableAppList(profile());
631 SendResponse(true);
632 return true; 594 return true;
633 } 595 }
634 596
635 bool WebstorePrivateGetBrowserLoginFunction::RunImpl() { 597 bool WebstorePrivateGetBrowserLoginFunction::RunImpl() {
636 SetResult(CreateLoginResult(profile_->GetOriginalProfile())); 598 GetBrowserLogin::Results::Info info;
599 info.login = profile_->GetOriginalProfile()->GetPrefs()->GetString(
600 prefs::kGoogleServicesUsername);
601 results_ = GetBrowserLogin::Results::Create(info);
637 return true; 602 return true;
638 } 603 }
639 604
640 bool WebstorePrivateGetStoreLoginFunction::RunImpl() { 605 bool WebstorePrivateGetStoreLoginFunction::RunImpl() {
641 SetResult(Value::CreateStringValue(GetWebstoreLogin(profile_))); 606 results_ = GetStoreLogin::Results::Create(GetWebstoreLogin(profile_));
642 return true; 607 return true;
643 } 608 }
644 609
645 bool WebstorePrivateSetStoreLoginFunction::RunImpl() { 610 bool WebstorePrivateSetStoreLoginFunction::RunImpl() {
646 std::string login; 611 scoped_ptr<SetStoreLogin::Params> params(
647 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &login)); 612 SetStoreLogin::Params::Create(*args_));
648 SetWebstoreLogin(profile_, login); 613 EXTENSION_FUNCTION_VALIDATE(params);
614 SetWebstoreLogin(profile_, params->login);
649 return true; 615 return true;
650 } 616 }
651 617
652 WebstorePrivateGetWebGLStatusFunction::WebstorePrivateGetWebGLStatusFunction() { 618 WebstorePrivateGetWebGLStatusFunction::WebstorePrivateGetWebGLStatusFunction() {
653 feature_checker_ = new GPUFeatureChecker( 619 feature_checker_ = new GPUFeatureChecker(
654 gpu::GPU_FEATURE_TYPE_WEBGL, 620 gpu::GPU_FEATURE_TYPE_WEBGL,
655 base::Bind(&WebstorePrivateGetWebGLStatusFunction::OnFeatureCheck, 621 base::Bind(&WebstorePrivateGetWebGLStatusFunction::OnFeatureCheck,
656 base::Unretained(this))); 622 base::Unretained(this)));
657 } 623 }
658 624
659 WebstorePrivateGetWebGLStatusFunction:: 625 WebstorePrivateGetWebGLStatusFunction::
660 ~WebstorePrivateGetWebGLStatusFunction() {} 626 ~WebstorePrivateGetWebGLStatusFunction() {}
661 627
662 void WebstorePrivateGetWebGLStatusFunction::CreateResult(bool webgl_allowed) { 628 void WebstorePrivateGetWebGLStatusFunction::CreateResult(bool webgl_allowed) {
663 SetResult(Value::CreateStringValue( 629 results_ = GetWebGLStatus::Results::Create(GetWebGLStatus::Results::
664 webgl_allowed ? "webgl_allowed" : "webgl_blocked")); 630 ParseWebgl_status(webgl_allowed ? "webgl_allowed" : "webgl_blocked"));
665 } 631 }
666 632
667 bool WebstorePrivateGetWebGLStatusFunction::RunImpl() { 633 bool WebstorePrivateGetWebGLStatusFunction::RunImpl() {
668 feature_checker_->CheckGPUFeatureAvailability(); 634 feature_checker_->CheckGPUFeatureAvailability();
669 return true; 635 return true;
670 } 636 }
671 637
672 void WebstorePrivateGetWebGLStatusFunction:: 638 void WebstorePrivateGetWebGLStatusFunction::
673 OnFeatureCheck(bool feature_allowed) { 639 OnFeatureCheck(bool feature_allowed) {
674 CreateResult(feature_allowed); 640 CreateResult(feature_allowed);
675 SendResponse(true); 641 SendResponse(true);
676 } 642 }
677 643
678 bool WebstorePrivateGetIsLauncherEnabledFunction::RunImpl() { 644 bool WebstorePrivateGetIsLauncherEnabledFunction::RunImpl() {
679 SetResult(Value::CreateBooleanValue(apps::IsAppLauncherEnabled())); 645 results_ = GetIsLauncherEnabled::Results::Create(
680 SendResponse(true); 646 apps::IsAppLauncherEnabled());
681 return true; 647 return true;
682 } 648 }
683 649
684 bool WebstorePrivateIsInIncognitoModeFunction::RunImpl() { 650 bool WebstorePrivateIsInIncognitoModeFunction::RunImpl() {
685 SetResult( 651 results_ = IsInIncognitoMode::Results::Create(
686 Value::CreateBooleanValue(profile_ != profile_->GetOriginalProfile())); 652 profile_ != profile_->GetOriginalProfile());
687 SendResponse(true);
688 return true; 653 return true;
689 } 654 }
690 655
691 } // namespace extensions 656 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/webstore_private/webstore_private_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698