Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: chrome/browser/extensions/standard_management_policy_provider.cc

Issue 602803002: Refactor ExtensionManagement (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ext-fix
Patch Set: fix addressing #7 Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm>
8 #include <string> 7 #include <string>
9 8
10 #include "base/logging.h" 9 #include "base/logging.h"
11 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
12 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/extensions/extension_management.h" 12 #include "chrome/browser/extensions/extension_management.h"
14 #include "chrome/browser/extensions/external_component_loader.h" 13 #include "chrome/browser/extensions/external_component_loader.h"
15 #include "extensions/common/extension.h" 14 #include "extensions/common/extension.h"
16 #include "extensions/common/manifest.h" 15 #include "extensions/common/manifest.h"
17 #include "grit/extensions_strings.h" 16 #include "grit/extensions_strings.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 #endif 69 #endif
71 } 70 }
72 71
73 bool StandardManagementPolicyProvider::UserMayLoad( 72 bool StandardManagementPolicyProvider::UserMayLoad(
74 const Extension* extension, 73 const Extension* extension,
75 base::string16* error) const { 74 base::string16* error) const {
76 // Component extensions are always allowed. 75 // Component extensions are always allowed.
77 if (Manifest::IsComponentLocation(extension->location())) 76 if (Manifest::IsComponentLocation(extension->location()))
78 return true; 77 return true;
79 78
80 // Fields in |by_id| will automatically fall back to default settings if 79 ExtensionManagement::InstallationMode installation_mode =
81 // they are not specified by policy. 80 settings_->GetInstallationMode(extension->id());
82 const ExtensionManagement::IndividualSettings& by_id =
83 settings_->ReadById(extension->id());
84 const ExtensionManagement::GlobalSettings& global =
85 settings_->ReadGlobalSettings();
86 81
87 // Force-installed extensions cannot be overwritten manually. 82 // Force-installed extensions cannot be overwritten manually.
88 if (!Manifest::IsPolicyLocation(extension->location()) && 83 if (!Manifest::IsPolicyLocation(extension->location()) &&
89 by_id.installation_mode == ExtensionManagement::INSTALLATION_FORCED) { 84 installation_mode == ExtensionManagement::INSTALLATION_FORCED) {
90 return ReturnLoadError(extension, error); 85 return ReturnLoadError(extension, error);
91 } 86 }
92 87
93 // Check whether the extension type is allowed. 88 // Check whether the extension type is allowed.
94 // 89 //
95 // If you get a compile error here saying that the type you added is not 90 // 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 91 // 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 92 // 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 93 // a branch to the second block and add a line to the definition of
99 // kExtensionAllowedTypesMap in configuration_policy_handler_list.cc. 94 // kExtensionAllowedTypesMap in configuration_policy_handler_list.cc.
100 switch (extension->GetType()) { 95 switch (extension->GetType()) {
101 case Manifest::TYPE_UNKNOWN: 96 case Manifest::TYPE_UNKNOWN:
102 break; 97 break;
103 case Manifest::TYPE_EXTENSION: 98 case Manifest::TYPE_EXTENSION:
104 case Manifest::TYPE_THEME: 99 case Manifest::TYPE_THEME:
105 case Manifest::TYPE_USER_SCRIPT: 100 case Manifest::TYPE_USER_SCRIPT:
106 case Manifest::TYPE_HOSTED_APP: 101 case Manifest::TYPE_HOSTED_APP:
107 case Manifest::TYPE_LEGACY_PACKAGED_APP: 102 case Manifest::TYPE_LEGACY_PACKAGED_APP:
108 case Manifest::TYPE_PLATFORM_APP: 103 case Manifest::TYPE_PLATFORM_APP:
109 case Manifest::TYPE_SHARED_MODULE: { 104 case Manifest::TYPE_SHARED_MODULE: {
110 if (global.has_restricted_allowed_types && 105 if (!settings_->IsAllowedManifestType(extension->GetType()))
111 std::find(global.allowed_types.begin(),
112 global.allowed_types.end(),
113 extension->GetType()) == global.allowed_types.end()) {
114 return ReturnLoadError(extension, error); 106 return ReturnLoadError(extension, error);
115 }
116 break; 107 break;
117 } 108 }
118 case Manifest::NUM_LOAD_TYPES: 109 case Manifest::NUM_LOAD_TYPES:
119 NOTREACHED(); 110 NOTREACHED();
120 } 111 }
121 112
122 if (by_id.installation_mode == ExtensionManagement::INSTALLATION_BLOCKED) 113 if (installation_mode == ExtensionManagement::INSTALLATION_BLOCKED)
123 return ReturnLoadError(extension, error); 114 return ReturnLoadError(extension, error);
124 115
125 return true; 116 return true;
126 } 117 }
127 118
128 bool StandardManagementPolicyProvider::UserMayModifySettings( 119 bool StandardManagementPolicyProvider::UserMayModifySettings(
129 const Extension* extension, 120 const Extension* extension,
130 base::string16* error) const { 121 base::string16* error) const {
131 return AdminPolicyIsModifiable(extension, error) || 122 return AdminPolicyIsModifiable(extension, error) ||
132 (extension->location() == extensions::Manifest::EXTERNAL_COMPONENT && 123 (extension->location() == extensions::Manifest::EXTERNAL_COMPONENT &&
133 ExternalComponentLoader::IsModifiable(extension)); 124 ExternalComponentLoader::IsModifiable(extension));
134 } 125 }
135 126
136 bool StandardManagementPolicyProvider::MustRemainEnabled( 127 bool StandardManagementPolicyProvider::MustRemainEnabled(
137 const Extension* extension, 128 const Extension* extension,
138 base::string16* error) const { 129 base::string16* error) const {
139 return !AdminPolicyIsModifiable(extension, error) || 130 return !AdminPolicyIsModifiable(extension, error) ||
140 (extension->location() == extensions::Manifest::EXTERNAL_COMPONENT && 131 (extension->location() == extensions::Manifest::EXTERNAL_COMPONENT &&
141 ExternalComponentLoader::IsModifiable(extension)); 132 ExternalComponentLoader::IsModifiable(extension));
142 } 133 }
143 134
144 } // namespace extensions 135 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_management_unittest.cc ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698