test_features_native_handler.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233
  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. #include "extensions/renderer/test_features_native_handler.h"
  5. #include "base/bind.h"
  6. #include "content/public/renderer/v8_value_converter.h"
  7. #include "extensions/common/extensions_client.h"
  8. #include "extensions/common/features/json_feature_provider_source.h"
  9. #include "extensions/renderer/script_context.h"
  10. namespace extensions {
  11. TestFeaturesNativeHandler::TestFeaturesNativeHandler(ScriptContext* context)
  12. : ObjectBackedNativeHandler(context) {}
  13. void TestFeaturesNativeHandler::AddRoutes() {
  14. RouteHandlerFunction(
  15. "GetAPIFeatures", "test",
  16. base::BindRepeating(&TestFeaturesNativeHandler::GetAPIFeatures,
  17. base::Unretained(this)));
  18. }
  19. void TestFeaturesNativeHandler::GetAPIFeatures(
  20. const v8::FunctionCallbackInfo<v8::Value>& args) {
  21. std::unique_ptr<JSONFeatureProviderSource> source(
  22. ExtensionsClient::Get()->CreateAPIFeatureSource());
  23. args.GetReturnValue().Set(content::V8ValueConverter::Create()->ToV8Value(
  24. source->dictionary(), context()->v8_context()));
  25. }
  26. } // namespace extensions