blob: 634ac93fd8adbf14ad9cc92a60ccae9caa07673e [file] [log] [blame]
Andreas Huber5f5719e2011-03-08 15:59:28 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SUPPORT_H_
18
19#define SUPPORT_H_
20
21#include <assert.h>
22
23#include "net/base/net_log.h"
24#include "net/url_request/url_request.h"
25#include "net/url_request/url_request_context.h"
26#include "net/base/android_network_library.h"
27#include "net/base/io_buffer.h"
28
29#include <utils/KeyedVector.h>
30#include <utils/String8.h>
31
32namespace android {
33
34struct SfNetLog : public net::NetLog {
35 SfNetLog();
36
37 virtual void AddEntry(
38 EventType type,
39 const base::TimeTicks &time,
40 const Source &source,
41 EventPhase phase,
42 EventParameters *params);
43
44 virtual uint32 NextID();
45 virtual LogLevel GetLogLevel() const;
46
47private:
48 uint32 mNextID;
49
50 DISALLOW_EVIL_CONSTRUCTORS(SfNetLog);
51};
52
53struct SfRequestContext : public URLRequestContext {
54 SfRequestContext();
55
56 virtual const std::string &GetUserAgent(const GURL &url) const;
57
58private:
59 std::string mUserAgent;
60
61 DISALLOW_EVIL_CONSTRUCTORS(SfRequestContext);
62};
63
64// This is required for https support, we don't really verify certificates,
65// we accept anything...
66struct SfNetworkLibrary : public net::AndroidNetworkLibrary {
67 SfNetworkLibrary();
68
69 virtual VerifyResult VerifyX509CertChain(
70 const std::vector<std::string>& cert_chain,
71 const std::string& hostname,
72 const std::string& auth_type);
73
74private:
75 DISALLOW_EVIL_CONSTRUCTORS(SfNetworkLibrary);
76};
77
78struct ChromiumHTTPDataSource;
79
80struct SfDelegate : public URLRequest::Delegate {
81 SfDelegate();
82 virtual ~SfDelegate();
83
84 void initiateConnection(
85 const char *uri,
86 const KeyedVector<String8, String8> *headers,
87 off64_t offset);
88
89 void initiateDisconnect();
90 void initiateRead(void *data, size_t size);
91
92 void setOwner(ChromiumHTTPDataSource *mOwner);
93
94 virtual void OnReceivedRedirect(
95 URLRequest *request, const GURL &new_url, bool *defer_redirect);
96
97 virtual void OnAuthRequired(
98 URLRequest *request, net::AuthChallengeInfo *auth_info);
99
100 virtual void OnCertificateRequested(
101 URLRequest *request, net::SSLCertRequestInfo *cert_request_info);
102
103 virtual void OnSSLCertificateError(
104 URLRequest *request, int cert_error, net::X509Certificate *cert);
105
106 virtual void OnGetCookies(URLRequest *request, bool blocked_by_policy);
107
108 virtual void OnSetCookie(
109 URLRequest *request,
110 const std::string &cookie_line,
111 const net::CookieOptions &options,
112 bool blocked_by_policy);
113
114 virtual void OnResponseStarted(URLRequest *request);
115
116 virtual void OnReadCompleted(URLRequest *request, int bytes_read);
117
118private:
119 typedef Delegate inherited;
120
121 ChromiumHTTPDataSource *mOwner;
122
123 URLRequest *mURLRequest;
124 scoped_refptr<net::IOBufferWithSize> mReadBuffer;
125
126 size_t mNumBytesRead;
127 size_t mNumBytesTotal;
128 void *mDataDestination;
129
130 bool mRangeRequested;
131 bool mAtEOS;
132
133 void readMore(URLRequest *request);
134
135 static void OnInitiateConnectionWrapper(
136 SfDelegate *me,
137 GURL url,
138 const KeyedVector<String8, String8> *headers,
139 off64_t offset);
140
141 static void OnInitiateDisconnectWrapper(SfDelegate *me);
142
143 static void OnInitiateReadWrapper(
144 SfDelegate *me, void *data, size_t size);
145
146 void onInitiateConnection(
147 const GURL &url,
148 const KeyedVector<String8, String8> *headers,
149 off64_t offset);
150
151 void onInitiateDisconnect();
152 void onInitiateRead(void *data, size_t size);
153
154 DISALLOW_EVIL_CONSTRUCTORS(SfDelegate);
155};
156
157} // namespace android
158
159#endif // SUPPORT_H_