source: trunk/WebKit/qt/Api/qwebnetworkinterface.h @ 27039

Revision 27039, 4.3 KB checked in by hausmann, 7 years ago (diff)
  • Implement our own queuing of network jobs to allow special handling of synchronous jobs. This makes us pass the fast/dom/xmlhttprequest-html-response-encoding.html test without a crash. Sync jobs will get a special treatment over the normals ones and in theory more than one sync job is supported.
  • This should be thread-safe besides QWebNetworkJob::{ref,deref}

Signed-off-by: Simon Hausmann <hausmann@kde.org>

Line 
1/*
2  Copyright (C) 2007 Trolltech ASA
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB.  If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 
19  This class provides all functionality needed for loading images, style sheets and html
20  pages from the web. It has a memory cache for these objects.
21*/
22#ifndef QWEBNETWORKINTERFACE_H
23#define QWEBNETWORKINTERFACE_H
24
25#include <qobject.h>
26#include <qurl.h>
27#include <qhttp.h>
28#include <qbytearray.h>
29
30#include <qwebkitglobal.h>
31
32class QAuthenticator;
33class QNetworkProxy;
34class QSslError;
35class QWebFrame;
36class QWebNetworkJobPrivate;
37class QWebNetworkInterface;
38class QWebObjectPluginConnector;
39
40namespace WebCore {
41    class WebCoreHttp;
42    class ResourceRequest;
43    class FrameLoaderClientQt;
44}
45
46struct QWebNetworkRequestPrivate;
47class QWEBKIT_EXPORT QWebNetworkRequest
48{
49public:
50    enum Method {
51        Get,
52        Post
53        //Head
54    };
55
56    QWebNetworkRequest();
57    explicit QWebNetworkRequest(const QUrl &url, Method method = Get, const QByteArray &postData = QByteArray());
58    QWebNetworkRequest(const QWebNetworkRequest &other);
59
60    QWebNetworkRequest &operator=(const QWebNetworkRequest &other);
61    ~QWebNetworkRequest();
62
63    QUrl url() const;
64    void setUrl(const QUrl &url);
65
66    QHttpRequestHeader httpHeader() const;
67    void setHttpHeader(const QHttpRequestHeader &header) const;
68
69    QString httpHeaderField(const QString &key) const;
70    void setHttpHeaderField(const QString &key, const QString &value);
71
72    QByteArray postData() const;
73    void setPostData(const QByteArray &data);
74
75private:
76    explicit QWebNetworkRequest(const QWebNetworkRequestPrivate &priv);
77    explicit QWebNetworkRequest(const WebCore::ResourceRequest &request);
78    friend class QWebNetworkJob;
79    friend class WebCore::FrameLoaderClientQt;
80
81    QWebNetworkRequestPrivate *d;
82    friend class QWebObjectPluginConnector;
83};
84
85class QWEBKIT_EXPORT QWebNetworkJob
86{
87public:
88    QUrl url() const;
89    QByteArray postData() const;
90    QHttpRequestHeader httpHeader() const;
91    QWebNetworkRequest request() const;
92
93    QHttpResponseHeader response() const;
94    void setResponse(const QHttpResponseHeader &response);
95
96    bool cancelled() const;
97
98    void ref();
99    bool deref();
100
101    QWebNetworkInterface *networkInterface() const;
102   
103    QWebFrame *frame() const;
104
105private:
106    QWebNetworkJob();
107    ~QWebNetworkJob();
108
109    friend class QWebNetworkManager;
110    friend class QWebObjectPluginConnector;
111
112    QWebNetworkJobPrivate *d;
113};
114
115class QWebNetworkInterfacePrivate;
116
117class QWEBKIT_EXPORT QWebNetworkInterface : public QObject
118{
119    Q_OBJECT
120public:
121    QWebNetworkInterface(QObject *parent = 0);
122    ~QWebNetworkInterface();
123
124    static void setDefaultInterface(QWebNetworkInterface *defaultInterface);
125    static QWebNetworkInterface *defaultInterface();
126
127    virtual void addJob(QWebNetworkJob *job);
128    virtual void cancelJob(QWebNetworkJob *job);
129
130protected:
131    void started(QWebNetworkJob*);
132    void data(QWebNetworkJob*, const QByteArray &data);
133    void finished(QWebNetworkJob*, int errorCode);
134   
135signals:
136    /**
137     * Signal is emitted when an SSL error occurs.
138     */
139    void sslErrors(QWebFrame *frame, const QUrl& url, const QList<QSslError>& errors, bool *continueAnyway);
140    /**
141     * Signal is emitted when network authentication is required.
142     */
143    void authenticate(QWebFrame *frame, const QUrl& url, const QString& hostname, quint16 port, QAuthenticator *auth);
144    /**
145     * Signal is emitted when proxy authentication is required.
146     */
147    void authenticateProxy(QWebFrame *frame, const QUrl& url, const QNetworkProxy& proxy, QAuthenticator *auth);
148
149private:
150    friend class QWebNetworkInterfacePrivate;
151    friend class WebCore::WebCoreHttp;
152    QWebNetworkInterfacePrivate *d;
153};
154
155#endif
Note: See TracBrowser for help on using the repository browser.