Chromium Code Reviews| 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/saved_files_service.h" | 8 #include "apps/saved_files_service.h" |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 | 83 |
| 84 using content::RenderViewHost; | 84 using content::RenderViewHost; |
| 85 | 85 |
| 86 namespace extensions { | 86 namespace extensions { |
| 87 | 87 |
| 88 namespace developer_private = api::developer_private; | 88 namespace developer_private = api::developer_private; |
| 89 | 89 |
| 90 namespace { | 90 namespace { |
| 91 | 91 |
| 92 const char kNoSuchExtensionError[] = "No such extension."; | 92 const char kNoSuchExtensionError[] = "No such extension."; |
| 93 const char kCannotModifyPolicyExtensionError[] = | |
| 94 "Cannot modify the extension by policy."; | |
| 95 const char kRequiresUserGestureError[] = | |
| 96 "This action requires a user gesture."; | |
| 93 | 97 |
| 94 const char kUnpackedAppsFolder[] = "apps_target"; | 98 const char kUnpackedAppsFolder[] = "apps_target"; |
| 95 | 99 |
| 96 ExtensionService* GetExtensionService(Profile* profile) { | 100 ExtensionService* GetExtensionService(content::BrowserContext* context) { |
| 97 return ExtensionSystem::Get(profile)->extension_service(); | 101 return ExtensionSystem::Get(context)->extension_service(); |
| 98 } | 102 } |
| 99 | 103 |
| 100 ExtensionUpdater* GetExtensionUpdater(Profile* profile) { | 104 ExtensionUpdater* GetExtensionUpdater(Profile* profile) { |
| 101 return GetExtensionService(profile)->updater(); | 105 return GetExtensionService(profile)->updater(); |
| 102 } | 106 } |
| 103 | 107 |
| 104 GURL GetImageURLFromData(const std::string& contents) { | 108 GURL GetImageURLFromData(const std::string& contents) { |
| 105 std::string contents_base64; | 109 std::string contents_base64; |
| 106 base::Base64Encode(contents, &contents_base64); | 110 base::Base64Encode(contents, &contents_base64); |
| 107 | 111 |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 664 base::Bind(&DeveloperPrivateGetItemsInfoFunction::GetIconsOnFileThread, | 668 base::Bind(&DeveloperPrivateGetItemsInfoFunction::GetIconsOnFileThread, |
| 665 this, | 669 this, |
| 666 item_list, | 670 item_list, |
| 667 id_to_icon)); | 671 id_to_icon)); |
| 668 | 672 |
| 669 return true; | 673 return true; |
| 670 } | 674 } |
| 671 | 675 |
| 672 DeveloperPrivateGetItemsInfoFunction::~DeveloperPrivateGetItemsInfoFunction() {} | 676 DeveloperPrivateGetItemsInfoFunction::~DeveloperPrivateGetItemsInfoFunction() {} |
| 673 | 677 |
| 674 bool DeveloperPrivateAllowFileAccessFunction::RunSync() { | 678 ExtensionFunction::ResponseAction |
| 679 DeveloperPrivateAllowFileAccessFunction::Run() { | |
| 675 scoped_ptr<AllowFileAccess::Params> params( | 680 scoped_ptr<AllowFileAccess::Params> params( |
| 676 AllowFileAccess::Params::Create(*args_)); | 681 AllowFileAccess::Params::Create(*args_)); |
| 677 EXTENSION_FUNCTION_VALIDATE(params.get()); | 682 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 678 | 683 |
| 679 EXTENSION_FUNCTION_VALIDATE(user_gesture_); | 684 const Extension* extension = |
| 685 ExtensionRegistry::Get(browser_context()) | |
| 686 ->GetExtensionById(params->item_id, ExtensionRegistry::EVERYTHING); | |
| 680 | 687 |
| 681 ExtensionSystem* system = ExtensionSystem::Get(GetProfile()); | 688 if (!extension) |
| 682 ManagementPolicy* management_policy = system->management_policy(); | 689 return RespondNow(Error(kNoSuchExtensionError)); |
| 683 const Extension* extension = | |
| 684 ExtensionRegistry::Get(GetProfile()) | |
| 685 ->GetExtensionById(params->item_id, ExtensionRegistry::EVERYTHING); | |
| 686 bool result = true; | |
| 687 | 690 |
| 688 if (!extension) { | 691 if (!user_gesture()) |
| 689 result = false; | 692 return RespondNow(Error(kRequiresUserGestureError)); |
| 690 } else if (!management_policy->UserMayModifySettings(extension, NULL)) { | 693 |
| 694 ManagementPolicy* management_policy = | |
| 695 ExtensionSystem::Get(browser_context())->management_policy(); | |
| 696 if (!management_policy->UserMayModifySettings(extension, nullptr)) { | |
| 691 LOG(ERROR) << "Attempt to change allow file access of an extension that " | 697 LOG(ERROR) << "Attempt to change allow file access of an extension that " |
| 692 << "non-usermanagable was made. Extension id : " | 698 << "non-usermanagable was made. Extension id : " |
| 693 << extension->id(); | 699 << extension->id(); |
| 694 result = false; | 700 return RespondNow(Error(kCannotModifyPolicyExtensionError)); |
| 695 } else { | |
| 696 util::SetAllowFileAccess(extension->id(), GetProfile(), params->allow); | |
| 697 result = true; | |
| 698 } | 701 } |
| 699 | 702 |
| 700 return result; | 703 util::SetAllowFileAccess(extension->id(), browser_context(), params->allow); |
| 704 return RespondNow(NoArguments()); | |
| 701 } | 705 } |
| 702 | 706 |
| 703 DeveloperPrivateAllowFileAccessFunction:: | 707 DeveloperPrivateAllowFileAccessFunction:: |
| 704 ~DeveloperPrivateAllowFileAccessFunction() {} | 708 ~DeveloperPrivateAllowFileAccessFunction() {} |
| 705 | 709 |
| 706 ExtensionFunction::ResponseAction | 710 ExtensionFunction::ResponseAction |
| 707 DeveloperPrivateAllowIncognitoFunction::Run() { | 711 DeveloperPrivateAllowIncognitoFunction::Run() { |
| 708 scoped_ptr<AllowIncognito::Params> params( | 712 scoped_ptr<AllowIncognito::Params> params( |
| 709 AllowIncognito::Params::Create(*args_)); | 713 AllowIncognito::Params::Create(*args_)); |
| 710 EXTENSION_FUNCTION_VALIDATE(params.get()); | 714 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 711 | 715 |
| 712 const Extension* extension = | 716 const Extension* extension = |
| 713 ExtensionRegistry::Get(browser_context()) | 717 ExtensionRegistry::Get(browser_context()) |
| 714 ->GetExtensionById(params->item_id, ExtensionRegistry::EVERYTHING); | 718 ->GetExtensionById(params->item_id, ExtensionRegistry::EVERYTHING); |
| 715 | 719 |
| 716 if (!extension) | 720 if (!extension) |
| 717 return RespondNow(Error(kNoSuchExtensionError)); | 721 return RespondNow(Error(kNoSuchExtensionError)); |
| 718 | 722 |
| 723 if (!user_gesture()) | |
|
not at google - send to devlin
2015/02/26 00:56:47
... drive by I guess?
Devlin
2015/02/26 01:14:03
Yes. :)
| |
| 724 return RespondNow(Error(kRequiresUserGestureError)); | |
| 725 | |
| 719 // Should this take into account policy settings? | 726 // Should this take into account policy settings? |
| 720 util::SetIsIncognitoEnabled( | 727 util::SetIsIncognitoEnabled( |
| 721 extension->id(), browser_context(), params->allow); | 728 extension->id(), browser_context(), params->allow); |
| 722 | 729 |
| 723 return RespondNow(NoArguments()); | 730 return RespondNow(NoArguments()); |
| 724 } | 731 } |
| 725 | 732 |
| 726 DeveloperPrivateAllowIncognitoFunction:: | 733 DeveloperPrivateAllowIncognitoFunction:: |
| 727 ~DeveloperPrivateAllowIncognitoFunction() {} | 734 ~DeveloperPrivateAllowIncognitoFunction() {} |
| 728 | 735 |
| 729 bool DeveloperPrivateReloadFunction::RunSync() { | 736 ExtensionFunction::ResponseAction DeveloperPrivateReloadFunction::Run() { |
| 730 scoped_ptr<Reload::Params> params(Reload::Params::Create(*args_)); | 737 scoped_ptr<Reload::Params> params(Reload::Params::Create(*args_)); |
| 731 EXTENSION_FUNCTION_VALIDATE(params.get()); | 738 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 732 | 739 |
| 733 CHECK(!params->item_id.empty()); | 740 const Extension* extension = |
| 734 ExtensionService* service = GetExtensionService(GetProfile()); | 741 ExtensionRegistry::Get(browser_context()) |
| 735 service->ReloadExtension(params->item_id); | 742 ->GetExtensionById(params->item_id, ExtensionRegistry::EVERYTHING); |
|
not at google - send to devlin
2015/02/26 00:56:47
Can we pull this huge 3-line "get me installed ext
Devlin
2015/02/26 01:14:03
Was meaning to do that for awhile. Done.
| |
| 736 return true; | 743 if (!extension) |
| 744 return RespondNow(Error(kNoSuchExtensionError)); | |
| 745 | |
| 746 // Default to failing "noisily". | |
|
not at google - send to devlin
2015/02/26 00:56:47
comment unnecssary
Devlin
2015/02/26 01:14:03
Done.
| |
| 747 bool fail_quietly = | |
| 748 params->options.get() && | |
| 749 params->options->fail_quietly.get() && | |
| 750 *params->options->fail_quietly; | |
| 751 | |
| 752 ExtensionService* service = GetExtensionService(browser_context()); | |
| 753 if (fail_quietly) | |
| 754 service->ReloadExtensionWithQuietFailure(params->item_id); | |
| 755 else | |
| 756 service->ReloadExtension(params->item_id); | |
| 757 | |
| 758 // TODO(devlin): We shouldn't return until the extension has finished trying | |
| 759 // to reload (and then we could also return the error). | |
| 760 return RespondNow(NoArguments()); | |
| 737 } | 761 } |
| 738 | 762 |
| 739 bool DeveloperPrivateShowPermissionsDialogFunction::RunSync() { | 763 bool DeveloperPrivateShowPermissionsDialogFunction::RunSync() { |
| 740 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id_)); | 764 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id_)); |
| 741 CHECK(!extension_id_.empty()); | 765 CHECK(!extension_id_.empty()); |
| 742 AppWindowRegistry* registry = AppWindowRegistry::Get(GetProfile()); | 766 AppWindowRegistry* registry = AppWindowRegistry::Get(GetProfile()); |
| 743 DCHECK(registry); | 767 DCHECK(registry); |
| 744 AppWindow* app_window = | 768 AppWindow* app_window = |
| 745 registry->GetAppWindowForRenderViewHost(render_view_host()); | 769 registry->GetAppWindowForRenderViewHost(render_view_host()); |
| 746 prompt_.reset(new ExtensionInstallPrompt(app_window->web_contents())); | 770 prompt_.reset(new ExtensionInstallPrompt(app_window->web_contents())); |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1398 } | 1422 } |
| 1399 | 1423 |
| 1400 error_ui_util::HandleOpenDevTools(dict); | 1424 error_ui_util::HandleOpenDevTools(dict); |
| 1401 | 1425 |
| 1402 return true; | 1426 return true; |
| 1403 } | 1427 } |
| 1404 | 1428 |
| 1405 } // namespace api | 1429 } // namespace api |
| 1406 | 1430 |
| 1407 } // namespace extensions | 1431 } // namespace extensions |
| OLD | NEW |