resource_loader_bridge.h revision 201ade2fbba22bfb27ae029f4d23fca6ded109a0
1c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Use of this source code is governed by a BSD-style license that can be
3c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// found in the LICENSE file.
4c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch//
5c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// The intent of this file is to provide a type-neutral abstraction between
6c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Chrome and WebKit for resource loading. This pure-virtual interface is
7c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// implemented by the embedder, which also provides a factory method Create
8c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// to instantiate this object.
9c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch//
10c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// One of these objects will be created by WebKit for each request. WebKit
11c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// will own the pointer to the bridge, and will delete it when the request is
12c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// no longer needed.
13c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch//
14c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// In turn, the bridge's owner on the WebKit end will implement the Peer
15c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// interface, which we will use to communicate notifications back.
16c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
17c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#ifndef WEBKIT_GLUE_RESOURCE_LOADER_BRIDGE_H_
18c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#define WEBKIT_GLUE_RESOURCE_LOADER_BRIDGE_H_
19c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
20731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick#include <utility>
21731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick#include <vector>
22731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
23c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "build/build_config.h"
24c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#if defined(OS_POSIX)
25c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/file_descriptor_posix.h"
26c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif
273345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#include "base/file_path.h"
28c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/platform_file.h"
29c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/ref_counted.h"
30731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick#include "base/scoped_ptr.h"
31c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/time.h"
32731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick#include "base/values.h"
33c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "googleurl/src/gurl.h"
34c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "net/url_request/url_request_status.h"
35c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "webkit/glue/resource_type.h"
36c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
37c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochnamespace net {
38c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass HttpResponseHeaders;
39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}
40c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
41c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochnamespace webkit_glue {
42c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
43731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick// Structure containing timing information for the request. It addresses
44731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick// http://groups.google.com/group/http-archive-specification/web/har-1-1-spec
45731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick// and http://dev.w3.org/2006/webapi/WebTiming/ needs.
46731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick//
47731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick// All the values for starts and ends are given in milliseconds and are
48731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick// offsets with respect to the given base time.
49731df977c0511bca2206b5f333555b1205ff1f43Iain Merrickstruct ResourceLoadTimingInfo {
50731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  ResourceLoadTimingInfo();
51731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  ~ResourceLoadTimingInfo();
52731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
53731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // All the values in this struct are given as offsets in milliseconds wrt
54731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // this base time.
55731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  base::Time base_time;
56731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
57731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time that proxy processing started. For requests with no proxy phase,
58731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // this time is -1.
59731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 proxy_start;
60731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
61731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time that proxy processing ended. For reused sockets this time
62731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // is -1.
63731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 proxy_end;
64731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
65731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time that DNS lookup started. For reused sockets this time is -1.
66731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 dns_start;
67731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
68731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time that DNS lookup ended. For reused sockets this time is -1.
69731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 dns_end;
70731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
71731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time that establishing connection started. Connect time includes
72731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // DNS, blocking, TCP, TCP retries and SSL time.
73731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 connect_start;
74731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
75731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time that establishing connection ended. Connect time includes
76731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // DNS, blocking, TCP, TCP retries and SSL time.
77731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 connect_end;
78731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
79731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time at which SSL handshake started. For non-HTTPS requests this
80731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // is 0.
81731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 ssl_start;
82731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
83731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time at which SSL handshake ended. For non-HTTPS requests this is 0.
84731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 ssl_end;
85731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
86731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time that HTTP request started. For non-HTTP requests this is 0.
87731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 send_start;
88731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
89731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time that HTTP request ended. For non-HTTP requests this is 0.
90731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 send_end;
91731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
92731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time at which receiving HTTP headers started. For non-HTTP requests
93731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // this is 0.
94731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 receive_headers_start;
95731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
96731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time at which receiving HTTP headers ended. For non-HTTP requests
97731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // this is 0.
98731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 receive_headers_end;
99731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick};
100731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
101731df977c0511bca2206b5f333555b1205ff1f43Iain Merrickstruct ResourceDevToolsInfo : base::RefCounted<ResourceDevToolsInfo> {
102731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  typedef std::vector<std::pair<std::string, std::string> >
103731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick      HeadersVector;
104731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
105731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  ResourceDevToolsInfo();
106731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  ~ResourceDevToolsInfo();
107731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
108201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch  int32 http_status_code;
109201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch  std::string http_status_text;
110731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  HeadersVector request_headers;
111731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  HeadersVector response_headers;
112731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick};
113731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
114731df977c0511bca2206b5f333555b1205ff1f43Iain Merrickstruct ResourceResponseInfo {
115731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  ResourceResponseInfo();
116731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  ~ResourceResponseInfo();
117731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
118731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time at which the request was made that resulted in this response.
119731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // For cached responses, this time could be "far" in the past.
120731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  base::Time request_time;
121731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
122731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time at which the response headers were received.  For cached
123731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // responses, this time could be "far" in the past.
124731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  base::Time response_time;
125731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
126731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The response headers or NULL if the URL type does not support headers.
127731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  scoped_refptr<net::HttpResponseHeaders> headers;
128731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
129731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The mime type of the response.  This may be a derived value.
130731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  std::string mime_type;
131731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
132731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The character encoding of the response or none if not applicable to the
133731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // response's mime type.  This may be a derived value.
134731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  std::string charset;
135731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
136731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // An opaque string carrying security information pertaining to this
137731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // response.  This may include information about the SSL connection used.
138731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  std::string security_info;
139731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
140731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // Content length if available. -1 if not available
141731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int64 content_length;
142731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
143731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The appcache this response was loaded from, or kNoCacheId.
144731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int64 appcache_id;
145731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
146731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The manifest url of the appcache this response was loaded from.
147731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // Note: this value is only populated for main resource requests.
148731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  GURL appcache_manifest_url;
149731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
150731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // Connection identifier from the underlying network stack. In case there
151731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // is no associated connection, contains 0.
152731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  uint32 connection_id;
153731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
154731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // Determines whether physical connection reused.
155731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  bool connection_reused;
156731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
157731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // Detailed timing information used by the WebTiming, HAR and Developer
158731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // Tools.
159731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  ResourceLoadTimingInfo load_timing;
160731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
161731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // Actual request and response headers, as obtained from the network stack.
162731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // Only present if request had LOAD_REPORT_RAW_HEADERS in load_flags, and
163731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // requesting renderer had CanReadRowCookies permission.
164731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  scoped_refptr<ResourceDevToolsInfo> devtools_info;
165731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
166731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The path to a file that will contain the response body.  It may only
167731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // contain a portion of the response body at the time that the ResponseInfo
168731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // becomes available.
169731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  FilePath download_file_path;
170731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
171731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // True if the response was delivered using SPDY.
172731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  bool was_fetched_via_spdy;
173731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
174731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // True if the response was delivered after NPN is negotiated.
175731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  bool was_npn_negotiated;
176731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
177731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // True if response could use alternate protocol. However, browser will
178731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // ignore the alternate protocol when spdy is not enabled on browser side.
179731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  bool was_alternate_protocol_available;
180731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
181731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // True if the response was fetched via an explicit proxy (as opposed to a
182731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // transparent proxy). The proxy could be any type of proxy, HTTP or SOCKS.
183731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // Note: we cannot tell if a transparent proxy may have been involved.
184731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  bool was_fetched_via_proxy;
185731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick};
186731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
187c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass ResourceLoaderBridge {
188c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public:
189c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Structure used when calling ResourceLoaderBridge::Create().
190c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  struct RequestInfo {
191c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    RequestInfo();
192c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    ~RequestInfo();
193c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
194c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // HTTP-style method name (e.g., "GET" or "POST").
195c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    std::string method;
196c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
197c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Absolute URL encoded in ASCII per the rules of RFC-2396.
198c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    GURL url;
199c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
200c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // URL of the document in the top-level window, which may be checked by the
201c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // third-party cookie blocking policy.
202c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    GURL first_party_for_cookies;
203c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
204c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Optional parameter, a URL with similar constraints in how it must be
205c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // encoded as the url member.
206c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    GURL referrer;
207c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
208c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    std::string frame_origin;
209c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    std::string main_frame_origin;
210c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
211c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // For HTTP(S) requests, the headers parameter can be a \r\n-delimited and
212c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // \r\n-terminated list of MIME headers.  They should be ASCII-encoded using
213c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // the standard MIME header encoding rules.  The headers parameter can also
214c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // be null if no extra request headers need to be set.
215c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    std::string headers;
216c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
217c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Composed of the values defined in url_request_load_flags.h.
218c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    int load_flags;
219c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
220c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Process id of the process making the request.
221c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    int requestor_pid;
222c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
223c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Indicates if the current request is the main frame load, a sub-frame
224c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // load, or a sub objects load.
225c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    ResourceType::Type request_type;
226c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
227c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Used for plugin to browser requests.
228c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    uint32 request_context;
229c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
230c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Identifies what appcache host this request is associated with.
231c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    int appcache_host_id;
232c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
233c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Used to associated the bridge with a frame's network context.
234c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    int routing_id;
2353345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
2363345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // If true, then the response body will be downloaded to a file and the
2373345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // path to that file will be provided in ResponseInfo::download_file_path.
2383345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    bool download_to_file;
239c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  };
240c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
241c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // See the SyncLoad method declared below.  (The name of this struct is not
242c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // suffixed with "Info" because it also contains the response data.)
243731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  struct SyncLoadResponse : ResourceResponseInfo {
244c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    SyncLoadResponse();
245c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    ~SyncLoadResponse();
246c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
247c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // The response status.
248c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    URLRequestStatus status;
249c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
250c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // The final URL of the response.  This may differ from the request URL in
251c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // the case of a server redirect.
252c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    GURL url;
253c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
254c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // The response data.
255c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    std::string data;
256c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  };
257c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
258c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Generated by the bridge. This is implemented by our custom resource loader
259c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // within webkit. The Peer and it's bridge should have identical lifetimes
260c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // as they represent each end of a communication channel.
261c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  //
262c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // These callbacks mirror URLRequest::Delegate and the order and conditions
263c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // in which they will be called are identical. See url_request.h for more
264c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // information.
265c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  class Peer {
266c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch   public:
267c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    virtual ~Peer() {}
268c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
269c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Called as upload progress is made.
270c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // note: only for requests with LOAD_ENABLE_UPLOAD_PROGRESS set
271c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    virtual void OnUploadProgress(uint64 position, uint64 size) = 0;
272c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
273c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Called when a redirect occurs.  The implementation may return false to
274c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // suppress the redirect.  The given ResponseInfo provides complete
275c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // information about the redirect, and new_url is the URL that will be
276c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // loaded if this method returns true.  If this method returns true, the
277c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // output parameter *has_new_first_party_for_cookies indicates whether the
278c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // output parameter *new_first_party_for_cookies contains the new URL that
279c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // should be consulted for the third-party cookie blocking policy.
280c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    virtual bool OnReceivedRedirect(const GURL& new_url,
281731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick                                    const ResourceResponseInfo& info,
282c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                    bool* has_new_first_party_for_cookies,
283c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                    GURL* new_first_party_for_cookies) = 0;
284c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
285c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Called when response headers are available (after all redirects have
286c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // been followed).  |content_filtered| is set to true if the contents is
287c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // altered or replaced (usually for security reasons when the resource is
288c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // deemed unsafe).
289731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick    virtual void OnReceivedResponse(const ResourceResponseInfo& info,
290c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                    bool content_filtered) = 0;
291c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
2923345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // Called when a chunk of response data is downloaded.  This method may be
2933345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // called multiple times or not at all if an error occurs.  This method is
2943345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // only called if RequestInfo::download_to_file was set to true, and in
2953345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // that case, OnReceivedData will not be called.
2963345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    virtual void OnDownloadedData(int len) = 0;
2973345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
298c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Called when a chunk of response data is available. This method may
299c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // be called multiple times or not at all if an error occurs.
300c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    virtual void OnReceivedData(const char* data, int len) = 0;
301c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
302c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Called when metadata generated by the renderer is retrieved from the
303c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // cache. This method may be called zero or one times.
304c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    virtual void OnReceivedCachedMetadata(const char* data, int len) { }
305c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
306c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Called when the response is complete.  This method signals completion of
307c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // the resource load.ff
308c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    virtual void OnCompletedRequest(const URLRequestStatus& status,
3093345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick                                    const std::string& security_info,
3103345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick                                    const base::Time& completion_time) = 0;
311c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  };
312c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
313c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // use Create() for construction, but anybody can delete at any time,
314c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // INCLUDING during processing of callbacks.
315c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual ~ResourceLoaderBridge();
316c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
317c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Call this method to make a new instance.
318c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  //
319c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // For HTTP(S) POST requests, the AppendDataToUpload and AppendFileToUpload
320c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // methods may be called to construct the body of the request.
321c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  static ResourceLoaderBridge* Create(const RequestInfo& request_info);
322c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
323c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Call this method before calling Start() to append a chunk of binary data
324c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // to the request body.  May only be used with HTTP(S) POST requests.
325c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void AppendDataToUpload(const char* data, int data_len) = 0;
326c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
327c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Call this method before calling Start() to append the contents of a file
328c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // to the request body.  May only be used with HTTP(S) POST requests.
329c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void AppendFileToUpload(const FilePath& file_path) {
330c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    AppendFileRangeToUpload(file_path, 0, kuint64max, base::Time());
331c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  }
332c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
333c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Call this method before calling Start() to append the contents of a file
334c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // to the request body.  May only be used with HTTP(S) POST requests.
335c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void AppendFileRangeToUpload(
336c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      const FilePath& file_path,
337c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      uint64 offset,
338c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      uint64 length,
339c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      const base::Time& expected_modification_time) = 0;
340c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
3413345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Call this method before calling Start() to append the contents of a blob
3423345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // to the request body.  May only be used with HTTP(S) POST requests.
3433345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  virtual void AppendBlobToUpload(const GURL& blob_url) = 0;
3443345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
345c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Call this method before calling Start() to assign an upload identifier to
346c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // this request.  This is used to enable caching of POST responses.  A value
347c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // of 0 implies the unspecified identifier.
348c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void SetUploadIdentifier(int64 identifier) = 0;
349c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
350c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Call this method to initiate the request.  If this method succeeds, then
351c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // the peer's methods will be called asynchronously to report various events.
352c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual bool Start(Peer* peer) = 0;
353c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
354c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Call this method to cancel a request that is in progress.  This method
355c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // causes the request to immediately transition into the 'done' state. The
356c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // OnCompletedRequest method will be called asynchronously; this assumes
357c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // the peer is still valid.
358c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void Cancel() = 0;
359c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
360c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Call this method to suspend or resume a load that is in progress.  This
361c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // method may only be called after a successful call to the Start method.
362c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void SetDefersLoading(bool value) = 0;
363c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
364c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Call this method to load the resource synchronously (i.e., in one shot).
365c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // This is an alternative to the Start method.  Be warned that this method
366c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // will block the calling thread until the resource is fully downloaded or an
367c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // error occurs.  It could block the calling thread for a long time, so only
368c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // use this if you really need it!  There is also no way for the caller to
369c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // interrupt this method.  Errors are reported via the status field of the
370c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // response parameter.
371c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void SyncLoad(SyncLoadResponse* response) = 0;
372c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
373c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch protected:
374c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // construction must go through Create()
375c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  ResourceLoaderBridge();
376c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
377c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch private:
378c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  DISALLOW_COPY_AND_ASSIGN(ResourceLoaderBridge);
379c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch};
380c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
381c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}  // namespace webkit_glue
382c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
383c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif  // WEBKIT_GLUE_RESOURCE_LOADER_BRIDGE_H_
384