electron/atom/browser/net/proxying_url_loader_factory.h
Cheng Zhao 54cbe5f749
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
2019-05-24 11:28:00 +09:00

52 lines
1.9 KiB
C++

// Copyright (c) 2019 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_BROWSER_NET_PROXYING_URL_LOADER_FACTORY_H_
#define ATOM_BROWSER_NET_PROXYING_URL_LOADER_FACTORY_H_
#include "atom/browser/net/atom_url_loader_factory.h"
namespace atom {
class ProxyingURLLoaderFactory : public network::mojom::URLLoaderFactory {
public:
ProxyingURLLoaderFactory(
const HandlersMap& handlers,
network::mojom::URLLoaderFactoryRequest loader_request,
network::mojom::URLLoaderFactoryPtrInfo target_factory_info);
~ProxyingURLLoaderFactory() override;
// network::mojom::URLLoaderFactory:
void CreateLoaderAndStart(network::mojom::URLLoaderRequest loader,
int32_t routing_id,
int32_t request_id,
uint32_t options,
const network::ResourceRequest& request,
network::mojom::URLLoaderClientPtr client,
const net::MutableNetworkTrafficAnnotationTag&
traffic_annotation) override;
void Clone(network::mojom::URLLoaderFactoryRequest request) override;
private:
void OnTargetFactoryError();
void OnProxyBindingError();
// This is passed from api::ProtocolNS.
//
// The ProtocolNS instance lives through the lifetime of BrowserContenxt,
// which is guarenteed to cover the lifetime of URLLoaderFactory, so the
// reference is guarenteed to be valid.
//
// In this way we can avoid using code from api namespace in this file.
const HandlersMap& handlers_;
mojo::BindingSet<network::mojom::URLLoaderFactory> proxy_bindings_;
network::mojom::URLLoaderFactoryPtr target_factory_;
DISALLOW_COPY_AND_ASSIGN(ProxyingURLLoaderFactory);
};
} // namespace atom
#endif // ATOM_BROWSER_NET_PROXYING_URL_LOADER_FACTORY_H_