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

Unified Diff: chrome/common/extensions/api/extension_api.cc

Issue 9460002: Convert app_bindings.js to the schema_generated_bindings.js infrastructure. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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
Index: chrome/common/extensions/api/extension_api.cc
diff --git a/chrome/common/extensions/api/extension_api.cc b/chrome/common/extensions/api/extension_api.cc
index acce2b0f19ff0e45284aab87e8e1cf860a580177..a496f56c8a694e9fd76e22a73fa4040a5e0f7646 100644
--- a/chrome/common/extensions/api/extension_api.cc
+++ b/chrome/common/extensions/api/extension_api.cc
@@ -15,6 +15,7 @@
#include "base/values.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_permission_set.h"
+#include "googleurl/src/gurl.h"
#include "grit/common_resources.h"
#include "ui/base/resource/resource_bundle.h"
@@ -95,6 +96,7 @@ void ExtensionAPI::LoadSchemaFromResource(int resource_id) {
ExtensionAPI::ExtensionAPI() {
static int kJsonApiResourceIds[] = {
+ IDR_EXTENSION_API_JSON_APP,
IDR_EXTENSION_API_JSON_BOOKMARKS,
IDR_EXTENSION_API_JSON_BROWSERACTION,
IDR_EXTENSION_API_JSON_CHROMEAUTHPRIVATE,
@@ -177,6 +179,27 @@ ExtensionAPI::ExtensionAPI() {
partially_unprivileged_apis_.insert(it->first);
}
}
+
+ // Populate |url_matching_apis_|.
+ for (SchemaMap::const_iterator it = schemas_.begin();
+ it != schemas_.end(); ++it) {
+ ListValue* matches = NULL;
+ {
+ Value* matches_value = NULL;
+ if (!it->second->Get("matches", &matches_value))
+ continue;
+ CHECK_EQ(Value::TYPE_LIST, matches_value->GetType());
+ matches = static_cast<ListValue*>(matches_value);
+ }
+ URLPatternSet pattern_set;
+ for (size_t i = 0; i < matches->GetSize(); ++i) {
+ std::string pattern;
+ CHECK(matches->GetString(i, &pattern));
+ pattern_set.AddPattern(
+ URLPattern(UserScript::kValidUserScriptSchemes, pattern));
+ }
+ url_matching_apis_[it->first] = pattern_set;
+ }
}
ExtensionAPI::~ExtensionAPI() {
@@ -311,4 +334,19 @@ bool ExtensionAPI::IsWholeAPIPrivileged(const std::string& api_name) const {
!partially_unprivileged_apis_.count(api_name);
}
+bool ExtensionAPI::MatchesURL(
+ const std::string& api_name, const GURL& url) const {
+ std::map<std::string, URLPatternSet>::const_iterator it =
+ url_matching_apis_.find(api_name);
+ return it != url_matching_apis_.end() && it->second.MatchesURL(url);
+}
+
+void ExtensionAPI::GetSchemasForURL(const GURL& url, SchemaMap* out) const {
+ for (std::map<std::string, URLPatternSet>::const_iterator it =
+ url_matching_apis_.begin(); it != url_matching_apis_.end(); ++it) {
+ if (it->second.MatchesURL(url))
+ (*out)[it->first] = schemas_.find(it->first)->second;
+ }
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698