feat: migrate protocol module to NetworkService (Part 9) (#18374)
* Compare final data instead of url The behavior of did-finish-load and getURL has changed for redirects when using NetworkService, so the test fails for NetworkService. Comparing the finally received data makes the test more reliable. * Implement intercept APIs * Setting mimeType should set "content-type" header * Passing no argument should not throw JS error * Don't access api namespace in ProxyingURLLoaderFactory * No need to create AtomURLLoaderFactory every time * No use of weak factory
This commit is contained in:
parent
646f572b77
commit
54cbe5f749
8 changed files with 120 additions and 38 deletions
|
@ -100,6 +100,10 @@ network::ResourceResponseHead ToResponseHead(const mate::Dictionary& dict) {
|
|||
"HTTP/1.1 %d %s", status_code,
|
||||
net::GetHttpReasonPhrase(static_cast<net::HttpStatusCode>(status_code))));
|
||||
|
||||
dict.Get("charset", &head.charset);
|
||||
bool has_mime_type = dict.Get("mimeType", &head.mime_type);
|
||||
bool has_content_type = false;
|
||||
|
||||
base::DictionaryValue headers;
|
||||
if (dict.Get("headers", &headers)) {
|
||||
for (const auto& iter : headers.DictItems()) {
|
||||
|
@ -117,12 +121,17 @@ network::ResourceResponseHead ToResponseHead(const mate::Dictionary& dict) {
|
|||
}
|
||||
// Some apps are passing content-type via headers, which is not accepted
|
||||
// in NetworkService.
|
||||
if (iter.first == "content-type" && iter.second.is_string())
|
||||
if (iter.first == "content-type" && iter.second.is_string()) {
|
||||
head.mime_type = iter.second.GetString();
|
||||
has_content_type = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
dict.Get("mimeType", &head.mime_type);
|
||||
dict.Get("charset", &head.charset);
|
||||
|
||||
// Setting |head.mime_type| does not automatically set the "content-type"
|
||||
// header in NetworkService.
|
||||
if (has_mime_type && !has_content_type)
|
||||
head.headers->AddHeader("content-type: " + head.mime_type);
|
||||
return head;
|
||||
}
|
||||
|
||||
|
@ -185,8 +194,18 @@ void AtomURLLoaderFactory::StartLoading(
|
|||
network::mojom::URLLoaderClientPtr client,
|
||||
const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
|
||||
ProtocolType type,
|
||||
v8::Local<v8::Value> response,
|
||||
mate::Arguments* args) {
|
||||
// Send network error when there is no argument passed.
|
||||
//
|
||||
// Note that we should not throw JS error in the callback no matter what is
|
||||
// passed, to keep compatibility with old code.
|
||||
v8::Local<v8::Value> response;
|
||||
if (!args->GetNext(&response)) {
|
||||
client->OnComplete(
|
||||
network::URLLoaderCompletionStatus(net::ERR_NOT_IMPLEMENTED));
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse {error} object.
|
||||
mate::Dictionary dict = ToDict(args->isolate(), response);
|
||||
if (!dict.IsEmpty()) {
|
||||
|
@ -224,16 +243,12 @@ void AtomURLLoaderFactory::StartLoading(
|
|||
break;
|
||||
case ProtocolType::kFree:
|
||||
ProtocolType type;
|
||||
v8::Local<v8::Value> extra_arg;
|
||||
if (!mate::ConvertFromV8(args->isolate(), response, &type) ||
|
||||
!args->GetNext(&extra_arg)) {
|
||||
if (!mate::ConvertFromV8(args->isolate(), response, &type)) {
|
||||
client->OnComplete(network::URLLoaderCompletionStatus(net::ERR_FAILED));
|
||||
args->ThrowError("Invalid args, must pass (type, options)");
|
||||
return;
|
||||
}
|
||||
StartLoading(std::move(loader), routing_id, request_id, options, request,
|
||||
std::move(client), traffic_annotation, type, extra_arg,
|
||||
args);
|
||||
std::move(client), traffic_annotation, type, args);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue