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 "chrome/browser/extensions/api/developer_private/developer_private_api.
h" | 5 #include "chrome/browser/extensions/api/developer_private/developer_private_api.
h" |
6 | 6 |
7 #include "apps/app_load_service.h" | 7 #include "apps/app_load_service.h" |
8 #include "apps/app_restore_service.h" | 8 #include "apps/app_restore_service.h" |
9 #include "apps/app_window.h" | 9 #include "apps/app_window.h" |
10 #include "apps/app_window_registry.h" | 10 #include "apps/app_window_registry.h" |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 info->runtime_errors.push_back(make_linked_ptr(value.release())); | 387 info->runtime_errors.push_back(make_linked_ptr(value.release())); |
388 break; | 388 break; |
389 } | 389 } |
390 case ExtensionError::NUM_ERROR_TYPES: | 390 case ExtensionError::NUM_ERROR_TYPES: |
391 NOTREACHED(); | 391 NOTREACHED(); |
392 break; | 392 break; |
393 } | 393 } |
394 } | 394 } |
395 } | 395 } |
396 } else { | 396 } else { |
397 for (std::vector<extensions::InstallWarning>::const_iterator it = | 397 for (std::vector<InstallWarning>::const_iterator it = |
398 item.install_warnings().begin(); | 398 item.install_warnings().begin(); |
399 it != item.install_warnings().end(); | 399 it != item.install_warnings().end(); |
400 ++it) { | 400 ++it) { |
401 scoped_ptr<developer::InstallWarning> warning( | 401 scoped_ptr<developer::InstallWarning> warning( |
402 new developer::InstallWarning); | 402 new developer::InstallWarning); |
403 warning->message = it->message; | 403 warning->message = it->message; |
404 info->install_warnings.push_back(make_linked_ptr(warning.release())); | 404 info->install_warnings.push_back(make_linked_ptr(warning.release())); |
405 } | 405 } |
406 } | 406 } |
407 } | 407 } |
(...skipping 12 matching lines...) Expand all Loading... |
420 info->options_url.reset( | 420 info->options_url.reset( |
421 new std::string(ManifestURL::GetOptionsPage(&item).spec())); | 421 new std::string(ManifestURL::GetOptionsPage(&item).spec())); |
422 } | 422 } |
423 | 423 |
424 if (!ManifestURL::GetUpdateURL(&item).is_empty()) { | 424 if (!ManifestURL::GetUpdateURL(&item).is_empty()) { |
425 info->update_url.reset( | 425 info->update_url.reset( |
426 new std::string(ManifestURL::GetUpdateURL(&item).spec())); | 426 new std::string(ManifestURL::GetUpdateURL(&item).spec())); |
427 } | 427 } |
428 | 428 |
429 if (item.is_app()) { | 429 if (item.is_app()) { |
430 info->app_launch_url.reset(new std::string( | 430 info->app_launch_url.reset( |
431 extensions::AppLaunchInfo::GetFullLaunchURL(&item).spec())); | 431 new std::string(AppLaunchInfo::GetFullLaunchURL(&item).spec())); |
432 } | 432 } |
433 | 433 |
434 info->may_disable = system->management_policy()-> | 434 info->may_disable = system->management_policy()-> |
435 UserMayModifySettings(&item, NULL); | 435 UserMayModifySettings(&item, NULL); |
436 info->is_app = item.is_app(); | 436 info->is_app = item.is_app(); |
437 info->views = GetInspectablePagesForExtension(&item, item_is_enabled); | 437 info->views = GetInspectablePagesForExtension(&item, item_is_enabled); |
438 | 438 |
439 return info.Pass(); | 439 return info.Pass(); |
440 } | 440 } |
441 | 441 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 view->generated_background_page = generated_background_page; | 540 view->generated_background_page = generated_background_page; |
541 return view; | 541 return view; |
542 } | 542 } |
543 | 543 |
544 ItemInspectViewList DeveloperPrivateGetItemsInfoFunction:: | 544 ItemInspectViewList DeveloperPrivateGetItemsInfoFunction:: |
545 GetInspectablePagesForExtension( | 545 GetInspectablePagesForExtension( |
546 const Extension* extension, | 546 const Extension* extension, |
547 bool extension_is_enabled) { | 547 bool extension_is_enabled) { |
548 ItemInspectViewList result; | 548 ItemInspectViewList result; |
549 // Get the extension process's active views. | 549 // Get the extension process's active views. |
550 extensions::ProcessManager* process_manager = | 550 ProcessManager* process_manager = |
551 ExtensionSystem::Get(GetProfile())->process_manager(); | 551 ExtensionSystem::Get(GetProfile())->process_manager(); |
552 GetInspectablePagesForExtensionProcess( | 552 GetInspectablePagesForExtensionProcess( |
553 extension, | 553 extension, |
554 process_manager->GetRenderViewHostsForExtension(extension->id()), | 554 process_manager->GetRenderViewHostsForExtension(extension->id()), |
555 &result); | 555 &result); |
556 | 556 |
557 // Get app window views. | 557 // Get app window views. |
558 GetAppWindowPagesForExtensionProfile(extension, &result); | 558 GetAppWindowPagesForExtensionProfile(extension, &result); |
559 | 559 |
560 // Include a link to start the lazy background page, if applicable. | 560 // Include a link to start the lazy background page, if applicable. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 } | 597 } |
598 | 598 |
599 bool DeveloperPrivateGetItemsInfoFunction::RunAsync() { | 599 bool DeveloperPrivateGetItemsInfoFunction::RunAsync() { |
600 scoped_ptr<developer::GetItemsInfo::Params> params( | 600 scoped_ptr<developer::GetItemsInfo::Params> params( |
601 developer::GetItemsInfo::Params::Create(*args_)); | 601 developer::GetItemsInfo::Params::Create(*args_)); |
602 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 602 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
603 | 603 |
604 bool include_disabled = params->include_disabled; | 604 bool include_disabled = params->include_disabled; |
605 bool include_terminated = params->include_terminated; | 605 bool include_terminated = params->include_terminated; |
606 | 606 |
607 extensions::ExtensionSet items; | 607 ExtensionSet items; |
608 | 608 |
609 ExtensionRegistry* registry = ExtensionRegistry::Get(GetProfile()); | 609 ExtensionRegistry* registry = ExtensionRegistry::Get(GetProfile()); |
610 | 610 |
611 items.InsertAll(registry->enabled_extensions()); | 611 items.InsertAll(registry->enabled_extensions()); |
612 | 612 |
613 if (include_disabled) { | 613 if (include_disabled) { |
614 items.InsertAll(registry->disabled_extensions()); | 614 items.InsertAll(registry->disabled_extensions()); |
615 } | 615 } |
616 | 616 |
617 if (include_terminated) { | 617 if (include_terminated) { |
618 items.InsertAll(registry->terminated_extensions()); | 618 items.InsertAll(registry->terminated_extensions()); |
619 } | 619 } |
620 | 620 |
621 ExtensionService* service = | 621 ExtensionService* service = |
622 ExtensionSystem::Get(GetProfile())->extension_service(); | 622 ExtensionSystem::Get(GetProfile())->extension_service(); |
623 std::map<std::string, ExtensionResource> id_to_icon; | 623 std::map<std::string, ExtensionResource> id_to_icon; |
624 ItemInfoList item_list; | 624 ItemInfoList item_list; |
625 | 625 |
626 for (extensions::ExtensionSet::const_iterator iter = items.begin(); | 626 for (ExtensionSet::const_iterator iter = items.begin(); iter != items.end(); |
627 iter != items.end(); ++iter) { | 627 ++iter) { |
628 const Extension& item = *iter->get(); | 628 const Extension& item = *iter->get(); |
629 | 629 |
630 ExtensionResource item_resource = | 630 ExtensionResource item_resource = |
631 IconsInfo::GetIconResource(&item, | 631 IconsInfo::GetIconResource(&item, |
632 extension_misc::EXTENSION_ICON_MEDIUM, | 632 extension_misc::EXTENSION_ICON_MEDIUM, |
633 ExtensionIconSet::MATCH_BIGGER); | 633 ExtensionIconSet::MATCH_BIGGER); |
634 id_to_icon[item.id()] = item_resource; | 634 id_to_icon[item.id()] = item_resource; |
635 | 635 |
636 // Don't show component extensions and invisible apps. | 636 // Don't show component extensions and invisible apps. |
637 if (ui_util::ShouldNotBeVisible(&item, GetProfile())) | 637 if (ui_util::ShouldNotBeVisible(&item, GetProfile())) |
(...skipping 17 matching lines...) Expand all Loading... |
655 | 655 |
656 bool DeveloperPrivateAllowFileAccessFunction::RunSync() { | 656 bool DeveloperPrivateAllowFileAccessFunction::RunSync() { |
657 scoped_ptr<AllowFileAccess::Params> params( | 657 scoped_ptr<AllowFileAccess::Params> params( |
658 AllowFileAccess::Params::Create(*args_)); | 658 AllowFileAccess::Params::Create(*args_)); |
659 EXTENSION_FUNCTION_VALIDATE(params.get()); | 659 EXTENSION_FUNCTION_VALIDATE(params.get()); |
660 | 660 |
661 EXTENSION_FUNCTION_VALIDATE(user_gesture_); | 661 EXTENSION_FUNCTION_VALIDATE(user_gesture_); |
662 | 662 |
663 ExtensionSystem* system = ExtensionSystem::Get(GetProfile()); | 663 ExtensionSystem* system = ExtensionSystem::Get(GetProfile()); |
664 ManagementPolicy* management_policy = system->management_policy(); | 664 ManagementPolicy* management_policy = system->management_policy(); |
665 ExtensionService* service = GetProfile()->GetExtensionService(); | 665 const Extension* extension = |
666 const Extension* extension = service->GetInstalledExtension(params->item_id); | 666 ExtensionRegistry::Get(GetProfile()) |
| 667 ->GetExtensionById(params->item_id, ExtensionRegistry::EVERYTHING); |
667 bool result = true; | 668 bool result = true; |
668 | 669 |
669 if (!extension) { | 670 if (!extension) { |
670 result = false; | 671 result = false; |
671 } else if (!management_policy->UserMayModifySettings(extension, NULL)) { | 672 } else if (!management_policy->UserMayModifySettings(extension, NULL)) { |
672 LOG(ERROR) << "Attempt to change allow file access of an extension that " | 673 LOG(ERROR) << "Attempt to change allow file access of an extension that " |
673 << "non-usermanagable was made. Extension id : " | 674 << "non-usermanagable was made. Extension id : " |
674 << extension->id(); | 675 << extension->id(); |
675 result = false; | 676 result = false; |
676 } else { | 677 } else { |
677 util::SetAllowFileAccess(extension->id(), GetProfile(), params->allow); | 678 util::SetAllowFileAccess(extension->id(), GetProfile(), params->allow); |
678 result = true; | 679 result = true; |
679 } | 680 } |
680 | 681 |
681 return result; | 682 return result; |
682 } | 683 } |
683 | 684 |
684 DeveloperPrivateAllowFileAccessFunction:: | 685 DeveloperPrivateAllowFileAccessFunction:: |
685 ~DeveloperPrivateAllowFileAccessFunction() {} | 686 ~DeveloperPrivateAllowFileAccessFunction() {} |
686 | 687 |
687 bool DeveloperPrivateAllowIncognitoFunction::RunSync() { | 688 bool DeveloperPrivateAllowIncognitoFunction::RunSync() { |
688 scoped_ptr<AllowIncognito::Params> params( | 689 scoped_ptr<AllowIncognito::Params> params( |
689 AllowIncognito::Params::Create(*args_)); | 690 AllowIncognito::Params::Create(*args_)); |
690 EXTENSION_FUNCTION_VALIDATE(params.get()); | 691 EXTENSION_FUNCTION_VALIDATE(params.get()); |
691 | 692 |
692 ExtensionService* service = GetProfile()->GetExtensionService(); | 693 const Extension* extension = |
693 const Extension* extension = service->GetInstalledExtension(params->item_id); | 694 ExtensionRegistry::Get(GetProfile()) |
| 695 ->GetExtensionById(params->item_id, ExtensionRegistry::EVERYTHING); |
694 bool result = true; | 696 bool result = true; |
695 | 697 |
696 if (!extension) | 698 if (!extension) |
697 result = false; | 699 result = false; |
698 else | 700 else |
699 util::SetIsIncognitoEnabled(extension->id(), GetProfile(), params->allow); | 701 util::SetIsIncognitoEnabled(extension->id(), GetProfile(), params->allow); |
700 | 702 |
701 return result; | 703 return result; |
702 } | 704 } |
703 | 705 |
704 DeveloperPrivateAllowIncognitoFunction:: | 706 DeveloperPrivateAllowIncognitoFunction:: |
705 ~DeveloperPrivateAllowIncognitoFunction() {} | 707 ~DeveloperPrivateAllowIncognitoFunction() {} |
706 | 708 |
707 bool DeveloperPrivateReloadFunction::RunSync() { | 709 bool DeveloperPrivateReloadFunction::RunSync() { |
708 scoped_ptr<Reload::Params> params(Reload::Params::Create(*args_)); | 710 scoped_ptr<Reload::Params> params(Reload::Params::Create(*args_)); |
709 EXTENSION_FUNCTION_VALIDATE(params.get()); | 711 EXTENSION_FUNCTION_VALIDATE(params.get()); |
710 | 712 |
711 ExtensionService* service = GetProfile()->GetExtensionService(); | 713 ExtensionService* service = GetProfile()->GetExtensionService(); |
712 CHECK(!params->item_id.empty()); | 714 CHECK(!params->item_id.empty()); |
713 service->ReloadExtension(params->item_id); | 715 service->ReloadExtension(params->item_id); |
714 return true; | 716 return true; |
715 } | 717 } |
716 | 718 |
717 bool DeveloperPrivateShowPermissionsDialogFunction::RunSync() { | 719 bool DeveloperPrivateShowPermissionsDialogFunction::RunSync() { |
718 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id_)); | 720 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id_)); |
719 ExtensionService* service = GetProfile()->GetExtensionService(); | |
720 CHECK(!extension_id_.empty()); | 721 CHECK(!extension_id_.empty()); |
721 AppWindowRegistry* registry = AppWindowRegistry::Get(GetProfile()); | 722 AppWindowRegistry* registry = AppWindowRegistry::Get(GetProfile()); |
722 DCHECK(registry); | 723 DCHECK(registry); |
723 AppWindow* app_window = | 724 AppWindow* app_window = |
724 registry->GetAppWindowForRenderViewHost(render_view_host()); | 725 registry->GetAppWindowForRenderViewHost(render_view_host()); |
725 prompt_.reset(new ExtensionInstallPrompt(app_window->web_contents())); | 726 prompt_.reset(new ExtensionInstallPrompt(app_window->web_contents())); |
726 const Extension* extension = service->GetInstalledExtension(extension_id_); | 727 const Extension* extension = |
| 728 ExtensionRegistry::Get(GetProfile()) |
| 729 ->GetExtensionById(extension_id_, ExtensionRegistry::EVERYTHING); |
727 | 730 |
728 if (!extension) | 731 if (!extension) |
729 return false; | 732 return false; |
730 | 733 |
731 // Released by InstallUIAbort or InstallUIProceed. | 734 // Released by InstallUIAbort or InstallUIProceed. |
732 AddRef(); | 735 AddRef(); |
733 std::vector<base::FilePath> retained_file_paths; | 736 std::vector<base::FilePath> retained_file_paths; |
734 if (extension->HasAPIPermission(extensions::APIPermission::kFileSystem)) { | 737 if (extension->HasAPIPermission(APIPermission::kFileSystem)) { |
735 std::vector<apps::SavedFileEntry> retained_file_entries = | 738 std::vector<apps::SavedFileEntry> retained_file_entries = |
736 apps::SavedFilesService::Get(GetProfile()) | 739 apps::SavedFilesService::Get(GetProfile()) |
737 ->GetAllFileEntries(extension_id_); | 740 ->GetAllFileEntries(extension_id_); |
738 for (size_t i = 0; i < retained_file_entries.size(); i++) { | 741 for (size_t i = 0; i < retained_file_entries.size(); i++) { |
739 retained_file_paths.push_back(retained_file_entries[i].path); | 742 retained_file_paths.push_back(retained_file_entries[i].path); |
740 } | 743 } |
741 } | 744 } |
742 prompt_->ReviewPermissions(this, extension, retained_file_paths); | 745 prompt_->ReviewPermissions(this, extension, retained_file_paths); |
743 return true; | 746 return true; |
744 } | 747 } |
(...skipping 25 matching lines...) Expand all Loading... |
770 ~DeveloperPrivateShowPermissionsDialogFunction() {} | 773 ~DeveloperPrivateShowPermissionsDialogFunction() {} |
771 | 774 |
772 DeveloperPrivateEnableFunction::DeveloperPrivateEnableFunction() {} | 775 DeveloperPrivateEnableFunction::DeveloperPrivateEnableFunction() {} |
773 | 776 |
774 bool DeveloperPrivateEnableFunction::RunSync() { | 777 bool DeveloperPrivateEnableFunction::RunSync() { |
775 scoped_ptr<Enable::Params> params(Enable::Params::Create(*args_)); | 778 scoped_ptr<Enable::Params> params(Enable::Params::Create(*args_)); |
776 EXTENSION_FUNCTION_VALIDATE(params.get()); | 779 EXTENSION_FUNCTION_VALIDATE(params.get()); |
777 | 780 |
778 std::string extension_id = params->item_id; | 781 std::string extension_id = params->item_id; |
779 | 782 |
780 ExtensionSystem* system = ExtensionSystem::Get(GetProfile()); | 783 const Extension* extension = |
781 ManagementPolicy* policy = system->management_policy(); | 784 ExtensionRegistry::Get(GetProfile()) |
782 ExtensionService* service = GetProfile()->GetExtensionService(); | 785 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); |
783 | |
784 const Extension* extension = service->GetInstalledExtension(extension_id); | |
785 if (!extension) { | 786 if (!extension) { |
786 LOG(ERROR) << "Did not find extension with id " << extension_id; | 787 LOG(ERROR) << "Did not find extension with id " << extension_id; |
787 return false; | 788 return false; |
788 } | 789 } |
| 790 ExtensionSystem* system = ExtensionSystem::Get(GetProfile()); |
| 791 ManagementPolicy* policy = system->management_policy(); |
789 bool enable = params->enable; | 792 bool enable = params->enable; |
790 if (!policy->UserMayModifySettings(extension, NULL) || | 793 if (!policy->UserMayModifySettings(extension, NULL) || |
791 (!enable && policy->MustRemainEnabled(extension, NULL)) || | 794 (!enable && policy->MustRemainEnabled(extension, NULL)) || |
792 (enable && policy->MustRemainDisabled(extension, NULL, NULL))) { | 795 (enable && policy->MustRemainDisabled(extension, NULL, NULL))) { |
793 LOG(ERROR) << "Attempt to change enable state denied by management policy. " | 796 LOG(ERROR) << "Attempt to change enable state denied by management policy. " |
794 << "Extension id: " << extension_id.c_str(); | 797 << "Extension id: " << extension_id.c_str(); |
795 return false; | 798 return false; |
796 } | 799 } |
797 | 800 |
| 801 ExtensionService* service = system->extension_service(); |
798 if (enable) { | 802 if (enable) { |
799 ExtensionPrefs* prefs = ExtensionPrefs::Get(GetProfile()); | 803 ExtensionPrefs* prefs = ExtensionPrefs::Get(GetProfile()); |
800 if (prefs->DidExtensionEscalatePermissions(extension_id)) { | 804 if (prefs->DidExtensionEscalatePermissions(extension_id)) { |
801 AppWindowRegistry* registry = AppWindowRegistry::Get(GetProfile()); | 805 AppWindowRegistry* registry = AppWindowRegistry::Get(GetProfile()); |
802 CHECK(registry); | 806 CHECK(registry); |
803 AppWindow* app_window = | 807 AppWindow* app_window = |
804 registry->GetAppWindowForRenderViewHost(render_view_host()); | 808 registry->GetAppWindowForRenderViewHost(render_view_host()); |
805 if (!app_window) { | 809 if (!app_window) { |
806 return false; | 810 return false; |
807 } | 811 } |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1355 } | 1359 } |
1356 | 1360 |
1357 error_ui_util::HandleOpenDevTools(dict); | 1361 error_ui_util::HandleOpenDevTools(dict); |
1358 | 1362 |
1359 return true; | 1363 return true; |
1360 } | 1364 } |
1361 | 1365 |
1362 } // namespace api | 1366 } // namespace api |
1363 | 1367 |
1364 } // namespace extensions | 1368 } // namespace extensions |
OLD | NEW |