blob: 9ce1066841fc0eb1f7df86786abd002103e948eb [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"
Philip Rogers7178f5c2018-07-09 18:52:5914#include "mojo/public/cpp/system/data_pipe.h"
Chong Zhangb7c8d1ce2018-03-13 19:14:1115#include "services/network/public/cpp/shared_url_loader_factory.h"
Ken Rockot54311e62018-02-10 19:01:5216#include "services/network/public/mojom/url_loader_factory.mojom.h"
Farah Charab66145a82018-07-23 13:17:2617#include "third_party/blink/public/platform/scheduler/web_resource_loading_task_runner_handle.h"
Blink Reformata30d4232018-04-07 15:31:0618#include "third_party/blink/public/platform/web_url_loader.h"
19#include "third_party/blink/public/platform/web_url_loader_factory.h"
[email protected]745dac282014-08-22 17:28:2320
Randy Smithff094aa2018-01-17 18:21:2721namespace network {
22struct ResourceResponseInfo;
23}
24
[email protected]b5126da42014-03-04 03:33:4025namespace content {
26
[email protected]a491fd92014-06-23 12:15:0327class ResourceDispatcher;
[email protected]0bf419d12014-05-28 01:02:2328
Kinuko Yasuda017b79e62017-10-24 17:46:1029// Default implementation of WebURLLoaderFactory.
30class CONTENT_EXPORT WebURLLoaderFactoryImpl
31 : public blink::WebURLLoaderFactory {
32 public:
Chong Zhangb7c8d1ce2018-03-13 19:14:1133 WebURLLoaderFactoryImpl(
34 base::WeakPtr<ResourceDispatcher> resource_dispatcher,
35 scoped_refptr<network::SharedURLLoaderFactory> loader_factory);
Kinuko Yasuda017b79e62017-10-24 17:46:1036 ~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 Charab66145a82018-07-23 13:17:2643 std::unique_ptr<blink::scheduler::WebResourceLoadingTaskRunnerHandle>
44 task_runner_handle) override;
Kinuko Yasuda017b79e62017-10-24 17:46:1045
46 private:
47 base::WeakPtr<ResourceDispatcher> resource_dispatcher_;
Chong Zhangb7c8d1ce2018-03-13 19:14:1148 scoped_refptr<network::SharedURLLoaderFactory> loader_factory_;
Kinuko Yasuda017b79e62017-10-24 17:46:1049 DISALLOW_COPY_AND_ASSIGN(WebURLLoaderFactoryImpl);
50};
51
Nico Weber43ddd7a32017-08-15 19:19:2752class CONTENT_EXPORT WebURLLoaderImpl : public blink::WebURLLoader {
[email protected]f92eb00342009-06-09 18:45:0453 public:
Chong Zhangb7c8d1ce2018-03-13 19:14:1154 WebURLLoaderImpl(
55 ResourceDispatcher* resource_dispatcher,
Farah Charab66145a82018-07-23 13:17:2656 std::unique_ptr<blink::scheduler::WebResourceLoadingTaskRunnerHandle>
57 task_runner_handle,
Chong Zhangb7c8d1ce2018-03-13 19:14:1158 scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
Yutaka Hiranof7f2f632017-09-06 10:40:0859 // When non-null |keep_alive_handle| is specified, this loader prolongs
60 // this render process's lifetime.
Chong Zhangb7c8d1ce2018-03-13 19:14:1161 WebURLLoaderImpl(
62 ResourceDispatcher* resource_dispatcher,
Farah Charab66145a82018-07-23 13:17:2663 std::unique_ptr<blink::scheduler::WebResourceLoadingTaskRunnerHandle>
64 task_runner_handle,
Chong Zhangb7c8d1ce2018-03-13 19:14:1165 scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
66 mojom::KeepAliveHandlePtr keep_alive_handle);
nick51208922015-04-24 21:38:3767 ~WebURLLoaderImpl() override;
[email protected]f92eb00342009-06-09 18:45:0468
Takeshi Yoshinod0c5d35b2017-07-27 23:13:2769 static void PopulateURLResponse(const blink::WebURL& url,
Randy Smithff094aa2018-01-17 18:21:2770 const network::ResourceResponseInfo& info,
lgarron19dc02322015-08-08 02:16:4071 blink::WebURLResponse* response,
Clark DuVall36164bd2018-08-09 22:49:0872 bool report_security_info,
73 int request_id);
Dmitry Gozman99961f22019-01-09 13:34:3974 static blink::WebURLError PopulateURLError(
75 const network::URLLoaderCompletionStatus& status,
76 const GURL& url);
77
[email protected]f92eb00342009-06-09 18:45:0478 // WebURLLoader methods:
Nate Chapin1b5126a2018-05-10 17:37:0579 void LoadSynchronously(const blink::WebURLRequest& request,
Nate Chapin4bd024a2018-05-17 18:32:0680 blink::WebURLLoaderClient* client,
Marijn Kruisselbrink090b1a4f2018-03-30 19:54:1281 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 Kruisselbrink090b1a4f2018-03-30 19:54:1286 blink::WebBlobInfo& downloaded_blob) override;
Blink Reformat1c4d759e2017-04-09 16:34:5487 void LoadAsynchronously(const blink::WebURLRequest& request,
88 blink::WebURLLoaderClient* client) override;
Blink Reformat1c4d759e2017-04-09 16:34:5489 void SetDefersLoading(bool value) override;
90 void DidChangePriority(blink::WebURLRequest::Priority new_priority,
nick51208922015-04-24 21:38:3791 int intra_priority_value) override;
Yutaka Hirano7eeae7b02019-03-26 11:37:4392 scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() override;
93
[email protected]f92eb00342009-06-09 18:45:0494 private:
[email protected]b2787cf2009-06-11 22:20:3995 class Context;
kinukoccbf2c9572016-02-03 22:54:3796 class RequestPeerImpl;
John Abd-El-Malekd2377982018-01-08 22:23:1297 class SinkPeer;
Tsuyoshi Horo0b619052019-05-17 08:44:1498
99 void Cancel();
100
[email protected]b2787cf2009-06-11 22:20:39101 scoped_refptr<Context> context_;
[email protected]a491fd92014-06-23 12:15:03102
103 DISALLOW_COPY_AND_ASSIGN(WebURLLoaderImpl);
[email protected]f92eb00342009-06-09 18:45:04104};
105
[email protected]b5126da42014-03-04 03:33:40106} // namespace content
[email protected]f92eb00342009-06-09 18:45:04107
John Abd-El-Malek6b56ef712017-10-21 22:52:46108#endif // CONTENT_RENDERER_LOADER_WEB_URL_LOADER_IMPL_H_