2016-10-25 12:41:01 +02:00
|
|
|
// Copyright (c) 2016 GitHub, Inc.
|
2016-09-15 15:59:40 +02:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-02-04 12:19:40 -08:00
|
|
|
#include "shell/browser/api/electron_api_net.h"
|
2019-07-04 10:56:19 +09:00
|
|
|
|
2019-11-26 17:01:13 -08:00
|
|
|
#include <string>
|
|
|
|
|
2019-10-24 14:47:58 +09:00
|
|
|
#include "gin/handle.h"
|
2019-07-04 10:56:19 +09:00
|
|
|
#include "services/network/public/cpp/features.h"
|
2020-02-04 12:19:40 -08:00
|
|
|
#include "shell/browser/api/electron_api_url_loader.h"
|
2019-10-24 14:47:58 +09:00
|
|
|
#include "shell/common/gin_helper/dictionary.h"
|
|
|
|
#include "shell/common/gin_helper/object_template_builder.h"
|
2019-07-04 10:56:19 +09:00
|
|
|
|
2019-06-19 13:46:59 -07:00
|
|
|
#include "shell/common/node_includes.h"
|
2016-09-15 15:59:40 +02:00
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
namespace electron {
|
2016-09-15 15:59:40 +02:00
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
|
|
|
Net::Net(v8::Isolate* isolate) {
|
|
|
|
Init(isolate);
|
|
|
|
}
|
|
|
|
|
2019-09-16 18:12:00 -04:00
|
|
|
Net::~Net() = default;
|
2016-09-15 15:59:40 +02:00
|
|
|
|
|
|
|
// static
|
|
|
|
v8::Local<v8::Value> Net::Create(v8::Isolate* isolate) {
|
2019-10-24 14:47:58 +09:00
|
|
|
return gin::CreateHandle(isolate, new Net(isolate)).ToV8();
|
2016-09-15 15:59:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void Net::BuildPrototype(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::FunctionTemplate> prototype) {
|
2019-10-24 14:47:58 +09:00
|
|
|
prototype->SetClassName(gin::StringToV8(isolate, "Net"));
|
2016-09-15 15:59:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
} // namespace electron
|
2016-09-15 15:59:40 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2019-11-26 17:01:13 -08:00
|
|
|
bool IsValidHeaderName(std::string header_name) {
|
|
|
|
return net::HttpUtil::IsValidHeaderName(header_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsValidHeaderValue(std::string header_value) {
|
|
|
|
return net::HttpUtil::IsValidHeaderValue(header_value);
|
|
|
|
}
|
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
using electron::api::Net;
|
2019-11-26 17:01:13 -08:00
|
|
|
using electron::api::SimpleURLLoaderWrapper;
|
2016-09-15 15:59:40 +02:00
|
|
|
|
2016-10-14 11:50:47 +02:00
|
|
|
void Initialize(v8::Local<v8::Object> exports,
|
|
|
|
v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context,
|
|
|
|
void* priv) {
|
2016-09-15 15:59:40 +02:00
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
|
|
|
|
2019-10-24 14:47:58 +09:00
|
|
|
gin_helper::Dictionary dict(isolate, exports);
|
2016-09-15 15:59:40 +02:00
|
|
|
dict.Set("net", Net::Create(isolate));
|
2019-01-09 11:17:05 -08:00
|
|
|
dict.Set("Net",
|
|
|
|
Net::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
|
2020-03-23 13:09:45 -07:00
|
|
|
dict.SetMethod("isValidHeaderName", &IsValidHeaderName);
|
|
|
|
dict.SetMethod("isValidHeaderValue", &IsValidHeaderValue);
|
|
|
|
dict.SetMethod("createURLLoader", &SimpleURLLoaderWrapper::Create);
|
2016-09-15 15:59:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2020-02-14 03:25:39 -08:00
|
|
|
NODE_LINKED_MODULE_CONTEXT_AWARE(electron_browser_net, Initialize)
|