172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen// Copyright (c) 2011 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"
28ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "base/memory/ref_counted.h"
29ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "base/memory/scoped_ptr.h"
30c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/platform_file.h"
31c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/time.h"
32731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick#include "base/values.h"
33c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "googleurl/src/gurl.h"
34dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen#include "net/base/host_port_pair.h"
35c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "net/url_request/url_request_status.h"
36c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "webkit/glue/resource_type.h"
37c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
38c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochnamespace net {
39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass HttpResponseHeaders;
40c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}
41c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
42c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochnamespace webkit_glue {
43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
44731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick// Structure containing timing information for the request. It addresses
45731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick// http://groups.google.com/group/http-archive-specification/web/har-1-1-spec
46731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick// and http://dev.w3.org/2006/webapi/WebTiming/ needs.
47731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick//
48731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick// All the values for starts and ends are given in milliseconds and are
49731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick// offsets with respect to the given base time.
50731df977c0511bca2206b5f333555b1205ff1f43Iain Merrickstruct ResourceLoadTimingInfo {
51731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  ResourceLoadTimingInfo();
52731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  ~ResourceLoadTimingInfo();
53731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
54731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // All the values in this struct are given as offsets in milliseconds wrt
55731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // this base time.
56731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  base::Time base_time;
57731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
58731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time that proxy processing started. For requests with no proxy phase,
59731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // this time is -1.
60731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 proxy_start;
61731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
62731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time that proxy processing ended. For reused sockets this time
63731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // is -1.
64731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 proxy_end;
65731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
66731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time that DNS lookup started. For reused sockets this time is -1.
67731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 dns_start;
68731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
69731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time that DNS lookup ended. For reused sockets this time is -1.
70731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 dns_end;
71731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
72731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time that establishing connection started. Connect time includes
73731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // DNS, blocking, TCP, TCP retries and SSL time.
74731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 connect_start;
75731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
76731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time that establishing connection ended. Connect time includes
77731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // DNS, blocking, TCP, TCP retries and SSL time.
78731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 connect_end;
79731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
80731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time at which SSL handshake started. For non-HTTPS requests this
81731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // is 0.
82731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 ssl_start;
83731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
84731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time at which SSL handshake ended. For non-HTTPS requests this is 0.
85731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 ssl_end;
86731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
87731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time that HTTP request started. For non-HTTP requests this is 0.
88731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 send_start;
89731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
90731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time that HTTP request ended. For non-HTTP requests this is 0.
91731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 send_end;
92731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
93731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time at which receiving HTTP headers started. For non-HTTP requests
94731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // this is 0.
95731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 receive_headers_start;
96731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
97731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time at which receiving HTTP headers ended. For non-HTTP requests
98731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // this is 0.
99731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int32 receive_headers_end;
100731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick};
101731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
102731df977c0511bca2206b5f333555b1205ff1f43Iain Merrickstruct ResourceDevToolsInfo : base::RefCounted<ResourceDevToolsInfo> {
103731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  typedef std::vector<std::pair<std::string, std::string> >
104731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick      HeadersVector;
105731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
106731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  ResourceDevToolsInfo();
107731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  ~ResourceDevToolsInfo();
108731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
109201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch  int32 http_status_code;
110201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch  std::string http_status_text;
111731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  HeadersVector request_headers;
112731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  HeadersVector response_headers;
113731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick};
114731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
115731df977c0511bca2206b5f333555b1205ff1f43Iain Merrickstruct ResourceResponseInfo {
116731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  ResourceResponseInfo();
117731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  ~ResourceResponseInfo();
118731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
119731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time at which the request was made that resulted in this response.
120731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // For cached responses, this time could be "far" in the past.
121731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  base::Time request_time;
122731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
123731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The time at which the response headers were received.  For cached
124731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // responses, this time could be "far" in the past.
125731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  base::Time response_time;
126731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
127731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The response headers or NULL if the URL type does not support headers.
128731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  scoped_refptr<net::HttpResponseHeaders> headers;
129731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
130731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The mime type of the response.  This may be a derived value.
131731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  std::string mime_type;
132731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
133731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The character encoding of the response or none if not applicable to the
134731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // response's mime type.  This may be a derived value.
135731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  std::string charset;
136731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
137731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // An opaque string carrying security information pertaining to this
138731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // response.  This may include information about the SSL connection used.
139731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  std::string security_info;
140731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
141731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // Content length if available. -1 if not available
142731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int64 content_length;
143731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
144ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Length of the encoded data transferred over the network. In case there is
145ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // no data, contains -1.
146ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  int64 encoded_data_length;
147ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
148731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The appcache this response was loaded from, or kNoCacheId.
149731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  int64 appcache_id;
150731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
151731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The manifest url of the appcache this response was loaded from.
152731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // Note: this value is only populated for main resource requests.
153731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  GURL appcache_manifest_url;
154731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
155731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // Connection identifier from the underlying network stack. In case there
156731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // is no associated connection, contains 0.
157731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  uint32 connection_id;
158731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
159731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // Determines whether physical connection reused.
160731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  bool connection_reused;
161731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
162731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // Detailed timing information used by the WebTiming, HAR and Developer
163731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // Tools.
164731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  ResourceLoadTimingInfo load_timing;
165731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
166731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // Actual request and response headers, as obtained from the network stack.
167731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // Only present if request had LOAD_REPORT_RAW_HEADERS in load_flags, and
168731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // requesting renderer had CanReadRowCookies permission.
169731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  scoped_refptr<ResourceDevToolsInfo> devtools_info;
170731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
171731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // The path to a file that will contain the response body.  It may only
172731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // contain a portion of the response body at the time that the ResponseInfo
173731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // becomes available.
174731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  FilePath download_file_path;
175731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
176731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // True if the response was delivered using SPDY.
177731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  bool was_fetched_via_spdy;
178731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
179731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // True if the response was delivered after NPN is negotiated.
180731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  bool was_npn_negotiated;
181731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
182731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // True if response could use alternate protocol. However, browser will
183731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // ignore the alternate protocol when spdy is not enabled on browser side.
184731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  bool was_alternate_protocol_available;
185731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
186731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // True if the response was fetched via an explicit proxy (as opposed to a
187731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // transparent proxy). The proxy could be any type of proxy, HTTP or SOCKS.
188731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // Note: we cannot tell if a transparent proxy may have been involved.
189731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  bool was_fetched_via_proxy;
190dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen
191dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // Remote address of the socket which fetched this resource.
192dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  net::HostPortPair socket_address;
193731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick};
194731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
195c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass ResourceLoaderBridge {
196c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public:
197c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Structure used when calling ResourceLoaderBridge::Create().
198c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  struct RequestInfo {
199c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    RequestInfo();
200c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    ~RequestInfo();
201c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
202c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // HTTP-style method name (e.g., "GET" or "POST").
203c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    std::string method;
204c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
205c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Absolute URL encoded in ASCII per the rules of RFC-2396.
206c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    GURL url;
207c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
208c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // URL of the document in the top-level window, which may be checked by the
209c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // third-party cookie blocking policy.
210c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    GURL first_party_for_cookies;
211c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
212c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Optional parameter, a URL with similar constraints in how it must be
213c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // encoded as the url member.
214c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    GURL referrer;
215c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
216c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    std::string frame_origin;
217c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    std::string main_frame_origin;
218c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
219c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // For HTTP(S) requests, the headers parameter can be a \r\n-delimited and
220c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // \r\n-terminated list of MIME headers.  They should be ASCII-encoded using
221c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // the standard MIME header encoding rules.  The headers parameter can also
222c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // be null if no extra request headers need to be set.
223c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    std::string headers;
224c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
225c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Composed of the values defined in url_request_load_flags.h.
226c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    int load_flags;
227c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
228c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Process id of the process making the request.
229c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    int requestor_pid;
230c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
231c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Indicates if the current request is the main frame load, a sub-frame
232c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // load, or a sub objects load.
233c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    ResourceType::Type request_type;
234c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
235c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Used for plugin to browser requests.
236c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    uint32 request_context;
237c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
238c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Identifies what appcache host this request is associated with.
239c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    int appcache_host_id;
240c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
241c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Used to associated the bridge with a frame's network context.
242c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    int routing_id;
2433345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
2443345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // If true, then the response body will be downloaded to a file and the
2453345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // path to that file will be provided in ResponseInfo::download_file_path.
2463345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    bool download_to_file;
24721d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen
24821d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen    // True if the request was user initiated.
24921d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen    bool has_user_gesture;
250c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  };
251c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
252c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // See the SyncLoad method declared below.  (The name of this struct is not
253c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // suffixed with "Info" because it also contains the response data.)
254731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  struct SyncLoadResponse : ResourceResponseInfo {
255c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    SyncLoadResponse();
256c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    ~SyncLoadResponse();
257c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
258c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // The response status.
25972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    net::URLRequestStatus status;
260c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
261c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // The final URL of the response.  This may differ from the request URL in
262c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // the case of a server redirect.
263c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    GURL url;
264c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
265c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // The response data.
266c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    std::string data;
267c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  };
268c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
269c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Generated by the bridge. This is implemented by our custom resource loader
270c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // within webkit. The Peer and it's bridge should have identical lifetimes
271c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // as they represent each end of a communication channel.
272c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  //
27321d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  // These callbacks mirror net::URLRequest::Delegate and the order and
27421d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  // conditions in which they will be called are identical. See url_request.h
27521d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  // for more information.
276c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  class Peer {
277c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch   public:
278c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    virtual ~Peer() {}
279c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
280c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Called as upload progress is made.
281c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // note: only for requests with LOAD_ENABLE_UPLOAD_PROGRESS set
282c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    virtual void OnUploadProgress(uint64 position, uint64 size) = 0;
283c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
284c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Called when a redirect occurs.  The implementation may return false to
285c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // suppress the redirect.  The given ResponseInfo provides complete
286c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // information about the redirect, and new_url is the URL that will be
287c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // loaded if this method returns true.  If this method returns true, the
288c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // output parameter *has_new_first_party_for_cookies indicates whether the
289c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // output parameter *new_first_party_for_cookies contains the new URL that
290c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // should be consulted for the third-party cookie blocking policy.
291c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    virtual bool OnReceivedRedirect(const GURL& new_url,
292731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick                                    const ResourceResponseInfo& info,
293c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                    bool* has_new_first_party_for_cookies,
294c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                    GURL* new_first_party_for_cookies) = 0;
295c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
296c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Called when response headers are available (after all redirects have
297dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen    // been followed).
298dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen    virtual void OnReceivedResponse(const ResourceResponseInfo& info) = 0;
299c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
3003345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // Called when a chunk of response data is downloaded.  This method may be
3013345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // called multiple times or not at all if an error occurs.  This method is
3023345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // only called if RequestInfo::download_to_file was set to true, and in
3033345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // that case, OnReceivedData will not be called.
3043345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    virtual void OnDownloadedData(int len) = 0;
3053345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
306c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Called when a chunk of response data is available. This method may
307c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // be called multiple times or not at all if an error occurs.
308ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen    // The encoded_data_length is the length of the encoded data transferred
309ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen    // over the network, which could be different from data length (e.g. for
310ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen    // gzipped content), or -1 if if unknown.
311ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen    virtual void OnReceivedData(const char* data,
312ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen                                int data_length,
313ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen                                int encoded_data_length) = 0;
314c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
315c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Called when metadata generated by the renderer is retrieved from the
316c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // cache. This method may be called zero or one times.
317c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    virtual void OnReceivedCachedMetadata(const char* data, int len) { }
318c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
319c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Called when the response is complete.  This method signals completion of
320c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // the resource load.ff
3213f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen    virtual void OnCompletedRequest(const net::URLRequestStatus& status,
3223345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick                                    const std::string& security_info,
3233345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick                                    const base::Time& completion_time) = 0;
324c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  };
325c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
326c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // use Create() for construction, but anybody can delete at any time,
327c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // INCLUDING during processing of callbacks.
328c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual ~ResourceLoaderBridge();
329c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
330c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Call this method to make a new instance.
331c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  //
332c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // For HTTP(S) POST requests, the AppendDataToUpload and AppendFileToUpload
333c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // methods may be called to construct the body of the request.
334c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  static ResourceLoaderBridge* Create(const RequestInfo& request_info);
335c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
336c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Call this method before calling Start() to append a chunk of binary data
337c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // to the request body.  May only be used with HTTP(S) POST requests.
338c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void AppendDataToUpload(const char* data, int data_len) = 0;
339c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
340c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Call this method before calling Start() to append the contents of a file
341c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // to the request body.  May only be used with HTTP(S) POST requests.
342c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void AppendFileToUpload(const FilePath& file_path) {
343c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    AppendFileRangeToUpload(file_path, 0, kuint64max, base::Time());
344c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  }
345c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
346c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Call this method before calling Start() to append the contents of a file
347c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // to the request body.  May only be used with HTTP(S) POST requests.
348c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void AppendFileRangeToUpload(
349c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      const FilePath& file_path,
350c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      uint64 offset,
351c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      uint64 length,
352c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      const base::Time& expected_modification_time) = 0;
353c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
3543345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Call this method before calling Start() to append the contents of a blob
3553345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // to the request body.  May only be used with HTTP(S) POST requests.
3563345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  virtual void AppendBlobToUpload(const GURL& blob_url) = 0;
3573345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
358c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Call this method before calling Start() to assign an upload identifier to
359c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // this request.  This is used to enable caching of POST responses.  A value
360c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // of 0 implies the unspecified identifier.
361c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void SetUploadIdentifier(int64 identifier) = 0;
362c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
363c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Call this method to initiate the request.  If this method succeeds, then
364c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // the peer's methods will be called asynchronously to report various events.
365c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual bool Start(Peer* peer) = 0;
366c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
367c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Call this method to cancel a request that is in progress.  This method
368c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // causes the request to immediately transition into the 'done' state. The
369c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // OnCompletedRequest method will be called asynchronously; this assumes
370c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // the peer is still valid.
371c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void Cancel() = 0;
372c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
373c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Call this method to suspend or resume a load that is in progress.  This
374c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // method may only be called after a successful call to the Start method.
375c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void SetDefersLoading(bool value) = 0;
376c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
377c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Call this method to load the resource synchronously (i.e., in one shot).
378c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // This is an alternative to the Start method.  Be warned that this method
379c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // will block the calling thread until the resource is fully downloaded or an
380c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // error occurs.  It could block the calling thread for a long time, so only
381c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // use this if you really need it!  There is also no way for the caller to
382c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // interrupt this method.  Errors are reported via the status field of the
383c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // response parameter.
384c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void SyncLoad(SyncLoadResponse* response) = 0;
385c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
386c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch protected:
387c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // construction must go through Create()
388c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  ResourceLoaderBridge();
389c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
390c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch private:
391c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  DISALLOW_COPY_AND_ASSIGN(ResourceLoaderBridge);
392c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch};
393c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
394c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}  // namespace webkit_glue
395c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
396c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif  // WEBKIT_GLUE_RESOURCE_LOADER_BRIDGE_H_
397