1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
4  *                     1999-2001 Lars Knoll <knoll@kde.org>
5  *                     1999-2001 Antti Koivisto <koivisto@kde.org>
6  *                     2000-2001 Simon Hausmann <hausmann@kde.org>
7  *                     2000-2001 Dirk Mueller <mueller@kde.org>
8  *                     2000 Stefan Schimanski <1Stein@gmx.de>
9  *                     2001-2005 George Staikos <staikos@kde.org>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public License
22  * along with this library; see the file COPYING.LIB.  If not, write to
23  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24  * Boston, MA 02110-1301, USA.
25  */
26 #ifndef khtmlpart_p_h
27 #define khtmlpart_p_h
28 
29 #include <kcursor.h>
30 #include <kxmlguifactory.h>
31 #include <kparts/partmanager.h>
32 #include <kparts/statusbarextension.h>
33 #include <kparts/browserextension.h>
34 #include <kparts/scriptableextension.h>
35 
36 #include <QAction>
37 #include <QDate>
38 #include <QPointer>
39 #include <QMap>
40 #include <QTimer>
41 #include <QList>
42 #include <QQueue>
43 
44 #include "html/html_formimpl.h"
45 #include "html/html_objectimpl.h"
46 #include "khtml_run.h"
47 #include "khtml_global.h"
48 #include "khtml_events.h"
49 #include "khtml_ext.h"
50 #include "khtml_settings.h"
51 #include "khtml_childframe_p.h"
52 
53 #include <kencodingdetector.h>
54 #include <kencodingprober.h>
55 #include "ecma/kjs_proxy.h"
56 #include "xml/dom_nodeimpl.h"
57 #include "editing/editing_p.h"
58 #include "ui/findbar/khtmlfind_p.h"
59 #include "ui/passwordbar/storepassbar.h"
60 #include "ecma/kjs_scriptable.h"
61 
62 class KFind;
63 class KFindDialog;
64 class KCodecAction;
65 class KUrlLabel;
66 class KJavaAppletContext;
67 class KJSErrorDlg;
68 class KToggleAction;
69 class KHTMLViewBar;
70 
71 namespace KIO
72 {
73 class Job;
74 class TransferJob;
75 }
76 namespace KParts
77 {
78 class StatusBarExtension;
79 }
80 
81 #include "khtml_wallet_p.h"
82 
83 enum MimeType {
84     MimeHTML,
85     MimeSVG,
86     MimeXHTML,
87     MimeXML, // XML but not SVG or XHTML
88     MimeImage,
89     MimeText,
90     MimeOther
91 };
92 
93 class KHTMLPartPrivate
94 {
95     KHTMLPartPrivate(const KHTMLPartPrivate &other);
96     KHTMLPartPrivate &operator=(const KHTMLPartPrivate &);
97 public:
KHTMLPartPrivate(KHTMLPart * part,QObject * parent)98     KHTMLPartPrivate(KHTMLPart *part, QObject *parent) :
99         m_find(part, (part->parentPart() ? &part->parentPart()->d->m_find : nullptr)), m_storePass(part)
100     {
101         q     = part;
102         m_doc = nullptr;
103         m_decoder = nullptr;
104 #ifndef KHTML_NO_WALLET
105         m_wallet = nullptr;
106 #endif
107         m_bWalletOpened = false;
108         m_runningScripts = 0;
109         m_job = nullptr;
110         m_bComplete = true;
111         m_bLoadEventEmitted = true;
112         m_cachePolicy = KIO::CC_Verify;
113         m_manager = nullptr;
114         m_settings = new KHTMLSettings(*KHTMLGlobal::defaultHTMLSettings());
115         m_bClearing = false;
116         m_bCleared = false;
117         m_zoomFactor = 100;
118         m_fontScaleFactor = 100;
119         m_bDnd = true;
120         m_linkCursor = QCursor(Qt::PointingHandCursor);
121         m_loadedObjects = 0;
122         m_totalObjectCount = 0;
123         m_jobPercent = 0;
124         m_haveEncoding = false;
125         m_activeFrame = nullptr;
126         m_ssl_in_use = false;
127         m_jsedlg = nullptr;
128         m_formNotification = KHTMLPart::NoNotification;
129 
130         m_cacheId = 0;
131         m_frameNameId = 1;
132 
133         m_restored = false;
134         m_restoreScrollPosition = false;
135 
136         m_focusNodeNumber = -1;
137         m_focusNodeRestored = false;
138 
139         m_bJScriptForce = false;
140         m_bJScriptOverride = false;
141         m_bJavaForce = false;
142         m_bJavaOverride = false;
143         m_bPluginsForce = false;
144         m_bPluginsOverride = false;
145         m_onlyLocalReferences = false;
146         m_forcePermitLocalImages = false;
147         m_bDNSPrefetch = KHTMLPart::DNSPrefetchDisabled;
148         m_bDNSPrefetchIsDefault = true;
149         m_DNSPrefetchTimer = -1;
150         m_DNSTTLTimer = -1;
151         m_numDNSPrefetchedNames = 0;
152 
153         m_caretMode = false;
154         m_designMode = false;
155 
156         m_metaRefreshEnabled = true;
157         m_statusMessagesEnabled = true;
158 
159         m_bFirstData = true;
160         m_bStrictModeQuirk = true;
161         m_submitForm = nullptr;
162         m_delayRedirect = 0;
163         m_autoDetectLanguage = KEncodingProber::Universal;
164 
165         // inherit settings from parent
166         if (parent && parent->inherits("KHTMLPart")) {
167             KHTMLPart *part = static_cast<KHTMLPart *>(parent);
168             if (part->d) {
169                 m_bJScriptForce = part->d->m_bJScriptForce;
170                 m_bJScriptOverride = part->d->m_bJScriptOverride;
171                 m_bJavaForce = part->d->m_bJavaForce;
172                 m_bJavaOverride = part->d->m_bJavaOverride;
173                 m_bPluginsForce = part->d->m_bPluginsForce;
174                 m_bPluginsOverride = part->d->m_bPluginsOverride;
175                 m_bDNSPrefetch = part->d->m_bDNSPrefetch;
176                 m_bDNSPrefetchIsDefault = part->d->m_bDNSPrefetchIsDefault;
177                 m_onlyLocalReferences = part->d->m_onlyLocalReferences;
178                 m_forcePermitLocalImages = part->d->m_forcePermitLocalImages;
179                 // Same for SSL settings
180                 m_ssl_in_use = part->d->m_ssl_in_use;
181                 m_caretMode = part->d->m_caretMode;
182                 m_designMode = part->d->m_designMode;
183                 m_zoomFactor = part->d->m_zoomFactor;
184                 m_fontScaleFactor = part->d->m_fontScaleFactor;
185                 m_autoDetectLanguage = part->d->m_autoDetectLanguage;
186                 m_encoding = part->d->m_encoding;
187                 m_haveEncoding = part->d->m_haveEncoding;
188             }
189         }
190 
191         m_focusNodeNumber = -1;
192         m_focusNodeRestored = false;
193         m_opener = nullptr;
194         m_openedByJS = false;
195         m_newJSInterpreterExists = false;
196         m_jobspeed = 0;
197         m_statusBarWalletLabel = nullptr;
198         m_statusBarUALabel = nullptr;
199         m_statusBarJSErrorLabel = nullptr;
200 #ifndef KHTML_NO_WALLET
201         m_wq = nullptr;
202 #endif
203     }
~KHTMLPartPrivate()204     ~KHTMLPartPrivate()
205     {
206         delete m_statusBarExtension;
207         delete m_scriptableExtension;
208         delete m_extension;
209         delete m_settings;
210 #ifndef KHTML_NO_WALLET
211         delete m_wallet;
212 #endif
213     }
214 
215     KHTMLPart *q;
216 
217     QPointer<khtml::ChildFrame> m_frame;
218     KHTMLFrameList m_frames;
219     KHTMLFrameList m_objects;
220 
221     QPointer<KHTMLView> m_view;
222     QPointer<KHTMLViewBar> m_topViewBar;
223     QPointer<KHTMLViewBar> m_bottomViewBar;
224     KHTMLPartBrowserExtension *m_extension;
225     KParts::StatusBarExtension *m_statusBarExtension;
226     KHTMLPartBrowserHostExtension *m_hostExtension;
227     KJS::KHTMLPartScriptable *m_scriptableExtension;
228     KUrlLabel *m_statusBarIconLabel;
229     KUrlLabel *m_statusBarWalletLabel;
230     KUrlLabel *m_statusBarUALabel;
231     KUrlLabel *m_statusBarJSErrorLabel;
232     KUrlLabel *m_statusBarPopupLabel;
233     QList<QPointer<KHTMLPart> > m_suppressedPopupOriginParts; // We need to guard these in case the origin
234     // is a child part.
235     int m_openableSuppressedPopups;
236     DOM::DocumentImpl *m_doc;
237     KEncodingProber::ProberType m_autoDetectLanguage;
238     KEncodingDetector *m_decoder;
239     QString m_encoding;
240     QString m_sheetUsed;
241     qlonglong m_cacheId;
242 
243 #ifndef KHTML_NO_WALLET
244     KWallet::Wallet *m_wallet;
245     QStringList m_walletForms;
246 #endif
247     int m_runningScripts;
248     bool m_bOpenMiddleClick;
249     bool m_bJScriptEnabled;
250     bool m_bJScriptDebugEnabled;
251     bool m_bJavaEnabled;
252     bool m_bPluginsEnabled;
253     bool m_bJScriptForce;
254     bool m_bJScriptOverride;
255     bool m_bJavaForce;
256     bool m_bJavaOverride;
257     bool m_bPluginsForce;
258     bool m_metaRefreshEnabled;
259     bool m_bPluginsOverride;
260     bool m_restored;
261     bool m_restoreScrollPosition;
262     bool m_statusMessagesEnabled;
263     bool m_bWalletOpened;
264     bool m_bDNSPrefetchIsDefault;
265     int m_DNSPrefetchTimer;
266     int m_DNSTTLTimer;
267     int m_numDNSPrefetchedNames;
268     QQueue<QString> m_DNSPrefetchQueue;
269     KHTMLPart::DNSPrefetch m_bDNSPrefetch;
270     int m_frameNameId;
271 
272     KHTMLSettings *m_settings;
273 
274     KIO::TransferJob *m_job;
275 
276     QString m_statusBarText[3];
277     unsigned long m_jobspeed;
278     QString m_lastModified;
279     QString m_httpHeaders;
280     QString m_pageServices;
281 
282     // QStrings for SSL metadata
283     // Note: When adding new variables don't forget to update ::saveState()/::restoreState()!
284     QString m_ssl_peer_chain,
285             m_ssl_peer_ip,
286             m_ssl_cipher,
287             m_ssl_protocol_version,
288             m_ssl_cipher_used_bits,
289             m_ssl_cipher_bits,
290             m_ssl_cert_errors,
291             m_ssl_parent_ip,
292             m_ssl_parent_cert;
293     bool m_ssl_in_use;
294 
295     bool m_bComplete;
296     bool m_bLoadEventEmitted;
297     bool m_haveEncoding;
298     bool m_onlyLocalReferences;
299     bool m_forcePermitLocalImages;
300     bool m_redirectLockHistory;
301 
302     QUrl m_workingURL;
303 
304     KIO::CacheControl m_cachePolicy;
305     QTimer m_redirectionTimer;
306     QTime m_parsetime;
307     int m_delayRedirect;
308     QString m_redirectURL;
309 
310     QAction *m_paViewDocument;
311     QAction *m_paViewFrame;
312     QAction *m_paViewInfo;
313     QAction *m_paSaveBackground;
314     QAction *m_paSaveDocument;
315     QAction *m_paSaveFrame;
316     QAction *m_paSecurity;
317     KCodecAction *m_paSetEncoding;
318     KSelectAction *m_paUseStylesheet;
319     KSelectAction *m_paIncZoomFactor;
320     KSelectAction *m_paDecZoomFactor;
321     QAction *m_paLoadImages;
322     QAction *m_paFind;
323     QAction *m_paFindNext;
324     QAction *m_paFindPrev;
325     QAction *m_paFindAheadText;
326     QAction *m_paFindAheadLinks;
327     QAction *m_paPrintFrame;
328     QAction *m_paSelectAll;
329     QAction *m_paDebugScript;
330     QAction *m_paDebugDOMTree;
331     QAction *m_paDebugRenderTree;
332     QAction *m_paStopAnimations;
333     KToggleAction *m_paToggleCaretMode;
334     QMap<QAction *, int> m_paLanguageMap;
335 
336     KParts::PartManager *m_manager;
337 
338     KHTMLPart::GUIProfile m_guiProfile;
339 
340     int m_zoomFactor;
341     int m_fontScaleFactor;
342 
343     QString m_strSelectedURL;
344     QString m_strSelectedURLTarget;
345     QString m_referrer;
346     QString m_pageReferrer;
347 
348     struct SubmitForm {
349         const char *submitAction;
350         QString submitUrl;
351         QByteArray submitFormData;
352         QString target;
353         QString submitContentType;
354         QString submitBoundary;
355     };
356 
357     SubmitForm *m_submitForm;
358 
359     bool m_bMousePressed;
360     bool m_bRightMousePressed;
361     DOM::Node m_mousePressNode; //node under the mouse when the mouse was pressed (set in the mouse handler)
362 
363     khtml::EditorContext editor_context;
364 
365     QString m_overURL;
366     QString m_overURLTarget;
367 
368     bool m_bDnd;
369     bool m_bFirstData;
370     bool m_bStrictModeQuirk;
371     bool m_bClearing;
372     bool m_bCleared;
373     bool m_focusNodeRestored;
374 
375     int m_focusNodeNumber;
376 
377     QPoint m_dragStartPos;
378 #ifdef KHTML_NO_SELECTION
379     QPoint m_dragLastPos;
380 #endif
381 
382     bool m_designMode;
383     bool m_caretMode;
384 
385     QCursor m_linkCursor;
386     QTimer m_scrollTimer;
387 
388     unsigned long m_loadedObjects;
389     unsigned long m_totalObjectCount;
390     unsigned int m_jobPercent;
391 
392     KHTMLPart::FormNotification m_formNotification;
393     QTimer m_progressUpdateTimer;
394 
395     QStringList m_pluginPageQuestionAsked;
396 
397     KHTMLFind m_find;
398     StorePass m_storePass;
399 
400     KJSErrorDlg *m_jsedlg;
401 
402     //QGuardedPtr<KParts::Part> m_activeFrame;
403     KParts::Part *m_activeFrame;
404     QPointer<KHTMLPart> m_opener;
405     bool m_openedByJS;
406     bool m_newJSInterpreterExists; // set to 1 by setOpenedByJS, for window.open
407 
408     void setFlagRecursively(bool KHTMLPartPrivate::*flag, bool value);
409 
410     QDateTime m_userStyleSheetLastModified;
411 
412     QSet<QString> m_lookedupHosts;
413     static bool s_dnsInitialised;
414 
415 #ifndef KHTML_NO_WALLET
416     KHTMLWalletQueue *m_wq;
417 #endif
418 
419     // Does determination of how we should handle the given type, as per HTML5 rules
420     MimeType classifyMimeType(const QString &mime);
421 
422     void clearRedirection();
423 
424     bool isLocalAnchorJump(const QUrl &url);
425     void executeAnchorJump(const QUrl &url, bool lockHistory);
426 
427     static bool isJavaScriptURL(const QString &url);
428     static QString codeForJavaScriptURL(const QString &url);
429     void executeJavascriptURL(const QString &u);
430 
isInPageURL(const QString & url)431     bool isInPageURL(const QString &url)
432     {
433         return isLocalAnchorJump(QUrl(url)) || isJavaScriptURL(url);
434     }
435 
executeInPageURL(const QString & url,bool lockHistory)436     void executeInPageURL(const QString &url, bool lockHistory)
437     {
438         QUrl kurl(url);
439         if (isLocalAnchorJump(kurl)) {
440             executeAnchorJump(kurl, lockHistory);
441         } else {
442             executeJavascriptURL(url);
443         }
444     }
445 
446     void propagateInitialDomainAndBaseTo(KHTMLPart *kid);
447 
448     void renameFrameForContainer(DOM::HTMLPartContainerElementImpl *cont,
449                                  const QString &newName);
450 
451     KHTMLPart *findFrameParent(KParts::ReadOnlyPart *callingPart, const QString &f,
452                                khtml::ChildFrame **childFrame, bool checkForNavigation);
453 
454     bool canNavigate(KParts::ReadOnlyPart *b);
455     KHTMLPart *top();
456 
457     // Check whether the frame is fully loaded.
458     // The return value doesn't consider any pending redirections.
459     // If the return value is true, however, pendingRedirections will
460     // report if there are any
461     bool isFullyLoaded(bool *pendingRedirections) const;
462 };
463 
464 #endif
465