2019-08-14 05:15:34 +00:00
|
|
|
// Copyright (c) 2019 GitHub, Inc.
|
2015-10-31 13:39:07 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-08-14 05:15:34 +00:00
|
|
|
#include "shell/common/gin_converters/net_converter.h"
|
2015-10-31 13:39:07 +00:00
|
|
|
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <memory>
|
2018-09-19 11:10:26 +00:00
|
|
|
#include <string>
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <utility>
|
2015-12-05 01:48:19 +00:00
|
|
|
#include <vector>
|
2015-11-05 14:06:36 +00:00
|
|
|
|
2021-06-25 00:06:42 +00:00
|
|
|
#include "base/containers/span.h"
|
2016-07-19 03:06:17 +00:00
|
|
|
#include "base/strings/string_number_conversions.h"
|
2016-10-13 15:14:23 +00:00
|
|
|
#include "base/strings/string_util.h"
|
2016-08-26 22:30:02 +00:00
|
|
|
#include "base/values.h"
|
2019-08-24 01:14:23 +00:00
|
|
|
#include "gin/converter.h"
|
2019-08-14 05:15:34 +00:00
|
|
|
#include "gin/dictionary.h"
|
2015-11-05 14:06:36 +00:00
|
|
|
#include "net/cert/x509_certificate.h"
|
2018-04-12 19:55:43 +00:00
|
|
|
#include "net/cert/x509_util.h"
|
2015-12-01 04:52:22 +00:00
|
|
|
#include "net/http/http_response_headers.h"
|
2019-11-27 01:01:13 +00:00
|
|
|
#include "net/http/http_version.h"
|
|
|
|
#include "net/url_request/redirect_info.h"
|
2019-04-29 02:37:45 +00:00
|
|
|
#include "services/network/public/cpp/resource_request.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/api/electron_api_data_pipe_holder.h"
|
2019-08-14 05:15:34 +00:00
|
|
|
#include "shell/common/gin_converters/gurl_converter.h"
|
|
|
|
#include "shell/common/gin_converters/std_converter.h"
|
2019-10-31 07:56:00 +00:00
|
|
|
#include "shell/common/gin_converters/value_converter.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/node_includes.h"
|
2015-10-31 13:39:07 +00:00
|
|
|
|
2019-08-14 05:15:34 +00:00
|
|
|
namespace gin {
|
2015-10-31 13:39:07 +00:00
|
|
|
|
2017-04-04 13:19:23 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool CertFromData(const std::string& data,
|
2018-04-18 01:55:30 +00:00
|
|
|
scoped_refptr<net::X509Certificate>* out) {
|
2017-04-04 13:19:23 +00:00
|
|
|
auto cert_list = net::X509Certificate::CreateCertificateListFromBytes(
|
2021-06-25 00:06:42 +00:00
|
|
|
base::as_bytes(base::make_span(data)),
|
2018-04-18 01:55:30 +00:00
|
|
|
net::X509Certificate::FORMAT_SINGLE_CERTIFICATE);
|
2017-04-04 13:19:23 +00:00
|
|
|
if (cert_list.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto leaf_cert = cert_list.front();
|
|
|
|
if (!leaf_cert)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*out = leaf_cert;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-04 13:23:30 +00:00
|
|
|
} // namespace
|
2017-04-04 13:19:23 +00:00
|
|
|
|
2015-10-31 13:39:07 +00:00
|
|
|
// static
|
2019-04-20 17:20:37 +00:00
|
|
|
v8::Local<v8::Value> Converter<net::AuthChallengeInfo>::ToV8(
|
2018-04-18 01:55:30 +00:00
|
|
|
v8::Isolate* isolate,
|
2019-04-20 17:20:37 +00:00
|
|
|
const net::AuthChallengeInfo& val) {
|
2019-08-14 05:15:34 +00:00
|
|
|
gin::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
|
2019-04-20 17:20:37 +00:00
|
|
|
dict.Set("isProxy", val.is_proxy);
|
|
|
|
dict.Set("scheme", val.scheme);
|
|
|
|
dict.Set("host", val.challenger.host());
|
|
|
|
dict.Set("port", static_cast<uint32_t>(val.challenger.port()));
|
|
|
|
dict.Set("realm", val.realm);
|
2019-08-14 05:15:34 +00:00
|
|
|
return gin::ConvertToV8(isolate, dict);
|
2015-10-31 13:39:07 +00:00
|
|
|
}
|
|
|
|
|
2015-11-05 14:06:36 +00:00
|
|
|
// static
|
|
|
|
v8::Local<v8::Value> Converter<scoped_refptr<net::X509Certificate>>::ToV8(
|
2018-04-18 01:55:30 +00:00
|
|
|
v8::Isolate* isolate,
|
|
|
|
const scoped_refptr<net::X509Certificate>& val) {
|
2019-08-14 05:15:34 +00:00
|
|
|
gin::Dictionary dict(isolate, v8::Object::New(isolate));
|
2015-11-05 14:06:36 +00:00
|
|
|
std::string encoded_data;
|
2018-04-12 19:55:43 +00:00
|
|
|
net::X509Certificate::GetPEMEncoded(val->cert_buffer(), &encoded_data);
|
2016-11-06 13:37:07 +00:00
|
|
|
|
2016-08-10 21:47:05 +00:00
|
|
|
dict.Set("data", encoded_data);
|
2016-11-12 12:18:38 +00:00
|
|
|
dict.Set("issuer", val->issuer());
|
2015-11-05 14:06:36 +00:00
|
|
|
dict.Set("issuerName", val->issuer().GetDisplayName());
|
2016-11-12 12:18:38 +00:00
|
|
|
dict.Set("subject", val->subject());
|
2016-07-12 17:05:28 +00:00
|
|
|
dict.Set("subjectName", val->subject().GetDisplayName());
|
2016-07-19 03:06:17 +00:00
|
|
|
dict.Set("serialNumber", base::HexEncode(val->serial_number().data(),
|
|
|
|
val->serial_number().size()));
|
2016-07-12 17:05:28 +00:00
|
|
|
dict.Set("validStart", val->valid_start().ToDoubleT());
|
|
|
|
dict.Set("validExpiry", val->valid_expiry().ToDoubleT());
|
2016-07-14 11:09:11 +00:00
|
|
|
dict.Set("fingerprint",
|
2018-04-12 19:55:43 +00:00
|
|
|
net::HashValue(val->CalculateFingerprint256(val->cert_buffer()))
|
2018-04-18 01:55:30 +00:00
|
|
|
.ToString());
|
2016-07-12 17:05:28 +00:00
|
|
|
|
2018-04-12 19:55:43 +00:00
|
|
|
const auto& intermediate_buffers = val->intermediate_buffers();
|
|
|
|
if (!intermediate_buffers.empty()) {
|
|
|
|
std::vector<bssl::UniquePtr<CRYPTO_BUFFER>> issuer_intermediates;
|
|
|
|
issuer_intermediates.reserve(intermediate_buffers.size() - 1);
|
|
|
|
for (size_t i = 1; i < intermediate_buffers.size(); ++i) {
|
|
|
|
issuer_intermediates.push_back(
|
2018-10-02 18:11:45 +00:00
|
|
|
bssl::UpRef(intermediate_buffers[i].get()));
|
2018-04-12 19:55:43 +00:00
|
|
|
}
|
2016-11-09 17:19:35 +00:00
|
|
|
const scoped_refptr<net::X509Certificate>& issuer_cert =
|
2018-04-12 19:55:43 +00:00
|
|
|
net::X509Certificate::CreateFromBuffer(
|
2018-10-02 18:11:45 +00:00
|
|
|
bssl::UpRef(intermediate_buffers[0].get()),
|
2018-04-12 19:55:43 +00:00
|
|
|
std::move(issuer_intermediates));
|
2016-11-12 12:18:38 +00:00
|
|
|
dict.Set("issuerCert", issuer_cert);
|
2016-11-09 17:19:35 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 05:15:34 +00:00
|
|
|
return ConvertToV8(isolate, dict);
|
2016-11-09 17:19:35 +00:00
|
|
|
}
|
|
|
|
|
2017-03-31 18:16:26 +00:00
|
|
|
bool Converter<scoped_refptr<net::X509Certificate>>::FromV8(
|
2018-04-18 01:55:30 +00:00
|
|
|
v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
2017-03-31 18:16:26 +00:00
|
|
|
scoped_refptr<net::X509Certificate>* out) {
|
2019-08-14 05:15:34 +00:00
|
|
|
gin::Dictionary dict(nullptr);
|
2017-03-31 18:16:26 +00:00
|
|
|
if (!ConvertFromV8(isolate, val, &dict))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::string data;
|
|
|
|
dict.Get("data", &data);
|
2017-04-01 01:27:49 +00:00
|
|
|
scoped_refptr<net::X509Certificate> leaf_cert;
|
|
|
|
if (!CertFromData(data, &leaf_cert))
|
2017-03-31 19:44:47 +00:00
|
|
|
return false;
|
|
|
|
|
2018-04-12 19:55:43 +00:00
|
|
|
scoped_refptr<net::X509Certificate> issuer_cert;
|
|
|
|
if (dict.Get("issuerCert", &issuer_cert)) {
|
|
|
|
std::vector<bssl::UniquePtr<CRYPTO_BUFFER>> intermediates;
|
2018-10-02 18:11:45 +00:00
|
|
|
intermediates.push_back(bssl::UpRef(issuer_cert->cert_buffer()));
|
2018-04-12 19:55:43 +00:00
|
|
|
auto cert = net::X509Certificate::CreateFromBuffer(
|
2018-10-02 18:11:45 +00:00
|
|
|
bssl::UpRef(leaf_cert->cert_buffer()), std::move(intermediates));
|
2017-04-03 20:27:53 +00:00
|
|
|
if (!cert)
|
2017-04-01 01:27:49 +00:00
|
|
|
return false;
|
|
|
|
|
2017-04-03 20:27:53 +00:00
|
|
|
*out = cert;
|
|
|
|
} else {
|
|
|
|
*out = leaf_cert;
|
2017-04-01 01:27:49 +00:00
|
|
|
}
|
|
|
|
|
2017-03-31 17:53:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 17:19:35 +00:00
|
|
|
// static
|
|
|
|
v8::Local<v8::Value> Converter<net::CertPrincipal>::ToV8(
|
2018-04-18 01:55:30 +00:00
|
|
|
v8::Isolate* isolate,
|
|
|
|
const net::CertPrincipal& val) {
|
2019-08-14 05:15:34 +00:00
|
|
|
gin::Dictionary dict(isolate, v8::Object::New(isolate));
|
2016-11-09 17:19:35 +00:00
|
|
|
|
|
|
|
dict.Set("commonName", val.common_name);
|
2016-11-12 12:18:38 +00:00
|
|
|
dict.Set("organizations", val.organization_names);
|
|
|
|
dict.Set("organizationUnits", val.organization_unit_names);
|
2016-11-09 17:19:35 +00:00
|
|
|
dict.Set("locality", val.locality_name);
|
|
|
|
dict.Set("state", val.state_or_province_name);
|
|
|
|
dict.Set("country", val.country_name);
|
|
|
|
|
2019-08-14 05:15:34 +00:00
|
|
|
return ConvertToV8(isolate, dict);
|
2015-11-05 14:06:36 +00:00
|
|
|
}
|
|
|
|
|
2016-10-13 15:14:23 +00:00
|
|
|
// static
|
2016-10-25 10:41:01 +00:00
|
|
|
v8::Local<v8::Value> Converter<net::HttpResponseHeaders*>::ToV8(
|
2016-10-13 15:14:23 +00:00
|
|
|
v8::Isolate* isolate,
|
2016-10-25 10:41:01 +00:00
|
|
|
net::HttpResponseHeaders* headers) {
|
2016-10-13 15:14:23 +00:00
|
|
|
base::DictionaryValue response_headers;
|
|
|
|
if (headers) {
|
|
|
|
size_t iter = 0;
|
|
|
|
std::string key;
|
|
|
|
std::string value;
|
|
|
|
while (headers->EnumerateHeaderLines(&iter, &key, &value)) {
|
|
|
|
key = base::ToLowerASCII(key);
|
2019-08-21 02:14:21 +00:00
|
|
|
base::Value* values = response_headers.FindListKey(key);
|
|
|
|
if (!values)
|
|
|
|
values = response_headers.SetKey(key, base::ListValue());
|
2020-01-17 18:41:52 +00:00
|
|
|
values->Append(value);
|
2016-10-13 15:14:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ConvertToV8(isolate, response_headers);
|
|
|
|
}
|
|
|
|
|
2017-11-03 17:46:49 +00:00
|
|
|
bool Converter<net::HttpResponseHeaders*>::FromV8(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
|
|
|
net::HttpResponseHeaders* out) {
|
|
|
|
if (!val->IsObject()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-25 00:34:20 +00:00
|
|
|
|
|
|
|
auto addHeaderFromValue = [&isolate, &out](
|
|
|
|
const std::string& key,
|
|
|
|
const v8::Local<v8::Value>& localVal) {
|
|
|
|
auto context = isolate->GetCurrentContext();
|
|
|
|
v8::Local<v8::String> localStrVal;
|
|
|
|
if (!localVal->ToString(context).ToLocal(&localStrVal)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
std::string value;
|
2019-08-14 05:15:34 +00:00
|
|
|
gin::ConvertFromV8(isolate, localStrVal, &value);
|
2020-04-30 20:20:44 +00:00
|
|
|
out->AddHeader(key, value);
|
2018-10-25 00:34:20 +00:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2017-11-03 17:46:49 +00:00
|
|
|
auto context = isolate->GetCurrentContext();
|
2021-05-12 07:38:21 +00:00
|
|
|
auto headers = val.As<v8::Object>();
|
2019-01-21 16:27:11 +00:00
|
|
|
auto keys = headers->GetOwnPropertyNames(context).ToLocalChecked();
|
2017-11-03 17:46:49 +00:00
|
|
|
for (uint32_t i = 0; i < keys->Length(); i++) {
|
2019-01-21 16:27:11 +00:00
|
|
|
v8::Local<v8::Value> keyVal;
|
|
|
|
if (!keys->Get(context, i).ToLocal(&keyVal)) {
|
2017-11-03 17:46:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-10-25 00:34:20 +00:00
|
|
|
std::string key;
|
2019-08-14 05:15:34 +00:00
|
|
|
gin::ConvertFromV8(isolate, keyVal, &key);
|
2018-10-25 00:34:20 +00:00
|
|
|
|
2019-01-21 16:27:11 +00:00
|
|
|
auto localVal = headers->Get(context, keyVal).ToLocalChecked();
|
2018-10-25 00:34:20 +00:00
|
|
|
if (localVal->IsArray()) {
|
2021-05-12 07:38:21 +00:00
|
|
|
auto values = localVal.As<v8::Array>();
|
2018-10-25 00:34:20 +00:00
|
|
|
for (uint32_t j = 0; j < values->Length(); j++) {
|
2019-05-01 00:18:22 +00:00
|
|
|
if (!addHeaderFromValue(key,
|
|
|
|
values->Get(context, j).ToLocalChecked())) {
|
2018-10-25 00:34:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!addHeaderFromValue(key, localVal)) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-11-03 17:46:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-16 01:19:05 +00:00
|
|
|
// static
|
|
|
|
v8::Local<v8::Value> Converter<net::HttpRequestHeaders>::ToV8(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
const net::HttpRequestHeaders& val) {
|
|
|
|
gin::Dictionary headers(isolate, v8::Object::New(isolate));
|
|
|
|
for (net::HttpRequestHeaders::Iterator it(val); it.GetNext();)
|
|
|
|
headers.Set(it.name(), it.value());
|
|
|
|
return ConvertToV8(isolate, headers);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool Converter<net::HttpRequestHeaders>::FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
|
|
|
net::HttpRequestHeaders* out) {
|
|
|
|
base::DictionaryValue dict;
|
|
|
|
if (!ConvertFromV8(isolate, val, &dict))
|
|
|
|
return false;
|
|
|
|
for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) {
|
|
|
|
if (it.value().is_string()) {
|
|
|
|
std::string value = it.value().GetString();
|
|
|
|
out->SetHeader(it.key(), value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-21 02:14:21 +00:00
|
|
|
// static
|
|
|
|
v8::Local<v8::Value> Converter<network::ResourceRequestBody>::ToV8(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
const network::ResourceRequestBody& val) {
|
|
|
|
const auto& elements = *val.elements();
|
|
|
|
v8::Local<v8::Array> arr = v8::Array::New(isolate, elements.size());
|
|
|
|
for (size_t i = 0; i < elements.size(); ++i) {
|
|
|
|
const auto& element = elements[i];
|
|
|
|
gin::Dictionary upload_data(isolate, v8::Object::New(isolate));
|
|
|
|
switch (element.type()) {
|
2021-01-25 16:46:00 +00:00
|
|
|
case network::mojom::DataElement::Tag::kFile: {
|
|
|
|
const auto& element_file = element.As<network::DataElementFile>();
|
2019-12-11 06:46:25 +00:00
|
|
|
upload_data.Set("type", "file");
|
2021-01-25 16:46:00 +00:00
|
|
|
upload_data.Set("file", element_file.path().value());
|
|
|
|
upload_data.Set("filePath",
|
|
|
|
base::Value(element_file.path().AsUTF8Unsafe()));
|
|
|
|
upload_data.Set("offset", static_cast<int>(element_file.offset()));
|
|
|
|
upload_data.Set("length", static_cast<int>(element_file.length()));
|
2019-12-11 06:46:25 +00:00
|
|
|
upload_data.Set("modificationTime",
|
2021-01-25 16:46:00 +00:00
|
|
|
element_file.expected_modification_time().ToDoubleT());
|
2019-08-21 02:14:21 +00:00
|
|
|
break;
|
2021-01-25 16:46:00 +00:00
|
|
|
}
|
|
|
|
case network::mojom::DataElement::Tag::kBytes: {
|
2019-12-11 06:46:25 +00:00
|
|
|
upload_data.Set("type", "rawData");
|
2021-01-25 16:46:00 +00:00
|
|
|
const auto& bytes = element.As<network::DataElementBytes>().bytes();
|
|
|
|
const char* data = reinterpret_cast<const char*>(bytes.data());
|
|
|
|
upload_data.Set(
|
|
|
|
"bytes",
|
|
|
|
node::Buffer::Copy(isolate, data, bytes.size()).ToLocalChecked());
|
2019-08-21 02:14:21 +00:00
|
|
|
break;
|
2021-01-25 16:46:00 +00:00
|
|
|
}
|
|
|
|
case network::mojom::DataElement::Tag::kDataPipe: {
|
2019-12-11 06:46:25 +00:00
|
|
|
upload_data.Set("type", "blob");
|
2019-09-03 22:54:14 +00:00
|
|
|
// TODO(zcbenz): After the NetworkService refactor, the old blobUUID API
|
2020-10-13 17:25:21 +00:00
|
|
|
// becomes unnecessarily complex, we should deprecate the getBlobData
|
|
|
|
// API and return the DataPipeHolder wrapper directly.
|
2019-09-03 22:54:14 +00:00
|
|
|
auto holder = electron::api::DataPipeHolder::Create(isolate, element);
|
|
|
|
upload_data.Set("blobUUID", holder->id());
|
|
|
|
// The lifetime of data pipe is bound to the uploadData object.
|
|
|
|
upload_data.Set("dataPipe", holder);
|
2019-08-21 02:14:21 +00:00
|
|
|
break;
|
2019-09-03 22:54:14 +00:00
|
|
|
}
|
2019-08-21 02:14:21 +00:00
|
|
|
default:
|
|
|
|
NOTREACHED() << "Found unsupported data element";
|
|
|
|
}
|
|
|
|
arr->Set(isolate->GetCurrentContext(), static_cast<uint32_t>(i),
|
|
|
|
ConvertToV8(isolate, upload_data))
|
|
|
|
.Check();
|
|
|
|
}
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
// static
|
|
|
|
v8::Local<v8::Value>
|
|
|
|
Converter<scoped_refptr<network::ResourceRequestBody>>::ToV8(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
const scoped_refptr<network::ResourceRequestBody>& val) {
|
|
|
|
if (!val)
|
|
|
|
return v8::Null(isolate);
|
|
|
|
return ConvertToV8(isolate, *val);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool Converter<scoped_refptr<network::ResourceRequestBody>>::FromV8(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
|
|
|
scoped_refptr<network::ResourceRequestBody>* out) {
|
|
|
|
auto list = std::make_unique<base::ListValue>();
|
|
|
|
if (!ConvertFromV8(isolate, val, list.get()))
|
|
|
|
return false;
|
2021-06-08 02:00:05 +00:00
|
|
|
*out = base::MakeRefCounted<network::ResourceRequestBody>();
|
2019-10-25 13:03:28 +00:00
|
|
|
for (size_t i = 0; i < list->GetSize(); ++i) {
|
|
|
|
base::DictionaryValue* dict = nullptr;
|
|
|
|
std::string type;
|
|
|
|
if (!list->GetDictionary(i, &dict))
|
|
|
|
return false;
|
|
|
|
dict->GetString("type", &type);
|
|
|
|
if (type == "rawData") {
|
|
|
|
base::Value* bytes = nullptr;
|
|
|
|
dict->GetBinary("bytes", &bytes);
|
|
|
|
(*out)->AppendBytes(
|
|
|
|
reinterpret_cast<const char*>(bytes->GetBlob().data()),
|
|
|
|
base::checked_cast<int>(bytes->GetBlob().size()));
|
|
|
|
} else if (type == "file") {
|
|
|
|
std::string file;
|
|
|
|
int offset = 0, length = -1;
|
|
|
|
double modification_time = 0.0;
|
|
|
|
dict->GetStringWithoutPathExpansion("filePath", &file);
|
|
|
|
dict->GetInteger("offset", &offset);
|
|
|
|
dict->GetInteger("file", &length);
|
|
|
|
dict->GetDouble("modificationTime", &modification_time);
|
|
|
|
(*out)->AppendFileRange(base::FilePath::FromUTF8Unsafe(file),
|
|
|
|
static_cast<uint64_t>(offset),
|
|
|
|
static_cast<uint64_t>(length),
|
|
|
|
base::Time::FromDoubleT(modification_time));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-29 02:37:45 +00:00
|
|
|
// static
|
|
|
|
v8::Local<v8::Value> Converter<network::ResourceRequest>::ToV8(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
const network::ResourceRequest& val) {
|
2019-11-27 01:01:13 +00:00
|
|
|
gin::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
|
2019-04-29 02:37:45 +00:00
|
|
|
dict.Set("method", val.method);
|
|
|
|
dict.Set("url", val.url.spec());
|
|
|
|
dict.Set("referrer", val.referrer.spec());
|
2019-08-16 01:19:05 +00:00
|
|
|
dict.Set("headers", val.headers);
|
2019-08-21 02:14:21 +00:00
|
|
|
if (val.request_body)
|
|
|
|
dict.Set("uploadData", ConvertToV8(isolate, *val.request_body));
|
2019-08-14 05:15:34 +00:00
|
|
|
return ConvertToV8(isolate, dict);
|
2019-04-29 02:37:45 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 15:04:09 +00:00
|
|
|
// static
|
|
|
|
v8::Local<v8::Value> Converter<electron::VerifyRequestParams>::ToV8(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
electron::VerifyRequestParams val) {
|
2019-08-14 05:15:34 +00:00
|
|
|
gin::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
|
2019-08-07 15:04:09 +00:00
|
|
|
dict.Set("hostname", val.hostname);
|
|
|
|
dict.Set("certificate", val.certificate);
|
2020-01-27 18:48:29 +00:00
|
|
|
dict.Set("validatedCertificate", val.validated_certificate);
|
2021-08-02 01:24:58 +00:00
|
|
|
dict.Set("isIssuedByKnownRoot", val.is_issued_by_known_root);
|
2019-08-07 15:04:09 +00:00
|
|
|
dict.Set("verificationResult", val.default_result);
|
|
|
|
dict.Set("errorCode", val.error_code);
|
2019-08-14 05:15:34 +00:00
|
|
|
return ConvertToV8(isolate, dict);
|
2019-08-07 15:04:09 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 01:01:13 +00:00
|
|
|
// static
|
|
|
|
v8::Local<v8::Value> Converter<net::HttpVersion>::ToV8(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
const net::HttpVersion& val) {
|
|
|
|
gin::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
|
|
|
|
dict.Set("major", static_cast<uint32_t>(val.major_value()));
|
|
|
|
dict.Set("minor", static_cast<uint32_t>(val.minor_value()));
|
|
|
|
return ConvertToV8(isolate, dict);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
v8::Local<v8::Value> Converter<net::RedirectInfo>::ToV8(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
const net::RedirectInfo& val) {
|
|
|
|
gin::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
|
|
|
|
|
|
|
|
dict.Set("statusCode", val.status_code);
|
|
|
|
dict.Set("newMethod", val.new_method);
|
|
|
|
dict.Set("newUrl", val.new_url);
|
2020-01-17 18:41:52 +00:00
|
|
|
dict.Set("newSiteForCookies", val.new_site_for_cookies.RepresentativeUrl());
|
2019-11-27 01:01:13 +00:00
|
|
|
dict.Set("newReferrer", val.new_referrer);
|
|
|
|
dict.Set("insecureSchemeWasUpgraded", val.insecure_scheme_was_upgraded);
|
|
|
|
dict.Set("isSignedExchangeFallbackRedirect",
|
|
|
|
val.is_signed_exchange_fallback_redirect);
|
|
|
|
|
|
|
|
return ConvertToV8(isolate, dict);
|
|
|
|
}
|
|
|
|
|
2019-08-14 05:15:34 +00:00
|
|
|
} // namespace gin
|