event.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (c) 2014 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_BROWSER_API_EVENT_H_
  5. #define ELECTRON_SHELL_BROWSER_API_EVENT_H_
  6. #include "electron/shell/common/api/api.mojom.h"
  7. #include "gin/handle.h"
  8. #include "gin/wrappable.h"
  9. namespace gin_helper {
  10. class Event : public gin::Wrappable<Event> {
  11. public:
  12. using InvokeCallback = electron::mojom::ElectronApiIPC::InvokeCallback;
  13. static gin::WrapperInfo kWrapperInfo;
  14. static gin::Handle<Event> Create(v8::Isolate* isolate);
  15. // Pass the callback to be invoked.
  16. void SetCallback(InvokeCallback callback);
  17. // event.PreventDefault().
  18. void PreventDefault(v8::Isolate* isolate);
  19. // event.sendReply(value), used for replying to synchronous messages and
  20. // `invoke` calls.
  21. bool SendReply(v8::Isolate* isolate, v8::Local<v8::Value> result);
  22. // disable copy
  23. Event(const Event&) = delete;
  24. Event& operator=(const Event&) = delete;
  25. protected:
  26. Event();
  27. ~Event() override;
  28. // gin::Wrappable:
  29. gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
  30. v8::Isolate* isolate) override;
  31. const char* GetTypeName() override;
  32. private:
  33. // Replier for the synchronous messages.
  34. InvokeCallback callback_;
  35. };
  36. } // namespace gin_helper
  37. #endif // ELECTRON_SHELL_BROWSER_API_EVENT_H_