Patch: Crash: blocking JS alert and deleting a window

Koos Vriezen koos.vriezen at xs4all.nl
Tue Nov 5 20:25:53 GMT 2002


On Tue, 29 Oct 2002, Koos Vriezen wrote:

> On Mon, 28 Oct 2002, David Faure wrote:
>
>
> > > Btw. if this is the only solution we can think of, we are still not done.
> > > What about scripts like: 'alert(foo);alert(bar)' or
> > > 'eval("alert(foo)");alert(bar)'? KJS::Window should also be informed
> > > not to spawn another message box.
> >
> > (saw your next msg). Hmm, strange indeed. Will check tomorrow (I'll also try
> > to come up with a patch for my CloseEvent idea).
>
> If you can produce one, I think between closeChildDialogs() and clear() of
> KHTMLView, there shouldn't be any child popups allowed. (already made a
> patch for it, but then couldn't find a testcase for it, yes the otherway
> around, mind crashing :-) )

Fortunately I didn't turn crazy, bug 50178. Breaking on
QApplication::exit_loop and QApplication::enter_loop shows that a second
messagebox is created after KHTMLView::closeChildDialog is called.
Attached a patch for it.

>
> Koos
>
>
-------------- next part --------------
Index: khtmlview.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtmlview.h,v
retrieving revision 1.168
diff -u -3 -p -r1.168 khtmlview.h
--- khtmlview.h	2002/10/29 21:14:40	1.168
+++ khtmlview.h	2002/11/05 20:22:03
@@ -147,6 +147,11 @@ public:
      **/
     void closeChildDialogs();
 
+    /**
+     * Between closeChildDialogs() and clear() no child dialog should be created
+     **/
+    bool popupsAllowed();
+
 signals:
     void cleared();
     void zoomView( int );
Index: khtmlview.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtmlview.cpp,v
retrieving revision 1.496
diff -u -3 -p -r1.496 khtmlview.cpp
--- khtmlview.cpp	2002/10/29 22:33:44	1.496
+++ khtmlview.cpp	2002/11/05 20:22:04
@@ -152,6 +152,7 @@ public:
         dirtyLayout = false;
         layoutSchedulingEnabled = true;
         updateRect = QRect();
+        m_popupsAllowed = true;
     }
     void newScrollTimer(QWidget *view, int tid)
     {
@@ -225,6 +226,7 @@ public:
     bool layoutSchedulingEnabled;
     bool possibleTripleClick;
     bool dirtyLayout;
+    bool m_popupsAllowed;
     QRect updateRect;
     KHTMLToolTip *tooltip;
     QPtrDict<QWidget> visibleWidgets;
@@ -482,6 +484,15 @@ void KHTMLView::closeChildDialogs()
         }
     }
     delete dlgs;
+    d->m_popupsAllowed = false;
+}
+
+bool KHTMLView::popupsAllowed() {
+    bool allowed = d->m_popupsAllowed;
+    KHTMLPart* p = m_part->parentPart();
+    if (p && p->view())
+        allowed &= p->view()->popupsAllowed();
+    return allowed;
 }
 
 void KHTMLView::closeEvent( QCloseEvent* ev )
Index: ecma/kjs_window.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/ecma/kjs_window.cpp,v
retrieving revision 1.294
diff -u -3 -p -r1.294 kjs_window.cpp
--- ecma/kjs_window.cpp	2002/11/04 19:28:20	1.294
+++ ecma/kjs_window.cpp	2002/11/05 20:22:06
@@ -1212,10 +1212,14 @@ Value WindowFunc::tryCall(ExecState *exe
 
   switch (id) {
   case Window::Alert:
+    if (!widget->popupsAllowed())
+      return Undefined();
     part->xmlDocImpl()->updateRendering();
     KMessageBox::error(widget, QStyleSheet::convertFromPlainText(str), "JavaScript");
     return Undefined();
   case Window::Confirm:
+    if (!widget->popupsAllowed())
+      return Undefined();
     part->xmlDocImpl()->updateRendering();
     return Boolean((KMessageBox::warningYesNo(widget, QStyleSheet::convertFromPlainText(str), "JavaScript",
                                                 i18n("OK"), i18n("Cancel")) == KMessageBox::Yes));


More information about the kfm-devel mailing list