runtime_hooks_delegate.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_RUNTIME_HOOKS_DELEGATE_H_
  5. #define EXTENSIONS_RENDERER_RUNTIME_HOOKS_DELEGATE_H_
  6. #include <vector>
  7. #include "extensions/renderer/bindings/api_binding_hooks_delegate.h"
  8. #include "extensions/renderer/bindings/api_signature.h"
  9. #include "v8/include/v8-forward.h"
  10. namespace extensions {
  11. class NativeRendererMessagingService;
  12. class ScriptContext;
  13. // The custom hooks for the runtime API.
  14. class RuntimeHooksDelegate : public APIBindingHooksDelegate {
  15. public:
  16. explicit RuntimeHooksDelegate(
  17. NativeRendererMessagingService* messaging_service);
  18. RuntimeHooksDelegate(const RuntimeHooksDelegate&) = delete;
  19. RuntimeHooksDelegate& operator=(const RuntimeHooksDelegate&) = delete;
  20. ~RuntimeHooksDelegate() override;
  21. // Returns an absolute url for a path inside of an extension, as requested
  22. // through the getURL API call.
  23. // NOTE: Static as the logic is used by both the runtime and extension
  24. // hooks.
  25. static APIBindingHooks::RequestResult GetURL(
  26. ScriptContext* script_context,
  27. const std::vector<v8::Local<v8::Value>>& arguments);
  28. // APIBindingHooksDelegate:
  29. APIBindingHooks::RequestResult HandleRequest(
  30. const std::string& method_name,
  31. const APISignature* signature,
  32. v8::Local<v8::Context> context,
  33. std::vector<v8::Local<v8::Value>>* arguments,
  34. const APITypeReferenceMap& refs) override;
  35. void InitializeTemplate(v8::Isolate* isolate,
  36. v8::Local<v8::ObjectTemplate> object_template,
  37. const APITypeReferenceMap& type_refs) override;
  38. private:
  39. // Request handlers for the corresponding API methods.
  40. APIBindingHooks::RequestResult HandleGetManifest(
  41. ScriptContext* script_context,
  42. const APISignature::V8ParseResult& parse_result);
  43. APIBindingHooks::RequestResult HandleGetURL(
  44. ScriptContext* script_context,
  45. const APISignature::V8ParseResult& parse_result);
  46. APIBindingHooks::RequestResult HandleSendMessage(
  47. ScriptContext* script_context,
  48. const APISignature::V8ParseResult& parse_result);
  49. APIBindingHooks::RequestResult HandleSendNativeMessage(
  50. ScriptContext* script_context,
  51. const APISignature::V8ParseResult& parse_result);
  52. APIBindingHooks::RequestResult HandleConnect(
  53. ScriptContext* script_context,
  54. const APISignature::V8ParseResult& parse_result);
  55. APIBindingHooks::RequestResult HandleConnectNative(
  56. ScriptContext* script_context,
  57. const APISignature::V8ParseResult& parse_result);
  58. APIBindingHooks::RequestResult HandleGetBackgroundPage(
  59. ScriptContext* script_context,
  60. const APISignature::V8ParseResult& parse_result);
  61. APIBindingHooks::RequestResult HandleGetPackageDirectoryEntryCallback(
  62. ScriptContext* script_context,
  63. const APISignature::V8ParseResult& parse_result);
  64. // The messaging service to handle connect() and sendMessage() calls.
  65. // Guaranteed to outlive this object.
  66. NativeRendererMessagingService* const messaging_service_;
  67. };
  68. } // namespace extensions
  69. #endif // EXTENSIONS_RENDERER_RUNTIME_HOOKS_DELEGATE_H_