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

Side by Side Diff: chrome/browser/extensions/api/management/management_api.cc

Issue 257333002: Drive extension functions from ExtensionFunction::Run. The (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comment Created 6 years, 7 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 | Annotate | Revision Log
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/management/management_api.h" 5 #include "chrome/browser/extensions/api/management/management_api.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 std::string manifest_; 369 std::string manifest_;
370 370
371 // Results of parsing. 371 // Results of parsing.
372 scoped_ptr<base::DictionaryValue> parsed_manifest_; 372 scoped_ptr<base::DictionaryValue> parsed_manifest_;
373 373
374 std::string error_; 374 std::string error_;
375 }; 375 };
376 376
377 } // namespace 377 } // namespace
378 378
379 bool ManagementGetPermissionWarningsByManifestFunction::RunImpl() { 379 bool ManagementGetPermissionWarningsByManifestFunction::RunAsync() {
380 scoped_ptr<management::GetPermissionWarningsByManifest::Params> params( 380 scoped_ptr<management::GetPermissionWarningsByManifest::Params> params(
381 management::GetPermissionWarningsByManifest::Params::Create(*args_)); 381 management::GetPermissionWarningsByManifest::Params::Create(*args_));
382 EXTENSION_FUNCTION_VALIDATE(params.get()); 382 EXTENSION_FUNCTION_VALIDATE(params.get());
383 383
384 scoped_refptr<SafeManifestJSONParser> parser = 384 scoped_refptr<SafeManifestJSONParser> parser =
385 new SafeManifestJSONParser(this, params->manifest_str); 385 new SafeManifestJSONParser(this, params->manifest_str);
386 parser->Start(); 386 parser->Start();
387 387
388 // Matched with a Release() in OnParseSuccess/Failure(). 388 // Matched with a Release() in OnParseSuccess/Failure().
389 AddRef(); 389 AddRef();
(...skipping 12 matching lines...) Expand all
402 if (!extension.get()) { 402 if (!extension.get()) {
403 OnParseFailure(keys::kExtensionCreateError); 403 OnParseFailure(keys::kExtensionCreateError);
404 return; 404 return;
405 } 405 }
406 406
407 std::vector<std::string> warnings = CreateWarningsList(extension.get()); 407 std::vector<std::string> warnings = CreateWarningsList(extension.get());
408 results_ = 408 results_ =
409 management::GetPermissionWarningsByManifest::Results::Create(warnings); 409 management::GetPermissionWarningsByManifest::Results::Create(warnings);
410 SendResponse(true); 410 SendResponse(true);
411 411
412 // Matched with AddRef() in RunImpl(). 412 // Matched with AddRef() in RunAsync().
413 Release(); 413 Release();
414 } 414 }
415 415
416 void ManagementGetPermissionWarningsByManifestFunction::OnParseFailure( 416 void ManagementGetPermissionWarningsByManifestFunction::OnParseFailure(
417 const std::string& error) { 417 const std::string& error) {
418 error_ = error; 418 error_ = error;
419 SendResponse(false); 419 SendResponse(false);
420 420
421 // Matched with AddRef() in RunImpl(). 421 // Matched with AddRef() in RunAsync().
422 Release(); 422 Release();
423 } 423 }
424 424
425 bool ManagementLaunchAppFunction::RunSync() { 425 bool ManagementLaunchAppFunction::RunSync() {
426 scoped_ptr<management::LaunchApp::Params> params( 426 scoped_ptr<management::LaunchApp::Params> params(
427 management::LaunchApp::Params::Create(*args_)); 427 management::LaunchApp::Params::Create(*args_));
428 EXTENSION_FUNCTION_VALIDATE(params.get()); 428 EXTENSION_FUNCTION_VALIDATE(params.get());
429 const Extension* extension = service()->GetExtensionById(params->id, true); 429 const Extension* extension = service()->GetExtensionById(params->id, true);
430 if (!extension) { 430 if (!extension) {
431 error_ = ErrorUtils::FormatErrorMessage(keys::kNoExtensionError, 431 error_ = ErrorUtils::FormatErrorMessage(keys::kNoExtensionError,
(...skipping 21 matching lines...) Expand all
453 453
454 return true; 454 return true;
455 } 455 }
456 456
457 ManagementSetEnabledFunction::ManagementSetEnabledFunction() { 457 ManagementSetEnabledFunction::ManagementSetEnabledFunction() {
458 } 458 }
459 459
460 ManagementSetEnabledFunction::~ManagementSetEnabledFunction() { 460 ManagementSetEnabledFunction::~ManagementSetEnabledFunction() {
461 } 461 }
462 462
463 bool ManagementSetEnabledFunction::RunImpl() { 463 bool ManagementSetEnabledFunction::RunAsync() {
464 scoped_ptr<management::SetEnabled::Params> params( 464 scoped_ptr<management::SetEnabled::Params> params(
465 management::SetEnabled::Params::Create(*args_)); 465 management::SetEnabled::Params::Create(*args_));
466 EXTENSION_FUNCTION_VALIDATE(params.get()); 466 EXTENSION_FUNCTION_VALIDATE(params.get());
467 467
468 extension_id_ = params->id; 468 extension_id_ = params->id;
469 469
470 const Extension* extension = service()->GetInstalledExtension(extension_id_); 470 const Extension* extension = service()->GetInstalledExtension(extension_id_);
471 if (!extension || extension->ShouldNotBeVisible()) { 471 if (!extension || extension->ShouldNotBeVisible()) {
472 error_ = ErrorUtils::FormatErrorMessage( 472 error_ = ErrorUtils::FormatErrorMessage(
473 keys::kNoExtensionError, extension_id_); 473 keys::kNoExtensionError, extension_id_);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 Finish(false); 604 Finish(false);
605 Release(); 605 Release();
606 } 606 }
607 607
608 ManagementUninstallFunction::ManagementUninstallFunction() { 608 ManagementUninstallFunction::ManagementUninstallFunction() {
609 } 609 }
610 610
611 ManagementUninstallFunction::~ManagementUninstallFunction() { 611 ManagementUninstallFunction::~ManagementUninstallFunction() {
612 } 612 }
613 613
614 bool ManagementUninstallFunction::RunImpl() { 614 bool ManagementUninstallFunction::RunAsync() {
615 scoped_ptr<management::Uninstall::Params> params( 615 scoped_ptr<management::Uninstall::Params> params(
616 management::Uninstall::Params::Create(*args_)); 616 management::Uninstall::Params::Create(*args_));
617 EXTENSION_FUNCTION_VALIDATE(extension_); 617 EXTENSION_FUNCTION_VALIDATE(extension_);
618 EXTENSION_FUNCTION_VALIDATE(params.get()); 618 EXTENSION_FUNCTION_VALIDATE(params.get());
619 619
620 bool show_confirm_dialog = true; 620 bool show_confirm_dialog = true;
621 // By default confirmation dialog isn't shown when uninstalling self, but this 621 // By default confirmation dialog isn't shown when uninstalling self, but this
622 // can be overridden with showConfirmDialog. 622 // can be overridden with showConfirmDialog.
623 if (params->id == extension_->id()) { 623 if (params->id == extension_->id()) {
624 show_confirm_dialog = params->options.get() && 624 show_confirm_dialog = params->options.get() &&
625 params->options->show_confirm_dialog.get() && 625 params->options->show_confirm_dialog.get() &&
626 *params->options->show_confirm_dialog; 626 *params->options->show_confirm_dialog;
627 } 627 }
628 if (show_confirm_dialog && !user_gesture()) { 628 if (show_confirm_dialog && !user_gesture()) {
629 error_ = keys::kGestureNeededForUninstallError; 629 error_ = keys::kGestureNeededForUninstallError;
630 return false; 630 return false;
631 } 631 }
632 return Uninstall(params->id, show_confirm_dialog); 632 return Uninstall(params->id, show_confirm_dialog);
633 } 633 }
634 634
635 ManagementUninstallSelfFunction::ManagementUninstallSelfFunction() { 635 ManagementUninstallSelfFunction::ManagementUninstallSelfFunction() {
636 } 636 }
637 637
638 ManagementUninstallSelfFunction::~ManagementUninstallSelfFunction() { 638 ManagementUninstallSelfFunction::~ManagementUninstallSelfFunction() {
639 } 639 }
640 640
641 bool ManagementUninstallSelfFunction::RunImpl() { 641 bool ManagementUninstallSelfFunction::RunAsync() {
642 scoped_ptr<management::UninstallSelf::Params> params( 642 scoped_ptr<management::UninstallSelf::Params> params(
643 management::UninstallSelf::Params::Create(*args_)); 643 management::UninstallSelf::Params::Create(*args_));
644 EXTENSION_FUNCTION_VALIDATE(params.get()); 644 EXTENSION_FUNCTION_VALIDATE(params.get());
645 645
646 bool show_confirm_dialog = false; 646 bool show_confirm_dialog = false;
647 if (params->options.get() && params->options->show_confirm_dialog.get()) 647 if (params->options.get() && params->options->show_confirm_dialog.get())
648 show_confirm_dialog = *params->options->show_confirm_dialog; 648 show_confirm_dialog = *params->options->show_confirm_dialog;
649 return Uninstall(extension_->id(), show_confirm_dialog); 649 return Uninstall(extension_->id(), show_confirm_dialog);
650 } 650 }
651 651
652 ManagementCreateAppShortcutFunction::ManagementCreateAppShortcutFunction() { 652 ManagementCreateAppShortcutFunction::ManagementCreateAppShortcutFunction() {
653 } 653 }
654 654
655 ManagementCreateAppShortcutFunction::~ManagementCreateAppShortcutFunction() { 655 ManagementCreateAppShortcutFunction::~ManagementCreateAppShortcutFunction() {
656 } 656 }
657 657
658 // static 658 // static
659 void ManagementCreateAppShortcutFunction::SetAutoConfirmForTest( 659 void ManagementCreateAppShortcutFunction::SetAutoConfirmForTest(
660 bool should_proceed) { 660 bool should_proceed) {
661 auto_confirm_for_test = should_proceed ? PROCEED : ABORT; 661 auto_confirm_for_test = should_proceed ? PROCEED : ABORT;
662 } 662 }
663 663
664 void ManagementCreateAppShortcutFunction::OnCloseShortcutPrompt(bool created) { 664 void ManagementCreateAppShortcutFunction::OnCloseShortcutPrompt(bool created) {
665 if (!created) 665 if (!created)
666 error_ = keys::kCreateShortcutCanceledError; 666 error_ = keys::kCreateShortcutCanceledError;
667 SendResponse(created); 667 SendResponse(created);
668 Release(); 668 Release();
669 } 669 }
670 670
671 bool ManagementCreateAppShortcutFunction::RunImpl() { 671 bool ManagementCreateAppShortcutFunction::RunAsync() {
672 if (!user_gesture()) { 672 if (!user_gesture()) {
673 error_ = keys::kGestureNeededForCreateAppShortcutError; 673 error_ = keys::kGestureNeededForCreateAppShortcutError;
674 return false; 674 return false;
675 } 675 }
676 676
677 scoped_ptr<management::CreateAppShortcut::Params> params( 677 scoped_ptr<management::CreateAppShortcut::Params> params(
678 management::CreateAppShortcut::Params::Create(*args_)); 678 management::CreateAppShortcut::Params::Create(*args_));
679 EXTENSION_FUNCTION_VALIDATE(params.get()); 679 EXTENSION_FUNCTION_VALIDATE(params.get());
680 const Extension* extension = service()->GetExtensionById(params->id, true); 680 const Extension* extension = service()->GetExtensionById(params->id, true);
681 if (!extension) { 681 if (!extension) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 return g_factory.Pointer(); 814 return g_factory.Pointer();
815 } 815 }
816 816
817 void ManagementAPI::OnListenerAdded(const EventListenerInfo& details) { 817 void ManagementAPI::OnListenerAdded(const EventListenerInfo& details) {
818 management_event_router_.reset( 818 management_event_router_.reset(
819 new ManagementEventRouter(Profile::FromBrowserContext(browser_context_))); 819 new ManagementEventRouter(Profile::FromBrowserContext(browser_context_)));
820 EventRouter::Get(browser_context_)->UnregisterObserver(this); 820 EventRouter::Get(browser_context_)->UnregisterObserver(this);
821 } 821 }
822 822
823 } // namespace extensions 823 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698