[email protected] | 701a94e | 2014-04-17 04:37:37 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "extensions/renderer/api_definitions_natives.h" |
| 6 | |
Devlin Cronin | cc02a0c | 2019-01-03 22:15:07 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | 701a94e | 2014-04-17 04:37:37 | [diff] [blame] | 8 | #include "extensions/common/features/feature.h" |
| 9 | #include "extensions/common/features/feature_provider.h" |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 10 | #include "extensions/renderer/dispatcher.h" |
[email protected] | 701a94e | 2014-04-17 04:37:37 | [diff] [blame] | 11 | #include "extensions/renderer/script_context.h" |
| 12 | |
| 13 | namespace extensions { |
| 14 | |
| 15 | ApiDefinitionsNatives::ApiDefinitionsNatives(Dispatcher* dispatcher, |
| 16 | ScriptContext* context) |
Devlin Cronin | d9ea834 | 2018-01-27 06:00:04 | [diff] [blame] | 17 | : ObjectBackedNativeHandler(context), dispatcher_(dispatcher) {} |
| 18 | |
| 19 | void ApiDefinitionsNatives::AddRoutes() { |
| 20 | RouteHandlerFunction( |
rdevlin.cronin | c0569cc | 2016-04-15 21:51:21 | [diff] [blame] | 21 | "GetExtensionAPIDefinitionsForTest", "test", |
Devlin Cronin | cc02a0c | 2019-01-03 22:15:07 | [diff] [blame] | 22 | base::BindRepeating( |
| 23 | &ApiDefinitionsNatives::GetExtensionAPIDefinitionsForTest, |
| 24 | base::Unretained(this))); |
[email protected] | 701a94e | 2014-04-17 04:37:37 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | void ApiDefinitionsNatives::GetExtensionAPIDefinitionsForTest( |
| 28 | const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 29 | std::vector<std::string> apis; |
[email protected] | bc495a18 | 2014-05-22 04:27:37 | [diff] [blame] | 30 | const FeatureProvider* feature_provider = FeatureProvider::GetAPIFeatures(); |
limasdf | 8477b57 | 2016-03-08 03:04:15 | [diff] [blame] | 31 | for (const auto& map_entry : feature_provider->GetAllFeatures()) { |
Devlin Cronin | 8432a8f3 | 2017-08-10 22:24:53 | [diff] [blame] | 32 | if (!feature_provider->GetParent(*map_entry.second) && |
limasdf | 8477b57 | 2016-03-08 03:04:15 | [diff] [blame] | 33 | context()->GetAvailability(map_entry.first).is_available()) { |
| 34 | apis.push_back(map_entry.first); |
[email protected] | 701a94e | 2014-04-17 04:37:37 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | args.GetReturnValue().Set( |
| 38 | dispatcher_->v8_schema_registry()->GetSchemas(apis)); |
| 39 | } |
| 40 | |
| 41 | } // namespace extensions |