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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/extensions/feature.h ('k') | chrome/common/extensions/feature_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/feature.cc
diff --git a/chrome/common/extensions/feature.cc b/chrome/common/extensions/feature.cc
index aad4d01ad28b1bc2d09fa0a0a0b38707a8c45bbb..8ee35d9059bad0b7a4f972e1119966be4610fa54 100644
--- a/chrome/common/extensions/feature.cc
+++ b/chrome/common/extensions/feature.cc
@@ -7,6 +7,7 @@
#include <map>
#include "base/lazy_instance.h"
+#include "base/stringprintf.h"
namespace {
@@ -151,40 +152,67 @@ Feature::Location Feature::ConvertLocation(Extension::Location location) {
return UNSPECIFIED_LOCATION;
}
-bool Feature::IsAvailable(const std::string& extension_id,
- Extension::Type type,
- Location location,
- Context context,
- Platform platform,
- int manifest_version) {
+std::string Feature::GetErrorMessage(Feature::Availability result) {
+ switch (result) {
+ case IS_AVAILABLE:
+ return "";
+ case NOT_FOUND_IN_WHITELIST:
+ return "Not allowed for specified extension ID.";
+ case INVALID_TYPE:
+ return "Not allowed for specified package type (theme, app, etc.).";
+ case INVALID_CONTEXT:
+ return "Not allowed for specified context type content script, extension "
+ "page, web page, etc.).";
+ case INVALID_LOCATION:
+ return "Not allowed for specified install location.";
+ case INVALID_PLATFORM:
+ return "Not allowed for specified platform.";
+ case INVALID_MIN_MANIFEST_VERSION:
+ return base::StringPrintf("Requires manifest version of at least %d.",
+ min_manifest_version_);
+ case INVALID_MAX_MANIFEST_VERSION:
+ return base::StringPrintf("Requires manifest version of %d or lower.",
+ max_manifest_version_);
+ default:
+ CHECK(false);
+ return "";
+ }
+}
+
+Feature::Availability Feature::IsAvailable(const std::string& extension_id,
+ Extension::Type type,
+ Location location,
+ Context context,
+ Platform platform,
+ int manifest_version) {
if (!whitelist_.empty() &&
whitelist_.find(extension_id) == whitelist_.end()) {
- return false;
+ return NOT_FOUND_IN_WHITELIST;
}
if (!extension_types_.empty() &&
extension_types_.find(type) == extension_types_.end()) {
- return false;
+ return INVALID_TYPE;
}
if (!contexts_.empty() &&
contexts_.find(context) == contexts_.end()) {
- return false;
+ return INVALID_CONTEXT;
}
if (location_ != UNSPECIFIED_LOCATION && location_ != location)
- return false;
+ return INVALID_LOCATION;
if (platform_ != UNSPECIFIED_PLATFORM && platform_ != platform)
- return false;
+ return INVALID_PLATFORM;
if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_)
- return false;
+ return INVALID_MIN_MANIFEST_VERSION;
if (max_manifest_version_ != 0 && manifest_version > max_manifest_version_)
- return false;
+ return INVALID_MAX_MANIFEST_VERSION;
- return true;
+ return IS_AVAILABLE;
}
} // namespace
« 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