feat: migrate protocol module to NetworkService (Part 2) (#17965)

* Pass protocol type and handler to factory

* Add converter for network::ResourceRequest

* Implement Buffer and String protocol handler

* Implement file protocol
This commit is contained in:
Cheng Zhao 2019-04-29 11:37:45 +09:00 committed by GitHub
parent fe618631f1
commit 6f83977f47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 266 additions and 39 deletions

View file

@ -24,6 +24,7 @@
#include "net/cert/x509_util.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
#include "services/network/public/cpp/resource_request.h"
#include "storage/browser/blob/upload_blob_element_reader.h"
namespace mate {
@ -223,6 +224,22 @@ bool Converter<net::HttpResponseHeaders*>::FromV8(
return true;
}
// static
v8::Local<v8::Value> Converter<network::ResourceRequest>::ToV8(
v8::Isolate* isolate,
const network::ResourceRequest& val) {
mate::Dictionary dict(isolate, v8::Object::New(isolate));
dict.Set("method", val.method);
dict.Set("url", val.url.spec());
dict.Set("referrer", val.referrer.spec());
mate::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);
// FIXME(zcbenz): Figure out how to support uploadData.
return dict.GetHandle();
}
} // namespace mate
namespace atom {

View file

@ -21,6 +21,10 @@ class HttpResponseHeaders;
struct CertPrincipal;
} // namespace net
namespace network {
struct ResourceRequest;
}
namespace mate {
template <>
@ -55,6 +59,12 @@ struct Converter<net::HttpResponseHeaders*> {
net::HttpResponseHeaders* out);
};
template <>
struct Converter<network::ResourceRequest> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const network::ResourceRequest& val);
};
} // namespace mate
namespace atom {