| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 scoped_ptr<Event> event(new Event( | 156 scoped_ptr<Event> event(new Event( |
| 157 developer_private::OnItemStateChanged::kEventName, args.Pass())); | 157 developer_private::OnItemStateChanged::kEventName, args.Pass())); |
| 158 EventRouter::Get(browser_context)->BroadcastEvent(event.Pass()); | 158 EventRouter::Get(browser_context)->BroadcastEvent(event.Pass()); |
| 159 } | 159 } |
| 160 | 160 |
| 161 } // namespace | 161 } // namespace |
| 162 | 162 |
| 163 namespace AllowFileAccess = api::developer_private::AllowFileAccess; | 163 namespace AllowFileAccess = api::developer_private::AllowFileAccess; |
| 164 namespace AllowIncognito = api::developer_private::AllowIncognito; | 164 namespace AllowIncognito = api::developer_private::AllowIncognito; |
| 165 namespace ChoosePath = api::developer_private::ChoosePath; | 165 namespace ChoosePath = api::developer_private::ChoosePath; |
| 166 namespace Enable = api::developer_private::Enable; | |
| 167 namespace GetItemsInfo = api::developer_private::GetItemsInfo; | 166 namespace GetItemsInfo = api::developer_private::GetItemsInfo; |
| 168 namespace Inspect = api::developer_private::Inspect; | 167 namespace Inspect = api::developer_private::Inspect; |
| 169 namespace PackDirectory = api::developer_private::PackDirectory; | 168 namespace PackDirectory = api::developer_private::PackDirectory; |
| 170 namespace Reload = api::developer_private::Reload; | 169 namespace Reload = api::developer_private::Reload; |
| 171 | 170 |
| 172 static base::LazyInstance<BrowserContextKeyedAPIFactory<DeveloperPrivateAPI> > | 171 static base::LazyInstance<BrowserContextKeyedAPIFactory<DeveloperPrivateAPI> > |
| 173 g_factory = LAZY_INSTANCE_INITIALIZER; | 172 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 174 | 173 |
| 175 // static | 174 // static |
| 176 BrowserContextKeyedAPIFactory<DeveloperPrivateAPI>* | 175 BrowserContextKeyedAPIFactory<DeveloperPrivateAPI>* |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 SendResponse(true); | 789 SendResponse(true); |
| 791 Release(); | 790 Release(); |
| 792 } | 791 } |
| 793 | 792 |
| 794 DeveloperPrivateShowPermissionsDialogFunction:: | 793 DeveloperPrivateShowPermissionsDialogFunction:: |
| 795 DeveloperPrivateShowPermissionsDialogFunction() {} | 794 DeveloperPrivateShowPermissionsDialogFunction() {} |
| 796 | 795 |
| 797 DeveloperPrivateShowPermissionsDialogFunction:: | 796 DeveloperPrivateShowPermissionsDialogFunction:: |
| 798 ~DeveloperPrivateShowPermissionsDialogFunction() {} | 797 ~DeveloperPrivateShowPermissionsDialogFunction() {} |
| 799 | 798 |
| 800 DeveloperPrivateEnableFunction::DeveloperPrivateEnableFunction() {} | |
| 801 | |
| 802 bool DeveloperPrivateEnableFunction::RunSync() { | |
| 803 scoped_ptr<Enable::Params> params(Enable::Params::Create(*args_)); | |
| 804 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 805 | |
| 806 const std::string& extension_id = params->item_id; | |
| 807 | |
| 808 const Extension* extension = | |
| 809 ExtensionRegistry::Get(GetProfile())->GetExtensionById( | |
| 810 extension_id, ExtensionRegistry::EVERYTHING); | |
| 811 if (!extension) { | |
| 812 LOG(ERROR) << "Did not find extension with id " << extension_id; | |
| 813 return false; | |
| 814 } | |
| 815 ExtensionSystem* system = ExtensionSystem::Get(GetProfile()); | |
| 816 ManagementPolicy* policy = system->management_policy(); | |
| 817 bool enable = params->enable; | |
| 818 if (!policy->UserMayModifySettings(extension, nullptr) || | |
| 819 (!enable && policy->MustRemainEnabled(extension, nullptr)) || | |
| 820 (enable && policy->MustRemainDisabled(extension, nullptr, nullptr))) { | |
| 821 LOG(ERROR) << "Attempt to change enable state denied by management policy. " | |
| 822 << "Extension id: " << extension_id; | |
| 823 return false; | |
| 824 } | |
| 825 | |
| 826 ExtensionService* service = system->extension_service(); | |
| 827 if (enable) { | |
| 828 ExtensionPrefs* prefs = ExtensionPrefs::Get(GetProfile()); | |
| 829 if (prefs->DidExtensionEscalatePermissions(extension_id)) { | |
| 830 // If the extension escalated permissions, we have to show a dialog. | |
| 831 content::WebContents* web_contents = GetSenderWebContents(); | |
| 832 if (!web_contents) | |
| 833 return false; | |
| 834 | |
| 835 ShowExtensionDisabledDialog(service, web_contents, extension); | |
| 836 } else if ((prefs->GetDisableReasons(extension_id) & | |
| 837 Extension::DISABLE_UNSUPPORTED_REQUIREMENT)) { | |
| 838 // Recheck the requirements. | |
| 839 requirements_checker_.reset(new ChromeRequirementsChecker()); | |
| 840 AddRef(); // Released in OnRequirementsChecked. | |
| 841 // TODO(devlin): Uh... asynchronous code in a sync extension function? | |
| 842 requirements_checker_->Check( | |
| 843 make_scoped_refptr(extension), | |
| 844 base::Bind(&DeveloperPrivateEnableFunction::OnRequirementsChecked, | |
| 845 this, extension_id)); | |
| 846 } else { | |
| 847 // Otherwise, we're good to re-enable the extension. | |
| 848 service->EnableExtension(extension_id); | |
| 849 } | |
| 850 } else { // !enable (i.e., disable) | |
| 851 service->DisableExtension(extension_id, Extension::DISABLE_USER_ACTION); | |
| 852 } | |
| 853 return true; | |
| 854 } | |
| 855 | |
| 856 void DeveloperPrivateEnableFunction::OnRequirementsChecked( | |
| 857 const std::string& extension_id, | |
| 858 const std::vector<std::string>& requirements_errors) { | |
| 859 if (requirements_errors.empty()) { | |
| 860 GetExtensionService(GetProfile())->EnableExtension(extension_id); | |
| 861 } else { | |
| 862 ExtensionErrorReporter::GetInstance()->ReportError( | |
| 863 base::UTF8ToUTF16(JoinString(requirements_errors, ' ')), | |
| 864 true); // Be noisy. | |
| 865 } | |
| 866 Release(); | |
| 867 } | |
| 868 | |
| 869 DeveloperPrivateEnableFunction::~DeveloperPrivateEnableFunction() {} | |
| 870 | |
| 871 bool DeveloperPrivateInspectFunction::RunSync() { | 799 bool DeveloperPrivateInspectFunction::RunSync() { |
| 872 scoped_ptr<developer::Inspect::Params> params( | 800 scoped_ptr<developer::Inspect::Params> params( |
| 873 developer::Inspect::Params::Create(*args_)); | 801 developer::Inspect::Params::Create(*args_)); |
| 874 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 802 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
| 875 const developer::InspectOptions& options = params->options; | 803 const developer::InspectOptions& options = params->options; |
| 876 | 804 |
| 877 int render_process_id; | 805 int render_process_id; |
| 878 base::StringToInt(options.render_process_id, &render_process_id); | 806 base::StringToInt(options.render_process_id, &render_process_id); |
| 879 | 807 |
| 880 if (render_process_id == -1) { | 808 if (render_process_id == -1) { |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1394 } | 1322 } |
| 1395 | 1323 |
| 1396 error_ui_util::HandleOpenDevTools(dict); | 1324 error_ui_util::HandleOpenDevTools(dict); |
| 1397 | 1325 |
| 1398 return true; | 1326 return true; |
| 1399 } | 1327 } |
| 1400 | 1328 |
| 1401 } // namespace api | 1329 } // namespace api |
| 1402 | 1330 |
| 1403 } // namespace extensions | 1331 } // namespace extensions |
| OLD | NEW |