What's new? | Help | Directory | Sign in
Google
             
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
// Copyright 2006, Google Inc.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// 3. Neither the name of Google Inc. nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef GEARS_LOCALSERVER_IE_HTTP_REQUEST_IE_H__
#define GEARS_LOCALSERVER_IE_HTTP_REQUEST_IE_H__

#include <string>
#include <vector>
#include "gears/base/common/security_model.h"
#include "gears/base/common/scoped_refptr.h"
#include "gears/base/ie/atl_headers.h"
#include "gears/localserver/common/http_request.h"
#include "gears/localserver/common/localserver_db.h"
#include "gears/localserver/common/progress_event.h"

class BlobInterface;
class ByteStore;

class IEHttpRequest
: public CComObjectRootEx<CComMultiThreadModel::ThreadModelNoCS>,
public IBindStatusCallback,
public IHttpNegotiate,
public IServiceProviderImpl<IEHttpRequest>,
public HttpRequest,
public ProgressEvent::Listener {
public:
// HttpRequest interface

// refcounting
virtual void Ref();
virtual void Unref();

// Get or set whether to use or bypass caches, the default is USE_ALL_CACHES
// May only be set prior to calling Send.
virtual CachingBehavior GetCachingBehavior() {
return caching_behavior_;
}

virtual bool SetCachingBehavior(CachingBehavior behavior) {
if (!(IsUninitialized() || IsOpen())) return false;
caching_behavior_ = behavior;
return true;
}

// Get or set the redirect behavior, the default is FOLLOW_ALL
// May only be set prior to calling Send.
virtual RedirectBehavior GetRedirectBehavior() {
return redirect_behavior_;
}

virtual bool SetRedirectBehavior(RedirectBehavior behavior) {
if (!(IsUninitialized() || IsOpen())) return false;
redirect_behavior_ = behavior;
return true;
}

// Set whether browser cookies are sent with the request. The default is
// SEND_BROWSER_COOKIES. May only be set prior to calling Send.
virtual bool SetCookieBehavior(CookieBehavior behavior) {
if (!(IsUninitialized() || IsOpen())) return false;
cookie_behavior_ = behavior;
return true;
}

// properties
virtual bool GetReadyState(ReadyState *state);
virtual bool GetResponseBody(scoped_refptr<BlobInterface>* blob);
virtual bool GetStatus(int *status);
virtual bool GetStatusText(std::string16 *status_text);
virtual bool GetStatusLine(std::string16 *status_line);

virtual bool WasRedirected();
virtual bool GetFinalUrl(std::string16 *full_url);
virtual bool GetInitialUrl(std::string16 *full_url);

// methods
virtual bool Open(const char16 *method, const char16* url, bool async,
BrowsingContext *browsing_context);
virtual bool SetRequestHeader(const char16* name, const char16* value);
virtual bool Send(BlobInterface *data);
virtual bool GetAllResponseHeaders(std::string16 *headers);
virtual std::string16 GetResponseCharset();
virtual bool GetResponseHeader(const char16* name, std::string16 *header);
virtual bool Abort();

// events
virtual bool SetListener(HttpListener *listener, bool enable_data_available);

// IE implementation specific

BEGIN_COM_MAP(IEHttpRequest)
COM_INTERFACE_ENTRY(IBindStatusCallback)
COM_INTERFACE_ENTRY(IHttpNegotiate)
COM_INTERFACE_ENTRY(IServiceProvider)
END_COM_MAP()

BEGIN_SERVICE_MAP(IEHttpRequest)
SERVICE_ENTRY(__uuidof(IHttpNegotiate))
END_SERVICE_MAP()

IEHttpRequest();
HRESULT FinalConstruct();
void FinalRelease();

// IBindStatusCallback

virtual HRESULT STDMETHODCALLTYPE OnStartBinding(
/* [in] */ DWORD dwReserved,
/* [in] */ IBinding *pib);

virtual HRESULT STDMETHODCALLTYPE GetPriority(
/* [out] */ LONG *pnPriority);

virtual HRESULT STDMETHODCALLTYPE OnLowResource(
/* [in] */ DWORD reserved);

virtual HRESULT STDMETHODCALLTYPE OnProgress(
/* [in] */ ULONG ulProgress,
/* [in] */ ULONG ulProgressMax,
/* [in] */ ULONG ulStatusCode,
/* [in] */ LPCWSTR szStatusText);

virtual HRESULT STDMETHODCALLTYPE OnStopBinding(
/* [in] */ HRESULT hresult,
/* [unique][in] */ LPCWSTR szError);

virtual HRESULT STDMETHODCALLTYPE GetBindInfo(
/* [out] */ DWORD *grfBINDF,
/* [unique][out][in] */ BINDINFO *pbindinfo);

virtual HRESULT STDMETHODCALLTYPE OnDataAvailable(
/* [in] */ DWORD grfBSCF,
/* [in] */ DWORD dwSize,
/* [in] */ FORMATETC *pformatetc,
/* [in] */ STGMEDIUM *pstgmed);

virtual HRESULT STDMETHODCALLTYPE OnObjectAvailable(
/* [in] */ REFIID riid,
/* [iid_is][in] */ IUnknown *punk);

// IHttpNegotiate

virtual HRESULT STDMETHODCALLTYPE BeginningTransaction(
/* [in] */ LPCWSTR szURL,
/* [unique][in] */ LPCWSTR szHeaders,
/* [in] */ DWORD dwReserved,
/* [out] */ LPWSTR *pszAdditionalHeaders);

virtual HRESULT STDMETHODCALLTYPE OnResponse(
/* [in] */ DWORD dwResponseCode,
/* [unique][in] */ LPCWSTR szResponseHeaders,
/* [unique][in] */ LPCWSTR szRequestHeaders,
/* [out] */ LPWSTR *pszAdditionalRequestHeaders);

// IServiceProvider

virtual HRESULT STDMETHODCALLTYPE QueryService(
/* [in] */ REFGUID guidService,
/* [in] */ REFIID riid,
/* [out] */ void __RPC_FAR *__RPC_FAR *ppvObject);

private:
// ProgressEvent::Listener implementation
virtual void OnUploadProgress(int64 position, int64 total);

HRESULT OnRedirect(const char16 *redirect_url);
void SetReadyState(ReadyState state);
bool IsUninitialized() { return ready_state_ == HttpRequest::UNINITIALIZED; }
bool IsOpen() { return ready_state_ == HttpRequest::OPEN; }
bool IsSent() { return ready_state_ == HttpRequest::SENT; }
bool IsInteractive() { return ready_state_ == HttpRequest::INTERACTIVE; }
bool IsComplete() { return ready_state_ == HttpRequest::COMPLETE; }
bool IsInteractiveOrComplete() { return IsInteractive() || IsComplete(); }
bool IsPostOrPut() {
return bind_verb_ == BINDVERB_POST ||
bind_verb_ == BINDVERB_PUT;
}
bool IsFileGet() {
#ifdef OFFICIAL_BUILD
return false;
#else
return method_ == HttpConstants::kHttpGET &&
origin_.scheme() == HttpConstants::kFileScheme;
#endif
}

// The (non-relative) request url
std::string16 url_;
SecurityOrigin origin_;

// Whether the request should be performed asynchronously
bool async_;

// Whether to bypass caches
CachingBehavior caching_behavior_;

// Whether to follow redirects
RedirectBehavior redirect_behavior_;

// Whether to include browser cookies in the request.
CookieBehavior cookie_behavior_;

// The request method
std::string16 method_;
int bind_verb_;

// The POST data
scoped_refptr<BlobInterface> post_data_;

// Additional request headers we've been asked to send with the request
std::string16 additional_headers_;

// Our XmlHttpRequest like ready state, 0 thru 4
ReadyState ready_state_;

// Whether this request was aborted by the caller
bool was_aborted_;

// Used to distinguish between actual binding errors and intentionally
// induced failures (see OnStopBinding).
bool ignore_stopbinding_error_;

// Whether or not we have been redirected
bool was_redirected_;

// Whether or not we should disable sending browser cookies with the request.
bool disable_browser_cookies_;

// If we've been redirected, the location of the redirect. If we experience
// a chain of redirects, this will be the last in the chain upon completion.
std::string16 redirect_url_;

// Our listener
HttpRequest::HttpListener *listener_;
bool listener_data_available_enabled_;

// We populate this structure with various pieces of response data:
// status code, status line, headers, data
WebCacheDB::PayloadInfo response_payload_;
scoped_refptr<ByteStore> response_body_;

bool has_synthesized_response_payload_;

// URLMON object references
CComPtr<IMoniker> url_moniker_;
CComPtr<IBindCtx> bind_ctx_;
CComPtr<IBinding> binding_;
};

#endif // GEARS_LOCALSERVER_IE_HTTP_REQUEST_IE_H__
Show details Hide details

Change log

r2577 by gears.daemon on Aug 04, 2008   Diff
[Author: steveblock]

Adds to HttpRequest and
AsyncTask::HttpPost the ability to disable
sending browser cookies with the request.
This option is not exposed through
AsyncTask::HttpGet simply to avoid code
churn at call sites, but could eaily be
exposed there too.

R=andreip
CC=gears-eng@googlegroups.com
...
Go to: 
Project members, sign in to write a code review

Older revisions

r2549 by gears.daemon on Jul 30, 2008   Diff
[Author: michaeln]

Validate content prior to accepting
responses for insertion into the
localserverDB.
...
r2278 by gears.daemon on Jul 08, 2008   Diff
[Author: dimich]

Make FF HttpRequest implementation to
work with file:// urls.

...
r2272 by gears.daemon on Jul 08, 2008   Diff
[Author: bgarcia]

Consolidate
HttpRequest::GetResponseBody.
Add ability to get the response body
...
All revisions of this file

File info

Size: 9318 bytes, 272 lines