event.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 SHELL_BROWSER_API_EVENT_H_
  5. #define 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. protected:
  23. Event();
  24. ~Event() override;
  25. // gin::Wrappable:
  26. gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
  27. v8::Isolate* isolate) override;
  28. const char* GetTypeName() override;
  29. private:
  30. // Replyer for the synchronous messages.
  31. InvokeCallback callback_;
  32. DISALLOW_COPY_AND_ASSIGN(Event);
  33. };
  34. } // namespace gin_helper
  35. #endif // SHELL_BROWSER_API_EVENT_H_