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/05 07:46:54
I added this TODO for the duration of the code rev
| |
| 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 api->Set(api_index, GetV8SchemaForAPI(self, context, *i)); |
| 144 api->Set(api_index, GetV8SchemaForAPI(self, context, api_name)); | |
| 145 ++api_index; | 143 ++api_index; |
| 146 } | 144 } |
| 147 | 145 |
| 148 // The persistent extension_api_ will keep the context alive. | 146 // The persistent extension_api_ will keep the context alive. |
| 149 context.Dispose(); | 147 context.Dispose(); |
| 150 | 148 |
| 151 return api; | 149 return api; |
| 152 } | 150 } |
| 153 | 151 |
| 154 static v8::Handle<v8::Value> GetNextRequestId(const v8::Arguments& args) { | 152 static v8::Handle<v8::Value> GetNextRequestId(const v8::Arguments& args) { |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 const std::string& extension_id) { | 382 const std::string& extension_id) { |
| 385 for (PendingRequestMap::const_iterator it = g_pending_requests.Get().begin(); | 383 for (PendingRequestMap::const_iterator it = g_pending_requests.Get().begin(); |
| 386 it != g_pending_requests.Get().end(); ++it) { | 384 it != g_pending_requests.Get().end(); ++it) { |
| 387 if (it->second->extension_id == extension_id) | 385 if (it->second->extension_id == extension_id) |
| 388 return true; | 386 return true; |
| 389 } | 387 } |
| 390 return false; | 388 return false; |
| 391 } | 389 } |
| 392 | 390 |
| 393 } // namespace | 391 } // namespace |
| OLD | NEW |