[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" |
Philip Rogers | 7178f5c | 2018-07-09 18:52:59 | [diff] [blame] | 14 | #include "mojo/public/cpp/system/data_pipe.h" |
Chong Zhang | b7c8d1ce | 2018-03-13 19:14:11 | [diff] [blame] | 15 | #include "services/network/public/cpp/shared_url_loader_factory.h" |
Ken Rockot | 54311e6 | 2018-02-10 19:01:52 | [diff] [blame] | 16 | #include "services/network/public/mojom/url_loader_factory.mojom.h" |
Farah Charab | 66145a8 | 2018-07-23 13:17:26 | [diff] [blame] | 17 | #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] | 18 | #include "third_party/blink/public/platform/web_url_loader.h" |
| 19 | #include "third_party/blink/public/platform/web_url_loader_factory.h" |
[email protected] | 745dac28 | 2014-08-22 17:28:23 | [diff] [blame] | 20 | |
Randy Smith | ff094aa | 2018-01-17 18:21:27 | [diff] [blame] | 21 | namespace network { |
| 22 | struct ResourceResponseInfo; |
| 23 | } |
| 24 | |
[email protected] | b5126da4 | 2014-03-04 03:33:40 | [diff] [blame] | 25 | namespace content { |
| 26 | |
[email protected] | a491fd9 | 2014-06-23 12:15:03 | [diff] [blame] | 27 | class ResourceDispatcher; |
[email protected] | 0bf419d1 | 2014-05-28 01:02:23 | [diff] [blame] | 28 | |
Kinuko Yasuda | 017b79e6 | 2017-10-24 17:46:10 | [diff] [blame] | 29 | // Default implementation of WebURLLoaderFactory. |
| 30 | class CONTENT_EXPORT WebURLLoaderFactoryImpl |
| 31 | : public blink::WebURLLoaderFactory { |
| 32 | public: |
Chong Zhang | b7c8d1ce | 2018-03-13 19:14:11 | [diff] [blame] | 33 | WebURLLoaderFactoryImpl( |
| 34 | base::WeakPtr<ResourceDispatcher> resource_dispatcher, |
| 35 | scoped_refptr<network::SharedURLLoaderFactory> loader_factory); |
Kinuko Yasuda | 017b79e6 | 2017-10-24 17:46:10 | [diff] [blame] | 36 | ~WebURLLoaderFactoryImpl() override; |
| 37 | |
| 38 | // Creates a test-only factory which can be used only for data URLs. |
| 39 | static std::unique_ptr<WebURLLoaderFactoryImpl> CreateTestOnlyFactory(); |
| 40 | |
| 41 | std::unique_ptr<blink::WebURLLoader> CreateURLLoader( |
| 42 | const blink::WebURLRequest& request, |
Farah Charab | 66145a8 | 2018-07-23 13:17:26 | [diff] [blame] | 43 | std::unique_ptr<blink::scheduler::WebResourceLoadingTaskRunnerHandle> |
| 44 | task_runner_handle) override; |
Kinuko Yasuda | 017b79e6 | 2017-10-24 17:46:10 | [diff] [blame] | 45 | |
| 46 | private: |
| 47 | base::WeakPtr<ResourceDispatcher> resource_dispatcher_; |
Chong Zhang | b7c8d1ce | 2018-03-13 19:14:11 | [diff] [blame] | 48 | scoped_refptr<network::SharedURLLoaderFactory> loader_factory_; |
Kinuko Yasuda | 017b79e6 | 2017-10-24 17:46:10 | [diff] [blame] | 49 | DISALLOW_COPY_AND_ASSIGN(WebURLLoaderFactoryImpl); |
| 50 | }; |
| 51 | |
Nico Weber | 43ddd7a3 | 2017-08-15 19:19:27 | [diff] [blame] | 52 | class CONTENT_EXPORT WebURLLoaderImpl : public blink::WebURLLoader { |
[email protected] | f92eb0034 | 2009-06-09 18:45:04 | [diff] [blame] | 53 | public: |
Chong Zhang | b7c8d1ce | 2018-03-13 19:14:11 | [diff] [blame] | 54 | WebURLLoaderImpl( |
| 55 | ResourceDispatcher* resource_dispatcher, |
Farah Charab | 66145a8 | 2018-07-23 13:17:26 | [diff] [blame] | 56 | std::unique_ptr<blink::scheduler::WebResourceLoadingTaskRunnerHandle> |
| 57 | task_runner_handle, |
Chong Zhang | b7c8d1ce | 2018-03-13 19:14:11 | [diff] [blame] | 58 | scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory); |
Yutaka Hirano | f7f2f63 | 2017-09-06 10:40:08 | [diff] [blame] | 59 | // When non-null |keep_alive_handle| is specified, this loader prolongs |
| 60 | // this render process's lifetime. |
Chong Zhang | b7c8d1ce | 2018-03-13 19:14:11 | [diff] [blame] | 61 | WebURLLoaderImpl( |
| 62 | ResourceDispatcher* resource_dispatcher, |
Farah Charab | 66145a8 | 2018-07-23 13:17:26 | [diff] [blame] | 63 | std::unique_ptr<blink::scheduler::WebResourceLoadingTaskRunnerHandle> |
| 64 | task_runner_handle, |
Chong Zhang | b7c8d1ce | 2018-03-13 19:14:11 | [diff] [blame] | 65 | scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory, |
| 66 | mojom::KeepAliveHandlePtr keep_alive_handle); |
nick | 5120892 | 2015-04-24 21:38:37 | [diff] [blame] | 67 | ~WebURLLoaderImpl() override; |
[email protected] | f92eb0034 | 2009-06-09 18:45:04 | [diff] [blame] | 68 | |
Takeshi Yoshino | d0c5d35b | 2017-07-27 23:13:27 | [diff] [blame] | 69 | static void PopulateURLResponse(const blink::WebURL& url, |
Randy Smith | ff094aa | 2018-01-17 18:21:27 | [diff] [blame] | 70 | const network::ResourceResponseInfo& info, |
lgarron | 19dc0232 | 2015-08-08 02:16:40 | [diff] [blame] | 71 | blink::WebURLResponse* response, |
Clark DuVall | 36164bd | 2018-08-09 22:49:08 | [diff] [blame] | 72 | bool report_security_info, |
| 73 | int request_id); |
Dmitry Gozman | 99961f2 | 2019-01-09 13:34:39 | [diff] [blame] | 74 | static blink::WebURLError PopulateURLError( |
| 75 | const network::URLLoaderCompletionStatus& status, |
| 76 | const GURL& url); |
| 77 | |
[email protected] | f92eb0034 | 2009-06-09 18:45:04 | [diff] [blame] | 78 | // WebURLLoader methods: |
Nate Chapin | 1b5126a | 2018-05-10 17:37:05 | [diff] [blame] | 79 | void LoadSynchronously(const blink::WebURLRequest& request, |
Nate Chapin | 4bd024a | 2018-05-17 18:32:06 | [diff] [blame] | 80 | blink::WebURLLoaderClient* client, |
Marijn Kruisselbrink | 090b1a4f | 2018-03-30 19:54:12 | [diff] [blame] | 81 | blink::WebURLResponse& response, |
| 82 | base::Optional<blink::WebURLError>& error, |
| 83 | blink::WebData& data, |
| 84 | int64_t& encoded_data_length, |
| 85 | int64_t& encoded_body_length, |
Marijn Kruisselbrink | 090b1a4f | 2018-03-30 19:54:12 | [diff] [blame] | 86 | blink::WebBlobInfo& downloaded_blob) override; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 87 | void LoadAsynchronously(const blink::WebURLRequest& request, |
| 88 | blink::WebURLLoaderClient* client) override; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 89 | void SetDefersLoading(bool value) override; |
| 90 | void DidChangePriority(blink::WebURLRequest::Priority new_priority, |
nick | 5120892 | 2015-04-24 21:38:37 | [diff] [blame] | 91 | int intra_priority_value) override; |
Yutaka Hirano | 7eeae7b0 | 2019-03-26 11:37:43 | [diff] [blame] | 92 | scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() override; |
| 93 | |
[email protected] | f92eb0034 | 2009-06-09 18:45:04 | [diff] [blame] | 94 | private: |
[email protected] | b2787cf | 2009-06-11 22:20:39 | [diff] [blame] | 95 | class Context; |
kinuko | ccbf2c957 | 2016-02-03 22:54:37 | [diff] [blame] | 96 | class RequestPeerImpl; |
John Abd-El-Malek | d237798 | 2018-01-08 22:23:12 | [diff] [blame] | 97 | class SinkPeer; |
Tsuyoshi Horo | 0b61905 | 2019-05-17 08:44:14 | [diff] [blame^] | 98 | |
| 99 | void Cancel(); |
| 100 | |
[email protected] | b2787cf | 2009-06-11 22:20:39 | [diff] [blame] | 101 | scoped_refptr<Context> context_; |
[email protected] | a491fd9 | 2014-06-23 12:15:03 | [diff] [blame] | 102 | |
| 103 | DISALLOW_COPY_AND_ASSIGN(WebURLLoaderImpl); |
[email protected] | f92eb0034 | 2009-06-09 18:45:04 | [diff] [blame] | 104 | }; |
| 105 | |
[email protected] | b5126da4 | 2014-03-04 03:33:40 | [diff] [blame] | 106 | } // namespace content |
[email protected] | f92eb0034 | 2009-06-09 18:45:04 | [diff] [blame] | 107 | |
John Abd-El-Malek | 6b56ef71 | 2017-10-21 22:52:46 | [diff] [blame] | 108 | #endif // CONTENT_RENDERER_LOADER_WEB_URL_LOADER_IMPL_H_ |