fix: handle redirects within registered protocols (#29796)
This commit is contained in:
parent
3f38681c55
commit
341b370213
4 changed files with 199 additions and 38 deletions
|
@ -8,6 +8,7 @@
|
|||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "mojo/public/cpp/bindings/pending_receiver.h"
|
||||
#include "mojo/public/cpp/bindings/pending_remote.h"
|
||||
|
@ -15,9 +16,11 @@
|
|||
#include "mojo/public/cpp/bindings/remote.h"
|
||||
#include "net/url_request/url_request_job_factory.h"
|
||||
#include "services/network/public/cpp/self_deleting_url_loader_factory.h"
|
||||
#include "services/network/public/mojom/url_loader.mojom.h"
|
||||
#include "services/network/public/mojom/url_loader_factory.mojom.h"
|
||||
#include "services/network/public/mojom/url_response_head.mojom.h"
|
||||
#include "shell/common/gin_helper/dictionary.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace electron {
|
||||
|
||||
|
@ -43,6 +46,52 @@ using HandlersMap =
|
|||
// Implementation of URLLoaderFactory.
|
||||
class ElectronURLLoaderFactory : public network::SelfDeletingURLLoaderFactory {
|
||||
public:
|
||||
// This class binds a URLLoader receiver in the case of a redirect, waiting
|
||||
// for |FollowRedirect| to be called at which point the new request will be
|
||||
// started, and the receiver will be unbound letting a new URLLoader bind it
|
||||
class RedirectedRequest : public network::mojom::URLLoader {
|
||||
public:
|
||||
RedirectedRequest(
|
||||
const net::RedirectInfo& redirect_info,
|
||||
mojo::PendingReceiver<network::mojom::URLLoader> loader_receiver,
|
||||
int32_t request_id,
|
||||
uint32_t options,
|
||||
const network::ResourceRequest& request,
|
||||
mojo::PendingRemote<network::mojom::URLLoaderClient> client,
|
||||
const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
|
||||
mojo::PendingRemote<network::mojom::URLLoaderFactory>
|
||||
target_factory_remote);
|
||||
~RedirectedRequest() override;
|
||||
|
||||
// network::mojom::URLLoader:
|
||||
void FollowRedirect(
|
||||
const std::vector<std::string>& removed_headers,
|
||||
const net::HttpRequestHeaders& modified_headers,
|
||||
const net::HttpRequestHeaders& modified_cors_exempt_headers,
|
||||
const absl::optional<GURL>& new_url) override;
|
||||
void SetPriority(net::RequestPriority priority,
|
||||
int32_t intra_priority_value) override {}
|
||||
void PauseReadingBodyFromNet() override {}
|
||||
void ResumeReadingBodyFromNet() override {}
|
||||
|
||||
void OnTargetFactoryError();
|
||||
void DeleteThis();
|
||||
|
||||
private:
|
||||
net::RedirectInfo redirect_info_;
|
||||
|
||||
mojo::Receiver<network::mojom::URLLoader> loader_receiver_{this};
|
||||
int32_t request_id_;
|
||||
uint32_t options_;
|
||||
network::ResourceRequest request_;
|
||||
mojo::PendingRemote<network::mojom::URLLoaderClient> client_;
|
||||
net::MutableNetworkTrafficAnnotationTag traffic_annotation_;
|
||||
|
||||
mojo::Remote<network::mojom::URLLoaderFactory> target_factory_remote_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(RedirectedRequest);
|
||||
};
|
||||
|
||||
static mojo::PendingRemote<network::mojom::URLLoaderFactory> Create(
|
||||
ProtocolType type,
|
||||
const ProtocolHandler& handler);
|
||||
|
@ -64,7 +113,7 @@ class ElectronURLLoaderFactory : public network::SelfDeletingURLLoaderFactory {
|
|||
const network::ResourceRequest& request,
|
||||
mojo::PendingRemote<network::mojom::URLLoaderClient> client,
|
||||
const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
|
||||
mojo::PendingRemote<network::mojom::URLLoaderFactory> proxy_factory,
|
||||
mojo::PendingRemote<network::mojom::URLLoaderFactory> target_factory,
|
||||
ProtocolType type,
|
||||
gin::Arguments* args);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue