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

Side by Side Diff: chrome/common/extensions/feature.cc

Issue 9664053: Re-land 125247: Better error messages when using unsupported manifest features. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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
« no previous file with comments | « chrome/common/extensions/feature.h ('k') | chrome/common/extensions/feature_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/common/extensions/feature.h" 5 #include "chrome/common/extensions/feature.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/stringprintf.h"
10 11
11 namespace { 12 namespace {
12 13
13 struct Mappings { 14 struct Mappings {
14 Mappings() { 15 Mappings() {
15 extension_types["extension"] = Extension::TYPE_EXTENSION; 16 extension_types["extension"] = Extension::TYPE_EXTENSION;
16 extension_types["theme"] = Extension::TYPE_THEME; 17 extension_types["theme"] = Extension::TYPE_THEME;
17 extension_types["packaged_app"] = Extension::TYPE_PACKAGED_APP; 18 extension_types["packaged_app"] = Extension::TYPE_PACKAGED_APP;
18 extension_types["hosted_app"] = Extension::TYPE_HOSTED_APP; 19 extension_types["hosted_app"] = Extension::TYPE_HOSTED_APP;
19 extension_types["platform_app"] = Extension::TYPE_PLATFORM_APP; 20 extension_types["platform_app"] = Extension::TYPE_PLATFORM_APP;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 } 145 }
145 146
146 // static 147 // static
147 Feature::Location Feature::ConvertLocation(Extension::Location location) { 148 Feature::Location Feature::ConvertLocation(Extension::Location location) {
148 if (location == Extension::COMPONENT) 149 if (location == Extension::COMPONENT)
149 return COMPONENT_LOCATION; 150 return COMPONENT_LOCATION;
150 else 151 else
151 return UNSPECIFIED_LOCATION; 152 return UNSPECIFIED_LOCATION;
152 } 153 }
153 154
154 bool Feature::IsAvailable(const std::string& extension_id, 155 std::string Feature::GetErrorMessage(Feature::Availability result) {
155 Extension::Type type, 156 switch (result) {
156 Location location, 157 case IS_AVAILABLE:
157 Context context, 158 return "";
158 Platform platform, 159 case NOT_FOUND_IN_WHITELIST:
159 int manifest_version) { 160 return "Not allowed for specified extension ID.";
161 case INVALID_TYPE:
162 return "Not allowed for specified package type (theme, app, etc.).";
163 case INVALID_CONTEXT:
164 return "Not allowed for specified context type content script, extension "
165 "page, web page, etc.).";
166 case INVALID_LOCATION:
167 return "Not allowed for specified install location.";
168 case INVALID_PLATFORM:
169 return "Not allowed for specified platform.";
170 case INVALID_MIN_MANIFEST_VERSION:
171 return base::StringPrintf("Requires manifest version of at least %d.",
172 min_manifest_version_);
173 case INVALID_MAX_MANIFEST_VERSION:
174 return base::StringPrintf("Requires manifest version of %d or lower.",
175 max_manifest_version_);
176 default:
177 CHECK(false);
178 return "";
179 }
180 }
181
182 Feature::Availability Feature::IsAvailable(const std::string& extension_id,
183 Extension::Type type,
184 Location location,
185 Context context,
186 Platform platform,
187 int manifest_version) {
160 if (!whitelist_.empty() && 188 if (!whitelist_.empty() &&
161 whitelist_.find(extension_id) == whitelist_.end()) { 189 whitelist_.find(extension_id) == whitelist_.end()) {
162 return false; 190 return NOT_FOUND_IN_WHITELIST;
163 } 191 }
164 192
165 if (!extension_types_.empty() && 193 if (!extension_types_.empty() &&
166 extension_types_.find(type) == extension_types_.end()) { 194 extension_types_.find(type) == extension_types_.end()) {
167 return false; 195 return INVALID_TYPE;
168 } 196 }
169 197
170 if (!contexts_.empty() && 198 if (!contexts_.empty() &&
171 contexts_.find(context) == contexts_.end()) { 199 contexts_.find(context) == contexts_.end()) {
172 return false; 200 return INVALID_CONTEXT;
173 } 201 }
174 202
175 if (location_ != UNSPECIFIED_LOCATION && location_ != location) 203 if (location_ != UNSPECIFIED_LOCATION && location_ != location)
176 return false; 204 return INVALID_LOCATION;
177 205
178 if (platform_ != UNSPECIFIED_PLATFORM && platform_ != platform) 206 if (platform_ != UNSPECIFIED_PLATFORM && platform_ != platform)
179 return false; 207 return INVALID_PLATFORM;
180 208
181 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_) 209 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_)
182 return false; 210 return INVALID_MIN_MANIFEST_VERSION;
183 211
184 if (max_manifest_version_ != 0 && manifest_version > max_manifest_version_) 212 if (max_manifest_version_ != 0 && manifest_version > max_manifest_version_)
185 return false; 213 return INVALID_MAX_MANIFEST_VERSION;
186 214
187 return true; 215 return IS_AVAILABLE;
188 } 216 }
189 217
190 } // namespace 218 } // namespace
OLDNEW
« no previous file with comments | « chrome/common/extensions/feature.h ('k') | chrome/common/extensions/feature_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698