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:
parent
fe618631f1
commit
6f83977f47
6 changed files with 266 additions and 39 deletions
|
@ -5,16 +5,34 @@
|
|||
#ifndef ATOM_BROWSER_NET_ATOM_URL_LOADER_FACTORY_H_
|
||||
#define ATOM_BROWSER_NET_ATOM_URL_LOADER_FACTORY_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "mojo/public/cpp/bindings/binding_set.h"
|
||||
#include "net/url_request/url_request_job_factory.h"
|
||||
#include "services/network/public/mojom/url_loader_factory.mojom.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
// Old Protocol API can only serve one type of response for one scheme.
|
||||
enum class ProtocolType {
|
||||
kBuffer,
|
||||
kString,
|
||||
kFile,
|
||||
kHttp,
|
||||
kStream,
|
||||
kFree, // special type for returning arbitrary type of response.
|
||||
};
|
||||
|
||||
using SendResponseCallback = base::OnceCallback<void(v8::Local<v8::Value>)>;
|
||||
using ProtocolHandler =
|
||||
base::Callback<void(const network::ResourceRequest&, SendResponseCallback)>;
|
||||
|
||||
// Implementation of URLLoaderFactory.
|
||||
class AtomURLLoaderFactory : public network::mojom::URLLoaderFactory {
|
||||
public:
|
||||
AtomURLLoaderFactory();
|
||||
AtomURLLoaderFactory(ProtocolType type, const ProtocolHandler& handler);
|
||||
~AtomURLLoaderFactory() override;
|
||||
|
||||
// network::mojom::URLLoaderFactory:
|
||||
|
@ -29,11 +47,37 @@ class AtomURLLoaderFactory : public network::mojom::URLLoaderFactory {
|
|||
void Clone(network::mojom::URLLoaderFactoryRequest request) override;
|
||||
|
||||
private:
|
||||
void SendResponseBuffer(network::mojom::URLLoaderClientPtr client,
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> response);
|
||||
void SendResponseString(network::mojom::URLLoaderClientPtr client,
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> response);
|
||||
void SendResponseFile(network::mojom::URLLoaderRequest loader,
|
||||
network::ResourceRequest request,
|
||||
network::mojom::URLLoaderClientPtr client,
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> response);
|
||||
|
||||
bool HandleError(network::mojom::URLLoaderClientPtr* client,
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> response);
|
||||
void SendContents(network::mojom::URLLoaderClientPtr client,
|
||||
std::string mime_type,
|
||||
std::string charset,
|
||||
const char* data,
|
||||
size_t size);
|
||||
|
||||
// TODO(zcbenz): This comes from extensions/browser/extension_protocols.cc
|
||||
// but I don't know what it actually does, find out the meanings of |Clone|
|
||||
// and |bindings_| and add comments for them.
|
||||
mojo::BindingSet<network::mojom::URLLoaderFactory> bindings_;
|
||||
|
||||
ProtocolType type_;
|
||||
ProtocolHandler handler_;
|
||||
|
||||
base::WeakPtrFactory<AtomURLLoaderFactory> weak_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomURLLoaderFactory);
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue