event.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 ATOM_BROWSER_API_EVENT_H_
  5. #define ATOM_BROWSER_API_EVENT_H_
  6. #include "content/public/browser/web_contents_observer.h"
  7. #include "native_mate/handle.h"
  8. #include "native_mate/wrappable.h"
  9. namespace IPC {
  10. class Message;
  11. }
  12. namespace mate {
  13. class Event : public Wrappable<Event>, public content::WebContentsObserver {
  14. public:
  15. static Handle<Event> Create(v8::Isolate* isolate);
  16. static void BuildPrototype(v8::Isolate* isolate,
  17. v8::Local<v8::FunctionTemplate> prototype);
  18. // Pass the sender and message to be replied.
  19. void SetSenderAndMessage(content::RenderFrameHost* sender,
  20. IPC::Message* message);
  21. // event.PreventDefault().
  22. void PreventDefault(v8::Isolate* isolate);
  23. // event.sendReply(array), used for replying synchronous message.
  24. bool SendReply(const base::ListValue& result);
  25. protected:
  26. explicit Event(v8::Isolate* isolate);
  27. ~Event() override;
  28. // content::WebContentsObserver implementations:
  29. void RenderFrameDeleted(content::RenderFrameHost* rfh) override;
  30. void RenderFrameHostChanged(content::RenderFrameHost* old_rfh,
  31. content::RenderFrameHost* new_rfh) override;
  32. void FrameDeleted(content::RenderFrameHost* rfh) override;
  33. private:
  34. // Replyer for the synchronous messages.
  35. content::RenderFrameHost* sender_ = nullptr;
  36. IPC::Message* message_ = nullptr;
  37. DISALLOW_COPY_AND_ASSIGN(Event);
  38. };
  39. } // namespace mate
  40. #endif // ATOM_BROWSER_API_EVENT_H_