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 kSupervisedUserError[] = |
| 94 "Supervised users cannot modify extension settings."; |
| 95 const char kCannotModifyPolicyExtensionError[] = |
| 96 "Cannot modify the extension by policy."; |
| 97 const char kRequiresUserGestureError[] = |
| 98 "This action requires a user gesture."; |
93 | 99 |
94 const char kUnpackedAppsFolder[] = "apps_target"; | 100 const char kUnpackedAppsFolder[] = "apps_target"; |
95 | 101 |
96 ExtensionService* GetExtensionService(Profile* profile) { | 102 ExtensionService* GetExtensionService(content::BrowserContext* context) { |
97 return ExtensionSystem::Get(profile)->extension_service(); | 103 return ExtensionSystem::Get(context)->extension_service(); |
98 } | 104 } |
99 | 105 |
100 ExtensionUpdater* GetExtensionUpdater(Profile* profile) { | 106 ExtensionUpdater* GetExtensionUpdater(Profile* profile) { |
101 return GetExtensionService(profile)->updater(); | 107 return GetExtensionService(profile)->updater(); |
102 } | 108 } |
103 | 109 |
104 GURL GetImageURLFromData(const std::string& contents) { | 110 GURL GetImageURLFromData(const std::string& contents) { |
105 std::string contents_base64; | 111 std::string contents_base64; |
106 base::Base64Encode(contents, &contents_base64); | 112 base::Base64Encode(contents, &contents_base64); |
107 | 113 |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 if (!EventRouter::Get(profile_)->HasEventListener( | 331 if (!EventRouter::Get(profile_)->HasEventListener( |
326 developer_private::OnItemStateChanged::kEventName)) { | 332 developer_private::OnItemStateChanged::kEventName)) { |
327 developer_private_event_router_.reset(NULL); | 333 developer_private_event_router_.reset(NULL); |
328 } else { | 334 } else { |
329 developer_private_event_router_->RemoveExtensionId(details.extension_id); | 335 developer_private_event_router_->RemoveExtensionId(details.extension_id); |
330 } | 336 } |
331 } | 337 } |
332 | 338 |
333 namespace api { | 339 namespace api { |
334 | 340 |
| 341 DeveloperPrivateAPIFunction::~DeveloperPrivateAPIFunction() { |
| 342 } |
| 343 |
| 344 const Extension* DeveloperPrivateAPIFunction::GetExtensionById( |
| 345 const std::string& id) { |
| 346 return ExtensionRegistry::Get(browser_context())->GetExtensionById( |
| 347 id, ExtensionRegistry::EVERYTHING); |
| 348 } |
| 349 |
335 bool DeveloperPrivateAutoUpdateFunction::RunSync() { | 350 bool DeveloperPrivateAutoUpdateFunction::RunSync() { |
336 ExtensionUpdater* updater = GetExtensionUpdater(GetProfile()); | 351 ExtensionUpdater* updater = GetExtensionUpdater(GetProfile()); |
337 if (updater) | 352 if (updater) |
338 updater->CheckNow(ExtensionUpdater::CheckParams()); | 353 updater->CheckNow(ExtensionUpdater::CheckParams()); |
339 SetResult(new base::FundamentalValue(true)); | 354 SetResult(new base::FundamentalValue(true)); |
340 return true; | 355 return true; |
341 } | 356 } |
342 | 357 |
343 DeveloperPrivateAutoUpdateFunction::~DeveloperPrivateAutoUpdateFunction() {} | 358 DeveloperPrivateAutoUpdateFunction::~DeveloperPrivateAutoUpdateFunction() {} |
344 | 359 |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 base::Bind(&DeveloperPrivateGetItemsInfoFunction::GetIconsOnFileThread, | 678 base::Bind(&DeveloperPrivateGetItemsInfoFunction::GetIconsOnFileThread, |
664 this, | 679 this, |
665 item_list, | 680 item_list, |
666 id_to_icon)); | 681 id_to_icon)); |
667 | 682 |
668 return true; | 683 return true; |
669 } | 684 } |
670 | 685 |
671 DeveloperPrivateGetItemsInfoFunction::~DeveloperPrivateGetItemsInfoFunction() {} | 686 DeveloperPrivateGetItemsInfoFunction::~DeveloperPrivateGetItemsInfoFunction() {} |
672 | 687 |
673 bool DeveloperPrivateAllowFileAccessFunction::RunSync() { | 688 ExtensionFunction::ResponseAction |
| 689 DeveloperPrivateAllowFileAccessFunction::Run() { |
674 scoped_ptr<AllowFileAccess::Params> params( | 690 scoped_ptr<AllowFileAccess::Params> params( |
675 AllowFileAccess::Params::Create(*args_)); | 691 AllowFileAccess::Params::Create(*args_)); |
676 EXTENSION_FUNCTION_VALIDATE(params.get()); | 692 EXTENSION_FUNCTION_VALIDATE(params.get()); |
677 | 693 |
678 EXTENSION_FUNCTION_VALIDATE(user_gesture_); | 694 const Extension* extension = GetExtensionById(params->extension_id); |
679 | 695 |
680 ExtensionSystem* system = ExtensionSystem::Get(GetProfile()); | 696 if (!extension) |
681 ManagementPolicy* management_policy = system->management_policy(); | 697 return RespondNow(Error(kNoSuchExtensionError)); |
682 const Extension* extension = | |
683 ExtensionRegistry::Get(GetProfile()) | |
684 ->GetExtensionById(params->extension_id, | |
685 ExtensionRegistry::EVERYTHING); | |
686 bool result = true; | |
687 | 698 |
688 if (!extension) { | 699 if (!user_gesture()) |
689 result = false; | 700 return RespondNow(Error(kRequiresUserGestureError)); |
690 } else if (!management_policy->UserMayModifySettings(extension, NULL)) { | 701 |
| 702 if (util::IsExtensionSupervised( |
| 703 extension, Profile::FromBrowserContext(browser_context()))) { |
| 704 return RespondNow(Error(kSupervisedUserError)); |
| 705 } |
| 706 |
| 707 ManagementPolicy* management_policy = |
| 708 ExtensionSystem::Get(browser_context())->management_policy(); |
| 709 if (!management_policy->UserMayModifySettings(extension, nullptr)) { |
691 LOG(ERROR) << "Attempt to change allow file access of an extension that " | 710 LOG(ERROR) << "Attempt to change allow file access of an extension that " |
692 << "non-usermanagable was made. Extension id : " | 711 << "non-usermanagable was made. Extension id : " |
693 << extension->id(); | 712 << extension->id(); |
694 result = false; | 713 return RespondNow(Error(kCannotModifyPolicyExtensionError)); |
695 } else { | |
696 util::SetAllowFileAccess(extension->id(), GetProfile(), params->allow); | |
697 result = true; | |
698 } | 714 } |
699 | 715 |
700 return result; | 716 util::SetAllowFileAccess(extension->id(), browser_context(), params->allow); |
| 717 return RespondNow(NoArguments()); |
701 } | 718 } |
702 | 719 |
703 DeveloperPrivateAllowFileAccessFunction:: | 720 DeveloperPrivateAllowFileAccessFunction:: |
704 ~DeveloperPrivateAllowFileAccessFunction() {} | 721 ~DeveloperPrivateAllowFileAccessFunction() {} |
705 | 722 |
706 ExtensionFunction::ResponseAction | 723 ExtensionFunction::ResponseAction |
707 DeveloperPrivateAllowIncognitoFunction::Run() { | 724 DeveloperPrivateAllowIncognitoFunction::Run() { |
708 scoped_ptr<AllowIncognito::Params> params( | 725 scoped_ptr<AllowIncognito::Params> params( |
709 AllowIncognito::Params::Create(*args_)); | 726 AllowIncognito::Params::Create(*args_)); |
710 EXTENSION_FUNCTION_VALIDATE(params.get()); | 727 EXTENSION_FUNCTION_VALIDATE(params.get()); |
711 | 728 |
712 const Extension* extension = | 729 const Extension* extension = GetExtensionById(params->extension_id); |
713 ExtensionRegistry::Get(browser_context()) | |
714 ->GetExtensionById(params->extension_id, | |
715 ExtensionRegistry::EVERYTHING); | |
716 | 730 |
717 if (!extension) | 731 if (!extension) |
718 return RespondNow(Error(kNoSuchExtensionError)); | 732 return RespondNow(Error(kNoSuchExtensionError)); |
719 | 733 |
| 734 if (!user_gesture()) |
| 735 return RespondNow(Error(kRequiresUserGestureError)); |
| 736 |
720 // Should this take into account policy settings? | 737 // Should this take into account policy settings? |
721 util::SetIsIncognitoEnabled( | 738 util::SetIsIncognitoEnabled( |
722 extension->id(), browser_context(), params->allow); | 739 extension->id(), browser_context(), params->allow); |
723 | 740 |
724 return RespondNow(NoArguments()); | 741 return RespondNow(NoArguments()); |
725 } | 742 } |
726 | 743 |
727 DeveloperPrivateAllowIncognitoFunction:: | 744 DeveloperPrivateAllowIncognitoFunction:: |
728 ~DeveloperPrivateAllowIncognitoFunction() {} | 745 ~DeveloperPrivateAllowIncognitoFunction() {} |
729 | 746 |
730 bool DeveloperPrivateReloadFunction::RunSync() { | 747 ExtensionFunction::ResponseAction DeveloperPrivateReloadFunction::Run() { |
731 scoped_ptr<Reload::Params> params(Reload::Params::Create(*args_)); | 748 scoped_ptr<Reload::Params> params(Reload::Params::Create(*args_)); |
732 EXTENSION_FUNCTION_VALIDATE(params.get()); | 749 EXTENSION_FUNCTION_VALIDATE(params.get()); |
733 | 750 |
734 CHECK(!params->extension_id.empty()); | 751 const Extension* extension = GetExtensionById(params->extension_id); |
735 ExtensionService* service = GetExtensionService(GetProfile()); | 752 if (!extension) |
736 service->ReloadExtension(params->extension_id); | 753 return RespondNow(Error(kNoSuchExtensionError)); |
737 return true; | 754 |
| 755 bool fail_quietly = params->options && params->options->fail_quietly; |
| 756 |
| 757 ExtensionService* service = GetExtensionService(browser_context()); |
| 758 if (fail_quietly) |
| 759 service->ReloadExtensionWithQuietFailure(params->extension_id); |
| 760 else |
| 761 service->ReloadExtension(params->extension_id); |
| 762 |
| 763 // TODO(devlin): We shouldn't return until the extension has finished trying |
| 764 // to reload (and then we could also return the error). |
| 765 return RespondNow(NoArguments()); |
738 } | 766 } |
739 | 767 |
740 bool DeveloperPrivateShowPermissionsDialogFunction::RunSync() { | 768 bool DeveloperPrivateShowPermissionsDialogFunction::RunSync() { |
741 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id_)); | 769 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id_)); |
742 CHECK(!extension_id_.empty()); | 770 CHECK(!extension_id_.empty()); |
743 AppWindowRegistry* registry = AppWindowRegistry::Get(GetProfile()); | 771 AppWindowRegistry* registry = AppWindowRegistry::Get(GetProfile()); |
744 DCHECK(registry); | 772 DCHECK(registry); |
745 AppWindow* app_window = | 773 AppWindow* app_window = |
746 registry->GetAppWindowForRenderViewHost(render_view_host()); | 774 registry->GetAppWindowForRenderViewHost(render_view_host()); |
747 prompt_.reset(new ExtensionInstallPrompt(app_window->web_contents())); | 775 prompt_.reset(new ExtensionInstallPrompt(app_window->web_contents())); |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1325 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0u, &dict)); | 1353 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0u, &dict)); |
1326 | 1354 |
1327 error_ui_util::HandleOpenDevTools(dict); | 1355 error_ui_util::HandleOpenDevTools(dict); |
1328 | 1356 |
1329 return true; | 1357 return true; |
1330 } | 1358 } |
1331 | 1359 |
1332 } // namespace api | 1360 } // namespace api |
1333 | 1361 |
1334 } // namespace extensions | 1362 } // namespace extensions |
OLD | NEW |