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

Unified Diff: chrome/common/extensions/extension.cc

Issue 8849010: Add 'web_accessible_resource" keyword for version 2 extension manifests. This makes extension res... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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/extension.h ('k') | chrome/common/extensions/extension_constants.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/extension.cc
===================================================================
--- chrome/common/extensions/extension.cc (revision 115399)
+++ chrome/common/extensions/extension.cc (working copy)
@@ -376,6 +376,27 @@
return ret_val;
}
+bool Extension::IsResourceWebAccessible(const std::string& relative_path)
+ const {
+ // For old manifest versions which do not specify web_accessible_resources
+ // we always allow resource loads.
+ if (manifest_version() < 2 && !HasWebAccessibleResources())
+ return true;
+
+ if (web_accessible_resources_.find(relative_path) !=
+ web_accessible_resources_.end())
+ return true;
+
+ return false;
+}
+
+bool Extension::HasWebAccessibleResources() const {
+ if (web_accessible_resources_.size())
+ return true;
+
+ return false;
+}
+
bool Extension::GenerateId(const std::string& input, std::string* output) {
DCHECK(output);
uint8 hash[Extension::kIdSize];
@@ -1832,6 +1853,26 @@
}
}
+ // Initialize web accessible resources (optional).
+ if (manifest->HasKey(keys::kWebAccessibleResources)) {
+ ListValue* list_value;
+ if (!manifest->GetList(keys::kWebAccessibleResources, &list_value)) {
+ *error = ASCIIToUTF16(errors::kInvalidWebAccessibleResourcesList);
+ return false;
+ }
+ for (size_t i = 0; i < list_value->GetSize(); ++i) {
+ std::string relative_path;
+ if (!list_value->GetString(i, &relative_path)) {
+ *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
+ errors::kInvalidWebAccessibleResource, base::IntToString(i));
+ return false;
+ }
+ if (relative_path[0] != '/')
+ relative_path = '/' + relative_path;
+ web_accessible_resources_.insert(relative_path);
+ }
+ }
+
// Initialize page action (optional).
DictionaryValue* page_action_value = NULL;
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698