summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/common/extensions')
-rw-r--r--chrome/common/extensions/extension.cc75
-rw-r--r--chrome/common/extensions/extension.h16
2 files changed, 64 insertions, 27 deletions
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index 719f61c..17fb867 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -31,26 +31,37 @@ namespace values = extension_manifest_values;
namespace errors = extension_manifest_errors;
namespace {
- const int kPEMOutputColumns = 65;
+const int kPEMOutputColumns = 65;
+
+// KEY MARKERS
+const char kKeyBeginHeaderMarker[] = "-----BEGIN";
+const char kKeyBeginFooterMarker[] = "-----END";
+const char kKeyInfoEndMarker[] = "KEY-----";
+const char kPublic[] = "PUBLIC";
+const char kPrivate[] = "PRIVATE";
+
+const int kRSAKeySize = 1024;
+
+// Converts a normal hexadecimal string into the alphabet used by extensions.
+// We use the characters 'a'-'p' instead of '0'-'f' to avoid ever having a
+// completely numeric host, since some software interprets that as an IP
+// address.
+static void ConvertHexadecimalToIDAlphabet(std::string* id) {
+ for (size_t i = 0; i < id->size(); ++i)
+ (*id)[i] = HexStringToInt(id->substr(i, 1)) + 'a';
+}
- // KEY MARKERS
- const char kKeyBeginHeaderMarker[] = "-----BEGIN";
- const char kKeyBeginFooterMarker[] = "-----END";
- const char kKeyInfoEndMarker[] = "KEY-----";
- const char kPublic[] = "PUBLIC";
- const char kPrivate[] = "PRIVATE";
+// Returns true if the given string is an API permission (see kPermissionNames).
+static bool IsAPIPermission(const std::string& str) {
+ for (size_t i = 0; i < Extension::kNumPermissions; ++i) {
+ if (str == Extension::kPermissionNames[i])
+ return true;
+ }
- const int kRSAKeySize = 1024;
+ return false;
+}
- // Converts a normal hexadecimal string into the alphabet used by extensions.
- // We use the characters 'a'-'p' instead of '0'-'f' to avoid ever having a
- // completely numeric host, since some software interprets that as an IP
- // address.
- static void ConvertHexadecimalToIDAlphabet(std::string* id) {
- for (size_t i = 0; i < id->size(); ++i)
- (*id)[i] = HexStringToInt(id->substr(i, 1)) + 'a';
- }
-};
+} // namespace
// static
int Extension::id_counter_ = 0;
@@ -85,6 +96,13 @@ const int Extension::kIconSizes[] = {
EXTENSION_ICON_BITTY
};
+const char* Extension::kPermissionNames[] = {
+ "tabs",
+ "bookmarks",
+};
+const size_t Extension::kNumPermissions =
+ arraysize(Extension::kPermissionNames);
+
Extension::~Extension() {
for (PageActionMap::iterator i = page_actions_.begin();
i != page_actions_.end(); ++i)
@@ -852,28 +870,35 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_id,
// Initialize the permissions (optional).
if (source.HasKey(keys::kPermissions)) {
- ListValue* hosts = NULL;
- if (!source.GetList(keys::kPermissions, &hosts)) {
+ ListValue* permissions = NULL;
+ if (!source.GetList(keys::kPermissions, &permissions)) {
*error = ExtensionErrorUtils::FormatErrorMessage(
errors::kInvalidPermissions, "");
return false;
}
- if (hosts->GetSize() == 0) {
+ if (permissions->GetSize() == 0) {
ExtensionErrorReporter::GetInstance()->ReportError(
errors::kInvalidPermissionCountWarning, false);
}
- for (size_t i = 0; i < hosts->GetSize(); ++i) {
- std::string host_str;
- if (!hosts->GetString(i, &host_str)) {
+ for (size_t i = 0; i < permissions->GetSize(); ++i) {
+ std::string permission_str;
+ if (!permissions->GetString(i, &permission_str)) {
*error = ExtensionErrorUtils::FormatErrorMessage(
errors::kInvalidPermission, IntToString(i));
return false;
}
+ // Check if it's a module permission. If so, enable that permission.
+ if (IsAPIPermission(permission_str)) {
+ api_permissions_.push_back(permission_str);
+ continue;
+ }
+
+ // Otherwise, it's a host pattern permission.
URLPattern pattern;
- if (!pattern.Parse(host_str)) {
+ if (!pattern.Parse(permission_str)) {
*error = ExtensionErrorUtils::FormatErrorMessage(
errors::kInvalidPermission, IntToString(i));
return false;
@@ -887,7 +912,7 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_id,
return false;
}
- permissions_.push_back(pattern);
+ host_permissions_.push_back(pattern);
}
}
diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h
index 550fbba..7969e96 100644
--- a/chrome/common/extensions/extension.h
+++ b/chrome/common/extensions/extension.h
@@ -58,6 +58,10 @@ class Extension {
// Icon sizes used by the extension system.
static const int kIconSizes[];
+ // Each permission is a module that the extension is permitted to use.
+ static const char* kPermissionNames[];
+ static const size_t kNumPermissions;
+
// An NPAPI plugin included in the extension.
struct PluginInfo {
FilePath path; // Path to the plugin.
@@ -172,7 +176,12 @@ class Extension {
const std::vector<PluginInfo>& plugins() const { return plugins_; }
const GURL& background_url() const { return background_url_; }
const std::vector<ToolstripInfo>& toolstrips() const { return toolstrips_; }
- const std::vector<URLPattern>& permissions() const { return permissions_; }
+ const std::vector<URLPattern>& host_permissions() const {
+ return host_permissions_;
+ }
+ const std::vector<std::string>& api_permissions() const {
+ return api_permissions_;
+ }
const GURL& update_url() const { return update_url_; }
const std::map<int, std::string>& icons() { return icons_; }
@@ -293,8 +302,11 @@ class Extension {
// Whether the extension is a theme - if it is, certain things are disabled.
bool is_theme_;
+ // The set of module-level APIs this extension can use.
+ std::vector<std::string> api_permissions_;
+
// The sites this extension has permission to talk to (using XHR, etc).
- std::vector<URLPattern> permissions_;
+ std::vector<URLPattern> host_permissions_;
// The paths to the icons the extension contains mapped by their width.
std::map<int, std::string> icons_;