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

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

Issue 10694106: Added support for multiple parameters to Extension API callbacks. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Synced. Created 8 years, 5 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
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 "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 253
254 BeginInstallWithManifestFunction::~BeginInstallWithManifestFunction() {} 254 BeginInstallWithManifestFunction::~BeginInstallWithManifestFunction() {}
255 255
256 bool BeginInstallWithManifestFunction::RunImpl() { 256 bool BeginInstallWithManifestFunction::RunImpl() {
257 DictionaryValue* details = NULL; 257 DictionaryValue* details = NULL;
258 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); 258 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
259 CHECK(details); 259 CHECK(details);
260 260
261 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIdKey, &id_)); 261 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIdKey, &id_));
262 if (!extensions::Extension::IdIsValid(id_)) { 262 if (!extensions::Extension::IdIsValid(id_)) {
263 SetResult(INVALID_ID); 263 SetResultCode(INVALID_ID);
264 error_ = kInvalidIdError; 264 error_ = kInvalidIdError;
265 return false; 265 return false;
266 } 266 }
267 267
268 EXTENSION_FUNCTION_VALIDATE(details->GetString(kManifestKey, &manifest_)); 268 EXTENSION_FUNCTION_VALIDATE(details->GetString(kManifestKey, &manifest_));
269 269
270 if (details->HasKey(kIconDataKey) && details->HasKey(kIconUrlKey)) { 270 if (details->HasKey(kIconDataKey) && details->HasKey(kIconUrlKey)) {
271 SetResult(ICON_ERROR); 271 SetResultCode(ICON_ERROR);
272 error_ = kCannotSpecifyIconDataAndUrlError; 272 error_ = kCannotSpecifyIconDataAndUrlError;
273 return false; 273 return false;
274 } 274 }
275 275
276 if (details->HasKey(kIconDataKey)) 276 if (details->HasKey(kIconDataKey))
277 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIconDataKey, &icon_data_)); 277 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIconDataKey, &icon_data_));
278 278
279 GURL icon_url; 279 GURL icon_url;
280 if (details->HasKey(kIconUrlKey)) { 280 if (details->HasKey(kIconUrlKey)) {
281 std::string tmp_url; 281 std::string tmp_url;
282 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIconUrlKey, &tmp_url)); 282 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIconUrlKey, &tmp_url));
283 icon_url = source_url().Resolve(tmp_url); 283 icon_url = source_url().Resolve(tmp_url);
284 if (!icon_url.is_valid()) { 284 if (!icon_url.is_valid()) {
285 SetResult(INVALID_ICON_URL); 285 SetResultCode(INVALID_ICON_URL);
286 error_ = kInvalidIconUrlError; 286 error_ = kInvalidIconUrlError;
287 return false; 287 return false;
288 } 288 }
289 } 289 }
290 290
291 if (details->HasKey(kLocalizedNameKey)) 291 if (details->HasKey(kLocalizedNameKey))
292 EXTENSION_FUNCTION_VALIDATE(details->GetString(kLocalizedNameKey, 292 EXTENSION_FUNCTION_VALIDATE(details->GetString(kLocalizedNameKey,
293 &localized_name_)); 293 &localized_name_));
294 294
295 if (details->HasKey(kAppInstallBubbleKey)) 295 if (details->HasKey(kAppInstallBubbleKey))
(...skipping 13 matching lines...) Expand all
309 309
310 // Matched with a Release in OnWebstoreParseSuccess/OnWebstoreParseFailure. 310 // Matched with a Release in OnWebstoreParseSuccess/OnWebstoreParseFailure.
311 AddRef(); 311 AddRef();
312 312
313 // The response is sent asynchronously in OnWebstoreParseSuccess/ 313 // The response is sent asynchronously in OnWebstoreParseSuccess/
314 // OnWebstoreParseFailure. 314 // OnWebstoreParseFailure.
315 return true; 315 return true;
316 } 316 }
317 317
318 318
319 void BeginInstallWithManifestFunction::SetResult(ResultCode code) { 319 void BeginInstallWithManifestFunction::SetResultCode(ResultCode code) {
320 switch (code) { 320 switch (code) {
321 case ERROR_NONE: 321 case ERROR_NONE:
322 result_.reset(Value::CreateStringValue("")); 322 SetResult(Value::CreateStringValue(""));
323 break; 323 break;
324 case UNKNOWN_ERROR: 324 case UNKNOWN_ERROR:
325 result_.reset(Value::CreateStringValue("unknown_error")); 325 SetResult(Value::CreateStringValue("unknown_error"));
326 break; 326 break;
327 case USER_CANCELLED: 327 case USER_CANCELLED:
328 result_.reset(Value::CreateStringValue("user_cancelled")); 328 SetResult(Value::CreateStringValue("user_cancelled"));
329 break; 329 break;
330 case MANIFEST_ERROR: 330 case MANIFEST_ERROR:
331 result_.reset(Value::CreateStringValue("manifest_error")); 331 SetResult(Value::CreateStringValue("manifest_error"));
332 break; 332 break;
333 case ICON_ERROR: 333 case ICON_ERROR:
334 result_.reset(Value::CreateStringValue("icon_error")); 334 SetResult(Value::CreateStringValue("icon_error"));
335 break; 335 break;
336 case INVALID_ID: 336 case INVALID_ID:
337 result_.reset(Value::CreateStringValue("invalid_id")); 337 SetResult(Value::CreateStringValue("invalid_id"));
338 break; 338 break;
339 case PERMISSION_DENIED: 339 case PERMISSION_DENIED:
340 result_.reset(Value::CreateStringValue("permission_denied")); 340 SetResult(Value::CreateStringValue("permission_denied"));
341 break; 341 break;
342 case INVALID_ICON_URL: 342 case INVALID_ICON_URL:
343 result_.reset(Value::CreateStringValue("invalid_icon_url")); 343 SetResult(Value::CreateStringValue("invalid_icon_url"));
344 break; 344 break;
345 default: 345 default:
346 CHECK(false); 346 CHECK(false);
347 } 347 }
348 } 348 }
349 349
350 void BeginInstallWithManifestFunction::OnWebstoreParseSuccess( 350 void BeginInstallWithManifestFunction::OnWebstoreParseSuccess(
351 const std::string& id, 351 const std::string& id,
352 const SkBitmap& icon, 352 const SkBitmap& icon,
353 DictionaryValue* parsed_manifest) { 353 DictionaryValue* parsed_manifest) {
(...skipping 20 matching lines...) Expand all
374 374
375 void BeginInstallWithManifestFunction::OnWebstoreParseFailure( 375 void BeginInstallWithManifestFunction::OnWebstoreParseFailure(
376 const std::string& id, 376 const std::string& id,
377 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code, 377 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code,
378 const std::string& error_message) { 378 const std::string& error_message) {
379 CHECK_EQ(id_, id); 379 CHECK_EQ(id_, id);
380 380
381 // Map from WebstoreInstallHelper's result codes to ours. 381 // Map from WebstoreInstallHelper's result codes to ours.
382 switch (result_code) { 382 switch (result_code) {
383 case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR: 383 case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR:
384 SetResult(UNKNOWN_ERROR); 384 SetResultCode(UNKNOWN_ERROR);
385 break; 385 break;
386 case WebstoreInstallHelper::Delegate::ICON_ERROR: 386 case WebstoreInstallHelper::Delegate::ICON_ERROR:
387 SetResult(ICON_ERROR); 387 SetResultCode(ICON_ERROR);
388 break; 388 break;
389 case WebstoreInstallHelper::Delegate::MANIFEST_ERROR: 389 case WebstoreInstallHelper::Delegate::MANIFEST_ERROR:
390 SetResult(MANIFEST_ERROR); 390 SetResultCode(MANIFEST_ERROR);
391 break; 391 break;
392 default: 392 default:
393 CHECK(false); 393 CHECK(false);
394 } 394 }
395 error_ = error_message; 395 error_ = error_message;
396 SendResponse(false); 396 SendResponse(false);
397 397
398 // Matches the AddRef in RunImpl(). 398 // Matches the AddRef in RunImpl().
399 Release(); 399 Release();
400 } 400 }
401 401
402 void BeginInstallWithManifestFunction::InstallUIProceed() { 402 void BeginInstallWithManifestFunction::InstallUIProceed() {
403 // This gets cleared in CrxInstaller::ConfirmInstall(). TODO(asargent) - in 403 // This gets cleared in CrxInstaller::ConfirmInstall(). TODO(asargent) - in
404 // the future we may also want to add time-based expiration, where a whitelist 404 // the future we may also want to add time-based expiration, where a whitelist
405 // entry is only valid for some number of minutes. 405 // entry is only valid for some number of minutes.
406 scoped_ptr<WebstoreInstaller::Approval> approval( 406 scoped_ptr<WebstoreInstaller::Approval> approval(
407 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( 407 WebstoreInstaller::Approval::CreateWithNoInstallPrompt(
408 profile(), id_, parsed_manifest_.Pass())); 408 profile(), id_, parsed_manifest_.Pass()));
409 approval->use_app_installed_bubble = use_app_installed_bubble_; 409 approval->use_app_installed_bubble = use_app_installed_bubble_;
410 approval->record_oauth2_grant = install_prompt_->record_oauth2_grant(); 410 approval->record_oauth2_grant = install_prompt_->record_oauth2_grant();
411 g_pending_approvals.Get().PushApproval(approval.Pass()); 411 g_pending_approvals.Get().PushApproval(approval.Pass());
412 412
413 SetResult(ERROR_NONE); 413 SetResultCode(ERROR_NONE);
414 SendResponse(true); 414 SendResponse(true);
415 415
416 // The Permissions_Install histogram is recorded from the ExtensionService 416 // The Permissions_Install histogram is recorded from the ExtensionService
417 // for all extension installs, so we only need to record the web store 417 // for all extension installs, so we only need to record the web store
418 // specific histogram here. 418 // specific histogram here.
419 ExtensionService::RecordPermissionMessagesHistogram( 419 ExtensionService::RecordPermissionMessagesHistogram(
420 dummy_extension_, "Extensions.Permissions_WebStoreInstall"); 420 dummy_extension_, "Extensions.Permissions_WebStoreInstall");
421 421
422 // Matches the AddRef in RunImpl(). 422 // Matches the AddRef in RunImpl().
423 Release(); 423 Release();
424 } 424 }
425 425
426 void BeginInstallWithManifestFunction::InstallUIAbort(bool user_initiated) { 426 void BeginInstallWithManifestFunction::InstallUIAbort(bool user_initiated) {
427 error_ = kUserCancelledError; 427 error_ = kUserCancelledError;
428 SetResult(USER_CANCELLED); 428 SetResultCode(USER_CANCELLED);
429 SendResponse(false); 429 SendResponse(false);
430 430
431 // The web store install histograms are a subset of the install histograms. 431 // The web store install histograms are a subset of the install histograms.
432 // We need to record both histograms here since CrxInstaller::InstallUIAbort 432 // We need to record both histograms here since CrxInstaller::InstallUIAbort
433 // is never called for web store install cancellations. 433 // is never called for web store install cancellations.
434 std::string histogram_name = user_initiated ? 434 std::string histogram_name = user_initiated ?
435 "Extensions.Permissions_WebStoreInstallCancel" : 435 "Extensions.Permissions_WebStoreInstallCancel" :
436 "Extensions.Permissions_WebStoreInstallAbort"; 436 "Extensions.Permissions_WebStoreInstallAbort";
437 ExtensionService::RecordPermissionMessagesHistogram( 437 ExtensionService::RecordPermissionMessagesHistogram(
438 dummy_extension_, histogram_name.c_str()); 438 dummy_extension_, histogram_name.c_str());
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 const std::string& id, const std::string& error) { 545 const std::string& id, const std::string& error) {
546 CHECK_EQ(id_, id); 546 CHECK_EQ(id_, id);
547 547
548 error_ = error; 548 error_ = error;
549 SendResponse(false); 549 SendResponse(false);
550 550
551 Release(); // Matches the AddRef() in RunImpl(). 551 Release(); // Matches the AddRef() in RunImpl().
552 } 552 }
553 553
554 bool GetBrowserLoginFunction::RunImpl() { 554 bool GetBrowserLoginFunction::RunImpl() {
555 result_.reset(CreateLoginResult(profile_->GetOriginalProfile())); 555 SetResult(CreateLoginResult(profile_->GetOriginalProfile()));
556 return true; 556 return true;
557 } 557 }
558 558
559 bool GetStoreLoginFunction::RunImpl() { 559 bool GetStoreLoginFunction::RunImpl() {
560 ExtensionService* service = profile_->GetExtensionService(); 560 ExtensionService* service = profile_->GetExtensionService();
561 ExtensionPrefs* prefs = service->extension_prefs(); 561 ExtensionPrefs* prefs = service->extension_prefs();
562 std::string login; 562 std::string login;
563 if (prefs->GetWebStoreLogin(&login)) { 563 if (prefs->GetWebStoreLogin(&login)) {
564 result_.reset(Value::CreateStringValue(login)); 564 SetResult(Value::CreateStringValue(login));
565 } else { 565 } else {
566 result_.reset(Value::CreateStringValue(std::string())); 566 SetResult(Value::CreateStringValue(std::string()));
567 } 567 }
568 return true; 568 return true;
569 } 569 }
570 570
571 bool SetStoreLoginFunction::RunImpl() { 571 bool SetStoreLoginFunction::RunImpl() {
572 std::string login; 572 std::string login;
573 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &login)); 573 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &login));
574 ExtensionService* service = profile_->GetExtensionService(); 574 ExtensionService* service = profile_->GetExtensionService();
575 ExtensionPrefs* prefs = service->extension_prefs(); 575 ExtensionPrefs* prefs = service->extension_prefs();
576 prefs->SetWebStoreLogin(login); 576 prefs->SetWebStoreLogin(login);
577 return true; 577 return true;
578 } 578 }
579 579
580 GetWebGLStatusFunction::GetWebGLStatusFunction() { 580 GetWebGLStatusFunction::GetWebGLStatusFunction() {
581 feature_checker_ = new GPUFeatureChecker( 581 feature_checker_ = new GPUFeatureChecker(
582 content::GPU_FEATURE_TYPE_WEBGL, 582 content::GPU_FEATURE_TYPE_WEBGL,
583 base::Bind(&GetWebGLStatusFunction::OnFeatureCheck, this)); 583 base::Bind(&GetWebGLStatusFunction::OnFeatureCheck, this));
584 } 584 }
585 585
586 GetWebGLStatusFunction::~GetWebGLStatusFunction() {} 586 GetWebGLStatusFunction::~GetWebGLStatusFunction() {}
587 587
588 void GetWebGLStatusFunction::CreateResult(bool webgl_allowed) { 588 void GetWebGLStatusFunction::CreateResult(bool webgl_allowed) {
589 result_.reset(Value::CreateStringValue( 589 SetResult(Value::CreateStringValue(
590 webgl_allowed ? "webgl_allowed" : "webgl_blocked")); 590 webgl_allowed ? "webgl_allowed" : "webgl_blocked"));
591 } 591 }
592 592
593 bool GetWebGLStatusFunction::RunImpl() { 593 bool GetWebGLStatusFunction::RunImpl() {
594 feature_checker_->CheckGPUFeatureAvailability(); 594 feature_checker_->CheckGPUFeatureAvailability();
595 return true; 595 return true;
596 } 596 }
597 597
598 void GetWebGLStatusFunction::OnFeatureCheck(bool feature_allowed) { 598 void GetWebGLStatusFunction::OnFeatureCheck(bool feature_allowed) {
599 CreateResult(feature_allowed); 599 CreateResult(feature_allowed);
600 SendResponse(true); 600 SendResponse(true);
601 } 601 }
602 602
603 } // namespace extensions 603 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698