1 /* 2 Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 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 20 #ifndef QWEBNETWORKINTERFACE_H 21 #define QWEBNETWORKINTERFACE_H 22 23 #include <QtCore/qobject.h> 24 #include <QtCore/qurl.h> 25 #include <QtNetwork/qhttp.h> 26 #include <QtCore/qbytearray.h> 27 28 #include "qwebkitglobal.h" 29 30 #if QT_VERSION < 0x040400 31 32 class QAuthenticator; 33 class QNetworkProxy; 34 class QSslError; 35 class QWebFrame; 36 class QWebNetworkJobPrivate; 37 class QWebNetworkInterface; 38 class QWebObjectPluginConnector; 39 40 namespace WebCore { 41 class WebCoreHttp; 42 class ResourceRequest; 43 class FrameLoaderClientQt; 44 } 45 46 struct QWebNetworkRequestPrivate; 47 class QWEBKIT_EXPORT QWebNetworkRequest 48 { 49 public: 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 75 private: 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 85 class QWEBKIT_EXPORT QWebNetworkJob 86 { 87 public: 88 89 QUrl url() const; 90 QByteArray postData() const; 91 QHttpRequestHeader httpHeader() const; 92 QWebNetworkRequest request() const; 93 QString errorString() const; 94 95 QHttpResponseHeader response() const; 96 void setResponse(const QHttpResponseHeader &response); 97 void setErrorString(const QString&); 98 99 bool cancelled() const; 100 101 void ref(); 102 bool deref(); 103 104 QWebNetworkInterface *networkInterface() const; 105 106 QWebFrame *frame() const; 107 108 protected: 109 enum JobStatus { 110 JobCreated, 111 JobRecreated, 112 JobStarted, 113 JobReceivingData, 114 JobFinished 115 }; 116 117 JobStatus status() const; 118 void setStatus(const JobStatus&); 119 120 private: 121 QWebNetworkJob(); 122 ~QWebNetworkJob(); 123 124 friend class QWebNetworkManager; 125 friend class QWebObjectPluginConnector; 126 friend class QWebNetworkJobPrivate; 127 128 QWebNetworkJobPrivate *d; 129 }; 130 131 class QWebNetworkInterfacePrivate; 132 133 class QWEBKIT_EXPORT QWebNetworkInterface : public QObject 134 { 135 Q_OBJECT 136 public: 137 QWebNetworkInterface(QObject *parent = 0); 138 ~QWebNetworkInterface(); 139 140 static void setDefaultInterface(QWebNetworkInterface *defaultInterface); 141 static QWebNetworkInterface *defaultInterface(); 142 143 virtual void addJob(QWebNetworkJob *job); 144 virtual void cancelJob(QWebNetworkJob *job); 145 146 protected: 147 void started(QWebNetworkJob*); 148 void data(QWebNetworkJob*, const QByteArray &data); 149 void finished(QWebNetworkJob*, int errorCode); 150 151 signals: 152 /** 153 * Signal is emitted when an SSL error occurs. 154 */ 155 void sslErrors(QWebFrame *frame, const QUrl& url, const QList<QSslError>& errors, bool *continueAnyway); 156 /** 157 * Signal is emitted when network authentication is required. 158 */ 159 void authenticate(QWebFrame *frame, const QUrl& url, const QString& hostname, quint16 port, QAuthenticator *auth); 160 /** 161 * Signal is emitted when proxy authentication is required. 162 */ 163 void authenticateProxy(QWebFrame *frame, const QUrl& url, const QNetworkProxy& proxy, QAuthenticator *auth); 164 165 private: 166 friend class QWebNetworkInterfacePrivate; 167 friend class WebCore::WebCoreHttp; 168 QWebNetworkInterfacePrivate *d; 169 }; 170 171 #endif 172 173 #endif 174