Crash: blocking JS and deleting a window
Koos Vriezen
koos.vriezen at xs4all.nl
Thu Oct 3 21:48:02 BST 2002
On Thu, 3 Oct 2002, Koos Vriezen wrote:
> Does the attached patch for kparts implements what you mean?
Might as well add the khtml implementation of it.
Also generalized BrowserExtension a bit for supporting other events.
Koos
-------------- next part --------------
Index: browserextension.cpp
===================================================================
RCS file: /home/kde/kdelibs/kparts/browserextension.cpp,v
retrieving revision 1.40
diff -u -3 -p -r1.40 browserextension.cpp
--- browserextension.cpp 2002/08/18 11:17:54 1.40
+++ browserextension.cpp 2002/10/03 20:40:01
@@ -281,8 +281,14 @@ public:
}
};
-class BrowserExtensionPrivate
+BrowserExtensionEvent::BrowserExtensionEvent(BEEventType type)
+ : QEvent(QEvent::Type(int(type))),
+ accepted( false )
{
+}
+
+class BrowserExtensionPrivate : public QObject
+{
public:
BrowserExtensionPrivate()
{
@@ -300,6 +306,15 @@ public:
bool m_urlDropHandlingEnabled;
KBitArray m_actionStatus;
BrowserInterface *m_browserInterface;
+protected:
+ bool eventFilter( QObject *, QEvent *e ) {
+ if ( int(e->type()) == int(BrowserExtensionEvent::can_delete_event) ) {
+ ((BrowserExtensionEvent*)e)->accept();
+ // we can eat this event because where the last one to receive it
+ return TRUE;
+ }
+ return FALSE;
+ }
};
};
@@ -338,11 +353,13 @@ BrowserExtension::BrowserExtension( KPar
this, SLOT( slotOpenURLRequest( const KURL &, const KParts::URLArgs & ) ) );
connect( this, SIGNAL( enableAction( const char *, bool ) ),
this, SLOT( slotEnableAction( const char *, bool ) ) );
+ installEventFilter( d );
}
BrowserExtension::~BrowserExtension()
{
//kdDebug() << "BrowserExtension::~BrowserExtension() " << this << endl;
+ removeEventFilter( d );
delete d;
}
Index: browserextension.h
===================================================================
RCS file: /home/kde/kdelibs/kparts/browserextension.h,v
retrieving revision 1.94
diff -u -3 -p -r1.94 browserextension.h
--- browserextension.h 2002/08/18 11:17:54 1.94
+++ browserextension.h 2002/10/03 20:40:01
@@ -574,6 +574,21 @@ private:
BrowserExtensionPrivate *d;
};
+class BrowserExtensionEvent : public QEvent
+{
+public:
+ enum BEEventType { can_delete_event = int(QEvent::User) + 0 };
+
+ BrowserExtensionEvent(BEEventType type);
+
+ bool isAccepted() const { return accepted; }
+ void accept() { accepted = true; }
+ void ignore() { accepted = false; }
+
+private:
+ bool accepted;
+};
+
/**
* An extension class for container parts, i.e. parts that contain
* other parts.
-------------- next part --------------
Index: khtml_ext.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtml_ext.h,v
retrieving revision 1.18
diff -u -3 -p -r1.18 khtml_ext.h
--- khtml_ext.h 2002/03/15 22:53:08 1.18
+++ khtml_ext.h 2002/10/03 20:38:13
@@ -43,6 +43,8 @@ public slots:
// on whether data is available in the clipboard
void updateEditActions();
+protected:
+ bool eventFilter( QObject *, QEvent *e );
private slots:
// connected to a frame's browserextensions enableAction signal
void extensionProxyActionEnabled( const char *action, bool enable );
Index: khtml_ext.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtml_ext.cpp,v
retrieving revision 1.50
diff -u -3 -p -r1.50 khtml_ext.cpp
--- khtml_ext.cpp 2002/07/03 01:35:11 1.50
+++ khtml_ext.cpp 2002/10/03 20:38:14
@@ -258,6 +258,17 @@ void KHTMLPartBrowserExtension::print()
m_part->view()->print();
}
+bool KHTMLPartBrowserExtension::eventFilter( QObject *, QEvent *e ) {
+ if ( int(e->type()) == int(BrowserExtensionEvent::can_delete_event) ) {
+ if (m_part->canDeleted())
+ ((BrowserExtensionEvent*)e)->accept();
+ else
+ ((BrowserExtensionEvent*)e)->ignore();
+ return TRUE;
+ }
+ return FALSE;
+}
+
class KHTMLPopupGUIClient::KHTMLPopupGUIClientPrivate
{
public:
Index: khtml_part.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtml_part.h,v
retrieving revision 1.197
diff -u -3 -p -r1.197 khtml_part.h
--- khtml_part.h 2002/09/06 10:28:46 1.197
+++ khtml_part.h 2002/10/03 20:38:14
@@ -252,6 +252,7 @@ public:
*/
bool jScriptEnabled() const;
+ bool canDeleted();
/**
* Enable/disable the automatic forwarding by <meta http-equiv="refresh" ....>
*/
Index: khtml_part.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtml_part.cpp,v
retrieving revision 1.751
diff -u -3 -p -r1.751 khtml_part.cpp
--- khtml_part.cpp 2002/09/29 09:25:33 1.751
+++ khtml_part.cpp 2002/10/03 20:38:17
@@ -581,6 +581,11 @@ bool KHTMLPart::jScriptEnabled() const
return d->m_bJScriptEnabled;
}
+bool KHTMLPart::canDeleted()
+{
+ return !(d->m_jscript && d->m_jscript->scriptActive());
+}
+
void KHTMLPart::setMetaRefreshEnabled( bool enable )
{
d->m_metaRefreshEnabled = enable;
Index: ecma/kjs_proxy.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/ecma/kjs_proxy.h,v
retrieving revision 1.19
diff -u -3 -p -r1.19 kjs_proxy.h
--- ecma/kjs_proxy.h 2002/08/21 20:22:30 1.19
+++ ecma/kjs_proxy.h 2002/10/03 20:38:17
@@ -57,6 +57,7 @@ public:
virtual void setDebugEnabled(bool enabled) = 0;
virtual bool paused() const = 0;
+ virtual bool scriptActive() const = 0;
virtual void setSourceFile(QString url, QString code) = 0;
virtual void appendSourceFile(QString url, QString code) = 0;
Index: ecma/kjs_proxy.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/ecma/kjs_proxy.cpp,v
retrieving revision 1.84
diff -u -3 -p -r1.84 kjs_proxy.cpp
--- ecma/kjs_proxy.cpp 2002/09/20 09:45:40 1.84
+++ ecma/kjs_proxy.cpp 2002/10/03 20:38:18
@@ -53,6 +53,7 @@ public:
virtual void setDebugEnabled(bool enabled);
virtual bool paused() const;
+ virtual bool scriptActive() const;
virtual void setSourceFile(QString url, QString code);
virtual void appendSourceFile(QString url, QString code);
@@ -62,6 +63,7 @@ public:
private:
KJS::ScriptInterpreter* m_script;
bool m_debugEnabled;
+ bool m_script_active;
#ifndef NDEBUG
static int s_count;
#endif
@@ -76,6 +78,7 @@ KJSProxyImpl::KJSProxyImpl(KHTMLPart *pa
m_script = 0;
m_part = part;
m_debugEnabled = false;
+ m_script_active = false;
#ifndef NDEBUG
s_count++;
#endif
@@ -141,11 +144,15 @@ QVariant KJSProxyImpl::evaluate(QString
UString code( str );
+ m_script_active = true;
+
KJSCPUGuard guard;
guard.start();
Completion comp = m_script->evaluate(code, thisNode);
guard.stop();
+ m_script_active = false;
+
bool success = ( comp.complType() == Normal ) || ( comp.complType() == ReturnValue );
#ifdef KJS_DEBUGGER
@@ -270,6 +277,10 @@ bool KJSProxyImpl::paused() const
return KJSDebugWin::instance()->inSession();
#endif
return false;
+}
+
+bool KJSProxyImpl::scriptActive() const {
+ return m_script_active;
}
void KJSProxyImpl::setSourceFile(QString url, QString code)
More information about the kfm-devel
mailing list