Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/renderer/extensions/schema_generated_bindings.h" | 5 #include "chrome/renderer/extensions/schema_generated_bindings.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 } | 111 } |
| 112 | 112 |
| 113 static v8::Handle<v8::Value> GetExtensionAPIDefinition( | 113 static v8::Handle<v8::Value> GetExtensionAPIDefinition( |
| 114 const v8::Arguments& args) { | 114 const v8::Arguments& args) { |
| 115 ExtensionImpl* self = GetFromArguments<ExtensionImpl>(args); | 115 ExtensionImpl* self = GetFromArguments<ExtensionImpl>(args); |
| 116 ExtensionDispatcher* dispatcher = self->extension_dispatcher_; | 116 ExtensionDispatcher* dispatcher = self->extension_dispatcher_; |
| 117 | 117 |
| 118 ChromeV8Context* v8_context = dispatcher->v8_context_set().GetCurrent(); | 118 ChromeV8Context* v8_context = dispatcher->v8_context_set().GetCurrent(); |
| 119 CHECK(v8_context); | 119 CHECK(v8_context); |
| 120 | 120 |
| 121 std::string extension_id = v8_context->extension_id(); | 121 // TODO(kalman): can we just cache this in the ChromeV8Context instance? |
|
not at google - send to devlin
2012/03/20 03:32:13
I deleted this TODO because it *was* no longer rel
koz (OOO until 15th September)
2012/03/20 04:43:05
I can't think of any particularly good reason not
not at google - send to devlin
2012/03/20 07:02:05
Bahhhhhhhhhhhhhhhhhhh turns out this is hard becau
koz (OOO until 15th September)
2012/03/20 23:04:18
Surely!
| |
| 122 ExtensionAPI::SchemaMap schemas; | 122 scoped_ptr<std::set<std::string> > apis; |
| 123 ExtensionAPI::GetSchemasFilter filter = | |
| 124 dispatcher->is_extension_process() ? | |
| 125 ExtensionAPI::ALL : ExtensionAPI::ONLY_UNPRIVILEGED; | |
| 126 | 123 |
| 124 const std::string& extension_id = v8_context->extension_id(); | |
| 127 if (dispatcher->IsTestExtensionId(extension_id)) { | 125 if (dispatcher->IsTestExtensionId(extension_id)) { |
| 128 ExtensionAPI::GetInstance()->GetDefaultSchemas(filter, &schemas); | 126 apis.reset(new std::set<std::string>()); |
| 127 // The minimal set of APIs that tests need. | |
| 128 apis->insert("extension"); | |
| 129 } else { | 129 } else { |
| 130 const ::Extension* extension = | 130 apis = ExtensionAPI::GetInstance()->GetAPIsForContext( |
| 131 dispatcher->extensions()->GetByID(extension_id); | 131 v8_context->context_type(), |
| 132 CHECK(extension) << extension_id << " not found"; | 132 dispatcher->extensions()->GetByID(extension_id), |
| 133 ExtensionAPI::GetInstance()->GetSchemasForExtension( | 133 UserScriptSlave::GetDataSourceURLForFrame(v8_context->web_frame())); |
| 134 *extension, filter, &schemas); | |
| 135 } | 134 } |
| 136 | 135 |
| 137 v8::Persistent<v8::Context> context(v8::Context::New()); | 136 v8::Persistent<v8::Context> context(v8::Context::New()); |
| 138 v8::Context::Scope context_scope(context); | 137 v8::Context::Scope context_scope(context); |
| 139 v8::Handle<v8::Array> api(v8::Array::New(schemas.size())); | 138 v8::Handle<v8::Array> api(v8::Array::New(apis->size())); |
| 140 size_t api_index = 0; | 139 size_t api_index = 0; |
| 141 for (ExtensionAPI::SchemaMap::iterator it = schemas.begin(); | 140 for (std::set<std::string>::iterator i = apis->begin(); i != apis->end(); |
| 142 it != schemas.end(); ++it) { | 141 ++i) { |
| 143 std::string api_name = it->first; | 142 // TODO(kalman): this caching is actually useless now, because |
|
koz (OOO until 15th September)
2012/03/20 04:43:05
"this caching" -> "the caching in GetV8SchemaForAP
not at google - send to devlin
2012/03/20 07:02:05
I've actually fixed this in a follow-up http://cod
| |
| 144 api->Set(api_index, GetV8SchemaForAPI(self, context, api_name)); | 143 // SchemaGeneratedBindings is per-context not per-process. We should |
| 144 // (e.g.) hang a SchemaRegistry off ExtensionDispatcher (which maintains | |
| 145 // a *single* v8::Context rather than multiple ones as here). | |
| 146 api->Set(api_index, GetV8SchemaForAPI(self, context, *i)); | |
| 145 ++api_index; | 147 ++api_index; |
| 146 } | 148 } |
| 147 | 149 |
| 148 // The persistent extension_api_ will keep the context alive. | 150 // The persistent extension_api_ will keep the context alive. |
| 149 context.Dispose(); | 151 context.Dispose(); |
| 150 | 152 |
| 151 return api; | 153 return api; |
| 152 } | 154 } |
| 153 | 155 |
| 154 static v8::Handle<v8::Value> GetNextRequestId(const v8::Arguments& args) { | 156 static v8::Handle<v8::Value> GetNextRequestId(const v8::Arguments& args) { |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 // We store this so that we don't have to parse it over and over again for | 318 // We store this so that we don't have to parse it over and over again for |
| 317 // every context that uses it. | 319 // every context that uses it. |
| 318 typedef std::map<std::string, v8::Persistent<v8::Object> > CachedSchemaMap; | 320 typedef std::map<std::string, v8::Persistent<v8::Object> > CachedSchemaMap; |
| 319 CachedSchemaMap schemas_; | 321 CachedSchemaMap schemas_; |
| 320 }; | 322 }; |
| 321 | 323 |
| 322 } // namespace | 324 } // namespace |
| 323 | 325 |
| 324 namespace extensions { | 326 namespace extensions { |
| 325 | 327 |
| 328 // static | |
| 326 ChromeV8Extension* SchemaGeneratedBindings::Get( | 329 ChromeV8Extension* SchemaGeneratedBindings::Get( |
| 327 ExtensionDispatcher* extension_dispatcher) { | 330 ExtensionDispatcher* extension_dispatcher) { |
| 328 return new ExtensionImpl(extension_dispatcher); | 331 return new ExtensionImpl(extension_dispatcher); |
| 329 } | 332 } |
| 330 | 333 |
| 331 // static | 334 // static |
| 332 void SchemaGeneratedBindings::HandleResponse(const ChromeV8ContextSet& contexts, | 335 void SchemaGeneratedBindings::HandleResponse(const ChromeV8ContextSet& contexts, |
| 333 int request_id, | 336 int request_id, |
| 334 bool success, | 337 bool success, |
| 335 const std::string& response, | 338 const std::string& response, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 const std::string& extension_id) { | 387 const std::string& extension_id) { |
| 385 for (PendingRequestMap::const_iterator it = g_pending_requests.Get().begin(); | 388 for (PendingRequestMap::const_iterator it = g_pending_requests.Get().begin(); |
| 386 it != g_pending_requests.Get().end(); ++it) { | 389 it != g_pending_requests.Get().end(); ++it) { |
| 387 if (it->second->extension_id == extension_id) | 390 if (it->second->extension_id == extension_id) |
| 388 return true; | 391 return true; |
| 389 } | 392 } |
| 390 return false; | 393 return false; |
| 391 } | 394 } |
| 392 | 395 |
| 393 } // namespace | 396 } // namespace |
| OLD | NEW |