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