feat: migrate webRequest module to NetworkService (Part 6) (#19752)

* Implement OnBeforeSendHeaders

* Pass the request

* Handle simple listeners

* Handle response listeners

* Read responses from listener
This commit is contained in:
Cheng Zhao 2019-08-16 10:19:05 +09:00 committed by GitHub
parent e59095423e
commit c3bb73a711
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 297 additions and 64 deletions

View file

@ -225,6 +225,32 @@ bool Converter<net::HttpResponseHeaders*>::FromV8(
return true;
}
// 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;
}
// static
v8::Local<v8::Value> Converter<network::ResourceRequest>::ToV8(
v8::Isolate* isolate,
@ -233,10 +259,7 @@ v8::Local<v8::Value> Converter<network::ResourceRequest>::ToV8(
dict.Set("method", val.method);
dict.Set("url", val.url.spec());
dict.Set("referrer", val.referrer.spec());
gin::Dictionary headers(isolate, v8::Object::New(isolate));
for (net::HttpRequestHeaders::Iterator it(val.headers); it.GetNext();)
headers.Set(it.name(), it.value());
dict.Set("headers", headers);
dict.Set("headers", val.headers);
if (val.request_body) {
const auto& elements = *val.request_body->elements();
v8::Local<v8::Array> arr = v8::Array::New(isolate, elements.size());

View file

@ -60,6 +60,15 @@ struct Converter<net::HttpResponseHeaders*> {
net::HttpResponseHeaders* out);
};
template <>
struct Converter<net::HttpRequestHeaders> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const net::HttpRequestHeaders& headers);
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
net::HttpRequestHeaders* out);
};
template <>
struct Converter<network::ResourceRequest> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,