2016-10-25 10:41:01 +00:00
|
|
|
// Copyright (c) 2016 GitHub, Inc.
|
2016-09-15 13:59:40 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/api/atom_api_net.h"
|
2019-07-04 01:56:19 +00:00
|
|
|
|
2016-09-29 09:31:08 +00:00
|
|
|
#include "native_mate/dictionary.h"
|
2019-07-04 01:56:19 +00:00
|
|
|
#include "services/network/public/cpp/features.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/api/atom_api_url_request.h"
|
2019-07-04 01:56:19 +00:00
|
|
|
#include "shell/browser/api/atom_api_url_request_ns.h"
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/node_includes.h"
|
2016-09-15 13:59:40 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2016-09-15 13:59:40 +00:00
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
|
|
|
Net::Net(v8::Isolate* isolate) {
|
|
|
|
Init(isolate);
|
|
|
|
}
|
|
|
|
|
2016-10-14 09:50:47 +00:00
|
|
|
Net::~Net() {}
|
2016-09-15 13:59:40 +00:00
|
|
|
|
|
|
|
// 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())
|
2016-10-25 10:41:01 +00:00
|
|
|
.SetProperty("URLRequest", &Net::URLRequest);
|
2016-09-15 13:59:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Value> Net::URLRequest(v8::Isolate* isolate) {
|
2019-07-04 01:56:19 +00:00
|
|
|
v8::Local<v8::FunctionTemplate> constructor;
|
|
|
|
if (base::FeatureList::IsEnabled(network::features::kNetworkService))
|
|
|
|
constructor = URLRequestNS::GetConstructor(isolate);
|
|
|
|
else
|
|
|
|
constructor = URLRequest::GetConstructor(isolate);
|
|
|
|
return constructor->GetFunction(isolate->GetCurrentContext())
|
2019-01-09 19:17:05 +00:00
|
|
|
.ToLocalChecked();
|
2016-09-15 13:59:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2016-09-15 13:59:40 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
using electron::api::Net;
|
|
|
|
using electron::api::URLRequest;
|
2019-07-04 01:56:19 +00:00
|
|
|
using electron::api::URLRequestNS;
|
2016-09-15 13:59:40 +00:00
|
|
|
|
2016-10-14 09:50:47 +00:00
|
|
|
void Initialize(v8::Local<v8::Object> exports,
|
|
|
|
v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context,
|
|
|
|
void* priv) {
|
2016-09-15 13:59:40 +00:00
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
|
|
|
|
2019-07-04 01:56:19 +00:00
|
|
|
if (base::FeatureList::IsEnabled(network::features::kNetworkService))
|
|
|
|
URLRequestNS::SetConstructor(isolate,
|
|
|
|
base::BindRepeating(URLRequestNS::New));
|
|
|
|
else
|
|
|
|
URLRequest::SetConstructor(isolate, base::BindRepeating(URLRequest::New));
|
2016-09-15 13:59:40 +00:00
|
|
|
|
|
|
|
mate::Dictionary dict(isolate, exports);
|
|
|
|
dict.Set("net", Net::Create(isolate));
|
2019-01-09 19:17:05 +00:00
|
|
|
dict.Set("Net",
|
|
|
|
Net::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
|
2019-07-04 01:56:19 +00:00
|
|
|
dict.Set("isNetworkServiceEnabled",
|
|
|
|
base::FeatureList::IsEnabled(network::features::kNetworkService));
|
2016-09-15 13:59:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-03-08 18:29:52 +00:00
|
|
|
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_net, Initialize)
|