multipageloader_p.hh 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
  2. // vi:set ts=4 sts=4 sw=4 noet :
  3. //
  4. // Copyright 2010-2020 wkhtmltopdf authors
  5. //
  6. // This file is part of wkhtmltopdf.
  7. //
  8. // wkhtmltopdf is free software: you can redistribute it and/or modify
  9. // it under the terms of the GNU Lesser General Public License as published by
  10. // the Free Software Foundation, either version 3 of the License, or
  11. // (at your option) any later version.
  12. //
  13. // wkhtmltopdf is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Lesser General Public License
  19. // along with wkhtmltopdf. If not, see <http://www.gnu.org/licenses/>.
  20. #ifndef __MULTIPAGELOADER_P_HH__
  21. #define __MULTIPAGELOADER_P_HH__
  22. #include "multipageloader.hh"
  23. #include "tempfile.hh"
  24. #include <QAtomicInt>
  25. #include <QAuthenticator>
  26. #include <QFile>
  27. #include <QFileInfo>
  28. #include <QNetworkAccessManager>
  29. #include <QNetworkCookieJar>
  30. #include <QNetworkReply>
  31. #include <QWebFrame>
  32. #include "dllbegin.inc"
  33. namespace wkhtmltopdf {
  34. class DLL_LOCAL MyNetworkProxyFactory: public QObject, public QNetworkProxyFactory {
  35. Q_OBJECT
  36. private:
  37. QList<QString> bypassHosts;
  38. QList<QNetworkProxy> originalProxy, noProxy;
  39. public:
  40. MyNetworkProxyFactory(QNetworkProxy defaultProxy, QList<QString> bypassHosts);
  41. QList<QNetworkProxy> queryProxy (const QNetworkProxyQuery & query);
  42. };
  43. class DLL_LOCAL MyNetworkAccessManager: public QNetworkAccessManager {
  44. Q_OBJECT
  45. private:
  46. bool disposed;
  47. QSet<QString> allowed;
  48. const settings::LoadPage & settings;
  49. public:
  50. void dispose();
  51. void allow(QString path);
  52. MyNetworkAccessManager(const settings::LoadPage & s);
  53. QNetworkReply * createRequest(Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0);
  54. signals:
  55. void warning(const QString & text);
  56. void error(const QString & text);
  57. };
  58. class DLL_LOCAL MultiPageLoaderPrivate;
  59. class DLL_LOCAL ResourceObject;
  60. class DLL_LOCAL MyQWebPage: public QWebPage {
  61. Q_OBJECT ;
  62. private:
  63. ResourceObject & resource;
  64. public:
  65. MyQWebPage(ResourceObject & res);
  66. virtual void javaScriptAlert(QWebFrame * frame, const QString & msg);
  67. virtual bool javaScriptConfirm(QWebFrame * frame, const QString & msg);
  68. virtual bool javaScriptPrompt(QWebFrame * frame, const QString & msg, const QString & defaultValue, QString * result);
  69. virtual void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID);
  70. public slots:
  71. bool shouldInterruptJavaScript();
  72. };
  73. class DLL_LOCAL ResourceObject: public QObject {
  74. Q_OBJECT
  75. private:
  76. MyNetworkAccessManager networkAccessManager;
  77. QUrl url;
  78. int loginTry;
  79. int progress;
  80. bool finished;
  81. bool signalPrint;
  82. MultiPageLoaderPrivate & multiPageLoader;
  83. public:
  84. ResourceObject(MultiPageLoaderPrivate & mpl, const QUrl & u, const settings::LoadPage & s);
  85. MyQWebPage webPage;
  86. LoaderObject lo;
  87. int httpErrorCode;
  88. const settings::LoadPage settings;
  89. public slots:
  90. void load();
  91. void loadStarted();
  92. void loadProgress(int progress);
  93. void loadFinished(bool ok);
  94. void waitWindowStatus();
  95. void printRequested(QWebFrame * frame);
  96. void loadDone();
  97. void handleAuthenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator);
  98. void warning(const QString & str);
  99. void error(const QString & str);
  100. void sslErrors(QNetworkReply *reply, const QList<QSslError> &);
  101. void amfinished(QNetworkReply * reply);
  102. };
  103. class DLL_LOCAL MyCookieJar: public QNetworkCookieJar {
  104. private:
  105. QList<QNetworkCookie> extraCookies;
  106. public:
  107. void clearExtraCookies();
  108. void useCookie(const QUrl & url, const QString & name, const QString & value);
  109. QList<QNetworkCookie> cookiesForUrl(const QUrl & url) const;
  110. void loadFromFile(const QString & path);
  111. void saveToFile(const QString & path);
  112. };
  113. class DLL_LOCAL MultiPageLoaderPrivate: public QObject {
  114. Q_OBJECT
  115. public:
  116. MyCookieJar * cookieJar;
  117. MultiPageLoader & outer;
  118. const settings::LoadGlobal settings;
  119. QList<ResourceObject *> resources;
  120. int loading;
  121. int progressSum;
  122. bool isMainLoader;
  123. bool loadStartedEmitted;
  124. bool hasError;
  125. bool finishedEmitted;
  126. TempFile tempIn;
  127. int dpi;
  128. MultiPageLoaderPrivate(const settings::LoadGlobal & settings, int dpi, MultiPageLoader & o);
  129. ~MultiPageLoaderPrivate();
  130. LoaderObject * addResource(const QUrl & url, const settings::LoadPage & settings);
  131. void load();
  132. void clearResources();
  133. void cancel();
  134. public slots:
  135. void fail();
  136. void loadDone();
  137. };
  138. }
  139. #include "dllend.inc"
  140. #endif //__MULTIPAGELOADER_P_HH__