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/api_definitions_natives.h" | 5 #include "chrome/renderer/extensions/api_definitions_natives.h" |
6 | 6 |
| 7 #include "chrome/common/extensions/api/extension_api.h" |
| 8 |
7 namespace extensions { | 9 namespace extensions { |
8 | 10 |
9 ApiDefinitionsNatives::ApiDefinitionsNatives( | 11 ApiDefinitionsNatives::ApiDefinitionsNatives( |
10 ExtensionDispatcher* extension_dispatcher) | 12 ExtensionDispatcher* extension_dispatcher) |
11 : ChromeV8Extension(extension_dispatcher) { | 13 : ChromeV8Extension(extension_dispatcher) { |
12 RouteFunction("GetExtensionAPIDefinition", | 14 RouteFunction("GetExtensionAPIDefinition", |
13 base::Bind(&ApiDefinitionsNatives::GetExtensionAPIDefinition, | 15 base::Bind(&ApiDefinitionsNatives::GetExtensionAPIDefinition, |
14 base::Unretained(this))); | 16 base::Unretained(this))); |
| 17 RouteFunction("IsMemberAllowed", |
| 18 base::Bind(&ApiDefinitionsNatives::IsMemberAllowed, |
| 19 base::Unretained(this))); |
15 } | 20 } |
16 | 21 |
17 v8::Handle<v8::Value> ApiDefinitionsNatives::GetExtensionAPIDefinition( | 22 v8::Handle<v8::Value> ApiDefinitionsNatives::GetExtensionAPIDefinition( |
18 const v8::Arguments& args) { | 23 const v8::Arguments& args) { |
19 ChromeV8Context* v8_context = | 24 ChromeV8Context* v8_context = |
20 extension_dispatcher()->v8_context_set().GetCurrent(); | 25 extension_dispatcher()->v8_context_set().GetCurrent(); |
21 CHECK(v8_context); | 26 CHECK(v8_context); |
22 return extension_dispatcher()->v8_schema_registry()->GetSchemas( | 27 return extension_dispatcher()->v8_schema_registry()->GetSchemas( |
23 v8_context->GetAvailableExtensionAPIs()); | 28 v8_context->GetAvailableExtensionAPIs()); |
24 } | 29 } |
25 | 30 |
| 31 v8::Handle<v8::Value> ApiDefinitionsNatives::IsMemberAllowed( |
| 32 const v8::Arguments& arguments) { |
| 33 if (arguments.Length() < 1 || !arguments[0]->IsString()) { |
| 34 LOG(ERROR) << "Invalid arguments"; |
| 35 return v8::Boolean::New(false); |
| 36 } |
| 37 |
| 38 ChromeV8Context* v8_context = |
| 39 extension_dispatcher()->v8_context_set().GetCurrent(); |
| 40 CHECK(v8_context); |
| 41 |
| 42 const Extension* extension = |
| 43 extension_dispatcher()->extensions()->GetByID( |
| 44 v8_context->GetExtensionID()); |
| 45 |
| 46 std::string api_name = *v8::String::AsciiValue(arguments[0]->ToString()); |
| 47 bool result = ExtensionAPI::GetSharedInstance()->IsAvailable( |
| 48 api_name, |
| 49 extension, |
| 50 v8_context->context_type()); |
| 51 return v8::Boolean::New(result); |
| 52 } |
| 53 |
26 } // namespace extensions | 54 } // namespace extensions |
OLD | NEW |