atom_api_web_request.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (c) 2015 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_ATOM_API_WEB_REQUEST_H_
  5. #define ATOM_BROWSER_API_ATOM_API_WEB_REQUEST_H_
  6. #include "atom/browser/api/trackable_object.h"
  7. #include "atom/browser/net/atom_network_delegate.h"
  8. #include "native_mate/arguments.h"
  9. #include "native_mate/handle.h"
  10. namespace atom {
  11. class AtomBrowserContext;
  12. namespace api {
  13. class WebRequest : public mate::TrackableObject<WebRequest> {
  14. public:
  15. static mate::Handle<WebRequest> Create(v8::Isolate* isolate,
  16. AtomBrowserContext* browser_context);
  17. static void BuildPrototype(v8::Isolate* isolate,
  18. v8::Local<v8::FunctionTemplate> prototype);
  19. protected:
  20. WebRequest(v8::Isolate* isolate, AtomBrowserContext* browser_context);
  21. ~WebRequest() override;
  22. // C++ can not distinguish overloaded member function.
  23. template <AtomNetworkDelegate::SimpleEvent type>
  24. void SetSimpleListener(mate::Arguments* args);
  25. template <AtomNetworkDelegate::ResponseEvent type>
  26. void SetResponseListener(mate::Arguments* args);
  27. template <typename Listener, typename Method, typename Event>
  28. void SetListener(Method method, Event type, mate::Arguments* args);
  29. private:
  30. scoped_refptr<AtomBrowserContext> browser_context_;
  31. DISALLOW_COPY_AND_ASSIGN(WebRequest);
  32. };
  33. } // namespace api
  34. } // namespace atom
  35. #endif // ATOM_BROWSER_API_ATOM_API_WEB_REQUEST_H_