[email protected] | b875d9b | 2014-03-03 00:14:14 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | b00ba70 | 2011-08-17 01:41:03 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | f92eb0034 | 2009-06-09 18:45:04 | [diff] [blame] | 4 | |
John Abd-El-Malek | 6b56ef71 | 2017-10-21 22:52:46 | [diff] [blame] | 5 | #ifndef CONTENT_RENDERER_LOADER_WEB_URL_LOADER_IMPL_H_ |
| 6 | #define CONTENT_RENDERER_LOADER_WEB_URL_LOADER_IMPL_H_ |
[email protected] | f92eb0034 | 2009-06-09 18:45:04 | [diff] [blame] | 7 | |
Farah Charab | 66145a8 | 2018-07-23 13:17:26 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
[email protected] | a491fd9 | 2014-06-23 12:15:03 | [diff] [blame] | 10 | #include "base/macros.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 11 | #include "base/memory/ref_counted.h" |
[email protected] | b5126da4 | 2014-03-04 03:33:40 | [diff] [blame] | 12 | #include "content/common/content_export.h" |
Yutaka Hirano | f7f2f63 | 2017-09-06 10:40:08 | [diff] [blame] | 13 | #include "content/common/frame.mojom.h" |
Henrique Ferreiro | 3a9751c | 2019-09-30 13:54:07 | [diff] [blame] | 14 | #include "mojo/public/cpp/bindings/pending_remote.h" |
Philip Rogers | 7178f5c | 2018-07-09 18:52:59 | [diff] [blame] | 15 | #include "mojo/public/cpp/system/data_pipe.h" |
Chong Zhang | b7c8d1ce | 2018-03-13 19:14:11 | [diff] [blame] | 16 | #include "services/network/public/cpp/shared_url_loader_factory.h" |
Gyuyoung Kim | 4c67f35 | 2019-12-25 11:28:58 | [diff] [blame] | 17 | #include "services/network/public/mojom/url_loader_factory.mojom-forward.h" |
Lucas Furukawa Gadani | 99701f7 | 2019-10-08 16:31:55 | [diff] [blame] | 18 | #include "services/network/public/mojom/url_response_head.mojom-forward.h" |
Farah Charab | 66145a8 | 2018-07-23 13:17:26 | [diff] [blame] | 19 | #include "third_party/blink/public/platform/scheduler/web_resource_loading_task_runner_handle.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 20 | #include "third_party/blink/public/platform/web_url_loader.h" |
| 21 | #include "third_party/blink/public/platform/web_url_loader_factory.h" |
[email protected] | 745dac28 | 2014-08-22 17:28:23 | [diff] [blame] | 22 | |
[email protected] | b5126da4 | 2014-03-04 03:33:40 | [diff] [blame] | 23 | namespace content { |
| 24 | |
[email protected] | a491fd9 | 2014-06-23 12:15:03 | [diff] [blame] | 25 | class ResourceDispatcher; |
[email protected] | 0bf419d1 | 2014-05-28 01:02:23 | [diff] [blame] | 26 | |
Kinuko Yasuda | 017b79e6 | 2017-10-24 17:46:10 | [diff] [blame] | 27 | // Default implementation of WebURLLoaderFactory. |
| 28 | class CONTENT_EXPORT WebURLLoaderFactoryImpl |
| 29 | : public blink::WebURLLoaderFactory { |
| 30 | public: |
Chong Zhang | b7c8d1ce | 2018-03-13 19:14:11 | [diff] [blame] | 31 | WebURLLoaderFactoryImpl( |
| 32 | base::WeakPtr<ResourceDispatcher> resource_dispatcher, |
| 33 | scoped_refptr<network::SharedURLLoaderFactory> loader_factory); |
Kinuko Yasuda | 017b79e6 | 2017-10-24 17:46:10 | [diff] [blame] | 34 | ~WebURLLoaderFactoryImpl() override; |
| 35 | |
Kinuko Yasuda | 017b79e6 | 2017-10-24 17:46:10 | [diff] [blame] | 36 | std::unique_ptr<blink::WebURLLoader> CreateURLLoader( |
| 37 | const blink::WebURLRequest& request, |
Farah Charab | 66145a8 | 2018-07-23 13:17:26 | [diff] [blame] | 38 | std::unique_ptr<blink::scheduler::WebResourceLoadingTaskRunnerHandle> |
| 39 | task_runner_handle) override; |
Kinuko Yasuda | 017b79e6 | 2017-10-24 17:46:10 | [diff] [blame] | 40 | |
| 41 | private: |
| 42 | base::WeakPtr<ResourceDispatcher> resource_dispatcher_; |
Chong Zhang | b7c8d1ce | 2018-03-13 19:14:11 | [diff] [blame] | 43 | scoped_refptr<network::SharedURLLoaderFactory> loader_factory_; |
Kinuko Yasuda | 017b79e6 | 2017-10-24 17:46:10 | [diff] [blame] | 44 | DISALLOW_COPY_AND_ASSIGN(WebURLLoaderFactoryImpl); |
| 45 | }; |
| 46 | |
Nico Weber | 43ddd7a3 | 2017-08-15 19:19:27 | [diff] [blame] | 47 | class CONTENT_EXPORT WebURLLoaderImpl : public blink::WebURLLoader { |
[email protected] | f92eb0034 | 2009-06-09 18:45:04 | [diff] [blame] | 48 | public: |
Yutaka Hirano | f7f2f63 | 2017-09-06 10:40:08 | [diff] [blame] | 49 | // When non-null |keep_alive_handle| is specified, this loader prolongs |
| 50 | // this render process's lifetime. |
Chong Zhang | b7c8d1ce | 2018-03-13 19:14:11 | [diff] [blame] | 51 | WebURLLoaderImpl( |
| 52 | ResourceDispatcher* resource_dispatcher, |
Farah Charab | 66145a8 | 2018-07-23 13:17:26 | [diff] [blame] | 53 | std::unique_ptr<blink::scheduler::WebResourceLoadingTaskRunnerHandle> |
| 54 | task_runner_handle, |
Chong Zhang | b7c8d1ce | 2018-03-13 19:14:11 | [diff] [blame] | 55 | scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, |
Henrique Ferreiro | 3a9751c | 2019-09-30 13:54:07 | [diff] [blame] | 56 | mojo::PendingRemote<mojom::KeepAliveHandle> keep_alive_handle); |
nick | 5120892 | 2015-04-24 21:38:37 | [diff] [blame] | 57 | ~WebURLLoaderImpl() override; |
[email protected] | f92eb0034 | 2009-06-09 18:45:04 | [diff] [blame] | 58 | |
Takeshi Yoshino | d0c5d35b | 2017-07-27 23:13:27 | [diff] [blame] | 59 | static void PopulateURLResponse(const blink::WebURL& url, |
Lucas Furukawa Gadani | 99701f7 | 2019-10-08 16:31:55 | [diff] [blame] | 60 | const network::mojom::URLResponseHead& head, |
lgarron | 19dc0232 | 2015-08-08 02:16:40 | [diff] [blame] | 61 | blink::WebURLResponse* response, |
Clark DuVall | 36164bd | 2018-08-09 22:49:08 | [diff] [blame] | 62 | bool report_security_info, |
| 63 | int request_id); |
Dmitry Gozman | 99961f2 | 2019-01-09 13:34:39 | [diff] [blame] | 64 | static blink::WebURLError PopulateURLError( |
| 65 | const network::URLLoaderCompletionStatus& status, |
| 66 | const GURL& url); |
| 67 | |
[email protected] | f92eb0034 | 2009-06-09 18:45:04 | [diff] [blame] | 68 | // WebURLLoader methods: |
Yutaka Hirano | 71a259e | 2020-02-05 06:51:02 | [diff] [blame] | 69 | 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 Yasuda | 131e773e | 2020-02-06 15:13:44 | [diff] [blame] | 75 | bool no_mime_sniffing, |
Yutaka Hirano | 71a259e | 2020-02-05 06:51:02 | [diff] [blame] | 76 | 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 Yasuda | 131e773e | 2020-02-06 15:13:44 | [diff] [blame] | 89 | bool no_mime_sniffing, |
Yutaka Hirano | 71a259e | 2020-02-05 06:51:02 | [diff] [blame] | 90 | blink::WebURLLoaderClient* client) override; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 91 | void SetDefersLoading(bool value) override; |
| 92 | void DidChangePriority(blink::WebURLRequest::Priority new_priority, |
nick | 5120892 | 2015-04-24 21:38:37 | [diff] [blame] | 93 | int intra_priority_value) override; |
Yutaka Hirano | 7eeae7b0 | 2019-03-26 11:37:43 | [diff] [blame] | 94 | scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() override; |
| 95 | |
[email protected] | f92eb0034 | 2009-06-09 18:45:04 | [diff] [blame] | 96 | private: |
[email protected] | b2787cf | 2009-06-11 22:20:39 | [diff] [blame] | 97 | class Context; |
kinuko | ccbf2c957 | 2016-02-03 22:54:37 | [diff] [blame] | 98 | class RequestPeerImpl; |
John Abd-El-Malek | d237798 | 2018-01-08 22:23:12 | [diff] [blame] | 99 | class SinkPeer; |
Tsuyoshi Horo | 0b61905 | 2019-05-17 08:44:14 | [diff] [blame] | 100 | |
| 101 | void Cancel(); |
| 102 | |
[email protected] | b2787cf | 2009-06-11 22:20:39 | [diff] [blame] | 103 | scoped_refptr<Context> context_; |
[email protected] | a491fd9 | 2014-06-23 12:15:03 | [diff] [blame] | 104 | |
| 105 | DISALLOW_COPY_AND_ASSIGN(WebURLLoaderImpl); |
[email protected] | f92eb0034 | 2009-06-09 18:45:04 | [diff] [blame] | 106 | }; |
| 107 | |
[email protected] | b5126da4 | 2014-03-04 03:33:40 | [diff] [blame] | 108 | } // namespace content |
[email protected] | f92eb0034 | 2009-06-09 18:45:04 | [diff] [blame] | 109 | |
John Abd-El-Malek | 6b56ef71 | 2017-10-21 22:52:46 | [diff] [blame] | 110 | #endif // CONTENT_RENDERER_LOADER_WEB_URL_LOADER_IMPL_H_ |