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-19 11:10:26 +00:00
|
|
|
#include <string>
|
2024-01-11 01:00:37 +00:00
|
|
|
#include <string_view>
|
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"
|
2023-05-11 20:07:39 +00:00
|
|
|
#include "base/memory/raw_ptr.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"
|
2023-03-27 17:00:55 +00:00
|
|
|
#include "gin/object_template_builder.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"
|
2023-03-27 17:00:55 +00:00
|
|
|
#include "services/network/public/cpp/data_element.h"
|
2019-04-29 02:37:45 +00:00
|
|
|
#include "services/network/public/cpp/resource_request.h"
|
2023-03-27 17:00:55 +00:00
|
|
|
#include "services/network/public/cpp/resource_request_body.h"
|
|
|
|
#include "services/network/public/mojom/chunked_data_pipe_getter.mojom.h"
|
2019-09-03 22:54:14 +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"
|
2023-03-27 17:00:55 +00:00
|
|
|
#include "shell/common/gin_helper/promise.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) {
|
2023-08-21 01:43:41 +00:00
|
|
|
auto 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()));
|
2023-11-01 14:02:12 +00:00
|
|
|
dict.Set("validStart", val->valid_start().InSecondsFSinceUnixEpoch());
|
|
|
|
dict.Set("validExpiry", val->valid_expiry().InSecondsFSinceUnixEpoch());
|
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) {
|
2022-06-22 08:14:57 +00:00
|
|
|
base::Value::Dict response_headers;
|
2016-10-13 15:14:23 +00:00
|
|
|
if (headers) {
|
|
|
|
size_t iter = 0;
|
|
|
|
std::string key;
|
|
|
|
std::string value;
|
|
|
|
while (headers->EnumerateHeaderLines(&iter, &key, &value)) {
|
|
|
|
key = base::ToLowerASCII(key);
|
2022-06-22 08:14:57 +00:00
|
|
|
base::Value::List* values = response_headers.FindList(key);
|
2019-08-21 02:14:21 +00:00
|
|
|
if (!values)
|
2022-06-22 08:14:57 +00:00
|
|
|
values = &response_headers.Set(key, base::Value::List())->GetList();
|
2020-01-17 18:41:52 +00:00
|
|
|
values->Append(value);
|
2016-10-13 15:14:23 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-20 14:26:42 +00:00
|
|
|
return ConvertToV8(isolate, response_headers);
|
2016-10-13 15:14:23 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2022-07-05 15:25:18 +00:00
|
|
|
base::Value::Dict dict;
|
2019-08-16 01:19:05 +00:00
|
|
|
if (!ConvertFromV8(isolate, val, &dict))
|
|
|
|
return false;
|
2022-07-05 15:25:18 +00:00
|
|
|
for (const auto it : dict) {
|
|
|
|
if (it.second.is_string()) {
|
|
|
|
std::string value = it.second.GetString();
|
|
|
|
out->SetHeader(it.first, value);
|
2019-08-16 01:19:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-03-27 17:00:55 +00:00
|
|
|
class ChunkedDataPipeReadableStream
|
|
|
|
: public gin::Wrappable<ChunkedDataPipeReadableStream> {
|
|
|
|
public:
|
|
|
|
static gin::Handle<ChunkedDataPipeReadableStream> Create(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
network::ResourceRequestBody* request,
|
|
|
|
network::DataElementChunkedDataPipe* data_element) {
|
|
|
|
return gin::CreateHandle(isolate, new ChunkedDataPipeReadableStream(
|
|
|
|
isolate, request, data_element));
|
|
|
|
}
|
|
|
|
|
|
|
|
// gin::Wrappable
|
|
|
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
|
|
|
v8::Isolate* isolate) override {
|
|
|
|
return gin::Wrappable<
|
|
|
|
ChunkedDataPipeReadableStream>::GetObjectTemplateBuilder(isolate)
|
|
|
|
.SetMethod("read", &ChunkedDataPipeReadableStream::Read);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gin::WrapperInfo kWrapperInfo;
|
|
|
|
|
|
|
|
private:
|
|
|
|
ChunkedDataPipeReadableStream(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
network::ResourceRequestBody* request,
|
|
|
|
network::DataElementChunkedDataPipe* data_element)
|
|
|
|
: isolate_(isolate),
|
|
|
|
resource_request_body_(request),
|
|
|
|
data_element_(data_element),
|
|
|
|
handle_watcher_(FROM_HERE,
|
|
|
|
mojo::SimpleWatcher::ArmingPolicy::MANUAL,
|
|
|
|
base::SequencedTaskRunner::GetCurrentDefault()) {}
|
|
|
|
|
|
|
|
~ChunkedDataPipeReadableStream() override = default;
|
|
|
|
|
|
|
|
int Init() {
|
|
|
|
chunked_data_pipe_getter_.Bind(
|
|
|
|
data_element_->ReleaseChunkedDataPipeGetter());
|
|
|
|
for (auto& element : *resource_request_body_->elements_mutable()) {
|
|
|
|
if (element.type() ==
|
|
|
|
network::mojom::DataElement::Tag::kChunkedDataPipe &&
|
|
|
|
data_element_ == &element.As<network::DataElementChunkedDataPipe>()) {
|
|
|
|
element = network::DataElement(
|
|
|
|
network::DataElementBytes(std::vector<uint8_t>()));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
chunked_data_pipe_getter_.set_disconnect_handler(
|
|
|
|
base::BindOnce(&ChunkedDataPipeReadableStream::OnDataPipeGetterClosed,
|
|
|
|
base::Unretained(this)));
|
|
|
|
chunked_data_pipe_getter_->GetSize(
|
|
|
|
base::BindOnce(&ChunkedDataPipeReadableStream::OnSizeReceived,
|
|
|
|
base::Unretained(this)));
|
|
|
|
mojo::ScopedDataPipeProducerHandle data_pipe_producer;
|
|
|
|
mojo::ScopedDataPipeConsumerHandle data_pipe_consumer;
|
|
|
|
MojoResult result =
|
|
|
|
mojo::CreateDataPipe(nullptr, data_pipe_producer, data_pipe_consumer);
|
|
|
|
if (result != MOJO_RESULT_OK)
|
|
|
|
return net::ERR_INSUFFICIENT_RESOURCES;
|
|
|
|
chunked_data_pipe_getter_->StartReading(std::move(data_pipe_producer));
|
|
|
|
data_pipe_ = std::move(data_pipe_consumer);
|
|
|
|
return net::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Promise> Read(v8::Local<v8::ArrayBufferView> buf) {
|
|
|
|
gin_helper::Promise<int> promise(isolate_);
|
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
|
|
|
|
|
|
|
int status = ReadInternal(buf);
|
|
|
|
|
|
|
|
if (status == net::ERR_IO_PENDING) {
|
|
|
|
promise_ = std::move(promise);
|
|
|
|
} else {
|
|
|
|
if (status < 0)
|
|
|
|
std::move(promise).RejectWithErrorMessage(net::ErrorToString(status));
|
|
|
|
else
|
|
|
|
std::move(promise).Resolve(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ReadInternal(v8::Local<v8::ArrayBufferView> buf) {
|
|
|
|
if (!data_pipe_)
|
|
|
|
status_ = Init();
|
|
|
|
// If there was an error either passed to the ReadCallback or as a result of
|
|
|
|
// closing the DataPipeGetter pipe, fail the read.
|
|
|
|
if (status_ != net::OK)
|
|
|
|
return status_;
|
|
|
|
|
|
|
|
// Nothing else to do, if the entire body was read.
|
|
|
|
if (size_ && bytes_read_ == *size_) {
|
|
|
|
// This shouldn't be called if the stream was already completed.
|
|
|
|
DCHECK(!is_eof_);
|
|
|
|
|
|
|
|
is_eof_ = true;
|
|
|
|
return net::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!handle_watcher_.IsWatching()) {
|
|
|
|
handle_watcher_.Watch(
|
|
|
|
data_pipe_.get(),
|
|
|
|
MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
|
|
|
|
base::BindRepeating(&ChunkedDataPipeReadableStream::OnHandleReadable,
|
|
|
|
base::Unretained(this)));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t num_bytes = buf->ByteLength();
|
|
|
|
if (size_ && num_bytes > *size_ - bytes_read_)
|
|
|
|
num_bytes = *size_ - bytes_read_;
|
|
|
|
MojoResult rv = data_pipe_->ReadData(
|
|
|
|
static_cast<void*>(static_cast<char*>(buf->Buffer()->Data()) +
|
|
|
|
buf->ByteOffset()),
|
|
|
|
&num_bytes, MOJO_READ_DATA_FLAG_NONE);
|
|
|
|
if (rv == MOJO_RESULT_OK) {
|
|
|
|
bytes_read_ += num_bytes;
|
|
|
|
// Not needed for correctness, but this allows the consumer to send the
|
|
|
|
// final chunk and the end of stream message together, for protocols that
|
|
|
|
// allow it.
|
|
|
|
if (size_ && *size_ == bytes_read_)
|
|
|
|
is_eof_ = true;
|
|
|
|
return num_bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rv == MOJO_RESULT_SHOULD_WAIT) {
|
|
|
|
handle_watcher_.ArmOrNotify();
|
|
|
|
buf_.Reset(isolate_, buf);
|
|
|
|
return net::ERR_IO_PENDING;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The pipe was closed. If the size isn't known yet, could be a success or a
|
|
|
|
// failure.
|
|
|
|
if (!size_) {
|
|
|
|
// Need to keep the buffer around because its presence is used to indicate
|
|
|
|
// that there's a pending UploadDataStream read.
|
|
|
|
buf_.Reset(isolate_, buf);
|
|
|
|
|
|
|
|
handle_watcher_.Cancel();
|
|
|
|
data_pipe_.reset();
|
|
|
|
return net::ERR_IO_PENDING;
|
|
|
|
}
|
|
|
|
|
|
|
|
// |size_| was checked earlier, so if this point is reached, the pipe was
|
|
|
|
// closed before receiving all bytes.
|
|
|
|
DCHECK_LT(bytes_read_, *size_);
|
|
|
|
|
|
|
|
return net::ERR_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnSizeReceived(int32_t status, uint64_t size) {
|
|
|
|
DCHECK(!size_);
|
|
|
|
DCHECK_EQ(net::OK, status_);
|
|
|
|
|
|
|
|
status_ = status;
|
|
|
|
if (status == net::OK) {
|
|
|
|
size_ = size;
|
|
|
|
if (size == bytes_read_) {
|
|
|
|
// Only set this as a final chunk if there's a read in progress. Setting
|
|
|
|
// it asynchronously could result in confusing consumers.
|
|
|
|
if (!buf_.IsEmpty())
|
|
|
|
is_eof_ = true;
|
|
|
|
} else if (size < bytes_read_ ||
|
|
|
|
(!buf_.IsEmpty() && !data_pipe_.is_valid())) {
|
|
|
|
// If more data was received than was expected, or there's a pending
|
|
|
|
// read and data pipe was closed without passing in as many bytes as
|
|
|
|
// expected, the upload can't continue. If there's no pending read but
|
|
|
|
// the pipe was closed, the closure and size difference will be noticed
|
|
|
|
// on the next read attempt.
|
|
|
|
status_ = net::ERR_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this is done, and there's a pending read, complete the pending read.
|
|
|
|
// If there's not a pending read, either |status_| will be reported on the
|
|
|
|
// next read, the file will be marked as done, so ReadInternal() won't be
|
|
|
|
// called again.
|
|
|
|
if (!buf_.IsEmpty() && (is_eof_ || status_ != net::OK)) {
|
|
|
|
// |data_pipe_| isn't needed any more, and if it's still open, a close
|
|
|
|
// pipe message would cause issues, since this class normally only watches
|
|
|
|
// the pipe when there's a pending read.
|
|
|
|
handle_watcher_.Cancel();
|
|
|
|
data_pipe_.reset();
|
|
|
|
// Clear |buf_| as well, so it's only non-null while there's a pending
|
|
|
|
// read.
|
|
|
|
buf_.Reset();
|
|
|
|
chunked_data_pipe_getter_.reset();
|
|
|
|
|
|
|
|
OnReadCompleted(status_);
|
|
|
|
|
|
|
|
// |this| may have been deleted at this point.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnHandleReadable(MojoResult result) {
|
|
|
|
DCHECK(!buf_.IsEmpty());
|
|
|
|
|
|
|
|
v8::HandleScope handle_scope(isolate_);
|
|
|
|
|
|
|
|
v8::Local<v8::ArrayBufferView> buf = buf_.Get(isolate_);
|
|
|
|
buf_.Reset();
|
|
|
|
|
|
|
|
int rv = ReadInternal(buf);
|
|
|
|
|
|
|
|
if (rv != net::ERR_IO_PENDING)
|
|
|
|
OnReadCompleted(rv);
|
|
|
|
|
|
|
|
// |this| may have been deleted at this point.
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnReadCompleted(int result) {
|
|
|
|
if (result < 0)
|
|
|
|
std::move(promise_).RejectWithErrorMessage(net::ErrorToString(result));
|
|
|
|
else
|
|
|
|
std::move(promise_).Resolve(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnDataPipeGetterClosed() {
|
|
|
|
// If the size hasn't been received yet, treat this as receiving an error.
|
|
|
|
// Otherwise, this will only be a problem if/when InitInternal() tries to
|
|
|
|
// start reading again, so do nothing.
|
|
|
|
if (status_ == net::OK && !size_)
|
|
|
|
OnSizeReceived(net::ERR_FAILED, 0);
|
|
|
|
}
|
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<v8::Isolate> isolate_;
|
2023-03-27 17:00:55 +00:00
|
|
|
int status_ = net::OK;
|
|
|
|
scoped_refptr<network::ResourceRequestBody> resource_request_body_;
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<network::DataElementChunkedDataPipe> data_element_;
|
2023-03-27 17:00:55 +00:00
|
|
|
mojo::Remote<network::mojom::ChunkedDataPipeGetter> chunked_data_pipe_getter_;
|
|
|
|
mojo::ScopedDataPipeConsumerHandle data_pipe_;
|
|
|
|
mojo::SimpleWatcher handle_watcher_;
|
2024-01-10 22:23:35 +00:00
|
|
|
std::optional<uint64_t> size_;
|
2023-03-27 17:00:55 +00:00
|
|
|
uint64_t bytes_read_ = 0;
|
|
|
|
bool is_eof_ = false;
|
|
|
|
v8::Global<v8::ArrayBufferView> buf_;
|
|
|
|
gin_helper::Promise<int> promise_;
|
|
|
|
};
|
|
|
|
gin::WrapperInfo ChunkedDataPipeReadableStream::kWrapperInfo = {
|
|
|
|
gin::kEmbedderNativeGin};
|
|
|
|
|
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",
|
2023-11-01 14:02:12 +00:00
|
|
|
element_file.expected_modification_time()
|
|
|
|
.InSecondsFSinceUnixEpoch());
|
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
|
|
|
}
|
2023-03-27 17:00:55 +00:00
|
|
|
case network::mojom::DataElement::Tag::kChunkedDataPipe: {
|
|
|
|
upload_data.Set("type", "stream");
|
|
|
|
// ReleaseChunkedDataPipeGetter mutates the element, but unfortunately
|
|
|
|
// gin converters are only allowed const references, so we need to cast
|
|
|
|
// off the const here.
|
|
|
|
auto& mutable_element =
|
|
|
|
const_cast<network::DataElementChunkedDataPipe&>(
|
|
|
|
element.As<network::DataElementChunkedDataPipe>());
|
|
|
|
upload_data.Set(
|
|
|
|
"body",
|
|
|
|
ChunkedDataPipeReadableStream::Create(
|
|
|
|
isolate, const_cast<network::ResourceRequestBody*>(&val),
|
|
|
|
&mutable_element));
|
|
|
|
break;
|
|
|
|
}
|
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) {
|
2022-06-22 08:14:57 +00:00
|
|
|
base::Value list_value;
|
|
|
|
if (!ConvertFromV8(isolate, val, &list_value) || !list_value.is_list())
|
2019-10-25 13:03:28 +00:00
|
|
|
return false;
|
2022-06-22 08:14:57 +00:00
|
|
|
base::Value::List& list = list_value.GetList();
|
2021-06-08 02:00:05 +00:00
|
|
|
*out = base::MakeRefCounted<network::ResourceRequestBody>();
|
2023-04-11 06:27:07 +00:00
|
|
|
for (base::Value& dict_value : list) {
|
2022-06-22 08:14:57 +00:00
|
|
|
if (!dict_value.is_dict())
|
2019-10-25 13:03:28 +00:00
|
|
|
return false;
|
2022-06-22 08:14:57 +00:00
|
|
|
base::Value::Dict& dict = dict_value.GetDict();
|
|
|
|
std::string* type = dict.FindString("type");
|
|
|
|
if (!type)
|
|
|
|
return false;
|
|
|
|
if (*type == "rawData") {
|
|
|
|
const base::Value::BlobStorage* bytes = dict.FindBlob("bytes");
|
2021-10-21 18:51:36 +00:00
|
|
|
(*out)->AppendBytes(reinterpret_cast<const char*>(bytes->data()),
|
|
|
|
base::checked_cast<int>(bytes->size()));
|
2022-06-22 08:14:57 +00:00
|
|
|
} else if (*type == "file") {
|
|
|
|
const std::string* file = dict.FindString("filePath");
|
|
|
|
if (!file)
|
2021-08-24 00:52:17 +00:00
|
|
|
return false;
|
2022-06-22 08:14:57 +00:00
|
|
|
double modification_time =
|
|
|
|
dict.FindDouble("modificationTime").value_or(0.0);
|
|
|
|
int offset = dict.FindInt("offset").value_or(0);
|
|
|
|
int length = dict.FindInt("length").value_or(-1);
|
2023-11-01 14:02:12 +00:00
|
|
|
(*out)->AppendFileRange(
|
|
|
|
base::FilePath::FromUTF8Unsafe(*file), static_cast<uint64_t>(offset),
|
|
|
|
static_cast<uint64_t>(length),
|
|
|
|
base::Time::FromSecondsSinceUnixEpoch(modification_time));
|
2019-10-25 13:03:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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) {
|
2023-08-21 01:43:41 +00:00
|
|
|
auto 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) {
|
2023-08-21 01:43:41 +00:00
|
|
|
auto 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) {
|
2023-08-21 01:43:41 +00:00
|
|
|
auto dict = gin::Dictionary::CreateEmpty(isolate);
|
2019-11-27 01:01:13 +00:00
|
|
|
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) {
|
2023-08-21 01:43:41 +00:00
|
|
|
auto dict = gin::Dictionary::CreateEmpty(isolate);
|
2019-11-27 01:01:13 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2023-04-05 14:06:14 +00:00
|
|
|
// static
|
|
|
|
v8::Local<v8::Value> Converter<net::IPEndPoint>::ToV8(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
const net::IPEndPoint& val) {
|
|
|
|
gin::Dictionary dict(isolate, v8::Object::New(isolate));
|
|
|
|
dict.Set("address", val.ToStringWithoutPort());
|
|
|
|
switch (val.GetFamily()) {
|
|
|
|
case net::ADDRESS_FAMILY_IPV4: {
|
|
|
|
dict.Set("family", "ipv4");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case net::ADDRESS_FAMILY_IPV6: {
|
|
|
|
dict.Set("family", "ipv6");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case net::ADDRESS_FAMILY_UNSPECIFIED: {
|
|
|
|
dict.Set("family", "unspec");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ConvertToV8(isolate, dict);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool Converter<net::DnsQueryType>::FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
|
|
|
net::DnsQueryType* out) {
|
2023-06-19 08:33:09 +00:00
|
|
|
static constexpr auto Lookup =
|
2024-01-11 01:00:37 +00:00
|
|
|
base::MakeFixedFlatMap<std::string_view, net::DnsQueryType>({
|
2023-06-19 08:33:09 +00:00
|
|
|
{"A", net::DnsQueryType::A},
|
|
|
|
{"AAAA", net::DnsQueryType::AAAA},
|
|
|
|
});
|
|
|
|
return FromV8WithLookup(isolate, val, Lookup, out);
|
2023-04-05 14:06:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool Converter<net::HostResolverSource>::FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
|
|
|
net::HostResolverSource* out) {
|
2023-06-19 08:33:09 +00:00
|
|
|
using Val = net::HostResolverSource;
|
2024-01-11 01:00:37 +00:00
|
|
|
static constexpr auto Lookup = base::MakeFixedFlatMap<std::string_view, Val>({
|
|
|
|
{"any", Val::ANY},
|
|
|
|
{"dns", Val::DNS},
|
|
|
|
{"localOnly", Val::LOCAL_ONLY},
|
|
|
|
{"mdns", Val::MULTICAST_DNS},
|
|
|
|
{"system", Val::SYSTEM},
|
|
|
|
});
|
2023-06-19 08:33:09 +00:00
|
|
|
return FromV8WithLookup(isolate, val, Lookup, out);
|
2023-04-05 14:06:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool Converter<network::mojom::ResolveHostParameters::CacheUsage>::FromV8(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
|
|
|
network::mojom::ResolveHostParameters::CacheUsage* out) {
|
2023-06-19 08:33:09 +00:00
|
|
|
using Val = network::mojom::ResolveHostParameters::CacheUsage;
|
2024-01-11 01:00:37 +00:00
|
|
|
static constexpr auto Lookup = base::MakeFixedFlatMap<std::string_view, Val>({
|
|
|
|
{"allowed", Val::ALLOWED},
|
|
|
|
{"disallowed", Val::DISALLOWED},
|
|
|
|
{"staleAllowed", Val::STALE_ALLOWED},
|
|
|
|
});
|
2023-06-19 08:33:09 +00:00
|
|
|
return FromV8WithLookup(isolate, val, Lookup, out);
|
2023-04-05 14:06:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool Converter<network::mojom::SecureDnsPolicy>::FromV8(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
|
|
|
network::mojom::SecureDnsPolicy* out) {
|
2023-06-19 08:33:09 +00:00
|
|
|
using Val = network::mojom::SecureDnsPolicy;
|
2024-01-11 01:00:37 +00:00
|
|
|
static constexpr auto Lookup = base::MakeFixedFlatMap<std::string_view, Val>({
|
|
|
|
{"allow", Val::ALLOW},
|
|
|
|
{"disable", Val::DISABLE},
|
|
|
|
});
|
2023-06-19 08:33:09 +00:00
|
|
|
return FromV8WithLookup(isolate, val, Lookup, out);
|
2023-04-05 14:06:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool Converter<network::mojom::ResolveHostParametersPtr>::FromV8(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
|
|
|
network::mojom::ResolveHostParametersPtr* out) {
|
|
|
|
gin::Dictionary dict(nullptr);
|
|
|
|
if (!ConvertFromV8(isolate, val, &dict))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
network::mojom::ResolveHostParametersPtr params =
|
|
|
|
network::mojom::ResolveHostParameters::New();
|
|
|
|
|
|
|
|
dict.Get("queryType", &(params->dns_query_type));
|
|
|
|
dict.Get("source", &(params->source));
|
|
|
|
dict.Get("cacheUsage", &(params->cache_usage));
|
|
|
|
dict.Get("secureDnsPolicy", &(params->secure_dns_policy));
|
|
|
|
|
|
|
|
*out = std::move(params);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-14 05:15:34 +00:00
|
|
|
} // namespace gin
|