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 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>,
  14. public content::WebContentsObserver {
  15. public:
  16. static Handle<Event> Create(v8::Isolate* isolate);
  17. static void BuildPrototype(v8::Isolate* isolate,
  18. v8::Local<v8::FunctionTemplate> prototype);
  19. // Pass the sender and message to be replied.
  20. void SetSenderAndMessage(content::WebContents* sender, IPC::Message* message);
  21. // event.PreventDefault().
  22. void PreventDefault(v8::Isolate* isolate);
  23. // event.sendReply(json), used for replying synchronous message.
  24. bool SendReply(const base::string16& json);
  25. protected:
  26. explicit Event(v8::Isolate* isolate);
  27. ~Event() override;
  28. // content::WebContentsObserver implementations:
  29. void WebContentsDestroyed() override;
  30. private:
  31. // Replyer for the synchronous messages.
  32. content::WebContents* sender_;
  33. IPC::Message* message_;
  34. DISALLOW_COPY_AND_ASSIGN(Event);
  35. };
  36. } // namespace mate
  37. #endif // ATOM_BROWSER_API_EVENT_H_