blob: 7b00faa7376df358f97bd2699cf2aa147e2126eb [file] [log] [blame]
[email protected]b875d9b2014-03-03 00:14:141// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]b00ba702011-08-17 01:41:032// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
[email protected]f92eb00342009-06-09 18:45:044
John Abd-El-Malek6b56ef712017-10-21 22:52:465#ifndef CONTENT_RENDERER_LOADER_WEB_URL_LOADER_IMPL_H_
6#define CONTENT_RENDERER_LOADER_WEB_URL_LOADER_IMPL_H_
[email protected]f92eb00342009-06-09 18:45:047
Farah Charab66145a82018-07-23 13:17:268#include <memory>
9
[email protected]a491fd92014-06-23 12:15:0310#include "base/macros.h"
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/ref_counted.h"
[email protected]b5126da42014-03-04 03:33:4012#include "content/common/content_export.h"
Yutaka Hiranof7f2f632017-09-06 10:40:0813#include "content/common/frame.mojom.h"
Henrique Ferreiro3a9751c2019-09-30 13:54:0714#include "mojo/public/cpp/bindings/pending_remote.h"
Philip Rogers7178f5c2018-07-09 18:52:5915#include "mojo/public/cpp/system/data_pipe.h"
Chong Zhangb7c8d1ce2018-03-13 19:14:1116#include "services/network/public/cpp/shared_url_loader_factory.h"
Gyuyoung Kim4c67f352019-12-25 11:28:5817#include "services/network/public/mojom/url_loader_factory.mojom-forward.h"
Lucas Furukawa Gadani99701f72019-10-08 16:31:5518#include "services/network/public/mojom/url_response_head.mojom-forward.h"
Farah Charab66145a82018-07-23 13:17:2619#include "third_party/blink/public/platform/scheduler/web_resource_loading_task_runner_handle.h"
Blink Reformata30d4232018-04-07 15:31:0620#include "third_party/blink/public/platform/web_url_loader.h"
21#include "third_party/blink/public/platform/web_url_loader_factory.h"
[email protected]745dac282014-08-22 17:28:2322
[email protected]b5126da42014-03-04 03:33:4023namespace content {
24
[email protected]a491fd92014-06-23 12:15:0325class ResourceDispatcher;
[email protected]0bf419d12014-05-28 01:02:2326
Kinuko Yasuda017b79e62017-10-24 17:46:1027// Default implementation of WebURLLoaderFactory.
28class CONTENT_EXPORT WebURLLoaderFactoryImpl
29 : public blink::WebURLLoaderFactory {
30 public:
Chong Zhangb7c8d1ce2018-03-13 19:14:1131 WebURLLoaderFactoryImpl(
32 base::WeakPtr<ResourceDispatcher> resource_dispatcher,
33 scoped_refptr<network::SharedURLLoaderFactory> loader_factory);
Kinuko Yasuda017b79e62017-10-24 17:46:1034 ~WebURLLoaderFactoryImpl() override;
35
Kinuko Yasuda017b79e62017-10-24 17:46:1036 std::unique_ptr<blink::WebURLLoader> CreateURLLoader(
37 const blink::WebURLRequest& request,
Farah Charab66145a82018-07-23 13:17:2638 std::unique_ptr<blink::scheduler::WebResourceLoadingTaskRunnerHandle>
39 task_runner_handle) override;
Kinuko Yasuda017b79e62017-10-24 17:46:1040
41 private:
42 base::WeakPtr<ResourceDispatcher> resource_dispatcher_;
Chong Zhangb7c8d1ce2018-03-13 19:14:1143 scoped_refptr<network::SharedURLLoaderFactory> loader_factory_;
Kinuko Yasuda017b79e62017-10-24 17:46:1044 DISALLOW_COPY_AND_ASSIGN(WebURLLoaderFactoryImpl);
45};
46
Nico Weber43ddd7a32017-08-15 19:19:2747class CONTENT_EXPORT WebURLLoaderImpl : public blink::WebURLLoader {
[email protected]f92eb00342009-06-09 18:45:0448 public:
Yutaka Hiranof7f2f632017-09-06 10:40:0849 // When non-null |keep_alive_handle| is specified, this loader prolongs
50 // this render process's lifetime.
Chong Zhangb7c8d1ce2018-03-13 19:14:1151 WebURLLoaderImpl(
52 ResourceDispatcher* resource_dispatcher,
Farah Charab66145a82018-07-23 13:17:2653 std::unique_ptr<blink::scheduler::WebResourceLoadingTaskRunnerHandle>
54 task_runner_handle,
Chong Zhangb7c8d1ce2018-03-13 19:14:1155 scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
Henrique Ferreiro3a9751c2019-09-30 13:54:0756 mojo::PendingRemote<mojom::KeepAliveHandle> keep_alive_handle);
nick51208922015-04-24 21:38:3757 ~WebURLLoaderImpl() override;
[email protected]f92eb00342009-06-09 18:45:0458
Takeshi Yoshinod0c5d35b2017-07-27 23:13:2759 static void PopulateURLResponse(const blink::WebURL& url,
Lucas Furukawa Gadani99701f72019-10-08 16:31:5560 const network::mojom::URLResponseHead& head,
lgarron19dc02322015-08-08 02:16:4061 blink::WebURLResponse* response,
Clark DuVall36164bd2018-08-09 22:49:0862 bool report_security_info,
63 int request_id);
Dmitry Gozman99961f22019-01-09 13:34:3964 static blink::WebURLError PopulateURLError(
65 const network::URLLoaderCompletionStatus& status,
66 const GURL& url);
67
[email protected]f92eb00342009-06-09 18:45:0468 // WebURLLoader methods:
Yutaka Hirano71a259e2020-02-05 06:51:0269 void LoadSynchronously(
70 std::unique_ptr<network::ResourceRequest> request,
71 scoped_refptr<blink::WebURLRequest::ExtraData> request_extra_data,
72 int requestor_id,
73 bool download_to_network_cache_only,
74 bool pass_response_pipe_to_client,
Kinuko Yasuda131e773e2020-02-06 15:13:4475 bool no_mime_sniffing,
Yutaka Hirano71a259e2020-02-05 06:51:0276 base::TimeDelta timeout_interval,
77 blink::WebURLLoaderClient* client,
78 blink::WebURLResponse& response,
79 base::Optional<blink::WebURLError>& error,
80 blink::WebData& data,
81 int64_t& encoded_data_length,
82 int64_t& encoded_body_length,
83 blink::WebBlobInfo& downloaded_blob) override;
84 void LoadAsynchronously(
85 std::unique_ptr<network::ResourceRequest> request,
86 scoped_refptr<blink::WebURLRequest::ExtraData> request_extra_data,
87 int requestor_id,
88 bool download_to_network_cache_only,
Kinuko Yasuda131e773e2020-02-06 15:13:4489 bool no_mime_sniffing,
Yutaka Hirano71a259e2020-02-05 06:51:0290 blink::WebURLLoaderClient* client) override;
Blink Reformat1c4d759e2017-04-09 16:34:5491 void SetDefersLoading(bool value) override;
92 void DidChangePriority(blink::WebURLRequest::Priority new_priority,
nick51208922015-04-24 21:38:3793 int intra_priority_value) override;
Yutaka Hirano7eeae7b02019-03-26 11:37:4394 scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() override;
95
[email protected]f92eb00342009-06-09 18:45:0496 private:
[email protected]b2787cf2009-06-11 22:20:3997 class Context;
kinukoccbf2c9572016-02-03 22:54:3798 class RequestPeerImpl;
John Abd-El-Malekd2377982018-01-08 22:23:1299 class SinkPeer;
Tsuyoshi Horo0b619052019-05-17 08:44:14100
101 void Cancel();
102
[email protected]b2787cf2009-06-11 22:20:39103 scoped_refptr<Context> context_;
[email protected]a491fd92014-06-23 12:15:03104
105 DISALLOW_COPY_AND_ASSIGN(WebURLLoaderImpl);
[email protected]f92eb00342009-06-09 18:45:04106};
107
[email protected]b5126da42014-03-04 03:33:40108} // namespace content
[email protected]f92eb00342009-06-09 18:45:04109
John Abd-El-Malek6b56ef712017-10-21 22:52:46110#endif // CONTENT_RENDERER_LOADER_WEB_URL_LOADER_IMPL_H_