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

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

Issue 12093036: Move Extension Location and Type enums to Manifest, and move InstallWarning to its own file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
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/admin_policy.h" 5 #include "chrome/browser/extensions/admin_policy.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/common/extensions/extension.h" 8 #include "chrome/common/extensions/extension.h"
9 #include "chrome/common/extensions/manifest.h"
9 #include "grit/generated_resources.h" 10 #include "grit/generated_resources.h"
10 #include "ui/base/l10n/l10n_util.h" 11 #include "ui/base/l10n/l10n_util.h"
11 12
12 namespace { 13 namespace {
13 14
14 bool ManagementPolicyImpl(const extensions::Extension* extension, 15 bool ManagementPolicyImpl(const extensions::Extension* extension,
15 string16* error, 16 string16* error,
16 bool modifiable_value) { 17 bool modifiable_value) {
17 bool modifiable = 18 bool modifiable =
18 extension->location() != extensions::Extension::COMPONENT && 19 extension->location() != extensions::Manifest::COMPONENT &&
19 extension->location() != extensions::Extension::EXTERNAL_POLICY_DOWNLOAD; 20 extension->location() != extensions::Manifest::EXTERNAL_POLICY_DOWNLOAD;
20 // Some callers equate "no restriction" to true, others to false. 21 // Some callers equate "no restriction" to true, others to false.
21 if (modifiable) 22 if (modifiable)
22 return modifiable_value; 23 return modifiable_value;
23 24
24 if (error) { 25 if (error) {
25 *error = l10n_util::GetStringFUTF16( 26 *error = l10n_util::GetStringFUTF16(
26 IDS_EXTENSION_CANT_MODIFY_POLICY_REQUIRED, 27 IDS_EXTENSION_CANT_MODIFY_POLICY_REQUIRED,
27 UTF8ToUTF16(extension->name())); 28 UTF8ToUTF16(extension->name()));
28 } 29 }
29 return !modifiable_value; 30 return !modifiable_value;
(...skipping 19 matching lines...) Expand all
49 return blacklist && blacklist->Find(wildcard) != blacklist->end(); 50 return blacklist && blacklist->Find(wildcard) != blacklist->end();
50 } 51 }
51 52
52 bool UserMayLoad(const base::ListValue* blacklist, 53 bool UserMayLoad(const base::ListValue* blacklist,
53 const base::ListValue* whitelist, 54 const base::ListValue* whitelist,
54 const base::DictionaryValue* forcelist, 55 const base::DictionaryValue* forcelist,
55 const base::ListValue* allowed_types, 56 const base::ListValue* allowed_types,
56 const Extension* extension, 57 const Extension* extension,
57 string16* error) { 58 string16* error) {
58 // Component extensions are always allowed. 59 // Component extensions are always allowed.
59 if (extension->location() == Extension::COMPONENT) 60 if (extension->location() == Manifest::COMPONENT)
60 return true; 61 return true;
61 62
62 // Early exit for the common case of no policy restrictions. 63 // Early exit for the common case of no policy restrictions.
63 if ((!blacklist || blacklist->empty()) && (!allowed_types)) 64 if ((!blacklist || blacklist->empty()) && (!allowed_types))
64 return true; 65 return true;
65 66
66 // Check whether the extension type is allowed. 67 // Check whether the extension type is allowed.
67 // 68 //
68 // If you get a compile error here saying that the type you added is not 69 // If you get a compile error here saying that the type you added is not
69 // handled by the switch statement below, please consider whether enterprise 70 // handled by the switch statement below, please consider whether enterprise
70 // policy should be able to disallow extensions of the new type. If so, add a 71 // policy should be able to disallow extensions of the new type. If so, add a
71 // branch to the second block and add a line to the definition of 72 // branch to the second block and add a line to the definition of
72 // kExtensionAllowedTypesMap in configuration_policy_handler_list.cc. 73 // kExtensionAllowedTypesMap in configuration_policy_handler_list.cc.
73 switch (extension->GetType()) { 74 switch (extension->GetType()) {
74 case Extension::TYPE_UNKNOWN: 75 case Manifest::TYPE_UNKNOWN:
75 break; 76 break;
76 case Extension::TYPE_EXTENSION: 77 case Manifest::TYPE_EXTENSION:
77 case Extension::TYPE_THEME: 78 case Manifest::TYPE_THEME:
78 case Extension::TYPE_USER_SCRIPT: 79 case Manifest::TYPE_USER_SCRIPT:
79 case Extension::TYPE_HOSTED_APP: 80 case Manifest::TYPE_HOSTED_APP:
80 case Extension::TYPE_LEGACY_PACKAGED_APP: 81 case Manifest::TYPE_LEGACY_PACKAGED_APP:
81 case Extension::TYPE_PLATFORM_APP: 82 case Manifest::TYPE_PLATFORM_APP:
82 base::FundamentalValue type_value(extension->GetType()); 83 base::FundamentalValue type_value(extension->GetType());
83 if (allowed_types && 84 if (allowed_types &&
84 allowed_types->Find(type_value) == allowed_types->end()) 85 allowed_types->Find(type_value) == allowed_types->end())
85 return ReturnLoadError(extension, error); 86 return ReturnLoadError(extension, error);
86 break; 87 break;
87 } 88 }
88 89
89 // Check the whitelist/forcelist first. 90 // Check the whitelist/forcelist first.
90 base::StringValue id_value(extension->id()); 91 base::StringValue id_value(extension->id());
91 if ((whitelist && whitelist->Find(id_value) != whitelist->end()) || 92 if ((whitelist && whitelist->Find(id_value) != whitelist->end()) ||
(...skipping 11 matching lines...) Expand all
103 bool UserMayModifySettings(const Extension* extension, string16* error) { 104 bool UserMayModifySettings(const Extension* extension, string16* error) {
104 return ManagementPolicyImpl(extension, error, true); 105 return ManagementPolicyImpl(extension, error, true);
105 } 106 }
106 107
107 bool MustRemainEnabled(const Extension* extension, string16* error) { 108 bool MustRemainEnabled(const Extension* extension, string16* error) {
108 return ManagementPolicyImpl(extension, error, false); 109 return ManagementPolicyImpl(extension, error, false);
109 } 110 }
110 111
111 } // namespace 112 } // namespace
112 } // namespace 113 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/kiosk_mode/kiosk_mode_screensaver.cc ('k') | chrome/browser/extensions/admin_policy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698