2019-06-11 05:07:58 +00:00
|
|
|
// Copyright (c) 2019 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_NET_URL_PIPE_LOADER_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_NET_URL_PIPE_LOADER_H_
|
2019-06-11 05:07:58 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2021-08-11 21:04:56 +00:00
|
|
|
#include "base/values.h"
|
2019-12-11 00:22:35 +00:00
|
|
|
#include "mojo/public/cpp/bindings/receiver.h"
|
|
|
|
#include "mojo/public/cpp/bindings/remote.h"
|
2019-07-24 22:58:51 +00:00
|
|
|
#include "mojo/public/cpp/system/data_pipe_producer.h"
|
2021-08-11 21:04:56 +00:00
|
|
|
#include "services/network/public/cpp/resource_request.h"
|
2019-06-11 05:07:58 +00:00
|
|
|
#include "services/network/public/cpp/simple_url_loader.h"
|
|
|
|
#include "services/network/public/cpp/simple_url_loader_stream_consumer.h"
|
|
|
|
#include "services/network/public/mojom/url_loader.mojom.h"
|
|
|
|
|
|
|
|
namespace network {
|
|
|
|
class SharedURLLoaderFactory;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
// Read data from URL and pipe it to NetworkService.
|
|
|
|
//
|
|
|
|
// Different from creating a new loader for the URL directly, protocol handlers
|
|
|
|
// using this loader can work around CORS restrictions.
|
|
|
|
//
|
|
|
|
// This class manages its own lifetime and should delete itself when the
|
|
|
|
// connection is lost or finished.
|
|
|
|
class URLPipeLoader : public network::mojom::URLLoader,
|
|
|
|
public network::SimpleURLLoaderStreamConsumer {
|
|
|
|
public:
|
|
|
|
URLPipeLoader(scoped_refptr<network::SharedURLLoaderFactory> factory,
|
|
|
|
std::unique_ptr<network::ResourceRequest> request,
|
2021-03-04 17:27:05 +00:00
|
|
|
mojo::PendingReceiver<network::mojom::URLLoader> loader,
|
2019-12-11 00:22:35 +00:00
|
|
|
mojo::PendingRemote<network::mojom::URLLoaderClient> client,
|
2019-06-11 23:37:06 +00:00
|
|
|
const net::NetworkTrafficAnnotationTag& annotation,
|
2022-07-05 15:25:18 +00:00
|
|
|
base::Value::Dict upload_data);
|
2019-06-11 05:07:58 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
URLPipeLoader(const URLPipeLoader&) = delete;
|
|
|
|
URLPipeLoader& operator=(const URLPipeLoader&) = delete;
|
|
|
|
|
2019-06-11 05:07:58 +00:00
|
|
|
private:
|
|
|
|
~URLPipeLoader() override;
|
|
|
|
|
|
|
|
void Start(scoped_refptr<network::SharedURLLoaderFactory> factory,
|
|
|
|
std::unique_ptr<network::ResourceRequest> request,
|
2019-06-11 23:37:06 +00:00
|
|
|
const net::NetworkTrafficAnnotationTag& annotation,
|
2022-07-05 15:25:18 +00:00
|
|
|
base::Value::Dict upload_data);
|
2019-06-11 05:07:58 +00:00
|
|
|
void NotifyComplete(int result);
|
|
|
|
void OnResponseStarted(const GURL& final_url,
|
2019-09-21 14:51:28 +00:00
|
|
|
const network::mojom::URLResponseHead& response_head);
|
2019-06-11 05:07:58 +00:00
|
|
|
void OnWrite(base::OnceClosure resume, MojoResult result);
|
|
|
|
|
|
|
|
// SimpleURLLoaderStreamConsumer:
|
|
|
|
void OnDataReceived(base::StringPiece string_piece,
|
|
|
|
base::OnceClosure resume) override;
|
|
|
|
void OnComplete(bool success) override;
|
|
|
|
void OnRetry(base::OnceClosure start_retry) override;
|
|
|
|
|
|
|
|
// URLLoader:
|
2020-05-26 20:06:26 +00:00
|
|
|
void FollowRedirect(
|
|
|
|
const std::vector<std::string>& removed_headers,
|
|
|
|
const net::HttpRequestHeaders& modified_headers,
|
|
|
|
const net::HttpRequestHeaders& modified_cors_exempt_headers,
|
2024-01-10 22:23:35 +00:00
|
|
|
const std::optional<GURL>& new_url) override {}
|
2019-06-11 05:07:58 +00:00
|
|
|
void SetPriority(net::RequestPriority priority,
|
|
|
|
int32_t intra_priority_value) override {}
|
|
|
|
void PauseReadingBodyFromNet() override {}
|
|
|
|
void ResumeReadingBodyFromNet() override {}
|
|
|
|
|
2021-03-04 17:27:05 +00:00
|
|
|
mojo::Receiver<network::mojom::URLLoader> url_loader_;
|
2019-12-11 00:22:35 +00:00
|
|
|
mojo::Remote<network::mojom::URLLoaderClient> client_;
|
2019-06-11 05:07:58 +00:00
|
|
|
|
2019-07-24 22:58:51 +00:00
|
|
|
std::unique_ptr<mojo::DataPipeProducer> producer_;
|
2019-06-11 05:07:58 +00:00
|
|
|
std::unique_ptr<network::SimpleURLLoader> loader_;
|
|
|
|
|
2021-01-26 18:16:21 +00:00
|
|
|
base::WeakPtrFactory<URLPipeLoader> weak_factory_{this};
|
2019-06-11 05:07:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_NET_URL_PIPE_LOADER_H_
|