File indexing completed on 2024-03-24 04:45:16
0001 /* 0002 SPDX-FileCopyrightText: 2008 Dirk Mueller <mueller@kde.org> 0003 SPDX-FileCopyrightText: 2008 Urs Wolfer <uwolfer@kde.org> 0004 SPDX-FileCopyrightText: 2009 Dawit Alemayehu <adawit@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-or-later 0007 */ 0008 0009 #ifndef WEBPAGE_H 0010 #define WEBPAGE_H 0011 0012 #include "websslinfo.h" 0013 0014 #include <KWebPage> 0015 #include <KParts/BrowserExtension> 0016 0017 #include <QPointer> 0018 0019 class QUrl; 0020 class KWebKitPart; 0021 class QWebFrame; 0022 0023 0024 class WebPage : public KWebPage 0025 { 0026 Q_OBJECT 0027 public: 0028 explicit WebPage(KWebKitPart *wpart, QWidget *parent = nullptr); 0029 ~WebPage() override; 0030 0031 /** 0032 * Returns the SSL information for the current page. 0033 * 0034 * @see WebSslInfo. 0035 */ 0036 const WebSslInfo& sslInfo() const; 0037 0038 /** 0039 * Sets the page's SSL information to @p other. 0040 * 0041 * @see WebSslInfo 0042 */ 0043 void setSslInfo (const WebSslInfo &other); 0044 0045 /** 0046 * Reimplemented for internal reasons. The API is not affected. 0047 * 0048 * @internal 0049 * @see KWebPage::downloadRequest. 0050 */ 0051 void downloadRequest(const QNetworkRequest &request) override; 0052 0053 /** 0054 * Returns the error page associated with the KIO error @p code. 0055 * 0056 * @param text the error message. 0057 * @param url the url where the error was encountered. 0058 * 0059 * @return html error page. 0060 */ 0061 QString errorPage(int code, const QString& text, const QUrl& url) const; 0062 0063 /** 0064 * Re-implemented to handle ErrorPageExtension. 0065 * 0066 * @see QWebPage::extension() 0067 */ 0068 bool extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output) override; 0069 0070 /** 0071 * Re-implemented to handle ErrorPageExtension. 0072 * 0073 * @see QWebPage::supportsExtension() 0074 */ 0075 bool supportsExtension(Extension extension) const override; 0076 0077 Q_SIGNALS: 0078 /** 0079 * This signal is emitted whenever a user cancels/aborts a load resource 0080 * request. 0081 */ 0082 void loadAborted(const QUrl &url); 0083 0084 protected: 0085 /** 0086 * Returns the webkit part in use by this object. 0087 * @internal 0088 */ 0089 KWebKitPart* part() const; 0090 0091 /** 0092 * Sets the webkit part to be used by this object. 0093 * @internal 0094 */ 0095 void setPart(KWebKitPart*); 0096 0097 /** 0098 * Reimplemented for internal reasons, the API is not affected. 0099 * @internal 0100 */ 0101 QWebPage* createWindow(WebWindowType type) override; 0102 0103 /** 0104 * Reimplemented for internal reasons, the API is not affected. 0105 * @internal 0106 */ 0107 bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, NavigationType type) override; 0108 0109 /** 0110 * Reimplemented for internal reasons, the API is not affected. 0111 * @internal 0112 */ 0113 QString userAgentForUrl(const QUrl& url) const override; 0114 0115 protected Q_SLOTS: 0116 void slotRequestFinished(QNetworkReply* reply); 0117 void slotUnsupportedContent(QNetworkReply* reply); 0118 virtual void slotGeometryChangeRequested(const QRect& rect); 0119 void slotFeaturePermissionRequested(QWebFrame* frame, QWebPage::Feature feature); 0120 0121 private: 0122 bool checkLinkSecurity(const QNetworkRequest& req, NavigationType type) const; 0123 bool checkFormData(const QNetworkRequest& req) const; 0124 bool handleMailToUrl (const QUrl& , NavigationType type) const; 0125 void setPageJScriptPolicy(const QUrl& url); 0126 0127 private: 0128 enum WebPageSecurity { PageUnencrypted, PageEncrypted, PageMixed }; 0129 0130 int m_kioErrorCode; 0131 bool m_ignoreError; 0132 bool m_noJSOpenWindowCheck; 0133 0134 WebSslInfo m_sslInfo; 0135 QList<QUrl> m_requestQueue; 0136 QPointer<KWebKitPart> m_part; 0137 }; 0138 0139 0140 /** 0141 * This is a fake implementation of WebPage to workaround the ugly API used 0142 * to request for the creation of a new window from javascript in QtWebKit. 0143 * 0144 * The KPart API for creating new windows requires all the information about the 0145 * new window up front. Unfortunately QWebPage::createWindow function does not 0146 * provide any of these necessary information except for the window type. All 0147 * the other necessary information is emitted as signals instead! Hence, the 0148 * need for this class to collect all of the necessary information, such as 0149 * window name, size and position, before calling KPart's createNewWindow 0150 * function. 0151 */ 0152 class NewWindowPage : public WebPage 0153 { 0154 Q_OBJECT 0155 public: 0156 NewWindowPage(WebWindowType windowType, KWebKitPart* part, 0157 bool disableJSWindowOpenCheck= false, QWidget* parent = nullptr); 0158 ~NewWindowPage() override; 0159 0160 protected: 0161 bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, NavigationType type) override; 0162 0163 private Q_SLOTS: 0164 void slotGeometryChangeRequested(const QRect& rect) override; 0165 void slotMenuBarVisibilityChangeRequested(bool visible); 0166 void slotStatusBarVisibilityChangeRequested(bool visible); 0167 void slotToolBarVisibilityChangeRequested(bool visible); 0168 void slotLoadFinished(bool); 0169 0170 private: 0171 KParts::WindowArgs m_windowArgs; 0172 WebWindowType m_type; 0173 bool m_createNewWindow; 0174 bool m_disableJSOpenwindowCheck; 0175 }; 0176 0177 #endif // WEBPAGE_H