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.
|
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#ifndef SHELL_BROWSER_NET_URL_PIPE_LOADER_H_
|
|
|
|
#define SHELL_BROWSER_NET_URL_PIPE_LOADER_H_
|
2019-06-11 05:07:58 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "mojo/public/cpp/bindings/strong_binding.h"
|
2019-07-24 22:58:51 +00:00
|
|
|
#include "mojo/public/cpp/system/data_pipe_producer.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;
|
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2019-06-11 05:07:58 +00:00
|
|
|
|
|
|
|
// 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,
|
|
|
|
network::mojom::URLLoaderRequest loader,
|
|
|
|
network::mojom::URLLoaderClientPtr client,
|
2019-06-11 23:37:06 +00:00
|
|
|
const net::NetworkTrafficAnnotationTag& annotation,
|
|
|
|
base::DictionaryValue upload_data);
|
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,
|
|
|
|
base::DictionaryValue upload_data);
|
2019-06-11 05:07:58 +00:00
|
|
|
void NotifyComplete(int result);
|
|
|
|
void OnResponseStarted(const GURL& final_url,
|
|
|
|
const network::ResourceResponseHead& response_head);
|
|
|
|
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:
|
|
|
|
void FollowRedirect(const std::vector<std::string>& removed_headers,
|
|
|
|
const net::HttpRequestHeaders& modified_headers,
|
|
|
|
const base::Optional<GURL>& new_url) override {}
|
|
|
|
void SetPriority(net::RequestPriority priority,
|
|
|
|
int32_t intra_priority_value) override {}
|
|
|
|
void PauseReadingBodyFromNet() override {}
|
|
|
|
void ResumeReadingBodyFromNet() override {}
|
|
|
|
|
|
|
|
mojo::Binding<network::mojom::URLLoader> binding_;
|
|
|
|
network::mojom::URLLoaderClientPtr client_;
|
|
|
|
|
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_;
|
|
|
|
|
|
|
|
base::WeakPtrFactory<URLPipeLoader> weak_factory_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(URLPipeLoader);
|
|
|
|
};
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2019-06-11 05:07:58 +00:00
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#endif // SHELL_BROWSER_NET_URL_PIPE_LOADER_H_
|