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