File indexing completed on 2024-05-26 15:24:04

0001 /* This file is part of the KDE project
0002  *
0003  * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
0004  *                     1999-2001 Lars Knoll <knoll@kde.org>
0005  *                     1999-2001 Antti Koivisto <koivisto@kde.org>
0006  *                     2000-2001 Simon Hausmann <hausmann@kde.org>
0007  *                     2000-2001 Dirk Mueller <mueller@kde.org>
0008  *                     2000 Stefan Schimanski <1Stein@gmx.de>
0009  *                     2001-2005 George Staikos <staikos@kde.org>
0010  *
0011  * This library is free software; you can redistribute it and/or
0012  * modify it under the terms of the GNU Library General Public
0013  * License as published by the Free Software Foundation; either
0014  * version 2 of the License, or (at your option) any later version.
0015  *
0016  * This library is distributed in the hope that it will be useful,
0017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0019  * Library General Public License for more details.
0020  *
0021  * You should have received a copy of the GNU Library General Public License
0022  * along with this library; see the file COPYING.LIB.  If not, write to
0023  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0024  * Boston, MA 02110-1301, USA.
0025  */
0026 #ifndef khtmlpart_p_h
0027 #define khtmlpart_p_h
0028 
0029 #include <kcursor.h>
0030 #include <kxmlguifactory.h>
0031 #include <kparts/partmanager.h>
0032 #include <kparts/statusbarextension.h>
0033 #include <kparts/browserextension.h>
0034 #include <kparts/scriptableextension.h>
0035 
0036 #include <QAction>
0037 #include <QDate>
0038 #include <QPointer>
0039 #include <QMap>
0040 #include <QTimer>
0041 #include <QList>
0042 #include <QQueue>
0043 
0044 #include "html/html_formimpl.h"
0045 #include "html/html_objectimpl.h"
0046 #include "khtml_run.h"
0047 #include "khtml_global.h"
0048 #include "khtml_events.h"
0049 #include "khtml_ext.h"
0050 #include "khtml_settings.h"
0051 #include "khtml_childframe_p.h"
0052 
0053 #include <kencodingdetector.h>
0054 #include <kencodingprober.h>
0055 #include "ecma/kjs_proxy.h"
0056 #include "xml/dom_nodeimpl.h"
0057 #include "editing/editing_p.h"
0058 #include "ui/findbar/khtmlfind_p.h"
0059 #include "ui/passwordbar/storepassbar.h"
0060 #include "ecma/kjs_scriptable.h"
0061 
0062 class KFind;
0063 class KFindDialog;
0064 class KCodecAction;
0065 class KUrlLabel;
0066 class KJavaAppletContext;
0067 class KJSErrorDlg;
0068 class KToggleAction;
0069 class KHTMLViewBar;
0070 
0071 namespace KIO
0072 {
0073 class Job;
0074 class TransferJob;
0075 }
0076 namespace KParts
0077 {
0078 class StatusBarExtension;
0079 }
0080 
0081 #include "khtml_wallet_p.h"
0082 
0083 enum MimeType {
0084     MimeHTML,
0085     MimeSVG,
0086     MimeXHTML,
0087     MimeXML, // XML but not SVG or XHTML
0088     MimeImage,
0089     MimeText,
0090     MimeOther
0091 };
0092 
0093 class KHTMLPartPrivate
0094 {
0095     KHTMLPartPrivate(const KHTMLPartPrivate &other);
0096     KHTMLPartPrivate &operator=(const KHTMLPartPrivate &);
0097 public:
0098     KHTMLPartPrivate(KHTMLPart *part, QObject *parent) :
0099         m_find(part, (part->parentPart() ? &part->parentPart()->d->m_find : nullptr)), m_storePass(part)
0100     {
0101         q     = part;
0102         m_doc = nullptr;
0103         m_decoder = nullptr;
0104 #ifndef KHTML_NO_WALLET
0105         m_wallet = nullptr;
0106 #endif
0107         m_bWalletOpened = false;
0108         m_runningScripts = 0;
0109         m_job = nullptr;
0110         m_bComplete = true;
0111         m_bLoadEventEmitted = true;
0112         m_cachePolicy = KIO::CC_Verify;
0113         m_manager = nullptr;
0114         m_settings = new KHTMLSettings(*KHTMLGlobal::defaultHTMLSettings());
0115         m_bClearing = false;
0116         m_bCleared = false;
0117         m_zoomFactor = 100;
0118         m_fontScaleFactor = 100;
0119         m_bDnd = true;
0120         m_linkCursor = QCursor(Qt::PointingHandCursor);
0121         m_loadedObjects = 0;
0122         m_totalObjectCount = 0;
0123         m_jobPercent = 0;
0124         m_haveEncoding = false;
0125         m_activeFrame = nullptr;
0126         m_ssl_in_use = false;
0127         m_jsedlg = nullptr;
0128         m_formNotification = KHTMLPart::NoNotification;
0129 
0130         m_cacheId = 0;
0131         m_frameNameId = 1;
0132 
0133         m_restored = false;
0134         m_restoreScrollPosition = false;
0135 
0136         m_focusNodeNumber = -1;
0137         m_focusNodeRestored = false;
0138 
0139         m_bJScriptForce = false;
0140         m_bJScriptOverride = false;
0141         m_bJavaForce = false;
0142         m_bJavaOverride = false;
0143         m_bPluginsForce = false;
0144         m_bPluginsOverride = false;
0145         m_onlyLocalReferences = false;
0146         m_forcePermitLocalImages = false;
0147         m_bDNSPrefetch = KHTMLPart::DNSPrefetchDisabled;
0148         m_bDNSPrefetchIsDefault = true;
0149         m_DNSPrefetchTimer = -1;
0150         m_DNSTTLTimer = -1;
0151         m_numDNSPrefetchedNames = 0;
0152 
0153         m_caretMode = false;
0154         m_designMode = false;
0155 
0156         m_metaRefreshEnabled = true;
0157         m_statusMessagesEnabled = true;
0158 
0159         m_bFirstData = true;
0160         m_bStrictModeQuirk = true;
0161         m_submitForm = nullptr;
0162         m_delayRedirect = 0;
0163         m_autoDetectLanguage = KEncodingProber::Universal;
0164 
0165         // inherit settings from parent
0166         if (parent && parent->inherits("KHTMLPart")) {
0167             KHTMLPart *part = static_cast<KHTMLPart *>(parent);
0168             if (part->d) {
0169                 m_bJScriptForce = part->d->m_bJScriptForce;
0170                 m_bJScriptOverride = part->d->m_bJScriptOverride;
0171                 m_bJavaForce = part->d->m_bJavaForce;
0172                 m_bJavaOverride = part->d->m_bJavaOverride;
0173                 m_bPluginsForce = part->d->m_bPluginsForce;
0174                 m_bPluginsOverride = part->d->m_bPluginsOverride;
0175                 m_bDNSPrefetch = part->d->m_bDNSPrefetch;
0176                 m_bDNSPrefetchIsDefault = part->d->m_bDNSPrefetchIsDefault;
0177                 m_onlyLocalReferences = part->d->m_onlyLocalReferences;
0178                 m_forcePermitLocalImages = part->d->m_forcePermitLocalImages;
0179                 // Same for SSL settings
0180                 m_ssl_in_use = part->d->m_ssl_in_use;
0181                 m_caretMode = part->d->m_caretMode;
0182                 m_designMode = part->d->m_designMode;
0183                 m_zoomFactor = part->d->m_zoomFactor;
0184                 m_fontScaleFactor = part->d->m_fontScaleFactor;
0185                 m_autoDetectLanguage = part->d->m_autoDetectLanguage;
0186                 m_encoding = part->d->m_encoding;
0187                 m_haveEncoding = part->d->m_haveEncoding;
0188             }
0189         }
0190 
0191         m_focusNodeNumber = -1;
0192         m_focusNodeRestored = false;
0193         m_opener = nullptr;
0194         m_openedByJS = false;
0195         m_newJSInterpreterExists = false;
0196         m_jobspeed = 0;
0197         m_statusBarWalletLabel = nullptr;
0198         m_statusBarUALabel = nullptr;
0199         m_statusBarJSErrorLabel = nullptr;
0200 #ifndef KHTML_NO_WALLET
0201         m_wq = nullptr;
0202 #endif
0203     }
0204     ~KHTMLPartPrivate()
0205     {
0206         delete m_statusBarExtension;
0207         delete m_scriptableExtension;
0208         delete m_extension;
0209         delete m_settings;
0210 #ifndef KHTML_NO_WALLET
0211         delete m_wallet;
0212 #endif
0213     }
0214 
0215     KHTMLPart *q;
0216 
0217     QPointer<khtml::ChildFrame> m_frame;
0218     KHTMLFrameList m_frames;
0219     KHTMLFrameList m_objects;
0220 
0221     QPointer<KHTMLView> m_view;
0222     QPointer<KHTMLViewBar> m_topViewBar;
0223     QPointer<KHTMLViewBar> m_bottomViewBar;
0224     KHTMLPartBrowserExtension *m_extension;
0225     KParts::StatusBarExtension *m_statusBarExtension;
0226     KHTMLPartBrowserHostExtension *m_hostExtension;
0227     KJS::KHTMLPartScriptable *m_scriptableExtension;
0228     KUrlLabel *m_statusBarIconLabel;
0229     KUrlLabel *m_statusBarWalletLabel;
0230     KUrlLabel *m_statusBarUALabel;
0231     KUrlLabel *m_statusBarJSErrorLabel;
0232     KUrlLabel *m_statusBarPopupLabel;
0233     QList<QPointer<KHTMLPart> > m_suppressedPopupOriginParts; // We need to guard these in case the origin
0234     // is a child part.
0235     int m_openableSuppressedPopups;
0236     DOM::DocumentImpl *m_doc;
0237     KEncodingProber::ProberType m_autoDetectLanguage;
0238     KEncodingDetector *m_decoder;
0239     QString m_encoding;
0240     QString m_sheetUsed;
0241     qlonglong m_cacheId;
0242 
0243 #ifndef KHTML_NO_WALLET
0244     KWallet::Wallet *m_wallet;
0245     QStringList m_walletForms;
0246 #endif
0247     int m_runningScripts;
0248     bool m_bOpenMiddleClick;
0249     bool m_bJScriptEnabled;
0250     bool m_bJScriptDebugEnabled;
0251     bool m_bJavaEnabled;
0252     bool m_bPluginsEnabled;
0253     bool m_bJScriptForce;
0254     bool m_bJScriptOverride;
0255     bool m_bJavaForce;
0256     bool m_bJavaOverride;
0257     bool m_bPluginsForce;
0258     bool m_metaRefreshEnabled;
0259     bool m_bPluginsOverride;
0260     bool m_restored;
0261     bool m_restoreScrollPosition;
0262     bool m_statusMessagesEnabled;
0263     bool m_bWalletOpened;
0264     bool m_bDNSPrefetchIsDefault;
0265     int m_DNSPrefetchTimer;
0266     int m_DNSTTLTimer;
0267     int m_numDNSPrefetchedNames;
0268     QQueue<QString> m_DNSPrefetchQueue;
0269     KHTMLPart::DNSPrefetch m_bDNSPrefetch;
0270     int m_frameNameId;
0271 
0272     KHTMLSettings *m_settings;
0273 
0274     KIO::TransferJob *m_job;
0275 
0276     QString m_statusBarText[3];
0277     unsigned long m_jobspeed;
0278     QString m_lastModified;
0279     QString m_httpHeaders;
0280     QString m_pageServices;
0281 
0282     // QStrings for SSL metadata
0283     // Note: When adding new variables don't forget to update ::saveState()/::restoreState()!
0284     QString m_ssl_peer_chain,
0285             m_ssl_peer_ip,
0286             m_ssl_cipher,
0287             m_ssl_protocol_version,
0288             m_ssl_cipher_used_bits,
0289             m_ssl_cipher_bits,
0290             m_ssl_cert_errors,
0291             m_ssl_parent_ip,
0292             m_ssl_parent_cert;
0293     bool m_ssl_in_use;
0294 
0295     bool m_bComplete;
0296     bool m_bLoadEventEmitted;
0297     bool m_haveEncoding;
0298     bool m_onlyLocalReferences;
0299     bool m_forcePermitLocalImages;
0300     bool m_redirectLockHistory;
0301 
0302     QUrl m_workingURL;
0303 
0304     KIO::CacheControl m_cachePolicy;
0305     QTimer m_redirectionTimer;
0306     QTime m_parsetime;
0307     int m_delayRedirect;
0308     QString m_redirectURL;
0309 
0310     QAction *m_paViewDocument;
0311     QAction *m_paViewFrame;
0312     QAction *m_paViewInfo;
0313     QAction *m_paSaveBackground;
0314     QAction *m_paSaveDocument;
0315     QAction *m_paSaveFrame;
0316     QAction *m_paSecurity;
0317     KCodecAction *m_paSetEncoding;
0318     KSelectAction *m_paUseStylesheet;
0319     KSelectAction *m_paIncZoomFactor;
0320     KSelectAction *m_paDecZoomFactor;
0321     QAction *m_paLoadImages;
0322     QAction *m_paFind;
0323     QAction *m_paFindNext;
0324     QAction *m_paFindPrev;
0325     QAction *m_paFindAheadText;
0326     QAction *m_paFindAheadLinks;
0327     QAction *m_paPrintFrame;
0328     QAction *m_paSelectAll;
0329     QAction *m_paDebugScript;
0330     QAction *m_paDebugDOMTree;
0331     QAction *m_paDebugRenderTree;
0332     QAction *m_paStopAnimations;
0333     KToggleAction *m_paToggleCaretMode;
0334     QMap<QAction *, int> m_paLanguageMap;
0335 
0336     KParts::PartManager *m_manager;
0337 
0338     KHTMLPart::GUIProfile m_guiProfile;
0339 
0340     int m_zoomFactor;
0341     int m_fontScaleFactor;
0342 
0343     QString m_strSelectedURL;
0344     QString m_strSelectedURLTarget;
0345     QString m_referrer;
0346     QString m_pageReferrer;
0347 
0348     struct SubmitForm {
0349         const char *submitAction;
0350         QString submitUrl;
0351         QByteArray submitFormData;
0352         QString target;
0353         QString submitContentType;
0354         QString submitBoundary;
0355     };
0356 
0357     SubmitForm *m_submitForm;
0358 
0359     bool m_bMousePressed;
0360     bool m_bRightMousePressed;
0361     DOM::Node m_mousePressNode; //node under the mouse when the mouse was pressed (set in the mouse handler)
0362 
0363     khtml::EditorContext editor_context;
0364 
0365     QString m_overURL;
0366     QString m_overURLTarget;
0367 
0368     bool m_bDnd;
0369     bool m_bFirstData;
0370     bool m_bStrictModeQuirk;
0371     bool m_bClearing;
0372     bool m_bCleared;
0373     bool m_focusNodeRestored;
0374 
0375     int m_focusNodeNumber;
0376 
0377     QPoint m_dragStartPos;
0378 #ifdef KHTML_NO_SELECTION
0379     QPoint m_dragLastPos;
0380 #endif
0381 
0382     bool m_designMode;
0383     bool m_caretMode;
0384 
0385     QCursor m_linkCursor;
0386     QTimer m_scrollTimer;
0387 
0388     unsigned long m_loadedObjects;
0389     unsigned long m_totalObjectCount;
0390     unsigned int m_jobPercent;
0391 
0392     KHTMLPart::FormNotification m_formNotification;
0393     QTimer m_progressUpdateTimer;
0394 
0395     QStringList m_pluginPageQuestionAsked;
0396 
0397     KHTMLFind m_find;
0398     StorePass m_storePass;
0399 
0400     KJSErrorDlg *m_jsedlg;
0401 
0402     //QGuardedPtr<KParts::Part> m_activeFrame;
0403     KParts::Part *m_activeFrame;
0404     QPointer<KHTMLPart> m_opener;
0405     bool m_openedByJS;
0406     bool m_newJSInterpreterExists; // set to 1 by setOpenedByJS, for window.open
0407 
0408     void setFlagRecursively(bool KHTMLPartPrivate::*flag, bool value);
0409 
0410     QDateTime m_userStyleSheetLastModified;
0411 
0412     QSet<QString> m_lookedupHosts;
0413     static bool s_dnsInitialised;
0414 
0415 #ifndef KHTML_NO_WALLET
0416     KHTMLWalletQueue *m_wq;
0417 #endif
0418 
0419     // Does determination of how we should handle the given type, as per HTML5 rules
0420     MimeType classifyMimeType(const QString &mime);
0421 
0422     void clearRedirection();
0423 
0424     bool isLocalAnchorJump(const QUrl &url);
0425     void executeAnchorJump(const QUrl &url, bool lockHistory);
0426 
0427     static bool isJavaScriptURL(const QString &url);
0428     static QString codeForJavaScriptURL(const QString &url);
0429     void executeJavascriptURL(const QString &u);
0430 
0431     bool isInPageURL(const QString &url)
0432     {
0433         return isLocalAnchorJump(QUrl(url)) || isJavaScriptURL(url);
0434     }
0435 
0436     void executeInPageURL(const QString &url, bool lockHistory)
0437     {
0438         QUrl kurl(url);
0439         if (isLocalAnchorJump(kurl)) {
0440             executeAnchorJump(kurl, lockHistory);
0441         } else {
0442             executeJavascriptURL(url);
0443         }
0444     }
0445 
0446     void propagateInitialDomainAndBaseTo(KHTMLPart *kid);
0447 
0448     void renameFrameForContainer(DOM::HTMLPartContainerElementImpl *cont,
0449                                  const QString &newName);
0450 
0451     KHTMLPart *findFrameParent(KParts::ReadOnlyPart *callingPart, const QString &f,
0452                                khtml::ChildFrame **childFrame, bool checkForNavigation);
0453 
0454     bool canNavigate(KParts::ReadOnlyPart *b);
0455     KHTMLPart *top();
0456 
0457     // Check whether the frame is fully loaded.
0458     // The return value doesn't consider any pending redirections.
0459     // If the return value is true, however, pendingRedirections will
0460     // report if there are any
0461     bool isFullyLoaded(bool *pendingRedirections) const;
0462 };
0463 
0464 #endif