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
|
/*
Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef QWEBNETWORKINTERFACE_P_H
#define QWEBNETWORKINTERFACE_P_H
#include "qwebnetworkinterface.h"
#if QT_VERSION < 0x040400
#include <qthread.h>
#include <qmutex.h>
namespace WebCore {
struct HostInfo;
class ResourceRequest;
};
uint qHash(const WebCore::HostInfo &info);
#include <qhash.h>
namespace WebCore {
class ResourceHandle;
}
struct QWebNetworkRequestPrivate
{
QUrl url;
QHttpRequestHeader httpHeader;
QByteArray postData;
void init(const WebCore::ResourceRequest &resourceRequest);
void init(const QString &method, const QUrl &url, const WebCore::ResourceRequest *resourceRequest = 0);
void setURL(const QUrl &u);
};
class QWebNetworkJobPrivate
{
public:
QWebNetworkJobPrivate()
: ref(1)
, resourceHandle(0)
, redirected(false)
, interface(0)
, jobStatus(QWebNetworkJob::JobCreated)
{}
int ref;
QWebNetworkRequestPrivate request;
QHttpResponseHeader response;
WebCore::ResourceHandle *resourceHandle;
bool redirected;
QWebNetworkInterface *interface;
QWebNetworkJob::JobStatus jobStatus;
QString errorString;
};
class QWebNetworkManager : public QObject
{
Q_OBJECT
public:
enum JobMode {
AsynchronousJob,
SynchronousJob
};
static QWebNetworkManager *self();
bool add(WebCore::ResourceHandle *resourceHandle, QWebNetworkInterface *interface, JobMode = AsynchronousJob);
void cancel(WebCore::ResourceHandle *resourceHandle);
void addHttpJob(QWebNetworkJob *job);
void cancelHttpJob(QWebNetworkJob *job);
protected:
void queueStart(QWebNetworkJob*);
void queueData(QWebNetworkJob*, const QByteArray&);
void queueFinished(QWebNetworkJob*, int errorCode);
private:
void started(QWebNetworkJob *);
void data(QWebNetworkJob *, const QByteArray &data);
void finished(QWebNetworkJob *, int errorCode);
void doScheduleWork();
signals:
void fileRequest(QWebNetworkJob*);
void scheduleWork();
private slots:
void httpConnectionClosed(const WebCore::HostInfo &);
void doWork();
private:
friend class QWebNetworkInterface;
QWebNetworkManager();
QHash<WebCore::HostInfo, WebCore::WebCoreHttp *> m_hostMapping;
struct JobWork {
enum WorkType {
JobStarted,
JobData,
JobFinished
};
explicit JobWork(QWebNetworkJob* _job)
: workType(JobStarted)
, errorCode(-1)
, job(_job)
{}
explicit JobWork(QWebNetworkJob* _job, int _errorCode)
: workType(JobFinished)
, errorCode(_errorCode)
, job(_job)
{}
explicit JobWork(QWebNetworkJob* _job, const QByteArray& _data)
: workType(JobData)
, errorCode(-1)
, job(_job)
, data(_data)
{}
const WorkType workType;
int errorCode;
QByteArray data;
QWebNetworkJob* job;
};
QMutex m_queueMutex;
bool m_scheduledWork;
QList<JobWork*> m_pendingWork;
QHash<QWebNetworkJob*, int> m_synchronousJobs;
};
namespace WebCore {
class NetworkLoader;
struct HostInfo {
HostInfo() {}
HostInfo(const QUrl& url);
QString protocol;
QString host;
int port;
};
class WebCoreHttp : public QObject
{
Q_OBJECT
public:
WebCoreHttp(QObject *parent, const HostInfo&);
~WebCoreHttp();
void request(QWebNetworkJob* resource);
void cancel(QWebNetworkJob*);
signals:
void connectionClosed(const WebCore::HostInfo &);
private slots:
void onResponseHeaderReceived(const QHttpResponseHeader& resp);
void onReadyRead();
void onRequestFinished(int, bool);
void onDone(bool);
void onStateChanged(int);
void onSslErrors(const QList<QSslError>&);
void onAuthenticationRequired(const QString& hostname, quint16 port, QAuthenticator *);
void onProxyAuthenticationRequired(const QNetworkProxy& proxy, QAuthenticator *);
void scheduleNextRequest();
int getConnection();
public:
HostInfo info;
private:
QList<QWebNetworkJob *> m_pendingRequests;
struct HttpConnection {
HttpConnection() : http(0), current(0), id(-1) {}
QHttp *http;
QWebNetworkJob *current;
int id; // the QHttp id
};
HttpConnection connection[2];
bool m_inCancel;
};
}
class QWebNetworkInterfacePrivate
{
public:
void sendFileData(QWebNetworkJob* job, int statusCode, const QByteArray &data);
void parseDataUrl(QWebNetworkJob* job);
QWebNetworkInterface *q;
};
#endif
#endif
|