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:
Cheng Zhao 2019-05-24 11:28:00 +09:00 committed by GitHub
parent 646f572b77
commit 54cbe5f749
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 120 additions and 38 deletions

View file

@ -5,7 +5,9 @@
#ifndef ATOM_BROWSER_NET_ATOM_URL_LOADER_FACTORY_H_
#define ATOM_BROWSER_NET_ATOM_URL_LOADER_FACTORY_H_
#include <map>
#include <string>
#include <utility>
#include "mojo/public/cpp/bindings/binding_set.h"
#include "native_mate/dictionary.h"
@ -24,11 +26,14 @@ enum class ProtocolType {
kFree, // special type for returning arbitrary type of response.
};
using StartLoadingCallback =
base::OnceCallback<void(v8::Local<v8::Value>, mate::Arguments*)>;
using StartLoadingCallback = base::OnceCallback<void(mate::Arguments*)>;
using ProtocolHandler =
base::Callback<void(const network::ResourceRequest&, StartLoadingCallback)>;
// scheme => (type, handler).
using HandlersMap =
std::map<std::string, std::pair<ProtocolType, ProtocolHandler>>;
// Implementation of URLLoaderFactory.
class AtomURLLoaderFactory : public network::mojom::URLLoaderFactory {
public:
@ -46,7 +51,6 @@ class AtomURLLoaderFactory : public network::mojom::URLLoaderFactory {
traffic_annotation) override;
void Clone(network::mojom::URLLoaderFactoryRequest request) override;
private:
static void StartLoading(
network::mojom::URLLoaderRequest loader,
int32_t routing_id,
@ -56,8 +60,9 @@ class AtomURLLoaderFactory : public network::mojom::URLLoaderFactory {
network::mojom::URLLoaderClientPtr client,
const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
ProtocolType type,
v8::Local<v8::Value> response,
mate::Arguments* args);
private:
static void StartLoadingBuffer(network::mojom::URLLoaderClientPtr client,
const mate::Dictionary& dict);
static void StartLoadingString(network::mojom::URLLoaderClientPtr client,