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