Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7577 from thomsonreuters/net_module
net module
- Loading branch information
Showing
19 changed files
with
3,382 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2016 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 "atom/common/node_includes.h" | ||
#include "native_mate/dictionary.h" | ||
|
||
namespace atom { | ||
|
||
namespace api { | ||
|
||
Net::Net(v8::Isolate* isolate) { | ||
Init(isolate); | ||
} | ||
|
||
Net::~Net() {} | ||
|
||
// static | ||
v8::Local<v8::Value> Net::Create(v8::Isolate* isolate) { | ||
return mate::CreateHandle(isolate, new Net(isolate)).ToV8(); | ||
} | ||
|
||
// static | ||
void Net::BuildPrototype(v8::Isolate* isolate, | ||
v8::Local<v8::FunctionTemplate> prototype) { | ||
prototype->SetClassName(mate::StringToV8(isolate, "Net")); | ||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) | ||
.SetProperty("URLRequest", &Net::URLRequest); | ||
} | ||
|
||
v8::Local<v8::Value> 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<v8::Object> exports, | ||
v8::Local<v8::Value> unused, | ||
v8::Local<v8::Context> 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)); | ||
dict.Set("Net", Net::GetConstructor(isolate)->GetFunction()); | ||
} | ||
|
||
} // namespace | ||
|
||
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_net, Initialize) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) 2016 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<Net> { | ||
public: | ||
static v8::Local<v8::Value> Create(v8::Isolate* isolate); | ||
|
||
static void BuildPrototype(v8::Isolate* isolate, | ||
v8::Local<v8::FunctionTemplate> prototype); | ||
|
||
v8::Local<v8::Value> URLRequest(v8::Isolate* isolate); | ||
|
||
protected: | ||
explicit Net(v8::Isolate* isolate); | ||
~Net() override; | ||
|
||
private: | ||
DISALLOW_COPY_AND_ASSIGN(Net); | ||
}; | ||
|
||
} // namespace api | ||
|
||
} // namespace atom | ||
|
||
#endif // ATOM_BROWSER_API_ATOM_API_NET_H_ |
Oops, something went wrong.