feat: session.resolveHost (#37690)
* feat: session.resolveHost Expose Chromium's host resolution API through the Session object. * Update shell/browser/api/electron_api_session.cc Co-authored-by: Jeremy Rose <nornagon@nornagon.net> * address feedback * fix tests * address feedback * Add options * Update shell/browser/api/electron_api_session.cc Co-authored-by: Cheng Zhao <github@zcbenz.com> * Update shell/browser/net/resolve_host_function.cc Co-authored-by: Cheng Zhao <github@zcbenz.com> * lint * return object * add missing file * fix crash * handle scope * links --------- Co-authored-by: Fedor Indutny <indutny@signal.org> Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Co-authored-by: Jeremy Rose <nornagon@nornagon.net> Co-authored-by: Cheng Zhao <github@zcbenz.com>
This commit is contained in:
parent
db27b9f433
commit
6bfef67aae
13 changed files with 477 additions and 0 deletions
|
@ -663,4 +663,154 @@ v8::Local<v8::Value> Converter<net::RedirectInfo>::ToV8(
|
|||
return ConvertToV8(isolate, dict);
|
||||
}
|
||||
|
||||
// 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) {
|
||||
std::string query_type;
|
||||
if (!ConvertFromV8(isolate, val, &query_type))
|
||||
return false;
|
||||
|
||||
if (query_type == "A") {
|
||||
*out = net::DnsQueryType::A;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (query_type == "AAAA") {
|
||||
*out = net::DnsQueryType::AAAA;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// static
|
||||
bool Converter<net::HostResolverSource>::FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
net::HostResolverSource* out) {
|
||||
std::string query_type;
|
||||
if (!ConvertFromV8(isolate, val, &query_type))
|
||||
return false;
|
||||
|
||||
if (query_type == "any") {
|
||||
*out = net::HostResolverSource::ANY;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (query_type == "system") {
|
||||
*out = net::HostResolverSource::SYSTEM;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (query_type == "dns") {
|
||||
*out = net::HostResolverSource::DNS;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (query_type == "mdns") {
|
||||
*out = net::HostResolverSource::MULTICAST_DNS;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (query_type == "localOnly") {
|
||||
*out = net::HostResolverSource::LOCAL_ONLY;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// static
|
||||
bool Converter<network::mojom::ResolveHostParameters::CacheUsage>::FromV8(
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
network::mojom::ResolveHostParameters::CacheUsage* out) {
|
||||
std::string query_type;
|
||||
if (!ConvertFromV8(isolate, val, &query_type))
|
||||
return false;
|
||||
|
||||
if (query_type == "allowed") {
|
||||
*out = network::mojom::ResolveHostParameters::CacheUsage::ALLOWED;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (query_type == "staleAllowed") {
|
||||
*out = network::mojom::ResolveHostParameters::CacheUsage::STALE_ALLOWED;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (query_type == "disallowed") {
|
||||
*out = network::mojom::ResolveHostParameters::CacheUsage::DISALLOWED;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// static
|
||||
bool Converter<network::mojom::SecureDnsPolicy>::FromV8(
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
network::mojom::SecureDnsPolicy* out) {
|
||||
std::string query_type;
|
||||
if (!ConvertFromV8(isolate, val, &query_type))
|
||||
return false;
|
||||
|
||||
if (query_type == "allow") {
|
||||
*out = network::mojom::SecureDnsPolicy::ALLOW;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (query_type == "disable") {
|
||||
*out = network::mojom::SecureDnsPolicy::DISABLE;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
} // namespace gin
|
||||
|
|
42
shell/common/gin_converters/net_converter.h
Executable file → Normal file
42
shell/common/gin_converters/net_converter.h
Executable file → Normal file
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "gin/converter.h"
|
||||
#include "services/network/public/mojom/fetch_api.mojom.h"
|
||||
#include "services/network/public/mojom/host_resolver.mojom.h"
|
||||
#include "services/network/public/mojom/url_request.mojom.h"
|
||||
#include "shell/browser/net/cert_verifier_client.h"
|
||||
|
||||
|
@ -109,6 +110,47 @@ struct Converter<net::RedirectInfo> {
|
|||
const net::RedirectInfo& val);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Converter<net::IPEndPoint> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const net::IPEndPoint& val);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Converter<net::DnsQueryType> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
net::DnsQueryType* out);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Converter<net::HostResolverSource> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
net::HostResolverSource* out);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Converter<network::mojom::ResolveHostParameters::CacheUsage> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
network::mojom::ResolveHostParameters::CacheUsage* out);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Converter<network::mojom::SecureDnsPolicy> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
network::mojom::SecureDnsPolicy* out);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Converter<network::mojom::ResolveHostParametersPtr> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
network::mojom::ResolveHostParametersPtr* out);
|
||||
};
|
||||
|
||||
template <typename K, typename V>
|
||||
struct Converter<std::vector<std::pair<K, V>>> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue