OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/renderer/extensions/api_definitions_natives.h" |
| 6 |
| 7 #include "chrome/common/extensions/api/extension_api.h" |
| 8 #include "chrome/renderer/extensions/user_script_slave.h" |
| 9 |
| 10 namespace extensions { |
| 11 |
| 12 ApiDefinitionsNatives::ApiDefinitionsNatives( |
| 13 ExtensionDispatcher* extension_dispatcher) |
| 14 : ChromeV8Extension(extension_dispatcher) { |
| 15 RouteFunction("GetExtensionAPIDefinition", |
| 16 base::Bind(&ApiDefinitionsNatives::GetExtensionAPIDefinition, |
| 17 base::Unretained(this))); |
| 18 } |
| 19 |
| 20 v8::Handle<v8::Value> ApiDefinitionsNatives::GetExtensionAPIDefinition( |
| 21 const v8::Arguments& args) { |
| 22 ChromeV8Context* v8_context = |
| 23 extension_dispatcher()->v8_context_set().GetCurrent(); |
| 24 CHECK(v8_context); |
| 25 |
| 26 // TODO(kalman): This is being calculated twice, first in |
| 27 // ExtensionDispatcher then again here. It might as well be a property of |
| 28 // ChromeV8Context, however, this would require making ChromeV8Context take |
| 29 // an Extension rather than an extension ID. In itself this is fine, |
| 30 // however it does not play correctly with the "IsTestExtensionId" checks. |
| 31 // We need to remove that first. |
| 32 scoped_ptr<std::set<std::string> > apis; |
| 33 |
| 34 const std::string& extension_id = v8_context->extension_id(); |
| 35 if (extension_dispatcher()->IsTestExtensionId(extension_id)) { |
| 36 apis.reset(new std::set<std::string>()); |
| 37 // The minimal set of APIs that tests need. |
| 38 apis->insert("extension"); |
| 39 } else { |
| 40 apis = ExtensionAPI::GetSharedInstance()->GetAPIsForContext( |
| 41 v8_context->context_type(), |
| 42 extension_dispatcher()->extensions()->GetByID(extension_id), |
| 43 UserScriptSlave::GetDataSourceURLForFrame(v8_context->web_frame())); |
| 44 } |
| 45 |
| 46 return extension_dispatcher()->v8_schema_registry()->GetSchemas(*apis); |
| 47 } |
| 48 |
| 49 } // namespace extensions |
OLD | NEW |