api_binding_types.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2016 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_BINDINGS_API_BINDING_TYPES_H_
  5. #define EXTENSIONS_RENDERER_BINDINGS_API_BINDING_TYPES_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "base/callback.h"
  9. #include "v8/include/v8.h"
  10. namespace extensions {
  11. namespace binding {
  12. // A value indicating an event has no maximum listener count.
  13. extern const int kNoListenerMax;
  14. // Types of changes for event listener registration.
  15. enum class EventListenersChanged {
  16. // Unfiltered Events:
  17. // The first unfiltered listener for the associated context was added.
  18. kFirstUnfilteredListenerForContextAdded,
  19. // The first unfiltered listener for the associated context owner was added.
  20. // This also implies the first listener for the context was added.
  21. kFirstUnfilteredListenerForContextOwnerAdded,
  22. // The last unfiltered listener for the associated context was removed.
  23. kLastUnfilteredListenerForContextRemoved,
  24. // The last unfiltered listener for the associated context owner was removed.
  25. // This also implies the last listener for the context was removed.
  26. kLastUnfilteredListenerForContextOwnerRemoved,
  27. // Filtered Events:
  28. // TODO(https://crbug.com/873017): The fact that we only have added/removed
  29. // at the context owner level for filtered events can cause issues.
  30. // The first listener for the associated context owner with a specific
  31. // filter was added.
  32. kFirstListenerWithFilterForContextOwnerAdded,
  33. // The last listener for the associated context owner with a specific
  34. // filter was removed.
  35. kLastListenerWithFilterForContextOwnerRemoved,
  36. };
  37. // Whether promises are supported in a given API function.
  38. enum class APIPromiseSupport {
  39. kSupported,
  40. kUnsupported,
  41. };
  42. // The type of async response handler an API caller can have.
  43. enum class AsyncResponseType {
  44. kNone,
  45. kCallback,
  46. kPromise,
  47. };
  48. // Adds an error message to the context's console.
  49. using AddConsoleError = base::RepeatingCallback<void(v8::Local<v8::Context>,
  50. const std::string& error)>;
  51. using V8ArgumentList = std::vector<v8::Local<v8::Value>>;
  52. using ResultModifierFunction =
  53. base::OnceCallback<V8ArgumentList(const V8ArgumentList&,
  54. v8::Local<v8::Context>,
  55. AsyncResponseType)>;
  56. } // namespace binding
  57. } // namespace extensions
  58. #endif // EXTENSIONS_RENDERER_BINDINGS_API_BINDING_TYPES_H_