OLD | NEW |
---|---|
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 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
534 | 534 |
535 // Note: null extension() means it's WebUI. | 535 // Note: null extension() means it's WebUI. |
536 bool self_uninstall = extension() && extension_id() == target_extension_id_; | 536 bool self_uninstall = extension() && extension_id() == target_extension_id_; |
537 // We need to show a dialog for any extension uninstalling another extension. | 537 // We need to show a dialog for any extension uninstalling another extension. |
538 show_confirm_dialog |= !self_uninstall; | 538 show_confirm_dialog |= !self_uninstall; |
539 | 539 |
540 if (show_confirm_dialog && !user_gesture()) | 540 if (show_confirm_dialog && !user_gesture()) |
541 return RespondNow(Error(keys::kGestureNeededForUninstallError)); | 541 return RespondNow(Error(keys::kGestureNeededForUninstallError)); |
542 | 542 |
543 if (show_confirm_dialog) { | 543 if (show_confirm_dialog) { |
544 switch (auto_confirm_for_test) { | 544 // We show the programmatic uninstall ui for extensions uninstalling |
Devlin
2015/05/29 15:29:20
Woo! Die, silly code, die!!
| |
545 case DO_NOT_SKIP: { | 545 // other extensions. |
546 // We show the programmatic uninstall ui for extensions uninstalling | 546 bool show_programmatic_uninstall_ui = !self_uninstall && extension(); |
547 // other extensions. | 547 AddRef(); // Balanced in OnExtensionUninstallDialogClosed. |
548 bool show_programmatic_uninstall_ui = !self_uninstall && extension(); | 548 // TODO(devlin): A method called "UninstallFunctionDelegate" does not in |
549 AddRef(); // Balanced in OnExtensionUninstallDialogClosed. | 549 // any way imply that this actually creates a dialog and runs it. |
550 // TODO(devlin): A method called "UninstallFunctionDelegate" does not in | 550 uninstall_dialog_ = delegate->UninstallFunctionDelegate( |
551 // any way imply that this actually creates a dialog and runs it. | 551 this, target_extension, show_programmatic_uninstall_ui); |
552 uninstall_dialog_ = | |
553 delegate->UninstallFunctionDelegate( | |
554 this, | |
555 target_extension, | |
556 show_programmatic_uninstall_ui); | |
557 break; | |
558 } | |
559 case PROCEED: { | |
560 // Skip the confirm dialog for testing. | |
561 base::MessageLoop::current()->PostTask( | |
562 FROM_HERE, | |
563 base::Bind(&ManagementUninstallFunctionBase::UninstallExtension, | |
564 this)); | |
565 break; | |
566 } | |
567 case ABORT: { | |
568 // Fake the user canceling. | |
569 base::MessageLoop::current()->PostTask( | |
570 FROM_HERE, | |
571 base::Bind( | |
572 &ManagementUninstallFunctionBase::Finish, this, false, | |
573 ErrorUtils::FormatErrorMessage(keys::kUninstallCanceledError, | |
574 target_extension_id_))); | |
575 } | |
576 } | |
577 } else { // No confirm dialog. | 552 } else { // No confirm dialog. |
578 base::MessageLoop::current()->PostTask( | 553 base::MessageLoop::current()->PostTask( |
579 FROM_HERE, | 554 FROM_HERE, |
580 base::Bind(&ManagementUninstallFunctionBase::UninstallExtension, this)); | 555 base::Bind(&ManagementUninstallFunctionBase::UninstallExtension, this)); |
581 } | 556 } |
582 | 557 |
583 return RespondLater(); | 558 return RespondLater(); |
584 } | 559 } |
585 | 560 |
586 void ManagementUninstallFunctionBase::Finish(bool did_start_uninstall, | 561 void ManagementUninstallFunctionBase::Finish(bool did_start_uninstall, |
587 const std::string& error) { | 562 const std::string& error) { |
588 Respond(did_start_uninstall ? NoArguments() : Error(error)); | 563 Respond(did_start_uninstall ? NoArguments() : Error(error)); |
589 } | 564 } |
590 | 565 |
591 void ManagementUninstallFunctionBase::OnExtensionUninstallDialogClosed( | 566 void ManagementUninstallFunctionBase::OnExtensionUninstallDialogClosed( |
592 bool did_start_uninstall, | 567 bool did_start_uninstall, |
593 const base::string16& error) { | 568 const base::string16& error) { |
594 Finish(did_start_uninstall, base::UTF16ToUTF8(error)); | 569 Finish(did_start_uninstall, |
570 ErrorUtils::FormatErrorMessage(keys::kUninstallCanceledError, | |
571 target_extension_id_)); | |
595 Release(); // Balanced in Uninstall(). | 572 Release(); // Balanced in Uninstall(). |
596 } | 573 } |
597 | 574 |
598 void ManagementUninstallFunctionBase::UninstallExtension() { | 575 void ManagementUninstallFunctionBase::UninstallExtension() { |
599 // The extension can be uninstalled in another window while the UI was | 576 // The extension can be uninstalled in another window while the UI was |
600 // showing. Do nothing in that case. | 577 // showing. Do nothing in that case. |
601 const Extension* target_extension = | 578 const Extension* target_extension = |
602 extensions::ExtensionRegistry::Get(browser_context()) | 579 extensions::ExtensionRegistry::Get(browser_context()) |
603 ->GetExtensionById(target_extension_id_, | 580 ->GetExtensionById(target_extension_id_, |
604 ExtensionRegistry::EVERYTHING); | 581 ExtensionRegistry::EVERYTHING); |
605 std::string error; | 582 std::string error; |
606 bool success = false; | 583 bool success = false; |
607 if (target_extension) { | 584 if (target_extension) { |
608 const ManagementAPIDelegate* delegate = ManagementAPI::GetFactoryInstance() | 585 const ManagementAPIDelegate* delegate = ManagementAPI::GetFactoryInstance() |
609 ->Get(browser_context()) | 586 ->Get(browser_context()) |
610 ->GetDelegate(); | 587 ->GetDelegate(); |
611 base::string16 utf16_error; | 588 base::string16 utf16_error; |
612 success = delegate->UninstallExtension( | 589 success = delegate->UninstallExtension( |
613 browser_context(), target_extension_id_, | 590 browser_context(), target_extension_id_, |
614 extensions::UNINSTALL_REASON_MANAGEMENT_API, | 591 extensions::UNINSTALL_REASON_MANAGEMENT_API, |
615 base::Bind(&base::DoNothing), &utf16_error); | 592 base::Bind(&base::DoNothing), &utf16_error); |
616 error = base::UTF16ToUTF8(utf16_error); | 593 error = base::UTF16ToUTF8(utf16_error); |
617 } else { | 594 } else { |
618 error = ErrorUtils::FormatErrorMessage(keys::kNoExtensionError, | 595 error = ErrorUtils::FormatErrorMessage(keys::kNoExtensionError, |
619 target_extension_id_); | 596 target_extension_id_); |
620 } | 597 } |
621 Finish(success, error); | 598 Finish(success, error); |
622 } | 599 } |
623 | 600 |
624 // static | |
625 void ManagementUninstallFunctionBase::SetAutoConfirmForTest( | |
626 bool should_proceed) { | |
627 auto_confirm_for_test = should_proceed ? PROCEED : ABORT; | |
628 } | |
629 | |
630 ManagementUninstallFunction::ManagementUninstallFunction() { | 601 ManagementUninstallFunction::ManagementUninstallFunction() { |
631 } | 602 } |
632 | 603 |
633 ManagementUninstallFunction::~ManagementUninstallFunction() { | 604 ManagementUninstallFunction::~ManagementUninstallFunction() { |
634 } | 605 } |
635 | 606 |
636 ExtensionFunction::ResponseAction ManagementUninstallFunction::Run() { | 607 ExtensionFunction::ResponseAction ManagementUninstallFunction::Run() { |
637 scoped_ptr<management::Uninstall::Params> params( | 608 scoped_ptr<management::Uninstall::Params> params( |
638 management::Uninstall::Params::Create(*args_)); | 609 management::Uninstall::Params::Create(*args_)); |
639 EXTENSION_FUNCTION_VALIDATE(params.get()); | 610 EXTENSION_FUNCTION_VALIDATE(params.get()); |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
927 ManagementAPI::GetFactoryInstance() { | 898 ManagementAPI::GetFactoryInstance() { |
928 return g_factory.Pointer(); | 899 return g_factory.Pointer(); |
929 } | 900 } |
930 | 901 |
931 void ManagementAPI::OnListenerAdded(const EventListenerInfo& details) { | 902 void ManagementAPI::OnListenerAdded(const EventListenerInfo& details) { |
932 management_event_router_.reset(new ManagementEventRouter(browser_context_)); | 903 management_event_router_.reset(new ManagementEventRouter(browser_context_)); |
933 EventRouter::Get(browser_context_)->UnregisterObserver(this); | 904 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
934 } | 905 } |
935 | 906 |
936 } // namespace extensions | 907 } // namespace extensions |
OLD | NEW |