1 /*
2  * Copyright (C) 2009, 2011 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_URL_LOADER_H_
32 #define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_URL_LOADER_H_
33 
34 #include <stdint.h>
35 #include "base/optional.h"
36 #include "base/time/time.h"
37 #include "third_party/blink/public/platform/web_blob_info.h"
38 #include "third_party/blink/public/platform/web_common.h"
39 #include "third_party/blink/public/platform/web_url_request.h"
40 
41 namespace base {
42 class SingleThreadTaskRunner;
43 }
44 
45 namespace network {
46 struct ResourceRequest;
47 }
48 
49 namespace blink {
50 
51 class ResourceLoadInfoNotifierWrapper;
52 class WebData;
53 class WebURLRequestExtraData;
54 class WebURLLoaderClient;
55 class WebURLResponse;
56 struct WebURLError;
57 
58 class WebURLLoader {
59  public:
60   // The WebURLLoader may be deleted in a call to its client.
61   virtual ~WebURLLoader() = default;
62 
63   // Load the request synchronously, returning results directly to the
64   // caller upon completion.  There is no mechanism to interrupt a
65   // synchronous load!!
66   // If the request's PassResponsePipeToClient flag is set to true, the response
67   // will instead be redirected to a blob, which is passed out in
68   // |downloaded_blob|.
69   virtual void LoadSynchronously(
70       std::unique_ptr<network::ResourceRequest> request,
71       scoped_refptr<WebURLRequestExtraData> url_request_extra_data,
72       int requestor_id,
73       bool pass_response_pipe_to_client,
74       bool no_mime_sniffing,
75       base::TimeDelta timeout_interval,
76       WebURLLoaderClient*,
77       WebURLResponse&,
78       base::Optional<WebURLError>&,
79       WebData&,
80       int64_t& encoded_data_length,
81       int64_t& encoded_body_length,
82       WebBlobInfo& downloaded_blob,
83       std::unique_ptr<blink::ResourceLoadInfoNotifierWrapper>
84           resource_load_info_notifier_wrapper) = 0;
85 
86   // Load the request asynchronously, sending notifications to the given
87   // client.  The client will receive no further notifications if the
88   // loader is disposed before it completes its work.
89   virtual void LoadAsynchronously(
90       std::unique_ptr<network::ResourceRequest> request,
91       scoped_refptr<WebURLRequestExtraData> url_request_extra_data,
92       int requestor_id,
93       bool no_mime_sniffing,
94       std::unique_ptr<ResourceLoadInfoNotifierWrapper>,
95       WebURLLoaderClient*) = 0;
96 
97   // |kDeferred| is when an asynchronous load is suspended.
98   // |kDeferredWithBackForwardCache| is when an asynchronous load is suspended
99   // with BackForwardCache, and BackForwardCache entry can be evicted when
100   // redirects etc. happen.
101   // |kNotDeferred| is when an asynchronous load is resumed.
102   // SetDefersLoading can be called with any value at any point.
103   enum class DeferType {
104     kDeferred,
105     kDeferredWithBackForwardCache,
106     kNotDeferred
107   };
108   // Suspends/resumes an asynchronous load.
109   virtual void SetDefersLoading(DeferType) = 0;
110 
111   // Notifies the loader that the priority of a WebURLRequest has changed from
112   // its previous value. For example, a preload request starts with low
113   // priority, but may increase when the resource is needed for rendering.
114   virtual void DidChangePriority(WebURLRequest::Priority new_priority,
115                                  int intra_priority_value) = 0;
116 
117   // Returns the task runner for this request.
118   virtual scoped_refptr<base::SingleThreadTaskRunner>
119   GetTaskRunnerForBodyLoader() = 0;
120 };
121 
122 }  // namespace blink
123 
124 #endif
125