• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #if QT_VERSION >= 0x040400
25 
26 #include <QNetworkRequest>
27 #include <QNetworkAccessManager>
28 
29 #include "FormData.h"
30 
31 QT_BEGIN_NAMESPACE
32 class QFile;
33 class QNetworkReply;
34 QT_END_NAMESPACE
35 
36 namespace WebCore {
37 
38 class ResourceHandle;
39 
40 class QNetworkReplyHandler : public QObject
41 {
42     Q_OBJECT
43 public:
44     enum LoadMode {
45         LoadNormal,
46         LoadDeferred,
47         LoadResuming
48     };
49 
50     QNetworkReplyHandler(ResourceHandle *handle, LoadMode);
51     void setLoadMode(LoadMode);
52 
reply()53     QNetworkReply* reply() const { return m_reply; }
54 
55     void abort();
56 
57     QNetworkReply* release();
58 
59 signals:
60     void processQueuedItems();
61 
62 private slots:
63     void finish();
64     void sendResponseIfNeeded();
65     void forwardData();
66     void sendQueuedItems();
67 
68 private:
69     void start();
70     void resetState();
71 
72     QNetworkReply* m_reply;
73     ResourceHandle* m_resourceHandle;
74     bool m_redirected;
75     bool m_responseSent;
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     void setParent(QNetworkReply*);
99     bool isSequential() const;
100 
101 protected:
102     qint64 readData(char*, qint64);
103     qint64 writeData(const char*, qint64);
104 
105 private Q_SLOTS:
106     void slotFinished();
107 
108 private:
109     void moveToNextElement();
110 
111 private:
112     Vector<FormDataElement> m_formElements;
113     QFile* m_currentFile;
114     qint64 m_currentDelta;
115 };
116 
117 }
118 
119 #endif
120 
121 #endif // QNETWORKREPLYHANDLER_H
122