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

Unified Diff: chrome/renderer/extensions/schema_generated_bindings.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: Go back to manually injecting app_custom_bindings.js 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
Index: chrome/renderer/extensions/schema_generated_bindings.cc
diff --git a/chrome/renderer/extensions/schema_generated_bindings.cc b/chrome/renderer/extensions/schema_generated_bindings.cc
index eda15d85c1bbbdc75c36801654dc534e67afcf29..0a8cd6189f941c19572a887a9ae4ce3c7dd4e720 100644
--- a/chrome/renderer/extensions/schema_generated_bindings.cc
+++ b/chrome/renderer/extensions/schema_generated_bindings.cc
@@ -31,6 +31,7 @@
#include "chrome/renderer/extensions/extension_dispatcher.h"
#include "chrome/renderer/extensions/miscellaneous_bindings.h"
#include "chrome/renderer/extensions/user_script_slave.h"
+#include "content/public/renderer/render_thread.h"
#include "content/public/renderer/render_view.h"
#include "content/public/renderer/v8_value_converter.h"
#include "grit/common_resources.h"
@@ -44,8 +45,10 @@
#include "v8/include/v8.h"
#include "webkit/glue/webkit_glue.h"
+using content::RenderThread;
using content::V8ValueConverter;
using extensions::ExtensionAPI;
+using extensions::Feature;
using WebKit::WebFrame;
using WebKit::WebSecurityOrigin;
@@ -118,30 +121,56 @@ class ExtensionImpl : public ChromeV8Extension {
ChromeV8Context* v8_context = dispatcher->v8_context_set().GetCurrent();
CHECK(v8_context);
- std::string extension_id = v8_context->extension_id();
- ExtensionAPI::SchemaMap schemas;
- ExtensionAPI::GetSchemasFilter filter =
- dispatcher->is_extension_process() ?
- ExtensionAPI::ALL : ExtensionAPI::ONLY_UNPRIVILEGED;
+ scoped_ptr<std::set<std::string> > apis;
+ const std::string& extension_id = v8_context->extension_id();
if (dispatcher->IsTestExtensionId(extension_id)) {
- ExtensionAPI::GetInstance()->GetDefaultSchemas(filter, &schemas);
+ apis.reset(new std::set<std::string>());
+ // The minimal set of APIs that tests need.
+ apis->insert("extension");
} else {
- const ::Extension* extension =
- dispatcher->extensions()->GetByID(extension_id);
- CHECK(extension) << extension_id << " not found";
- ExtensionAPI::GetInstance()->GetSchemasForExtension(
- *extension, filter, &schemas);
+ const Extension* extension = NULL;
+ GURL url;
+
+ switch (v8_context->context_type()) {
+ case Feature::UNSPECIFIED_CONTEXT:
+ break;
+
+ case Feature::PRIVILEGED_CONTEXT:
+ case Feature::UNPRIVILEGED_CONTEXT:
+ case Feature::CONTENT_SCRIPT_CONTEXT:
+ extension = dispatcher->extensions()->GetByID(extension_id);
+ if (!extension && extension_id != "invalid") {
+ // There are conditions where despite a context being associated
+ // with an extension, no extension actually gets found. Ignore
+ // "invalid" because CSP blocks extension page loading by switching
+ // the extension ID to "invalid". This isn't interesting.
+ LOG(ERROR) << "Extension \"" << extension_id << "\" not found";
+ RenderThread::Get()->RecordUserMetrics("ExtensionNotFound_ED");
+ }
+ break;
+
+ case Feature::WEB_PAGE_CONTEXT:
+ url = UserScriptSlave::GetDataSourceURLForFrame(
+ v8_context->web_frame());
+ break;
+ }
+
not at google - send to devlin 2012/03/20 03:32:13 This is basically http://codereview.chromium.org/9
+ apis = ExtensionAPI::GetInstance()->GetAPIsForContext(
+ v8_context->context_type(), extension, url);
}
v8::Persistent<v8::Context> context(v8::Context::New());
v8::Context::Scope context_scope(context);
- v8::Handle<v8::Array> api(v8::Array::New(schemas.size()));
+ v8::Handle<v8::Array> api(v8::Array::New(apis->size()));
size_t api_index = 0;
- for (ExtensionAPI::SchemaMap::iterator it = schemas.begin();
- it != schemas.end(); ++it) {
- std::string api_name = it->first;
- api->Set(api_index, GetV8SchemaForAPI(self, context, api_name));
+ for (std::set<std::string>::iterator i = apis->begin(); i != apis->end();
+ ++i) {
+ // TODO(kalman): this caching is actually useless now, because
+ // SchemaGeneratedBindings is per-context not per-process. We should
+ // (e.g.) hang a SchemaRegistry off ExtensionDispatcher (which maintains
+ // a *single* v8::Context rather than multiple ones as here).
+ api->Set(api_index, GetV8SchemaForAPI(self, context, *i));
++api_index;
}
@@ -323,6 +352,7 @@ class ExtensionImpl : public ChromeV8Extension {
namespace extensions {
+// static
ChromeV8Extension* SchemaGeneratedBindings::Get(
ExtensionDispatcher* extension_dispatcher) {
return new ExtensionImpl(extension_dispatcher);

Powered by Google App Engine
This is Rietveld 408576698