OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/standard_management_policy_provider.h" | 5 #include "chrome/browser/extensions/standard_management_policy_provider.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include <algorithm> |
8 #include "chrome/browser/extensions/blacklist.h" | 8 #include <string> |
| 9 |
| 10 #include "base/logging.h" |
| 11 #include "base/strings/string16.h" |
| 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/extensions/extension_management.h" |
9 #include "chrome/browser/extensions/external_component_loader.h" | 14 #include "chrome/browser/extensions/external_component_loader.h" |
10 #include "chrome/common/pref_names.h" | |
11 #include "extensions/browser/admin_policy.h" | |
12 #include "extensions/browser/extension_prefs.h" | |
13 #include "extensions/browser/pref_names.h" | |
14 #include "extensions/common/extension.h" | 15 #include "extensions/common/extension.h" |
| 16 #include "extensions/common/manifest.h" |
| 17 #include "grit/extensions_strings.h" |
| 18 #include "ui/base/l10n/l10n_util.h" |
15 | 19 |
16 namespace extensions { | 20 namespace extensions { |
17 | 21 |
| 22 namespace { |
| 23 |
| 24 // Returns whether the extension can be modified under admin policy or not, and |
| 25 // fills |error| with corresponding error message if necessary. |
| 26 bool AdminPolicyIsModifiable(const extensions::Extension* extension, |
| 27 base::string16* error) { |
| 28 if (!extensions::Manifest::IsComponentLocation(extension->location()) && |
| 29 !extensions::Manifest::IsPolicyLocation(extension->location())) { |
| 30 return true; |
| 31 } |
| 32 |
| 33 if (error) { |
| 34 *error = l10n_util::GetStringFUTF16( |
| 35 IDS_EXTENSION_CANT_MODIFY_POLICY_REQUIRED, |
| 36 base::UTF8ToUTF16(extension->name())); |
| 37 } |
| 38 |
| 39 return false; |
| 40 } |
| 41 |
| 42 bool ReturnLoadError(const extensions::Extension* extension, |
| 43 base::string16* error) { |
| 44 if (error) { |
| 45 *error = l10n_util::GetStringFUTF16( |
| 46 IDS_EXTENSION_CANT_INSTALL_POLICY_BLOCKED, |
| 47 base::UTF8ToUTF16(extension->name()), |
| 48 base::UTF8ToUTF16(extension->id())); |
| 49 } |
| 50 return false; |
| 51 } |
| 52 |
| 53 } // namespace |
| 54 |
18 StandardManagementPolicyProvider::StandardManagementPolicyProvider( | 55 StandardManagementPolicyProvider::StandardManagementPolicyProvider( |
19 ExtensionPrefs* prefs) | 56 const ExtensionManagement* settings) |
20 : prefs_(prefs) { | 57 : settings_(settings) { |
21 } | 58 } |
22 | 59 |
23 StandardManagementPolicyProvider::~StandardManagementPolicyProvider() { | 60 StandardManagementPolicyProvider::~StandardManagementPolicyProvider() { |
24 } | 61 } |
25 | 62 |
26 std::string | 63 std::string |
27 StandardManagementPolicyProvider::GetDebugPolicyProviderName() const { | 64 StandardManagementPolicyProvider::GetDebugPolicyProviderName() const { |
28 #ifdef NDEBUG | 65 #ifdef NDEBUG |
29 NOTREACHED(); | 66 NOTREACHED(); |
30 return std::string(); | 67 return std::string(); |
31 #else | 68 #else |
32 return "admin policy black/white/forcelist, via the ExtensionPrefs"; | 69 return "extension management policy controlled settings"; |
33 #endif | 70 #endif |
34 } | 71 } |
35 | 72 |
36 bool StandardManagementPolicyProvider::UserMayLoad( | 73 bool StandardManagementPolicyProvider::UserMayLoad( |
37 const Extension* extension, | 74 const Extension* extension, |
38 base::string16* error) const { | 75 base::string16* error) const { |
39 PrefService* pref_service = prefs_->pref_service(); | 76 // Component extensions are always allowed. |
| 77 if (Manifest::IsComponentLocation(extension->location())) |
| 78 return true; |
40 | 79 |
41 const base::ListValue* blacklist = | 80 // Fields in |by_id| will automatically fall back to default settings if |
42 pref_service->GetList(pref_names::kInstallDenyList); | 81 // they are not specified by policy. |
43 const base::ListValue* whitelist = | 82 const ExtensionManagement::IndividualSettings& by_id = |
44 pref_service->GetList(pref_names::kInstallAllowList); | 83 settings_->ReadById(extension->id()); |
45 const base::DictionaryValue* forcelist = | 84 const ExtensionManagement::GlobalSettings& global = |
46 pref_service->GetDictionary(pref_names::kInstallForceList); | 85 settings_->ReadGlobalSettings(); |
47 const base::ListValue* allowed_types = NULL; | |
48 if (pref_service->HasPrefPath(pref_names::kAllowedTypes)) | |
49 allowed_types = pref_service->GetList(pref_names::kAllowedTypes); | |
50 | 86 |
51 return admin_policy::UserMayLoad( | 87 // Force-installed extensions cannot be overwritten manually. |
52 blacklist, whitelist, forcelist, allowed_types, extension, error); | 88 if (!Manifest::IsPolicyLocation(extension->location()) && |
| 89 by_id.installation_mode == ExtensionManagement::INSTALLATION_FORCED) { |
| 90 return ReturnLoadError(extension, error); |
| 91 } |
| 92 |
| 93 // Check whether the extension type is allowed. |
| 94 // |
| 95 // If you get a compile error here saying that the type you added is not |
| 96 // handled by the switch statement below, please consider whether enterprise |
| 97 // policy should be able to disallow extensions of the new type. If so, add |
| 98 // a branch to the second block and add a line to the definition of |
| 99 // kExtensionAllowedTypesMap in configuration_policy_handler_list.cc. |
| 100 switch (extension->GetType()) { |
| 101 case Manifest::TYPE_UNKNOWN: |
| 102 break; |
| 103 case Manifest::TYPE_EXTENSION: |
| 104 case Manifest::TYPE_THEME: |
| 105 case Manifest::TYPE_USER_SCRIPT: |
| 106 case Manifest::TYPE_HOSTED_APP: |
| 107 case Manifest::TYPE_LEGACY_PACKAGED_APP: |
| 108 case Manifest::TYPE_PLATFORM_APP: |
| 109 case Manifest::TYPE_SHARED_MODULE: { |
| 110 if (global.has_restricted_allowed_types && |
| 111 std::find(global.allowed_types.begin(), |
| 112 global.allowed_types.end(), |
| 113 extension->GetType()) == global.allowed_types.end()) { |
| 114 return ReturnLoadError(extension, error); |
| 115 } |
| 116 break; |
| 117 } |
| 118 case Manifest::NUM_LOAD_TYPES: |
| 119 NOTREACHED(); |
| 120 } |
| 121 |
| 122 if (by_id.installation_mode == ExtensionManagement::INSTALLATION_BLOCKED) |
| 123 return ReturnLoadError(extension, error); |
| 124 |
| 125 return true; |
53 } | 126 } |
54 | 127 |
55 bool StandardManagementPolicyProvider::UserMayModifySettings( | 128 bool StandardManagementPolicyProvider::UserMayModifySettings( |
56 const Extension* extension, | 129 const Extension* extension, |
57 base::string16* error) const { | 130 base::string16* error) const { |
58 return admin_policy::UserMayModifySettings(extension, error) || | 131 return AdminPolicyIsModifiable(extension, error) || |
59 (extension->location() == extensions::Manifest::EXTERNAL_COMPONENT && | 132 (extension->location() == extensions::Manifest::EXTERNAL_COMPONENT && |
60 ExternalComponentLoader::IsModifiable(extension)); | 133 ExternalComponentLoader::IsModifiable(extension)); |
61 } | 134 } |
62 | 135 |
63 bool StandardManagementPolicyProvider::MustRemainEnabled( | 136 bool StandardManagementPolicyProvider::MustRemainEnabled( |
64 const Extension* extension, | 137 const Extension* extension, |
65 base::string16* error) const { | 138 base::string16* error) const { |
66 return admin_policy::MustRemainEnabled(extension, error) || | 139 return !AdminPolicyIsModifiable(extension, error) || |
67 (extension->location() == extensions::Manifest::EXTERNAL_COMPONENT && | 140 (extension->location() == extensions::Manifest::EXTERNAL_COMPONENT && |
68 ExternalComponentLoader::IsModifiable(extension)); | 141 ExternalComponentLoader::IsModifiable(extension)); |
69 } | 142 } |
70 | 143 |
71 } // namespace extensions | 144 } // namespace extensions |
OLD | NEW |