1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/permissions_based_management_policy_provider.h"
7 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/extensions/extension_management.h"
10 #include "extensions/common/extension.h"
11 #include "extensions/common/manifest_handlers/permissions_parser.h"
12 #include "extensions/common/permissions/permission_set.h"
13 #include "grit/extensions_strings.h"
14 #include "ui/base/l10n/l10n_util.h"
16 namespace extensions
{
18 PermissionsBasedManagementPolicyProvider::
19 PermissionsBasedManagementPolicyProvider(ExtensionManagement
* settings
)
20 : settings_(settings
) {
23 PermissionsBasedManagementPolicyProvider::
24 ~PermissionsBasedManagementPolicyProvider() {
28 PermissionsBasedManagementPolicyProvider::GetDebugPolicyProviderName() const {
33 return "Controlled by enterprise policy, restricting extension permissions.";
37 bool PermissionsBasedManagementPolicyProvider::UserMayLoad(
38 const Extension
* extension
,
39 base::string16
* error
) const {
40 // Component extensions are always allowed.
41 if (Manifest::IsComponentLocation(extension
->location()))
44 scoped_refptr
<const PermissionSet
> required_permissions
=
45 PermissionsParser::GetRequiredPermissions(extension
);
47 if (!settings_
->IsPermissionSetAllowed(extension
, required_permissions
)) {
50 l10n_util::GetStringFUTF16(IDS_EXTENSION_CANT_INSTALL_POLICY_BLOCKED
,
51 base::UTF8ToUTF16(extension
->name()),
52 base::UTF8ToUTF16(extension
->id()));
60 } // namespace extensions