1 /* This file is part of the KDE project
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>
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.
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.
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.
30 #include <klibloader.h>
31 #include <kxmlguifactory.h>
33 #include <kparts/partmanager.h>
34 #include <kparts/statusbarextension.h>
35 #include <kparts/browserextension.h>
37 #include <QtCore/QDate>
38 #include <QtCore/QPointer>
39 #include <QtCore/QMap>
40 #include <QtCore/QTimer>
41 #include <QtCore/QList>
42 #include <QtCore/QQueue>
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 <kencodingdetector.h>
52 #include "ecma/kjs_proxy.h"
53 #include "xml/dom_nodeimpl.h"
54 #include "editing/editing_p.h"
55 #include "find/khtmlfind_p.h"
61 class KJavaAppletContext
;
73 class StatusBarExtension
;
76 #include "khtml_wallet_p.h"
80 class KHTML_EXPORT ChildFrame
: public QObject
84 enum Type
{ Frame
, IFrame
, Object
};
86 ChildFrame() : QObject (0) {
87 setObjectName( "khtml_child_frame" );
89 #ifndef DIRECT_LINKAGE_TO_ECMA
92 m_bCompleted
= false; m_bPreloaded
= false; m_type
= Frame
; m_bNotify
= false;
93 m_bPendingRedirection
= false;
97 if (m_run
) m_run
->abort();
99 #ifndef DIRECT_LINKAGE_TO_ECMA
105 QPointer
<DOM::HTMLPartContainerElementImpl
> m_partContainerElement
;
106 QPointer
<KParts::ReadOnlyPart
> m_part
;
107 QPointer
<KParts::BrowserExtension
> m_extension
;
108 QPointer
<KParts::LiveConnectExtension
> m_liveconnect
;
109 QString m_serviceName
;
110 QString m_serviceType
;
112 #ifndef DIRECT_LINKAGE_TO_ECMA
117 KParts::OpenUrlArguments m_args
;
118 KParts::BrowserArguments m_browserArgs
;
119 QPointer
<KHTMLRun
> m_run
;
122 QStringList m_params
;
125 bool m_bPendingRedirection
;
127 void liveConnectEvent(const unsigned long, const QString
&, const KParts::LiveConnectExtension::ArgList
&);
132 struct KHTMLFrameList
: public QList
<khtml::ChildFrame
*>
134 Iterator
find( const QString
&name
) KDE_NO_EXPORT
;
137 typedef KHTMLFrameList::ConstIterator ConstFrameIt
;
138 typedef KHTMLFrameList::Iterator FrameIt
;
142 class KHTMLPartPrivate
144 KHTMLPartPrivate(const KHTMLPartPrivate
& other
);
145 KHTMLPartPrivate
& operator=(const KHTMLPartPrivate
&);
147 KHTMLPartPrivate(KHTMLPart
* part
, QObject
* parent
) :
153 #ifndef KHTML_NO_WALLET
156 m_bWalletOpened
= false;
157 m_runningScripts
= 0;
160 m_bLoadEventEmitted
= true;
161 m_cachePolicy
= KIO::CC_Verify
;
163 m_settings
= new KHTMLSettings(*KHTMLGlobal::defaultHTMLSettings());
167 m_fontScaleFactor
= 100;
169 m_linkCursor
= QCursor(Qt::PointingHandCursor
);
171 m_totalObjectCount
= 0;
173 m_haveEncoding
= false;
175 m_ssl_in_use
= false;
177 m_formNotification
= KHTMLPart::NoNotification
;
183 m_restoreScrollPosition
= false;
185 m_focusNodeNumber
= -1;
186 m_focusNodeRestored
= false;
188 m_bJScriptForce
= false;
189 m_bJScriptOverride
= false;
190 m_bJavaForce
= false;
191 m_bJavaOverride
= false;
192 m_bPluginsForce
= false;
193 m_bPluginsOverride
= false;
194 m_onlyLocalReferences
= false;
195 m_bDNSPrefetch
= KHTMLPart::DNSPrefetchDisabled
;
196 m_bDNSPrefetchIsDefault
= true;
197 m_DNSPrefetchTimer
= -1;
199 m_numDNSPrefetchedNames
= 0;
202 m_designMode
= false;
204 m_metaRefreshEnabled
= true;
205 m_statusMessagesEnabled
= true;
208 m_bStrictModeQuirk
= true;
211 m_autoDetectLanguage
= KEncodingDetector::SemiautomaticDetection
;
213 // inherit settings from parent
214 if(parent
&& parent
->inherits("KHTMLPart"))
216 KHTMLPart
* part
= static_cast<KHTMLPart
*>(parent
);
219 m_bJScriptForce
= part
->d
->m_bJScriptForce
;
220 m_bJScriptOverride
= part
->d
->m_bJScriptOverride
;
221 m_bJavaForce
= part
->d
->m_bJavaForce
;
222 m_bJavaOverride
= part
->d
->m_bJavaOverride
;
223 m_bPluginsForce
= part
->d
->m_bPluginsForce
;
224 m_bPluginsOverride
= part
->d
->m_bPluginsOverride
;
225 m_bDNSPrefetch
= part
->d
->m_bDNSPrefetch
;
226 m_bDNSPrefetchIsDefault
= part
->d
->m_bDNSPrefetchIsDefault
;
227 // Same for SSL settings
228 m_ssl_in_use
= part
->d
->m_ssl_in_use
;
229 m_onlyLocalReferences
= part
->d
->m_onlyLocalReferences
;
230 m_caretMode
= part
->d
->m_caretMode
;
231 m_designMode
= part
->d
->m_designMode
;
232 m_zoomFactor
= part
->d
->m_zoomFactor
;
233 m_fontScaleFactor
= part
->d
->m_fontScaleFactor
;
234 m_autoDetectLanguage
= part
->d
->m_autoDetectLanguage
;
235 m_encoding
= part
->d
->m_encoding
;
236 m_haveEncoding
= part
->d
->m_haveEncoding
;
240 m_focusNodeNumber
= -1;
241 m_focusNodeRestored
= false;
243 m_openedByJS
= false;
244 m_newJSInterpreterExists
= false;
246 m_statusBarWalletLabel
= 0L;
247 m_statusBarUALabel
= 0L;
248 m_statusBarJSErrorLabel
= 0L;
249 m_userStyleSheetLastModified
= 0;
250 #ifndef KHTML_NO_WALLET
256 delete m_statusBarExtension
;
259 #ifndef KHTML_NO_WALLET
263 //delete m_javaContext;
269 QPointer
<khtml::ChildFrame
> m_frame
;
270 KHTMLFrameList m_frames
;
271 KHTMLFrameList m_objects
;
273 QPointer
<KHTMLView
> m_view
;
274 QPointer
<KHTMLViewBar
> m_topViewBar
;
275 QPointer
<KHTMLViewBar
> m_bottomViewBar
;
276 KHTMLPartBrowserExtension
*m_extension
;
277 KParts::StatusBarExtension
*m_statusBarExtension
;
278 KHTMLPartBrowserHostExtension
*m_hostExtension
;
279 KUrlLabel
* m_statusBarIconLabel
;
280 KUrlLabel
* m_statusBarWalletLabel
;
281 KUrlLabel
* m_statusBarUALabel
;
282 KUrlLabel
* m_statusBarJSErrorLabel
;
283 KUrlLabel
* m_statusBarPopupLabel
;
284 QList
<QPointer
<KHTMLPart
> > m_suppressedPopupOriginParts
; // We need to guard these in case the origin
286 int m_openableSuppressedPopups
;
287 DOM::DocumentImpl
*m_doc
;
288 KEncodingDetector::AutoDetectScript m_autoDetectLanguage
;
289 KEncodingDetector
*m_decoder
;
294 #ifndef KHTML_NO_WALLET
295 KWallet::Wallet
* m_wallet
;
297 int m_runningScripts
;
298 bool m_bOpenMiddleClick
;
299 bool m_bBackRightClick
;
300 bool m_bJScriptEnabled
;
301 bool m_bJScriptDebugEnabled
;
303 bool m_bPluginsEnabled
;
304 bool m_bJScriptForce
;
305 bool m_bJScriptOverride
;
307 bool m_bJavaOverride
;
308 bool m_bPluginsForce
;
309 bool m_metaRefreshEnabled
;
310 bool m_bPluginsOverride
;
312 bool m_restoreScrollPosition
;
313 bool m_statusMessagesEnabled
;
314 bool m_bWalletOpened
;
315 bool m_urlSelectedOpenedURL
; // KDE4: remove
316 bool m_bDNSPrefetchIsDefault
;
317 int m_DNSPrefetchTimer
;
319 int m_numDNSPrefetchedNames
;
320 QQueue
<QString
> m_DNSPrefetchQueue
;
321 KHTMLPart::DNSPrefetch m_bDNSPrefetch
;
324 KHTMLSettings
*m_settings
;
326 KIO::TransferJob
* m_job
;
328 QString m_statusBarText
[3];
329 unsigned long m_jobspeed
;
330 QString m_lastModified
;
331 QString m_httpHeaders
;
332 QString m_pageServices
;
334 // QStrings for SSL metadata
335 // Note: When adding new variables don't forget to update ::saveState()/::restoreState()!
336 QString m_ssl_peer_chain
,
339 m_ssl_protocol_version
,
340 m_ssl_cipher_used_bits
,
348 bool m_bLoadEventEmitted
;
350 bool m_onlyLocalReferences
;
351 bool m_redirectLockHistory
;
355 KIO::CacheControl m_cachePolicy
;
356 QTimer m_redirectionTimer
;
359 QString m_redirectURL
;
361 KAction
*m_paViewDocument
;
362 KAction
*m_paViewFrame
;
363 KAction
*m_paViewInfo
;
364 KAction
*m_paSaveBackground
;
365 KAction
*m_paSaveDocument
;
366 KAction
*m_paSaveFrame
;
367 KAction
*m_paSecurity
;
368 KCodecAction
*m_paSetEncoding
;
369 KSelectAction
*m_paUseStylesheet
;
370 KSelectAction
*m_paIncZoomFactor
;
371 KSelectAction
*m_paDecZoomFactor
;
372 KAction
*m_paLoadImages
;
374 KAction
*m_paFindNext
;
375 KAction
*m_paFindPrev
;
376 KAction
*m_paFindAheadText
;
377 KAction
*m_paFindAheadLinks
;
378 KAction
*m_paPrintFrame
;
379 KAction
*m_paSelectAll
;
380 KAction
*m_paDebugScript
;
381 KAction
*m_paDebugDOMTree
;
382 KAction
*m_paDebugRenderTree
;
383 KAction
*m_paStopAnimations
;
384 KToggleAction
*m_paToggleCaretMode
;
385 QMap
<QAction
*, int> m_paLanguageMap
;
387 KParts::PartManager
*m_manager
;
389 KHTMLPart::GUIProfile m_guiProfile
;
392 int m_fontScaleFactor
;
394 QString m_strSelectedURL
;
395 QString m_strSelectedURLTarget
;
397 QString m_pageReferrer
;
401 const char *submitAction
;
403 QByteArray submitFormData
;
405 QString submitContentType
;
406 QString submitBoundary
;
409 SubmitForm
*m_submitForm
;
411 bool m_bMousePressed
;
412 bool m_bRightMousePressed
;
413 DOM::Node m_mousePressNode
; //node under the mouse when the mouse was pressed (set in the mouse handler)
415 khtml::EditorContext editor_context
;
418 QString m_overURLTarget
;
422 bool m_bStrictModeQuirk
;
425 bool m_focusNodeRestored
;
427 int m_focusNodeNumber
;
429 QPoint m_dragStartPos
;
430 #ifdef KHTML_NO_SELECTION
431 QPoint m_dragLastPos
;
437 QCursor m_linkCursor
;
438 QTimer m_scrollTimer
;
440 unsigned long m_loadedObjects
;
441 unsigned long m_totalObjectCount
;
442 unsigned int m_jobPercent
;
444 KHTMLPart::FormNotification m_formNotification
;
445 QTimer m_progressUpdateTimer
;
447 QStringList m_pluginPageQuestionAsked
;
451 KJSErrorDlg
*m_jsedlg
;
453 //QGuardedPtr<KParts::Part> m_activeFrame;
454 KParts::Part
* m_activeFrame
;
455 QPointer
<KHTMLPart
> m_opener
;
457 bool m_newJSInterpreterExists
; // set to 1 by setOpenedByJS, for window.open
459 void setFlagRecursively(bool KHTMLPartPrivate::*flag
, bool value
);
461 time_t m_userStyleSheetLastModified
;
463 QSet
<QString
> m_lookedupHosts
;
464 static bool s_dnsInitialised
;
466 #ifndef KHTML_NO_WALLET
467 KHTMLWalletQueue
*m_wq
;
470 void clearRedirection();
472 bool isLocalAnchorJump(const KUrl
& url
);
473 void executeAnchorJump(const KUrl
& url
, bool lockHistory
);
475 static bool isJavaScriptURL(const QString
& url
);
476 static QString
codeForJavaScriptURL(const QString
& url
);
477 void executeJavascriptURL(const QString
&u
);
479 bool isInPageURL(const QString
& url
) {
480 return isLocalAnchorJump(KUrl(url
)) || isJavaScriptURL(url
);
483 void executeInPageURL(const QString
& url
, bool lockHistory
) {
485 if (isLocalAnchorJump(kurl
))
486 executeAnchorJump(kurl
, lockHistory
);
488 executeJavascriptURL(url
);
491 void propagateInitialDomainTo(KHTMLPart
* kid
);