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

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

Issue 948413005: [Extensions] Make chrome://extensions use management.uninstall (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 "extensions/browser/api/management/management_api.h" 5 #include "extensions/browser/api/management/management_api.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 JoinString(requirements_errors, ' '))); 504 JoinString(requirements_errors, ' ')));
505 } 505 }
506 } 506 }
507 507
508 ManagementUninstallFunctionBase::ManagementUninstallFunctionBase() { 508 ManagementUninstallFunctionBase::ManagementUninstallFunctionBase() {
509 } 509 }
510 510
511 ManagementUninstallFunctionBase::~ManagementUninstallFunctionBase() { 511 ManagementUninstallFunctionBase::~ManagementUninstallFunctionBase() {
512 } 512 }
513 513
514 bool ManagementUninstallFunctionBase::Uninstall( 514 ExtensionFunction::ResponseAction ManagementUninstallFunctionBase::Uninstall(
515 const std::string& target_extension_id, 515 const std::string& target_extension_id,
516 bool show_confirm_dialog) { 516 bool show_confirm_dialog) {
517 const ManagementAPIDelegate* delegate = ManagementAPI::GetFactoryInstance() 517 const ManagementAPIDelegate* delegate = ManagementAPI::GetFactoryInstance()
518 ->Get(browser_context()) 518 ->Get(browser_context())
519 ->GetDelegate(); 519 ->GetDelegate();
520 extension_id_ = target_extension_id; 520 extension_id_ = target_extension_id;
not at google - send to devlin 2015/02/25 21:37:58 ugh, can we call |extension_id_| actually |target_
Devlin 2015/02/25 23:12:47 Done.
521 const Extension* target_extension = 521 const Extension* target_extension =
522 extensions::ExtensionRegistry::Get(browser_context()) 522 extensions::ExtensionRegistry::Get(browser_context())
523 ->GetExtensionById(extension_id_, ExtensionRegistry::EVERYTHING); 523 ->GetExtensionById(extension_id_, ExtensionRegistry::EVERYTHING);
524 if (!target_extension || 524 if (!target_extension ||
525 ShouldNotBeVisible(target_extension, browser_context())) { 525 ShouldNotBeVisible(target_extension, browser_context())) {
526 error_ = 526 return RespondNow(Error(keys::kNoExtensionError, extension_id_));
527 ErrorUtils::FormatErrorMessage(keys::kNoExtensionError, extension_id_);
528 return false;
529 } 527 }
530 528
531 ManagementPolicy* policy = 529 ManagementPolicy* policy =
532 ExtensionSystem::Get(browser_context())->management_policy(); 530 ExtensionSystem::Get(browser_context())->management_policy();
533 if (!policy->UserMayModifySettings(target_extension, nullptr) || 531 if (!policy->UserMayModifySettings(target_extension, nullptr) ||
534 policy->MustRemainInstalled(target_extension, nullptr)) { 532 policy->MustRemainInstalled(target_extension, nullptr)) {
535 error_ = ErrorUtils::FormatErrorMessage(keys::kUserCantModifyError, 533 return RespondNow(Error(keys::kUserCantModifyError, extension_id_));
536 extension_id_);
537 return false;
538 } 534 }
539 535
540 if (auto_confirm_for_test == DO_NOT_SKIP) { 536 if (show_confirm_dialog && auto_confirm_for_test == DO_NOT_SKIP) {
not at google - send to devlin 2015/02/25 21:37:58 There are just too many checks for |auto_confirm_f
Devlin 2015/02/25 23:12:47 Done.
541 if (show_confirm_dialog) { 537 AddRef(); // Balanced in ExtensionUninstallAccepted/Canceled
542 AddRef(); // Balanced in ExtensionUninstallAccepted/Canceled 538 // TODO(devlin): A method called "UninstallFunctionDelegate" does not in
not at google - send to devlin 2015/02/25 21:37:58 Indeed!
543 uninstall_dialog_ = 539 // any way imply that this actually creates a dialog and runs it.
544 delegate->UninstallFunctionDelegate(this, target_extension_id); 540 uninstall_dialog_ =
545 } else { 541 delegate->UninstallFunctionDelegate(this, target_extension_id);
546 Finish(true); 542 } else { // No confirm dialog.
not at google - send to devlin 2015/02/25 21:37:58 This is (at least, allowing me to not squint at th
Devlin 2015/02/25 23:12:47 Duplicating a post task is particularly ugly, IMO.
547 } 543 // Uninstall should succeed, unless we would normally show the confirm
548 } else { 544 // dialog but are taking a shortcut to the cancel for a test.
549 Finish(auto_confirm_for_test == PROCEED); 545 bool should_uninstall =
546 !(auto_confirm_for_test == ABORT && show_confirm_dialog);
547 // We do this asynchronously because Finish() Respond()s, which assumes that
548 // this function doesn't.
549 base::MessageLoop::current()->PostTask(
550 FROM_HERE,
551 base::Bind(&ManagementUninstallFunctionBase::Finish,
552 this,
553 should_uninstall)); // This bind adds a ref.
not at google - send to devlin 2015/02/25 21:37:58 Seems like an obvious thing to comment?
Devlin 2015/02/25 23:12:47 Done.
550 } 554 }
551 555
552 return true; 556 return RespondLater();
553 } 557 }
554 558
555 // static 559 // static
556 void ManagementUninstallFunctionBase::SetAutoConfirmForTest( 560 void ManagementUninstallFunctionBase::SetAutoConfirmForTest(
557 bool should_proceed) { 561 bool should_proceed) {
558 auto_confirm_for_test = should_proceed ? PROCEED : ABORT; 562 auto_confirm_for_test = should_proceed ? PROCEED : ABORT;
559 } 563 }
560 564
561 void ManagementUninstallFunctionBase::Finish(bool should_uninstall) { 565 void ManagementUninstallFunctionBase::Finish(bool should_uninstall) {
562 if (should_uninstall) { 566 if (!should_uninstall) {
563 // The extension can be uninstalled in another window while the UI was 567 Respond(Error(keys::kUninstallCanceledError, extension_id_));
564 // showing. Do nothing in that case. 568 return;
565 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context()); 569 }
566 const Extension* extension = registry->GetExtensionById(
567 extension_id_, ExtensionRegistry::EVERYTHING);
568 if (!extension) {
569 error_ = ErrorUtils::FormatErrorMessage(keys::kNoExtensionError,
570 extension_id_);
571 SendResponse(false);
572 } else {
573 const ManagementAPIDelegate* delegate =
574 ManagementAPI::GetFactoryInstance()
575 ->Get(browser_context())
576 ->GetDelegate();
577 bool success = delegate->UninstallExtension(
578 browser_context(), extension_id_,
579 extensions::UNINSTALL_REASON_MANAGEMENT_API,
580 base::Bind(&base::DoNothing), NULL);
581 570
582 // TODO set error_ if !success 571 // The extension can be uninstalled in another window while the UI was
583 SendResponse(success); 572 // showing. Do nothing in that case.
584 } 573 const Extension* extension =
585 } else { 574 extensions::ExtensionRegistry::Get(browser_context())
586 error_ = ErrorUtils::FormatErrorMessage(keys::kUninstallCanceledError, 575 ->GetExtensionById(extension_id_, ExtensionRegistry::EVERYTHING);
587 extension_id_); 576 if (!extension) {
588 SendResponse(false); 577 Respond(Error(keys::kNoExtensionError, extension_id_));
578 return;
589 } 579 }
580
581 const ManagementAPIDelegate* delegate =
582 ManagementAPI::GetFactoryInstance()
583 ->Get(browser_context())
584 ->GetDelegate();
585 base::string16 error;
586 bool success = delegate->UninstallExtension(
587 browser_context(), extension_id_,
588 extensions::UNINSTALL_REASON_MANAGEMENT_API,
589 base::Bind(&base::DoNothing), &error);
590 ResponseValue response =
591 success ? NoArguments() : Error(base::UTF16ToUTF8(error));
592 Respond(response.Pass());
not at google - send to devlin 2015/02/25 21:37:57 Inline |response|?
Devlin 2015/02/25 23:12:47 Done.
590 } 593 }
591 594
592 void ManagementUninstallFunctionBase::ExtensionUninstallAccepted() { 595 void ManagementUninstallFunctionBase::ExtensionUninstallAccepted() {
593 Finish(true); 596 Finish(true);
594 Release(); 597 Release();
595 } 598 }
596 599
597 void ManagementUninstallFunctionBase::ExtensionUninstallCanceled() { 600 void ManagementUninstallFunctionBase::ExtensionUninstallCanceled() {
598 Finish(false); 601 Finish(false);
599 Release(); 602 Release();
600 } 603 }
601 604
602 ManagementUninstallFunction::ManagementUninstallFunction() { 605 ManagementUninstallFunction::ManagementUninstallFunction() {
603 } 606 }
604 607
605 ManagementUninstallFunction::~ManagementUninstallFunction() { 608 ManagementUninstallFunction::~ManagementUninstallFunction() {
606 } 609 }
607 610
608 bool ManagementUninstallFunction::RunAsync() { 611 ExtensionFunction::ResponseAction ManagementUninstallFunction::Run() {
609 scoped_ptr<management::Uninstall::Params> params( 612 scoped_ptr<management::Uninstall::Params> params(
610 management::Uninstall::Params::Create(*args_)); 613 management::Uninstall::Params::Create(*args_));
611 EXTENSION_FUNCTION_VALIDATE(extension_.get());
612 EXTENSION_FUNCTION_VALIDATE(params.get()); 614 EXTENSION_FUNCTION_VALIDATE(params.get());
613 615
614 bool show_confirm_dialog = true; 616 bool show_confirm_dialog = true;
615 // By default confirmation dialog isn't shown when uninstalling self, but this 617 // By default confirmation dialog isn't shown when uninstalling self, but this
616 // can be overridden with showConfirmDialog. 618 // can be overridden with showConfirmDialog.
617 if (params->id == extension_->id()) { 619 if (extension_.get() && params->id == extension_->id()) {
618 show_confirm_dialog = params->options.get() && 620 show_confirm_dialog = params->options.get() &&
619 params->options->show_confirm_dialog.get() && 621 params->options->show_confirm_dialog.get() &&
620 *params->options->show_confirm_dialog; 622 *params->options->show_confirm_dialog;
not at google - send to devlin 2015/02/25 21:37:57 The Base already does this checking logic, no need
Devlin 2015/02/25 23:12:47 Done, ish. Too messy for one line.
621 } 623 }
622 if (show_confirm_dialog && !user_gesture()) { 624 if (show_confirm_dialog && !user_gesture())
not at google - send to devlin 2015/02/25 21:37:58 The user gesture logic should be moved into the ba
Devlin 2015/02/25 23:12:47 Done.
623 error_ = keys::kGestureNeededForUninstallError; 625 return RespondNow(Error(keys::kGestureNeededForUninstallError));
624 return false; 626
625 }
626 return Uninstall(params->id, show_confirm_dialog); 627 return Uninstall(params->id, show_confirm_dialog);
627 } 628 }
628 629
629 ManagementUninstallSelfFunction::ManagementUninstallSelfFunction() { 630 ManagementUninstallSelfFunction::ManagementUninstallSelfFunction() {
630 } 631 }
631 632
632 ManagementUninstallSelfFunction::~ManagementUninstallSelfFunction() { 633 ManagementUninstallSelfFunction::~ManagementUninstallSelfFunction() {
633 } 634 }
634 635
635 bool ManagementUninstallSelfFunction::RunAsync() { 636 ExtensionFunction::ResponseAction ManagementUninstallSelfFunction::Run() {
636 scoped_ptr<management::UninstallSelf::Params> params( 637 scoped_ptr<management::UninstallSelf::Params> params(
637 management::UninstallSelf::Params::Create(*args_)); 638 management::UninstallSelf::Params::Create(*args_));
638 EXTENSION_FUNCTION_VALIDATE(params.get()); 639 EXTENSION_FUNCTION_VALIDATE(params.get());
640 EXTENSION_FUNCTION_VALIDATE(extension_.get());
639 641
640 bool show_confirm_dialog = false; 642 bool show_confirm_dialog = params->options.get() &&
641 if (params->options.get() && params->options->show_confirm_dialog.get()) 643 params->options->show_confirm_dialog.get() &&
642 show_confirm_dialog = *params->options->show_confirm_dialog; 644 *params->options->show_confirm_dialog;
643 return Uninstall(extension_->id(), show_confirm_dialog); 645 return Uninstall(extension_->id(), show_confirm_dialog);
644 } 646 }
645 647
646 ManagementCreateAppShortcutFunction::ManagementCreateAppShortcutFunction() { 648 ManagementCreateAppShortcutFunction::ManagementCreateAppShortcutFunction() {
647 } 649 }
648 650
649 ManagementCreateAppShortcutFunction::~ManagementCreateAppShortcutFunction() { 651 ManagementCreateAppShortcutFunction::~ManagementCreateAppShortcutFunction() {
650 } 652 }
651 653
652 // static 654 // static
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 ManagementAPI::GetFactoryInstance() { 910 ManagementAPI::GetFactoryInstance() {
909 return g_factory.Pointer(); 911 return g_factory.Pointer();
910 } 912 }
911 913
912 void ManagementAPI::OnListenerAdded(const EventListenerInfo& details) { 914 void ManagementAPI::OnListenerAdded(const EventListenerInfo& details) {
913 management_event_router_.reset(new ManagementEventRouter(browser_context_)); 915 management_event_router_.reset(new ManagementEventRouter(browser_context_));
914 EventRouter::Get(browser_context_)->UnregisterObserver(this); 916 EventRouter::Get(browser_context_)->UnregisterObserver(this);
915 } 917 }
916 918
917 } // namespace extensions 919 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698