| 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 <algorithm> | |
| 8 | |
| 9 namespace { | |
| 10 const char kInvalidExtensionNamespace[] = "Invalid extension namespace"; | |
| 11 } | |
| 12 | |
| 13 namespace extensions { | 7 namespace extensions { |
| 14 | 8 |
| 15 ApiDefinitionsNatives::ApiDefinitionsNatives( | 9 ApiDefinitionsNatives::ApiDefinitionsNatives( |
| 16 ExtensionDispatcher* extension_dispatcher) | 10 ExtensionDispatcher* extension_dispatcher) |
| 17 : ChromeV8Extension(extension_dispatcher) { | 11 : ChromeV8Extension(extension_dispatcher) { |
| 18 RouteFunction("GetExtensionAPIDefinition", | 12 RouteFunction("GetExtensionAPIDefinition", |
| 19 base::Bind(&ApiDefinitionsNatives::GetExtensionAPIDefinition, | 13 base::Bind(&ApiDefinitionsNatives::GetExtensionAPIDefinition, |
| 20 base::Unretained(this))); | 14 base::Unretained(this))); |
| 21 } | 15 } |
| 22 | 16 |
| 23 v8::Handle<v8::Value> ApiDefinitionsNatives::GetExtensionAPIDefinition( | 17 v8::Handle<v8::Value> ApiDefinitionsNatives::GetExtensionAPIDefinition( |
| 24 const v8::Arguments& args) { | 18 const v8::Arguments& args) { |
| 25 ChromeV8Context* v8_context = | 19 ChromeV8Context* v8_context = |
| 26 extension_dispatcher()->v8_context_set().GetCurrent(); | 20 extension_dispatcher()->v8_context_set().GetCurrent(); |
| 27 CHECK(v8_context); | 21 CHECK(v8_context); |
| 28 | |
| 29 std::set<std::string> available_apis(v8_context->GetAvailableExtensionAPIs()); | |
| 30 if (args.Length() == 0) { | |
| 31 return extension_dispatcher()->v8_schema_registry()->GetSchemas( | |
| 32 available_apis); | |
| 33 } | |
| 34 // Build set of APIs requested by the user. | |
| 35 std::set<std::string> requested_apis; | |
| 36 for (int i = 0; i < args.Length(); ++i) { | |
| 37 if (!args[i]->IsString()) { | |
| 38 v8::ThrowException(v8::String::New(kInvalidExtensionNamespace)); | |
| 39 return v8::Undefined(); | |
| 40 } | |
| 41 requested_apis.insert(*v8::String::Utf8Value(args[i]->ToString())); | |
| 42 } | |
| 43 | |
| 44 // Filter those that are unknown. | |
| 45 std::set<std::string> apis_to_check; | |
| 46 std::set_intersection(requested_apis.begin(), requested_apis.end(), | |
| 47 available_apis.begin(), available_apis.end(), | |
| 48 std::inserter(apis_to_check, apis_to_check.begin())); | |
| 49 return extension_dispatcher()->v8_schema_registry()->GetSchemas( | 22 return extension_dispatcher()->v8_schema_registry()->GetSchemas( |
| 50 apis_to_check); | 23 v8_context->GetAvailableExtensionAPIs()); |
| 51 } | 24 } |
| 52 | 25 |
| 53 } // namespace extensions | 26 } // namespace extensions |
| OLD | NEW |