OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/extension_management_internal.h" | 5 #include "chrome/browser/extensions/extension_management_internal.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "base/version.h" | |
9 #include "chrome/browser/extensions/extension_management_constants.h" | 10 #include "chrome/browser/extensions/extension_management_constants.h" |
10 #include "extensions/common/url_pattern_set.h" | 11 #include "extensions/common/url_pattern_set.h" |
11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
12 | 13 |
13 namespace extensions { | 14 namespace extensions { |
14 | 15 |
15 namespace internal { | 16 namespace internal { |
16 | 17 |
17 namespace { | 18 namespace { |
18 const char kMalformedPreferenceWarning[] = | 19 const char kMalformedPreferenceWarning[] = |
19 "Malformed extension management preference."; | 20 "Malformed extension management preference."; |
20 } // namespace | 21 } // namespace |
21 | 22 |
22 IndividualSettings::IndividualSettings() { | 23 IndividualSettings::IndividualSettings() { |
23 Reset(); | 24 Reset(); |
24 } | 25 } |
25 | 26 |
27 // Initializes from default settings. | |
28 IndividualSettings::IndividualSettings( | |
29 const IndividualSettings* default_settings) { | |
30 installation_mode = default_settings->installation_mode; | |
31 update_url = default_settings->installation_mode; | |
32 blocked_permissions = default_settings->blocked_permissions; | |
33 // We are not initializing |minimum_version| from |default_settings| here | |
34 // since it's not applicable to default settings. | |
35 } | |
36 | |
26 IndividualSettings::~IndividualSettings() { | 37 IndividualSettings::~IndividualSettings() { |
27 } | 38 } |
28 | 39 |
29 bool IndividualSettings::Parse(const base::DictionaryValue* dict, | 40 bool IndividualSettings::Parse(const base::DictionaryValue* dict, |
30 ParsingScope scope) { | 41 ParsingScope scope) { |
31 std::string installation_mode_str; | 42 std::string installation_mode_str; |
32 if (dict->GetStringWithoutPathExpansion(schema_constants::kInstallationMode, | 43 if (dict->GetStringWithoutPathExpansion(schema_constants::kInstallationMode, |
33 &installation_mode_str)) { | 44 &installation_mode_str)) { |
34 if (installation_mode_str == schema_constants::kAllowed) { | 45 if (installation_mode_str == schema_constants::kAllowed) { |
35 installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; | 46 installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 APIPermissionSet::kDisallowInternalPermissions, | 122 APIPermissionSet::kDisallowInternalPermissions, |
112 &permissions_parsed, | 123 &permissions_parsed, |
113 &error, | 124 &error, |
114 nullptr)) { | 125 nullptr)) { |
115 LOG(WARNING) << error; | 126 LOG(WARNING) << error; |
116 } | 127 } |
117 APIPermissionSet::Union( | 128 APIPermissionSet::Union( |
118 permissions_to_merge_from, permissions_parsed, &blocked_permissions); | 129 permissions_to_merge_from, permissions_parsed, &blocked_permissions); |
119 } | 130 } |
120 | 131 |
132 // Parses the minimum version settings. | |
133 std::string minimum_version_str; | |
134 if (scope == SCOPE_INDIVIDUAL && | |
135 dict->GetStringWithoutPathExpansion(schema_constants::kMinimumVersion, | |
136 &minimum_version_str)) { | |
137 scoped_ptr<base::Version> version(new Version(minimum_version_str)); | |
138 // We accept a general version string here. Note that count of components in | |
139 // version string of extensions is limited to 4. | |
140 if (!version->IsValid()) | |
141 LOG(WARNING) << kMalformedPreferenceWarning; | |
Joao da Silva
2014/11/17 16:17:41
In this case, the administrator won't see any prob
binjin
2014/11/18 13:25:55
It's possible to enforce the exact requirement wit
| |
142 else | |
143 minimum_version = version.Pass(); | |
144 } | |
145 | |
121 return true; | 146 return true; |
122 } | 147 } |
123 | 148 |
124 void IndividualSettings::Reset() { | 149 void IndividualSettings::Reset() { |
125 installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; | 150 installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; |
126 update_url.clear(); | 151 update_url.clear(); |
127 blocked_permissions.clear(); | 152 blocked_permissions.clear(); |
128 } | 153 } |
129 | 154 |
130 GlobalSettings::GlobalSettings() { | 155 GlobalSettings::GlobalSettings() { |
131 Reset(); | 156 Reset(); |
132 } | 157 } |
133 | 158 |
134 GlobalSettings::~GlobalSettings() { | 159 GlobalSettings::~GlobalSettings() { |
135 } | 160 } |
136 | 161 |
137 void GlobalSettings::Reset() { | 162 void GlobalSettings::Reset() { |
138 has_restricted_install_sources = false; | 163 has_restricted_install_sources = false; |
139 install_sources.ClearPatterns(); | 164 install_sources.ClearPatterns(); |
140 has_restricted_allowed_types = false; | 165 has_restricted_allowed_types = false; |
141 allowed_types.clear(); | 166 allowed_types.clear(); |
142 } | 167 } |
143 | 168 |
144 } // namespace internal | 169 } // namespace internal |
145 | 170 |
146 } // namespace extensions | 171 } // namespace extensions |
OLD | NEW |