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 #ifndef QNETWORKREPLYHANDLER_H 20 #define QNETWORKREPLYHANDLER_H 21 22 #include <QObject> 23 24 #include <QNetworkRequest> 25 #include <QNetworkAccessManager> 26 27 #include "FormData.h" 28 29 QT_BEGIN_NAMESPACE 30 class QFile; 31 class QNetworkReply; 32 QT_END_NAMESPACE 33 34 namespace WebCore { 35 36 class ResourceHandle; 37 38 class QNetworkReplyHandler : public QObject 39 { 40 Q_OBJECT 41 public: 42 enum LoadMode { 43 LoadNormal, 44 LoadDeferred, 45 LoadResuming 46 }; 47 48 QNetworkReplyHandler(ResourceHandle *handle, LoadMode); 49 void setLoadMode(LoadMode); 50 51 QNetworkReply* reply() const { return m_reply; } 52 53 void abort(); 54 55 QNetworkReply* release(); 56 57 signals: 58 void processQueuedItems(); 59 60 private slots: 61 void finish(); 62 void sendResponseIfNeeded(); 63 void forwardData(); 64 void sendQueuedItems(); 65 void uploadProgress(qint64 bytesSent, qint64 bytesTotal); 66 67 private: 68 void start(); 69 void resetState(); 70 71 QNetworkReply* m_reply; 72 ResourceHandle* m_resourceHandle; 73 bool m_redirected; 74 bool m_responseSent; 75 bool m_responseDataSent; 76 LoadMode m_loadMode; 77 QNetworkAccessManager::Operation m_method; 78 QNetworkRequest m_request; 79 80 // defer state holding 81 bool m_shouldStart; 82 bool m_shouldFinish; 83 bool m_shouldSendResponse; 84 bool m_shouldForwardData; 85 }; 86 87 // Self destructing QIODevice for FormData 88 // For QNetworkAccessManager::put we will have to gurantee that the 89 // QIODevice is valid as long finished() of the QNetworkReply has not 90 // been emitted. With the presence of QNetworkReplyHandler::release I do 91 // not want to gurantee this. 92 class FormDataIODevice : public QIODevice { 93 Q_OBJECT 94 public: 95 FormDataIODevice(FormData*); 96 ~FormDataIODevice(); 97 98 bool isSequential() const; 99 100 protected: 101 qint64 readData(char*, qint64); 102 qint64 writeData(const char*, qint64); 103 104 private: 105 void moveToNextElement(); 106 107 private: 108 Vector<FormDataElement> m_formElements; 109 QFile* m_currentFile; 110 qint64 m_currentDelta; 111 }; 112 113 } 114 115 #endif // QNETWORKREPLYHANDLER_H 116