declarative_content_hooks_delegate.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2017 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. #ifndef EXTENSIONS_RENDERER_DECLARATIVE_CONTENT_HOOKS_DELEGATE_H_
  5. #define EXTENSIONS_RENDERER_DECLARATIVE_CONTENT_HOOKS_DELEGATE_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "base/callback.h"
  10. #include "extensions/renderer/bindings/api_binding_hooks_delegate.h"
  11. #include "v8/include/v8-forward.h"
  12. namespace extensions {
  13. class APITypeReferenceMap;
  14. class ArgumentSpec;
  15. // Custom hooks for the declarativeContent API.
  16. class DeclarativeContentHooksDelegate : public APIBindingHooksDelegate {
  17. public:
  18. // The callback type for handling an API call.
  19. using HandlerCallback =
  20. base::RepeatingCallback<void(const v8::FunctionCallbackInfo<v8::Value>&)>;
  21. DeclarativeContentHooksDelegate();
  22. DeclarativeContentHooksDelegate(const DeclarativeContentHooksDelegate&) =
  23. delete;
  24. DeclarativeContentHooksDelegate& operator=(
  25. const DeclarativeContentHooksDelegate&) = delete;
  26. ~DeclarativeContentHooksDelegate() override;
  27. void InitializeTemplate(v8::Isolate* isolate,
  28. v8::Local<v8::ObjectTemplate> object_template,
  29. const APITypeReferenceMap& type_refs) override;
  30. private:
  31. void HandleCall(const ArgumentSpec* spec,
  32. const APITypeReferenceMap* type_refs,
  33. const std::string& type_name,
  34. const v8::FunctionCallbackInfo<v8::Value>& info);
  35. // The owned callbacks for the constructor functions. Since these pointers
  36. // are passed to v8::External, we need to use unique_ptrs rather than just
  37. // storing the callback directly in a vector.
  38. std::vector<std::unique_ptr<HandlerCallback>> callbacks_;
  39. };
  40. } // namespace extensions
  41. #endif // EXTENSIONS_RENDERER_DECLARATIVE_CONTENT_HOOKS_DELEGATE_H_