OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // The intent of this file is to provide a type-neutral abstraction between | 5 // The intent of this file is to provide a type-neutral abstraction between |
6 // Chrome and WebKit for resource loading. This pure-virtual interface is | 6 // Chrome and WebKit for resource loading. This pure-virtual interface is |
7 // implemented by the embedder. | 7 // implemented by the embedder. |
8 // | 8 // |
9 // One of these objects will be created by WebKit for each request. WebKit | 9 // One of these objects will be created by WebKit for each request. WebKit |
10 // will own the pointer to the bridge, and will delete it when the request is | 10 // will own the pointer to the bridge, and will delete it when the request is |
11 // no longer needed. | 11 // no longer needed. |
12 // | 12 // |
13 // In turn, the bridge's owner on the WebKit end will implement the Peer | 13 // In turn, the bridge's owner on the WebKit end will implement the Peer |
14 // interface, which we will use to communicate notifications back. | 14 // interface, which we will use to communicate notifications back. |
15 | 15 |
16 #ifndef WEBKIT_CHILD_RESOURCE_LOADER_BRIDGE_H_ | 16 #ifndef CONTENT_PUBLIC_CHILD_RESOURCE_LOADER_BRIDGE_H_ |
17 #define WEBKIT_CHILD_RESOURCE_LOADER_BRIDGE_H_ | 17 #define CONTENT_PUBLIC_CHILD_RESOURCE_LOADER_BRIDGE_H_ |
18 | 18 |
19 #include <utility> | 19 #include <utility> |
20 | 20 |
21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
22 #if defined(OS_POSIX) | 22 #if defined(OS_POSIX) |
23 #include "base/file_descriptor_posix.h" | 23 #include "base/file_descriptor_posix.h" |
24 #endif | 24 #endif |
25 #include "base/memory/ref_counted.h" | 25 #include "base/memory/ref_counted.h" |
26 #include "base/platform_file.h" | 26 #include "base/platform_file.h" |
27 #include "base/values.h" | 27 #include "base/values.h" |
28 #include "content/common/content_export.h" | |
28 #include "net/base/request_priority.h" | 29 #include "net/base/request_priority.h" |
29 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" | 30 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
30 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 31 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
31 #include "url/gurl.h" | 32 #include "url/gurl.h" |
32 #include "webkit/child/webkit_child_export.h" | |
33 #include "webkit/common/resource_response_info.h" | 33 #include "webkit/common/resource_response_info.h" |
34 #include "webkit/common/resource_type.h" | 34 #include "webkit/common/resource_type.h" |
35 | 35 |
36 namespace webkit_glue { | 36 namespace webkit_glue { |
37 class ResourceRequestBody; | 37 class ResourceRequestBody; |
38 } | |
39 | |
40 namespace content { | |
38 | 41 |
39 class ResourceLoaderBridge { | 42 class ResourceLoaderBridge { |
jam
2014/03/04 20:36:04
This class was originally created to bridge code i
| |
40 public: | 43 public: |
41 // Structure used when calling | 44 // Structure used when calling |
42 // WebKitPlatformSupportImpl::CreateResourceLoader(). | 45 // WebKitPlatformSupportImpl::CreateResourceLoader(). |
43 struct WEBKIT_CHILD_EXPORT RequestInfo { | 46 struct CONTENT_EXPORT RequestInfo { |
jam
2014/03/04 20:36:04
this is only used inside content, so it should go
| |
44 RequestInfo(); | 47 RequestInfo(); |
45 ~RequestInfo(); | 48 ~RequestInfo(); |
46 | 49 |
47 // HTTP-style method name (e.g., "GET" or "POST"). | 50 // HTTP-style method name (e.g., "GET" or "POST"). |
48 std::string method; | 51 std::string method; |
49 | 52 |
50 // Absolute URL encoded in ASCII per the rules of RFC-2396. | 53 // Absolute URL encoded in ASCII per the rules of RFC-2396. |
51 GURL url; | 54 GURL url; |
52 | 55 |
53 // URL of the document in the top-level window, which may be checked by the | 56 // URL of the document in the top-level window, which may be checked by the |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 | 101 |
99 // Extra data associated with this request. We do not own this pointer. | 102 // Extra data associated with this request. We do not own this pointer. |
100 blink::WebURLRequest::ExtraData* extra_data; | 103 blink::WebURLRequest::ExtraData* extra_data; |
101 | 104 |
102 private: | 105 private: |
103 DISALLOW_COPY_AND_ASSIGN(RequestInfo); | 106 DISALLOW_COPY_AND_ASSIGN(RequestInfo); |
104 }; | 107 }; |
105 | 108 |
106 // See the SyncLoad method declared below. (The name of this struct is not | 109 // See the SyncLoad method declared below. (The name of this struct is not |
107 // suffixed with "Info" because it also contains the response data.) | 110 // suffixed with "Info" because it also contains the response data.) |
108 struct SyncLoadResponse : ResourceResponseInfo { | 111 struct SyncLoadResponse : webkit_glue::ResourceResponseInfo { |
jam
2014/03/04 20:36:04
ditto: content/child/sync_load_response.*
| |
109 WEBKIT_CHILD_EXPORT SyncLoadResponse(); | 112 CONTENT_EXPORT SyncLoadResponse(); |
110 WEBKIT_CHILD_EXPORT ~SyncLoadResponse(); | 113 CONTENT_EXPORT ~SyncLoadResponse(); |
111 | 114 |
112 // The response error code. | 115 // The response error code. |
113 int error_code; | 116 int error_code; |
114 | 117 |
115 // The final URL of the response. This may differ from the request URL in | 118 // The final URL of the response. This may differ from the request URL in |
116 // the case of a server redirect. | 119 // the case of a server redirect. |
117 GURL url; | 120 GURL url; |
118 | 121 |
119 // The response data. | 122 // The response data. |
120 std::string data; | 123 std::string data; |
121 }; | 124 }; |
122 | 125 |
123 // Generated by the bridge. This is implemented by our custom resource loader | 126 // Generated by the bridge. This is implemented by our custom resource loader |
124 // within webkit. The Peer and it's bridge should have identical lifetimes | 127 // within webkit. The Peer and it's bridge should have identical lifetimes |
125 // as they represent each end of a communication channel. | 128 // as they represent each end of a communication channel. |
126 // | 129 // |
127 // These callbacks mirror net::URLRequest::Delegate and the order and | 130 // These callbacks mirror net::URLRequest::Delegate and the order and |
128 // conditions in which they will be called are identical. See url_request.h | 131 // conditions in which they will be called are identical. See url_request.h |
129 // for more information. | 132 // for more information. |
130 class WEBKIT_CHILD_EXPORT Peer { | 133 class CONTENT_EXPORT Peer { |
jam
2014/03/04 20:36:04
this should be in its own file in content/public/c
| |
131 public: | 134 public: |
132 // Called as upload progress is made. | 135 // Called as upload progress is made. |
133 // note: only for requests with LOAD_ENABLE_UPLOAD_PROGRESS set | 136 // note: only for requests with LOAD_ENABLE_UPLOAD_PROGRESS set |
134 virtual void OnUploadProgress(uint64 position, uint64 size) = 0; | 137 virtual void OnUploadProgress(uint64 position, uint64 size) = 0; |
135 | 138 |
136 // Called when a redirect occurs. The implementation may return false to | 139 // Called when a redirect occurs. The implementation may return false to |
137 // suppress the redirect. The given ResponseInfo provides complete | 140 // suppress the redirect. The given ResponseInfo provides complete |
138 // information about the redirect, and new_url is the URL that will be | 141 // information about the redirect, and new_url is the URL that will be |
139 // loaded if this method returns true. If this method returns true, the | 142 // loaded if this method returns true. If this method returns true, the |
140 // output parameter *has_new_first_party_for_cookies indicates whether the | 143 // output parameter *has_new_first_party_for_cookies indicates whether the |
141 // output parameter *new_first_party_for_cookies contains the new URL that | 144 // output parameter *new_first_party_for_cookies contains the new URL that |
142 // should be consulted for the third-party cookie blocking policy. | 145 // should be consulted for the third-party cookie blocking policy. |
143 virtual bool OnReceivedRedirect(const GURL& new_url, | 146 virtual bool OnReceivedRedirect( |
144 const ResourceResponseInfo& info, | 147 const GURL& new_url, |
145 bool* has_new_first_party_for_cookies, | 148 const webkit_glue::ResourceResponseInfo& info, |
146 GURL* new_first_party_for_cookies) = 0; | 149 bool* has_new_first_party_for_cookies, |
150 GURL* new_first_party_for_cookies) = 0; | |
147 | 151 |
148 // Called when response headers are available (after all redirects have | 152 // Called when response headers are available (after all redirects have |
149 // been followed). | 153 // been followed). |
150 virtual void OnReceivedResponse(const ResourceResponseInfo& info) = 0; | 154 virtual void OnReceivedResponse( |
155 const webkit_glue::ResourceResponseInfo& info) = 0; | |
151 | 156 |
152 // Called when a chunk of response data is downloaded. This method may be | 157 // Called when a chunk of response data is downloaded. This method may be |
153 // called multiple times or not at all if an error occurs. This method is | 158 // called multiple times or not at all if an error occurs. This method is |
154 // only called if RequestInfo::download_to_file was set to true, and in | 159 // only called if RequestInfo::download_to_file was set to true, and in |
155 // that case, OnReceivedData will not be called. | 160 // that case, OnReceivedData will not be called. |
156 // The encoded_data_length is the length of the encoded data transferred | 161 // The encoded_data_length is the length of the encoded data transferred |
157 // over the network, which could be different from data length (e.g. for | 162 // over the network, which could be different from data length (e.g. for |
158 // gzipped content). | 163 // gzipped content). |
159 virtual void OnDownloadedData(int len, int encoded_data_length) = 0; | 164 virtual void OnDownloadedData(int len, int encoded_data_length) = 0; |
160 | 165 |
161 // Called when a chunk of response data is available. This method may | 166 // Called when a chunk of response data is available. This method may |
162 // be called multiple times or not at all if an error occurs. | 167 // be called multiple times or not at all if an error occurs. |
163 // The encoded_data_length is the length of the encoded data transferred | 168 // The encoded_data_length is the length of the encoded data transferred |
164 // over the network, which could be different from data length (e.g. for | 169 // over the network, which could be different from data length (e.g. for |
165 // gzipped content). | 170 // gzipped content). |
166 virtual void OnReceivedData(const char* data, | 171 virtual void OnReceivedData(const char* data, |
167 int data_length, | 172 int data_length, |
168 int encoded_data_length) = 0; | 173 int encoded_data_length) = 0; |
169 | 174 |
170 // Called when metadata generated by the renderer is retrieved from the | 175 // Called when metadata generated by the renderer is retrieved from the |
171 // cache. This method may be called zero or one times. | 176 // cache. This method may be called zero or one times. |
172 virtual void OnReceivedCachedMetadata(const char* data, int len) { } | 177 virtual void OnReceivedCachedMetadata(const char* data, int len) {} |
173 | 178 |
174 // Called when the response is complete. This method signals completion of | 179 // Called when the response is complete. This method signals completion of |
175 // the resource load. | 180 // the resource load. |
176 virtual void OnCompletedRequest( | 181 virtual void OnCompletedRequest(int error_code, |
177 int error_code, | 182 bool was_ignored_by_handler, |
178 bool was_ignored_by_handler, | 183 bool stale_copy_in_cache, |
179 bool stale_copy_in_cache, | 184 const std::string& security_info, |
180 const std::string& security_info, | 185 const base::TimeTicks& completion_time, |
181 const base::TimeTicks& completion_time, | 186 int64 total_transfer_size) = 0; |
182 int64 total_transfer_size) = 0; | |
183 | 187 |
184 protected: | 188 protected: |
185 virtual ~Peer() {} | 189 virtual ~Peer() {} |
186 }; | 190 }; |
187 | 191 |
188 // use WebKitPlatformSupportImpl::CreateResourceLoader() for construction, but | 192 // use WebKitPlatformSupportImpl::CreateResourceLoader() for construction, but |
189 // anybody can delete at any time, INCLUDING during processing of callbacks. | 193 // anybody can delete at any time, INCLUDING during processing of callbacks. |
190 WEBKIT_CHILD_EXPORT virtual ~ResourceLoaderBridge(); | 194 CONTENT_EXPORT virtual ~ResourceLoaderBridge(); |
191 | 195 |
192 // Call this method before calling Start() to set the request body. | 196 // Call this method before calling Start() to set the request body. |
193 // May only be used with HTTP(S) POST requests. | 197 // May only be used with HTTP(S) POST requests. |
194 virtual void SetRequestBody(ResourceRequestBody* request_body) = 0; | 198 virtual void SetRequestBody( |
199 webkit_glue::ResourceRequestBody* request_body) = 0; | |
195 | 200 |
196 // Call this method to initiate the request. If this method succeeds, then | 201 // Call this method to initiate the request. If this method succeeds, then |
197 // the peer's methods will be called asynchronously to report various events. | 202 // the peer's methods will be called asynchronously to report various events. |
198 virtual bool Start(Peer* peer) = 0; | 203 virtual bool Start(Peer* peer) = 0; |
199 | 204 |
200 // Call this method to cancel a request that is in progress. This method | 205 // Call this method to cancel a request that is in progress. This method |
201 // causes the request to immediately transition into the 'done' state. The | 206 // causes the request to immediately transition into the 'done' state. The |
202 // OnCompletedRequest method will be called asynchronously; this assumes | 207 // OnCompletedRequest method will be called asynchronously; this assumes |
203 // the peer is still valid. | 208 // the peer is still valid. |
204 virtual void Cancel() = 0; | 209 virtual void Cancel() = 0; |
(...skipping 14 matching lines...) Expand all Loading... | |
219 // use this if you really need it! There is also no way for the caller to | 224 // use this if you really need it! There is also no way for the caller to |
220 // interrupt this method. Errors are reported via the status field of the | 225 // interrupt this method. Errors are reported via the status field of the |
221 // response parameter. | 226 // response parameter. |
222 virtual void SyncLoad(SyncLoadResponse* response) = 0; | 227 virtual void SyncLoad(SyncLoadResponse* response) = 0; |
223 | 228 |
224 protected: | 229 protected: |
225 // Construction must go through | 230 // Construction must go through |
226 // WebKitPlatformSupportImpl::CreateResourceLoader() | 231 // WebKitPlatformSupportImpl::CreateResourceLoader() |
227 // For HTTP(S) POST requests, the AppendDataToUpload and AppendFileToUpload | 232 // For HTTP(S) POST requests, the AppendDataToUpload and AppendFileToUpload |
228 // methods may be called to construct the body of the request. | 233 // methods may be called to construct the body of the request. |
229 WEBKIT_CHILD_EXPORT ResourceLoaderBridge(); | 234 CONTENT_EXPORT ResourceLoaderBridge(); |
230 | 235 |
231 private: | 236 private: |
232 DISALLOW_COPY_AND_ASSIGN(ResourceLoaderBridge); | 237 DISALLOW_COPY_AND_ASSIGN(ResourceLoaderBridge); |
233 }; | 238 }; |
234 | 239 |
235 } // namespace webkit_glue | 240 } // namespace webkit_glue |
236 | 241 |
237 #endif // WEBKIT_CHILD_RESOURCE_LOADER_BRIDGE_H_ | 242 #endif // CONTENT_PUBLIC_CHILD_RESOURCE_LOADER_BRIDGE_H_ |
OLD | NEW |