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
// Copyright 2008, 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_SAFARI_HTTP_REQUEST_SF_H__
#define GEARS_LOCALSERVER_SAFARI_HTTP_REQUEST_SF_H__

#import <Foundation/NSStream.h>
#include <vector>

#include "gears/base/common/common.h"
#include "gears/base/common/scoped_refptr.h"
#include "gears/base/common/security_model.h"
#include "gears/localserver/common/http_constants.h"
#include "gears/localserver/common/http_request.h"
#include "gears/localserver/common/progress_event.h"
#include "third_party/scoped_ptr/scoped_ptr.h"

class BlobInterface;

//------------------------------------------------------------------------------
// SFHttpRequest
//------------------------------------------------------------------------------
class SFHttpRequest : public HttpRequest, public ProgressEvent::Listener {
public:

// 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 (was_sent_) 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 (was_sent_) 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 (was_sent_) 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);

// Methods used to communicate between Obj C delegate and C++ class.
// You can't make an objc-c selector a friend of a C++ class, so these
// need to be declared public.
public:

// Called by the delegate if a redirect is requested by the server
// returns: true - allow redirect, false - deny redirect.
bool AllowRedirect(const std::string16 &redirect_url);
void SetReadyState(ReadyState state);
// New data has arrived over the connection.
void OnDataAvailable(int64 length);
void SetResponseCharset(const std::string16 &charset);

// Holders for http headers.
typedef std::pair<std::string16, std::string16> HttpHeader;
typedef std::vector<HttpHeader> HttpHeaderVector;
typedef HttpHeaderVector::const_iterator HttpHeaderVectorConstIterator;

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

friend bool HttpRequest::Create(scoped_refptr<HttpRequest>* request);

SFHttpRequest();
~SFHttpRequest();

bool IsUninitialized() { return ready_state_ == UNINITIALIZED; }
bool IsOpen() { return ready_state_ == OPEN; }
bool IsSent() { return ready_state_ == SENT; }
bool IsInteractive() { return ready_state_ == INTERACTIVE; }
bool IsComplete() { return ready_state_ == COMPLETE; }
bool IsInteractiveOrComplete() { return IsInteractive() || IsComplete(); }

bool IsPostOrPut() {
return method_ == HttpConstants::kHttpPOST ||
method_ == HttpConstants::kHttpPUT;
}

void Reset();

HttpRequest::HttpListener *listener_;
bool listener_data_available_enabled_;
ReadyState ready_state_;
RefCount count_;
std::string16 method_;
std::string16 url_;
SecurityOrigin origin_;
CachingBehavior caching_behavior_;
RedirectBehavior redirect_behavior_;
CookieBehavior cookie_behavior_;
bool was_sent_;
bool was_aborted_;
bool was_redirected_;
bool async_;
std::string16 redirect_url_;
std::string16 charset_;

HttpHeaderVector headers_to_send_;

// Use PIMPL idiom to mask obj-c object, so we can include
// this header in C++ code.
struct HttpRequestData;
HttpRequestData *delegate_holder_;
};

#endif // GEARS_LOCALSERVER_SAFARI_HTTP_REQUEST_SF_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

r2289 by gears.daemon on Jul 09, 2008   Diff
[Author: fry]

download progress

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

Consolidate
HttpRequest::GetResponseBody.
Add ability to get the response body
...
r2066 by gears.daemon on Jun 23, 2008   Diff
[Author: bgarcia]

Replace all HttpRequest::Send*
functions with a single
Send(BlobInterface *) function.
...
All revisions of this file

File info

Size: 6542 bytes, 174 lines