From e8d4abe78fcaafccbf265ed33db7afe12f91d010 Mon Sep 17 00:00:00 2001 From: "ali.ibrahim" Date: Thu, 15 Sep 2016 15:59:40 +0200 Subject: [PATCH] Adding net module and URLRequest class. --- atom/browser/api/atom_api_net.cc | 65 ++++++++++++++++++++++++ atom/browser/api/atom_api_net.h | 37 ++++++++++++++ atom/browser/api/atom_api_url_request.cc | 39 ++++++++++++++ atom/browser/api/atom_api_url_request.h | 37 ++++++++++++++ atom/common/node_bindings.cc | 1 + filenames.gypi | 5 ++ lib/browser/api/exports/electron.js | 6 +++ lib/browser/api/net.js | 13 +++++ 8 files changed, 203 insertions(+) create mode 100644 atom/browser/api/atom_api_net.cc create mode 100644 atom/browser/api/atom_api_net.h create mode 100644 atom/browser/api/atom_api_url_request.cc create mode 100644 atom/browser/api/atom_api_url_request.h create mode 100644 lib/browser/api/net.js diff --git a/atom/browser/api/atom_api_net.cc b/atom/browser/api/atom_api_net.cc new file mode 100644 index 000000000000..ee1b4373925a --- /dev/null +++ b/atom/browser/api/atom_api_net.cc @@ -0,0 +1,65 @@ +// Copyright (c) 2013 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "atom/browser/api/atom_api_net.h" +#include "atom/browser/api/atom_api_url_request.h" +#include "native_mate/dictionary.h" +#include "atom/common/node_includes.h" + +namespace atom { + +namespace api { + +Net::Net(v8::Isolate* isolate) { + Init(isolate); +} + +Net::~Net() { +} + + +// static +v8::Local Net::Create(v8::Isolate* isolate) { + return mate::CreateHandle(isolate, new Net(isolate)).ToV8(); +} + +// static +void Net::BuildPrototype(v8::Isolate* isolate, + v8::Local prototype) { + prototype->SetClassName(mate::StringToV8(isolate, "Net")); + mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + .SetProperty("URLRequest", &Net::URLRequest); +} + +v8::Local Net::URLRequest(v8::Isolate* isolate) { + return URLRequest::GetConstructor(isolate)->GetFunction(); +} + + + +} // namespace api + +} // namespace atom + + +namespace { + +using atom::api::Net; +using atom::api::URLRequest; + +void Initialize(v8::Local exports, v8::Local unused, + v8::Local context, void* priv) { + + v8::Isolate* isolate = context->GetIsolate(); + + URLRequest::SetConstructor(isolate, base::Bind(URLRequest::New)); + + mate::Dictionary dict(isolate, exports); + dict.Set("net", Net::Create(isolate)); + +} + +} // namespace + +NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_net, Initialize) \ No newline at end of file diff --git a/atom/browser/api/atom_api_net.h b/atom/browser/api/atom_api_net.h new file mode 100644 index 000000000000..dd97bb9653dd --- /dev/null +++ b/atom/browser/api/atom_api_net.h @@ -0,0 +1,37 @@ +// Copyright (c) 2013 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef ATOM_BROWSER_API_ATOM_API_NET_H_ +#define ATOM_BROWSER_API_ATOM_API_NET_H_ + +#include "atom/browser/api/event_emitter.h" + +namespace atom { + +namespace api { + +class Net : public mate::EventEmitter { + +public: + static v8::Local Create(v8::Isolate* isolate); + + static void BuildPrototype(v8::Isolate* isolate, + v8::Local prototype); + + v8::Local URLRequest(v8::Isolate* isolate); +protected: + Net(v8::Isolate* isolate); + ~Net() override; + +private: + + DISALLOW_COPY_AND_ASSIGN(Net); +}; + +} // namespace api + +} // namespace atom + + +#endif // ATOM_BROWSER_API_ATOM_API_NET_H_ \ No newline at end of file diff --git a/atom/browser/api/atom_api_url_request.cc b/atom/browser/api/atom_api_url_request.cc new file mode 100644 index 000000000000..8862fbaee2fb --- /dev/null +++ b/atom/browser/api/atom_api_url_request.cc @@ -0,0 +1,39 @@ +// Copyright (c) 2013 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "atom/browser/api/atom_api_url_request.h" + +namespace atom { + +namespace api { + +URLRequest::URLRequest(v8::Isolate* isolate) { + Init(isolate); +} + +URLRequest::~URLRequest() { +} + +// static +mate::WrappableBase* URLRequest::New(mate::Arguments* args) { + + return new URLRequest(args->isolate()); +} + + +// static +void URLRequest::BuildPrototype(v8::Isolate* isolate, + v8::Local prototype) { + prototype->SetClassName(mate::StringToV8(isolate, "WebRequest")); + mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + .SetMethod("start", &URLRequest::start); +} + +void URLRequest::start() { + +} + +} // namespace mate + +} // namepsace mate \ No newline at end of file diff --git a/atom/browser/api/atom_api_url_request.h b/atom/browser/api/atom_api_url_request.h new file mode 100644 index 000000000000..3d07b0712b43 --- /dev/null +++ b/atom/browser/api/atom_api_url_request.h @@ -0,0 +1,37 @@ +// Copyright (c) 2013 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef ATOM_BROWSER_API_ATOM_API_URL_REQUEST_H_ +#define ATOM_BROWSER_API_ATOM_API_URL_REQUEST_H_ + +#include "atom/browser/api/trackable_object.h" +#include "native_mate/handle.h" + +namespace atom { + +namespace api { + + +class URLRequest : public mate::TrackableObject { + public: + static mate::WrappableBase* New(mate::Arguments* args); + + static void BuildPrototype(v8::Isolate* isolate, + v8::Local prototype); + + void start(); + + protected: + URLRequest(v8::Isolate* isolate); + ~URLRequest() override; + + private: + DISALLOW_COPY_AND_ASSIGN(URLRequest); +}; + +} // namepsace api + +} // namepsace atom + +#endif // ATOM_BROWSER_API_ATOM_API_URL_REQUEST_H_ \ No newline at end of file diff --git a/atom/common/node_bindings.cc b/atom/common/node_bindings.cc index a049be23a67e..e869d2a7031c 100644 --- a/atom/common/node_bindings.cc +++ b/atom/common/node_bindings.cc @@ -39,6 +39,7 @@ REFERENCE_MODULE(atom_browser_debugger); REFERENCE_MODULE(atom_browser_desktop_capturer); REFERENCE_MODULE(atom_browser_download_item); REFERENCE_MODULE(atom_browser_menu); +REFERENCE_MODULE(atom_browser_net); REFERENCE_MODULE(atom_browser_power_monitor); REFERENCE_MODULE(atom_browser_power_save_blocker); REFERENCE_MODULE(atom_browser_protocol); diff --git a/filenames.gypi b/filenames.gypi index 9c4b42f622d5..db6bd23d6894 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -23,6 +23,7 @@ 'lib/browser/api/menu-item.js', 'lib/browser/api/menu-item-roles.js', 'lib/browser/api/navigation-controller.js', + 'lib/browser/api/net.js', 'lib/browser/api/power-monitor.js', 'lib/browser/api/power-save-blocker.js', 'lib/browser/api/protocol.js', @@ -116,6 +117,8 @@ 'atom/browser/api/atom_api_menu_views.h', 'atom/browser/api/atom_api_menu_mac.h', 'atom/browser/api/atom_api_menu_mac.mm', + 'atom/browser/api/atom_api_net.cc', + 'atom/browser/api/atom_api_net.h', 'atom/browser/api/atom_api_power_monitor.cc', 'atom/browser/api/atom_api_power_monitor.h', 'atom/browser/api/atom_api_power_save_blocker.cc', @@ -134,6 +137,8 @@ 'atom/browser/api/atom_api_system_preferences_win.cc', 'atom/browser/api/atom_api_tray.cc', 'atom/browser/api/atom_api_tray.h', + 'atom/browser/api/atom_api_url_request.cc', + 'atom/browser/api/atom_api_url_request.h', 'atom/browser/api/atom_api_web_contents.cc', 'atom/browser/api/atom_api_web_contents.h', 'atom/browser/api/atom_api_web_contents_mac.mm', diff --git a/lib/browser/api/exports/electron.js b/lib/browser/api/exports/electron.js index c47c04690659..a96f5a711b74 100644 --- a/lib/browser/api/exports/electron.js +++ b/lib/browser/api/exports/electron.js @@ -107,6 +107,12 @@ Object.defineProperties(exports, { return require('../web-contents') } }, + //net: { + // enumerable: true, + // get: function () { + // return require('../net') + // } + //}, // The internal modules, invisible unless you know their names. NavigationController: { diff --git a/lib/browser/api/net.js b/lib/browser/api/net.js new file mode 100644 index 000000000000..98e8104e92fa --- /dev/null +++ b/lib/browser/api/net.js @@ -0,0 +1,13 @@ +'use strict' + +const binding = process.atomBinding('net') +const {URLRequest} = binding + +// Public API. +Object.defineProperties(exports, { + URLRequest: { + enumerable: true, + value: URLRequest + } +}) + \ No newline at end of file