atom_api_net.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright (c) 2016 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "atom/browser/api/atom_api_net.h"
  5. #include "atom/browser/api/atom_api_url_request.h"
  6. #include "atom/common/node_includes.h"
  7. #include "native_mate/dictionary.h"
  8. namespace atom {
  9. namespace api {
  10. Net::Net(v8::Isolate* isolate) {
  11. Init(isolate);
  12. }
  13. Net::~Net() {}
  14. // static
  15. v8::Local<v8::Value> Net::Create(v8::Isolate* isolate) {
  16. return mate::CreateHandle(isolate, new Net(isolate)).ToV8();
  17. }
  18. // static
  19. void Net::BuildPrototype(v8::Isolate* isolate,
  20. v8::Local<v8::FunctionTemplate> prototype) {
  21. prototype->SetClassName(mate::StringToV8(isolate, "Net"));
  22. mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
  23. .SetProperty("URLRequest", &Net::URLRequest);
  24. }
  25. v8::Local<v8::Value> Net::URLRequest(v8::Isolate* isolate) {
  26. return URLRequest::GetConstructor(isolate)->GetFunction();
  27. }
  28. } // namespace api
  29. } // namespace atom
  30. namespace {
  31. using atom::api::Net;
  32. using atom::api::URLRequest;
  33. void Initialize(v8::Local<v8::Object> exports,
  34. v8::Local<v8::Value> unused,
  35. v8::Local<v8::Context> context,
  36. void* priv) {
  37. v8::Isolate* isolate = context->GetIsolate();
  38. URLRequest::SetConstructor(isolate, base::Bind(URLRequest::New));
  39. mate::Dictionary dict(isolate, exports);
  40. dict.Set("net", Net::Create(isolate));
  41. dict.Set("Net", Net::GetConstructor(isolate)->GetFunction());
  42. }
  43. } // namespace
  44. NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_net, Initialize)