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 <kaction.h>
32#include <kparts/partmanager.h>
33#include <kparts/statusbarextension.h>
34#include <kparts/browserextension.h>
35#include <kparts/scriptableextension.h>
36
37#include <QtCore/QDate>
38#include <QtCore/QPointer>
39#include <QtCore/QMap>
40#include <QtCore/QTimer>
41#include <QtCore/QList>
42#include <QtCore/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 "ecma/kjs_proxy.h"
55#include "xml/dom_nodeimpl.h"
56#include "editing/editing_p.h"
57#include "ui/findbar/khtmlfind_p.h"
58#include "ui/passwordbar/storepassbar.h"
59#include "ecma/kjs_scriptable.h"
60
61class KFind;
62class KFindDialog;
63class KCodecAction;
64class KUrlLabel;
65class KJavaAppletContext;
66class KJSErrorDlg;
67class KToggleAction;
68class KHTMLViewBar;
69
70namespace KIO
71{
72 class Job;
73 class TransferJob;
74}
75namespace KParts
76{
77 class StatusBarExtension;
78}
79
80#include "khtml_wallet_p.h"
81
82enum MimeType {
83 MimeHTML,
84 MimeSVG,
85 MimeXHTML,
86 MimeXML, // XML but not SVG or XHTML
87 MimeImage,
88 MimeText,
89 MimeOther
90};
91
92
93class KHTMLPartPrivate
94{
95 KHTMLPartPrivate(const KHTMLPartPrivate & other);
96 KHTMLPartPrivate& operator=(const KHTMLPartPrivate&);
97public:
98 KHTMLPartPrivate(KHTMLPart* part, QObject* parent) :
99 m_find( part, (part->parentPart() ? &part->parentPart()->d->m_find : 0) ), m_storePass( part )
100 {
101 q = part;
102 m_doc = 0L;
103 m_decoder = 0L;
104#ifndef KHTML_NO_WALLET
105 m_wallet = 0L;
106#endif
107 m_bWalletOpened = false;
108 m_runningScripts = 0;
109 m_job = 0L;
110 m_bComplete = true;
111 m_bLoadEventEmitted = true;
112 m_cachePolicy = KIO::CC_Verify;
113 m_manager = 0L;
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 = 0L;
126 m_ssl_in_use = false;
127 m_jsedlg = 0;
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 = 0;
162 m_delayRedirect = 0;
163 m_autoDetectLanguage = KEncodingDetector::SemiautomaticDetection;
164
165 // inherit settings from parent
166 if(parent && parent->inherits("KHTMLPart"))
167 {
168 KHTMLPart* part = static_cast<KHTMLPart*>(parent);
169 if(part->d)
170 {
171 m_bJScriptForce = part->d->m_bJScriptForce;
172 m_bJScriptOverride = part->d->m_bJScriptOverride;
173 m_bJavaForce = part->d->m_bJavaForce;
174 m_bJavaOverride = part->d->m_bJavaOverride;
175 m_bPluginsForce = part->d->m_bPluginsForce;
176 m_bPluginsOverride = part->d->m_bPluginsOverride;
177 m_bDNSPrefetch = part->d->m_bDNSPrefetch;
178 m_bDNSPrefetchIsDefault = part->d->m_bDNSPrefetchIsDefault;
179 m_onlyLocalReferences = part->d->m_onlyLocalReferences;
180 m_forcePermitLocalImages = part->d->m_forcePermitLocalImages;
181 // Same for SSL settings
182 m_ssl_in_use = part->d->m_ssl_in_use;
183 m_caretMode = part->d->m_caretMode;
184 m_designMode = part->d->m_designMode;
185 m_zoomFactor = part->d->m_zoomFactor;
186 m_fontScaleFactor = part->d->m_fontScaleFactor;
187 m_autoDetectLanguage = part->d->m_autoDetectLanguage;
188 m_encoding = part->d->m_encoding;
189 m_haveEncoding = part->d->m_haveEncoding;
190 }
191 }
192
193 m_focusNodeNumber = -1;
194 m_focusNodeRestored = false;
195 m_opener = 0;
196 m_openedByJS = false;
197 m_newJSInterpreterExists = false;
198 m_jobspeed = 0;
199 m_statusBarWalletLabel = 0L;
200 m_statusBarUALabel = 0L;
201 m_statusBarJSErrorLabel = 0L;
202 m_userStyleSheetLastModified = 0;
203#ifndef KHTML_NO_WALLET
204 m_wq = 0;
205#endif
206 }
207 ~KHTMLPartPrivate()
208 {
209 delete m_statusBarExtension;
210 delete m_scriptableExtension;
211 delete m_extension;
212 delete m_settings;
213#ifndef KHTML_NO_WALLET
214 delete m_wallet;
215#endif
216#ifndef Q_WS_QWS
217 //delete m_javaContext;
218#endif
219 }
220
221 KHTMLPart* q;
222
223 QPointer<khtml::ChildFrame> m_frame;
224 KHTMLFrameList m_frames;
225 KHTMLFrameList m_objects;
226
227 QPointer<KHTMLView> m_view;
228 QPointer<KHTMLViewBar> m_topViewBar;
229 QPointer<KHTMLViewBar> m_bottomViewBar;
230 KHTMLPartBrowserExtension *m_extension;
231 KParts::StatusBarExtension *m_statusBarExtension;
232 KHTMLPartBrowserHostExtension *m_hostExtension;
233 KJS::KHTMLPartScriptable *m_scriptableExtension;
234 KUrlLabel* m_statusBarIconLabel;
235 KUrlLabel* m_statusBarWalletLabel;
236 KUrlLabel* m_statusBarUALabel;
237 KUrlLabel* m_statusBarJSErrorLabel;
238 KUrlLabel* m_statusBarPopupLabel;
239 QList<QPointer<KHTMLPart> > m_suppressedPopupOriginParts; // We need to guard these in case the origin
240 // is a child part.
241 int m_openableSuppressedPopups;
242 DOM::DocumentImpl *m_doc;
243 KEncodingDetector::AutoDetectScript m_autoDetectLanguage;
244 KEncodingDetector *m_decoder;
245 QString m_encoding;
246 QString m_sheetUsed;
247 qlonglong m_cacheId;
248
249#ifndef KHTML_NO_WALLET
250 KWallet::Wallet* m_wallet;
251 QStringList m_walletForms;
252#endif
253 int m_runningScripts;
254 bool m_bOpenMiddleClick;
255 bool m_bJScriptEnabled;
256 bool m_bJScriptDebugEnabled;
257 bool m_bJavaEnabled;
258 bool m_bPluginsEnabled;
259 bool m_bJScriptForce;
260 bool m_bJScriptOverride;
261 bool m_bJavaForce;
262 bool m_bJavaOverride;
263 bool m_bPluginsForce;
264 bool m_metaRefreshEnabled;
265 bool m_bPluginsOverride;
266 bool m_restored;
267 bool m_restoreScrollPosition;
268 bool m_statusMessagesEnabled;
269 bool m_bWalletOpened;
270 bool m_urlSelectedOpenedURL; // KDE4: remove
271 bool m_bDNSPrefetchIsDefault;
272 int m_DNSPrefetchTimer;
273 int m_DNSTTLTimer;
274 int m_numDNSPrefetchedNames;
275 QQueue<QString> m_DNSPrefetchQueue;
276 KHTMLPart::DNSPrefetch m_bDNSPrefetch;
277 int m_frameNameId;
278
279 KHTMLSettings *m_settings;
280
281 KIO::TransferJob * m_job;
282
283 QString m_statusBarText[3];
284 unsigned long m_jobspeed;
285 QString m_lastModified;
286 QString m_httpHeaders;
287 QString m_pageServices;
288
289 // QStrings for SSL metadata
290 // Note: When adding new variables don't forget to update ::saveState()/::restoreState()!
291 QString m_ssl_peer_chain,
292 m_ssl_peer_ip,
293 m_ssl_cipher,
294 m_ssl_protocol_version,
295 m_ssl_cipher_used_bits,
296 m_ssl_cipher_bits,
297 m_ssl_cert_errors,
298 m_ssl_parent_ip,
299 m_ssl_parent_cert;
300 bool m_ssl_in_use;
301
302 bool m_bComplete;
303 bool m_bLoadEventEmitted;
304 bool m_haveEncoding;
305 bool m_onlyLocalReferences;
306 bool m_forcePermitLocalImages;
307 bool m_redirectLockHistory;
308
309 KUrl m_workingURL;
310
311 KIO::CacheControl m_cachePolicy;
312 QTimer m_redirectionTimer;
313 QTime m_parsetime;
314 int m_delayRedirect;
315 QString m_redirectURL;
316
317 KAction *m_paViewDocument;
318 KAction *m_paViewFrame;
319 KAction *m_paViewInfo;
320 KAction *m_paSaveBackground;
321 KAction *m_paSaveDocument;
322 KAction *m_paSaveFrame;
323 KAction *m_paSecurity;
324 KCodecAction *m_paSetEncoding;
325 KSelectAction *m_paUseStylesheet;
326 KSelectAction *m_paIncZoomFactor;
327 KSelectAction *m_paDecZoomFactor;
328 KAction *m_paLoadImages;
329 KAction *m_paFind;
330 KAction *m_paFindNext;
331 KAction *m_paFindPrev;
332 KAction *m_paFindAheadText;
333 KAction *m_paFindAheadLinks;
334 KAction *m_paPrintFrame;
335 KAction *m_paSelectAll;
336 KAction *m_paDebugScript;
337 KAction *m_paDebugDOMTree;
338 KAction *m_paDebugRenderTree;
339 KAction *m_paStopAnimations;
340 KToggleAction *m_paToggleCaretMode;
341 QMap<QAction*, int> m_paLanguageMap;
342
343 KParts::PartManager *m_manager;
344
345 KHTMLPart::GUIProfile m_guiProfile;
346
347 int m_zoomFactor;
348 int m_fontScaleFactor;
349
350 QString m_strSelectedURL;
351 QString m_strSelectedURLTarget;
352 QString m_referrer;
353 QString m_pageReferrer;
354
355 struct SubmitForm
356 {
357 const char *submitAction;
358 QString submitUrl;
359 QByteArray submitFormData;
360 QString target;
361 QString submitContentType;
362 QString submitBoundary;
363 };
364
365 SubmitForm *m_submitForm;
366
367 bool m_bMousePressed;
368 bool m_bRightMousePressed;
369 DOM::Node m_mousePressNode; //node under the mouse when the mouse was pressed (set in the mouse handler)
370
371 khtml::EditorContext editor_context;
372
373 QString m_overURL;
374 QString m_overURLTarget;
375
376 bool m_bDnd;
377 bool m_bFirstData;
378 bool m_bStrictModeQuirk;
379 bool m_bClearing;
380 bool m_bCleared;
381 bool m_focusNodeRestored;
382
383 int m_focusNodeNumber;
384
385 QPoint m_dragStartPos;
386#ifdef KHTML_NO_SELECTION
387 QPoint m_dragLastPos;
388#endif
389
390 bool m_designMode;
391 bool m_caretMode;
392
393 QCursor m_linkCursor;
394 QTimer m_scrollTimer;
395
396 unsigned long m_loadedObjects;
397 unsigned long m_totalObjectCount;
398 unsigned int m_jobPercent;
399
400 KHTMLPart::FormNotification m_formNotification;
401 QTimer m_progressUpdateTimer;
402
403 QStringList m_pluginPageQuestionAsked;
404
405 KHTMLFind m_find;
406 StorePass m_storePass;
407
408 KJSErrorDlg *m_jsedlg;
409
410 //QGuardedPtr<KParts::Part> m_activeFrame;
411 KParts::Part * m_activeFrame;
412 QPointer<KHTMLPart> m_opener;
413 bool m_openedByJS;
414 bool m_newJSInterpreterExists; // set to 1 by setOpenedByJS, for window.open
415
416 void setFlagRecursively(bool KHTMLPartPrivate::*flag, bool value);
417
418 time_t m_userStyleSheetLastModified;
419
420 QSet<QString> m_lookedupHosts;
421 static bool s_dnsInitialised;
422
423#ifndef KHTML_NO_WALLET
424 KHTMLWalletQueue *m_wq;
425#endif
426
427 // Does determination of how we should handle the given type, as per HTML5 rules
428 MimeType classifyMimeType(const QString& mime);
429
430 void clearRedirection();
431
432 bool isLocalAnchorJump(const KUrl& url);
433 void executeAnchorJump(const KUrl& url, bool lockHistory);
434
435 static bool isJavaScriptURL(const QString& url);
436 static QString codeForJavaScriptURL(const QString& url);
437 void executeJavascriptURL(const QString &u);
438
439 bool isInPageURL(const QString& url) {
440 return isLocalAnchorJump(KUrl(url)) || isJavaScriptURL(url);
441 }
442
443 void executeInPageURL(const QString& url, bool lockHistory) {
444 KUrl kurl(url);
445 if (isLocalAnchorJump(kurl))
446 executeAnchorJump(kurl, lockHistory);
447 else
448 executeJavascriptURL(url);
449 }
450
451 void propagateInitialDomainAndBaseTo(KHTMLPart* kid);
452
453 void renameFrameForContainer(DOM::HTMLPartContainerElementImpl* cont,
454 const QString& newName);
455
456 KHTMLPart* findFrameParent(KParts::ReadOnlyPart* callingPart, const QString& f,
457 khtml::ChildFrame **childFrame, bool checkForNavigation);
458
459 bool canNavigate(KParts::ReadOnlyPart* b);
460 KHTMLPart* top();
461
462 // Check whether the frame is fully loaded.
463 // The return value doesn't consider any pending redirections.
464 // If the return value is true, however, pendingRedirections will
465 // report if there are any
466 bool isFullyLoaded(bool* pendingRedirections) const;
467};
468
469#endif
470