OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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, which also provides a factory method Create | 7 // implemented by the embedder, which also provides a factory method Create |
8 // to instantiate this object. | 8 // to instantiate this object. |
9 // | 9 // |
10 // One of these objects will be created by WebKit for each request. WebKit | 10 // One of these objects will be created by WebKit for each request. WebKit |
11 // will own the pointer to the bridge, and will delete it when the request is | 11 // will own the pointer to the bridge, and will delete it when the request is |
12 // no longer needed. | 12 // no longer needed. |
13 // | 13 // |
14 // In turn, the bridge's owner on the WebKit end will implement the Peer | 14 // In turn, the bridge's owner on the WebKit end will implement the Peer |
15 // interface, which we will use to communicate notifications back. | 15 // interface, which we will use to communicate notifications back. |
16 | 16 |
17 #ifndef RESOURCE_LOADER_BRIDGE_H__ | 17 #ifndef RESOURCE_LOADER_BRIDGE_H_ |
18 #define RESOURCE_LOADER_BRIDGE_H__ | 18 #define RESOURCE_LOADER_BRIDGE_H_ |
19 | 19 |
20 #include <string> | |
21 | |
22 #include "base/basictypes.h" | |
23 #include "base/ref_counted.h" | 20 #include "base/ref_counted.h" |
24 #include "base/time.h" | 21 #include "base/time.h" |
25 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
26 #include "net/http/http_response_headers.h" | |
27 #include "net/url_request/url_request_status.h" | 23 #include "net/url_request/url_request_status.h" |
28 #include "webkit/glue/resource_type.h" | 24 #include "webkit/glue/resource_type.h" |
29 | 25 |
30 class WebFrame; | 26 class WebFrame; |
31 | 27 |
| 28 namespace net { |
| 29 class HttpResponseHeaders; |
| 30 } |
| 31 |
32 namespace webkit_glue { | 32 namespace webkit_glue { |
33 | 33 |
34 class ResourceLoaderBridge { | 34 class ResourceLoaderBridge { |
35 public: | 35 public: |
36 struct ResponseInfo { | 36 struct ResponseInfo { |
| 37 ResponseInfo(); |
| 38 ~ResponseInfo(); |
| 39 |
37 // The time at which the request was made that resulted in this response. | 40 // The time at which the request was made that resulted in this response. |
38 // For cached responses, this time could be "far" in the past. | 41 // For cached responses, this time could be "far" in the past. |
39 base::Time request_time; | 42 base::Time request_time; |
40 | 43 |
41 // The time at which the response headers were received. For cached | 44 // The time at which the response headers were received. For cached |
42 // responses, this time could be "far" in the past. | 45 // responses, this time could be "far" in the past. |
43 base::Time response_time; | 46 base::Time response_time; |
44 | 47 |
45 // The response headers or NULL if the URL type does not support headers. | 48 // The response headers or NULL if the URL type does not support headers. |
46 scoped_refptr<net::HttpResponseHeaders> headers; | 49 scoped_refptr<net::HttpResponseHeaders> headers; |
47 | 50 |
48 // The mime type of the response. This may be a derived value. | 51 // The mime type of the response. This may be a derived value. |
49 std::string mime_type; | 52 std::string mime_type; |
50 | 53 |
51 // The character encoding of the response or none if not applicable to the | 54 // The character encoding of the response or none if not applicable to the |
52 // response's mime type. This may be a derived value. | 55 // response's mime type. This may be a derived value. |
53 std::string charset; | 56 std::string charset; |
54 | 57 |
55 // An opaque string carrying security information pertaining to this | 58 // An opaque string carrying security information pertaining to this |
56 // response. This may include information about the SSL connection used. | 59 // response. This may include information about the SSL connection used. |
57 std::string security_info; | 60 std::string security_info; |
58 | 61 |
59 // Content length if available. -1 if not available | 62 // Content length if available. -1 if not available |
60 int64 content_length; | 63 int64 content_length; |
61 }; | 64 }; |
62 | 65 |
63 // generated by the bridge. This is implemented by our custom resource loader | 66 // See the SyncLoad method declared below. (The name of this struct is not |
| 67 // suffixed with "Info" because it also contains the response data.) |
| 68 struct SyncLoadResponse : ResponseInfo { |
| 69 SyncLoadResponse(); |
| 70 ~SyncLoadResponse(); |
| 71 |
| 72 // The response status. |
| 73 URLRequestStatus status; |
| 74 |
| 75 // The final URL of the response. This may differ from the request URL in |
| 76 // the case of a server redirect. |
| 77 GURL url; |
| 78 |
| 79 // The response data. |
| 80 std::string data; |
| 81 }; |
| 82 |
| 83 // Generated by the bridge. This is implemented by our custom resource loader |
64 // within webkit. The Peer and it's bridge should have identical lifetimes | 84 // within webkit. The Peer and it's bridge should have identical lifetimes |
65 // as they represent each end of a communication channel. | 85 // as they represent each end of a communication channel. |
66 // | 86 // |
67 // These callbacks mirror URLRequest::Delegate and the order and conditions | 87 // These callbacks mirror URLRequest::Delegate and the order and conditions |
68 // in which they will be called are identical. See url_request.h for more | 88 // in which they will be called are identical. See url_request.h for more |
69 // information. | 89 // information. |
70 class Peer { | 90 class Peer { |
71 public: | 91 public: |
72 virtual ~Peer() {} | 92 virtual ~Peer() {} |
73 | 93 |
(...skipping 19 matching lines...) Expand all Loading... |
93 // the resource load. | 113 // the resource load. |
94 virtual void OnCompletedRequest(const URLRequestStatus& status) = 0; | 114 virtual void OnCompletedRequest(const URLRequestStatus& status) = 0; |
95 | 115 |
96 // Returns the URL of the request, which allows us to display it in | 116 // Returns the URL of the request, which allows us to display it in |
97 // debugging situations. | 117 // debugging situations. |
98 virtual std::string GetURLForDebugging() = 0; | 118 virtual std::string GetURLForDebugging() = 0; |
99 }; | 119 }; |
100 | 120 |
101 // use Create() for construction, but anybody can delete at any time, | 121 // use Create() for construction, but anybody can delete at any time, |
102 // INCLUDING during processing of callbacks. | 122 // INCLUDING during processing of callbacks. |
103 virtual ~ResourceLoaderBridge() {} | 123 virtual ~ResourceLoaderBridge(); |
104 | 124 |
105 // Call this method to make a new instance. The method name is a HTTP-style | 125 // Call this method to make a new instance. The method name is a HTTP-style |
106 // method name (e.g., "GET" or "POST"). The URL should be an absolute URL | 126 // method name (e.g., "GET" or "POST"). The URL should be an absolute URL |
107 // encoded in ASCII per the rules of RFC-2396. The referrer parameter is | 127 // encoded in ASCII per the rules of RFC-2396. The referrer parameter is |
108 // optional (may be NULL) and is a URL with similar constraints in how it | 128 // optional (may be NULL) and is a URL with similar constraints in how it |
109 // must be encoded. | 129 // must be encoded. |
110 // | 130 // |
111 // For HTTP(S) POST requests, the AppendDataToUpload and AppendFileToUpload | 131 // For HTTP(S) POST requests, the AppendDataToUpload and AppendFileToUpload |
112 // methods may be called to construct the body of the request. | 132 // methods may be called to construct the body of the request. |
113 // | 133 // |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // Call this method to cancel a request that is in progress. This method | 182 // Call this method to cancel a request that is in progress. This method |
163 // causes the request to immediately transition into the 'done' state. The | 183 // causes the request to immediately transition into the 'done' state. The |
164 // OnCompletedRequest method will be called asynchronously; this assumes | 184 // OnCompletedRequest method will be called asynchronously; this assumes |
165 // the peer is still valid. | 185 // the peer is still valid. |
166 virtual void Cancel() = 0; | 186 virtual void Cancel() = 0; |
167 | 187 |
168 // Call this method to suspend or resume a load that is in progress. This | 188 // Call this method to suspend or resume a load that is in progress. This |
169 // method may only be called after a successful call to the Start method. | 189 // method may only be called after a successful call to the Start method. |
170 virtual void SetDefersLoading(bool value) = 0; | 190 virtual void SetDefersLoading(bool value) = 0; |
171 | 191 |
172 // See the SyncLoad method declared below. (The name of this struct is not | |
173 // suffixed with "Info" because it also contains the response data.) | |
174 struct SyncLoadResponse : ResponseInfo { | |
175 // The response status. | |
176 URLRequestStatus status; | |
177 | |
178 // The final URL of the response. This may differ from the request URL in | |
179 // the case of a server redirect. | |
180 GURL url; | |
181 | |
182 // The response data. | |
183 std::string data; | |
184 }; | |
185 | |
186 // Call this method to load the resource synchronously (i.e., in one shot). | 192 // Call this method to load the resource synchronously (i.e., in one shot). |
187 // This is an alternative to the Start method. Be warned that this method | 193 // This is an alternative to the Start method. Be warned that this method |
188 // will block the calling thread until the resource is fully downloaded or an | 194 // will block the calling thread until the resource is fully downloaded or an |
189 // error occurs. It could block the calling thread for a long time, so only | 195 // error occurs. It could block the calling thread for a long time, so only |
190 // use this if you really need it! There is also no way for the caller to | 196 // use this if you really need it! There is also no way for the caller to |
191 // interrupt this method. Errors are reported via the status field of the | 197 // interrupt this method. Errors are reported via the status field of the |
192 // response parameter. | 198 // response parameter. |
193 virtual void SyncLoad(SyncLoadResponse* response) = 0; | 199 virtual void SyncLoad(SyncLoadResponse* response) = 0; |
194 | 200 |
195 protected: | 201 protected: |
196 // construction must go through Create() | 202 // construction must go through Create() |
197 ResourceLoaderBridge() {} | 203 ResourceLoaderBridge(); |
198 | 204 |
199 private: | 205 private: |
200 DISALLOW_EVIL_CONSTRUCTORS(ResourceLoaderBridge); | 206 DISALLOW_EVIL_CONSTRUCTORS(ResourceLoaderBridge); |
201 }; | 207 }; |
202 | 208 |
203 } // namespace webkit_glue | 209 } // namespace webkit_glue |
204 | 210 |
205 #endif // RESOURCE_LOADER_BRIDGE__ | 211 #endif // RESOURCE_LOADER_BRIDGE_ |
206 | |
OLD | NEW |