9a198e8ef4
* chore: bump chromium in DEPS to 0476932294da8809a19189b9f54cee11d50cc512 * update chromium patches (#20838) * chore: bump chromium in DEPS to 838863f5ec9e8a12132a10bb47be8382ad9756a7 * IsRendererTransferNeededForNavigation went away https://chromium-review.googlesource.com/c/chromium/src/+/1867031 * [arraybuffer] Move the ArrayBuffer implementation from wtf to core https://chromium-review.googlesource.com/c/chromium/src/+/1875731 * URLLoaderRequest new mojo types * context menu enums moved around https://chromium-review.googlesource.com/c/chromium/src/+/1872004 https://chromium-review.googlesource.com/c/chromium/src/+/1876088 https://chromium-review.googlesource.com/c/chromium/src/+/1866520 * chore: bump chromium in DEPS to dc9525d251bf30828899e4cd7161f6dc6507023f * update chromium patches * [WIP] Convert network hints IPC to Mojo https://chromium-review.googlesource.com/c/chromium/src/+/1881967 * jumbo build is no longer supported https://chromium-review.googlesource.com/c/chromium/src/+/1881967 * fix disable-color-correct-rendering * [FIXME] fix printing patch compiles but prob doesn't work * explicitly include ax_enums https://chromium-review.googlesource.com/c/chromium/src/+/1759821 * fixup! [WIP] Convert network hints IPC to Mojo * fix base::span * fix AsarURLLoader to not double-std::move * fix debug build * fix msstl patch * lint * more fix msstl * mooooore fix msstl * fix compile * update backport_fix_msstl_compat_in_ui_events.patch * update msstl compat patch * don't try to build chrome's prefetch predictor * build: fix compilation on windows * Fixup patches for MAS build * Free up disk space for mac debug builds * fix: apply custom site instance only for main frame * Fixup from rebase * Try not generating symbols for mac debug builds * Remove double entry of patch * FIx compile errors * Trigger CI * Set symbol_level to 1 for mac debug builds
117 lines
4.4 KiB
C++
117 lines
4.4 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 SHELL_BROWSER_NET_ATOM_URL_LOADER_FACTORY_H_
|
|
#define SHELL_BROWSER_NET_ATOM_URL_LOADER_FACTORY_H_
|
|
|
|
#include <map>
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
#include "mojo/public/cpp/bindings/pending_receiver.h"
|
|
#include "mojo/public/cpp/bindings/receiver_set.h"
|
|
#include "net/url_request/url_request_job_factory.h"
|
|
#include "services/network/public/cpp/resource_response.h"
|
|
#include "services/network/public/mojom/url_loader_factory.mojom.h"
|
|
#include "shell/common/gin_helper/dictionary.h"
|
|
|
|
namespace electron {
|
|
|
|
// 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 StartLoadingCallback = base::OnceCallback<void(gin::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:
|
|
AtomURLLoaderFactory(ProtocolType type, const ProtocolHandler& handler);
|
|
~AtomURLLoaderFactory() override;
|
|
|
|
// network::mojom::URLLoaderFactory:
|
|
void CreateLoaderAndStart(
|
|
mojo::PendingReceiver<network::mojom::URLLoader> 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(mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver)
|
|
override;
|
|
|
|
static void StartLoading(
|
|
mojo::PendingReceiver<network::mojom::URLLoader> 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,
|
|
network::mojom::URLLoaderFactory* proxy_factory,
|
|
ProtocolType type,
|
|
gin::Arguments* args);
|
|
|
|
private:
|
|
static void StartLoadingBuffer(network::mojom::URLLoaderClientPtr client,
|
|
network::ResourceResponseHead head,
|
|
const gin_helper::Dictionary& dict);
|
|
static void StartLoadingString(network::mojom::URLLoaderClientPtr client,
|
|
network::ResourceResponseHead head,
|
|
const gin_helper::Dictionary& dict,
|
|
v8::Isolate* isolate,
|
|
v8::Local<v8::Value> response);
|
|
static void StartLoadingFile(
|
|
mojo::PendingReceiver<network::mojom::URLLoader> loader,
|
|
network::ResourceRequest request,
|
|
network::mojom::URLLoaderClientPtr client,
|
|
network::ResourceResponseHead head,
|
|
const gin_helper::Dictionary& dict,
|
|
v8::Isolate* isolate,
|
|
v8::Local<v8::Value> response);
|
|
static void StartLoadingHttp(
|
|
mojo::PendingReceiver<network::mojom::URLLoader> loader,
|
|
const network::ResourceRequest& original_request,
|
|
network::mojom::URLLoaderClientPtr client,
|
|
const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
|
|
const gin_helper::Dictionary& dict);
|
|
static void StartLoadingStream(
|
|
mojo::PendingReceiver<network::mojom::URLLoader> loader,
|
|
network::mojom::URLLoaderClientPtr client,
|
|
network::ResourceResponseHead head,
|
|
const gin_helper::Dictionary& dict);
|
|
|
|
// Helper to send string as response.
|
|
static void SendContents(network::mojom::URLLoaderClientPtr client,
|
|
network::ResourceResponseHead head,
|
|
std::string data);
|
|
|
|
// 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::ReceiverSet<network::mojom::URLLoaderFactory> receivers_;
|
|
|
|
ProtocolType type_;
|
|
ProtocolHandler handler_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(AtomURLLoaderFactory);
|
|
};
|
|
|
|
} // namespace electron
|
|
|
|
#endif // SHELL_BROWSER_NET_ATOM_URL_LOADER_FACTORY_H_
|