[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    Re: [PATCH] popups on prosieben.de
From:       David Faure <david () mandrakesoft ! com>
Date:       2002-10-25 23:30:44
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Friday 25 October 2002 19:16, Dirk Mueller wrote:
> Hi, 
> 
> thanks to David's help I've figured out why the popups on prosieben don't 
> work. apparently document.open(3 parameters) is supposed to call 
> window.open() in this case. 
> 
> below the patch, please review. 

I like the code factorization :) but the patch has a bug:
the wrong Window object is being used, in case someOtherWindow.document.open(...) is called.
This is equivalent to someOtherWindow.open, so we need to get hold of the window
object for the HTMLDocument, not the one "currently running the interpreter".

The attached patch does it.

(It also includes a forgotten DOMNodeList change in hasProperty as we did in tryGet.)

- -- 
David FAURE, david@mandrakesoft.com, faure@kde.org
http://people.mandrakesoft.com/~david/
Contributing to: http://www.konqueror.org/, http://www.koffice.org/
Get the latest KOffice - http://download.kde.org/stable/koffice-1.2/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9udRx72KcVAmwbhARAgqyAJ9mdc+7+OSeuqPijkRtd8LGpvO4rQCgsCz2
FeuH6YzxSJiiz9NSazzF9js=
=kY+8
-----END PGP SIGNATURE-----

["prosieben_2.diff" (text/x-diff)]

? core.16324
? core.16363
? core.16384
? enums
? inp
? kjs_html_more_debug_output
? spec_dom2_core.html
? spec_dom2_events.html
? spec_dom2_html.html
? spec_dom2_style_css.html
? spec_dom2_style_stylesheets.html
? spec_dom3_core.html
? spec_dom3_events.html
? switch
? table
? tentative.kjs_dom.storing_as_attribute.diff
Index: kjs_html.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/ecma/kjs_html.cpp,v
retrieving revision 1.207
diff -u -p -r1.207 kjs_html.cpp
--- kjs_html.cpp	2002/10/24 17:35:26	1.207
+++ kjs_html.cpp	2002/10/25 23:20:39
@@ -70,6 +70,17 @@ Value KJS::HTMLDocFunction::tryCall(Exec
     //doc.clear(); // TODO
     return Undefined();
   case HTMLDocument::Open:
+    if (args.size() >= 3) // IE extension for document.open: it means window.open if \
it has 3 args or more +    {
+      KHTMLView *view = static_cast<DOM::DocumentImpl*>(doc.handle())->view();
+      if ( view && view->part() ) {
+        Window* win = Window::retrieveWindow(view->part());
+        if( win ) {
+          win->openWindow(exec, args);
+        }
+      }
+    }
+
     doc.open();
     return Undefined();
   case HTMLDocument::Close:
@@ -144,18 +155,12 @@ bool KJS::HTMLDocument::hasProperty(Exec
 #endif
   DOM::HTMLDocument doc = static_cast<DOM::HTMLDocument>(node);
   // Keep in sync with tryGet
-  DOM::NodeListImpl* list = new DOM::NamedTagNodeListImpl( doc.handle(), ID_IMG, \
                propertyName.string() );
-  if ( list->length() ) {
-    delete list;
+  DOM::NodeList list( new DOM::NamedTagNodeListImpl( doc.handle(), ID_IMG, \
propertyName.string() ) ); +  if ( list.length() )
     return true;
-  }
-  delete list;
   list = new DOM::NamedTagNodeListImpl( doc.handle(), ID_FORM, propertyName.string() \
                );
-  if ( list->length() ) {
-    delete list;
+  if ( list.length() )
     return true;
-  }
-  delete list;
   KHTMLView *view = static_cast<DOM::DocumentImpl*>(doc.handle())->view();
   if ( view && view->part() )
   {
Index: kjs_window.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/ecma/kjs_window.cpp,v
retrieving revision 1.282
diff -u -p -r1.282 kjs_window.cpp
--- kjs_window.cpp	2002/10/24 17:05:01	1.282
+++ kjs_window.cpp	2002/10/25 23:20:40
@@ -994,6 +994,161 @@ void Window::goHistory( int steps )
   //emit ext->goHistory(steps);
 }
 
+Value Window::openWindow(ExecState *exec, const List& args)
+{
+  KHTMLView *widget = m_part->view();
+  Value v = args[0];
+  UString s = v.toString(exec);
+  QString str = s.qstring();
+
+  KConfig *config = new KConfig("konquerorrc");
+  config->setGroup("Java/JavaScript Settings");
+  int policy = config->readUnsignedNumEntry( "WindowOpenPolicy", 0 ); // 0=allow, \
1=ask, 2=deny, 3=smart +  delete config;
+  if ( policy == 1 ) {
+    if ( KMessageBox::questionYesNo(widget,
+                                    i18n( "This site is trying to open up a new \
browser " +                                          "window using Javascript.\n"
+                                          "Do you want to allow this?" ),
+                                    i18n( "Confirmation: Javascript Popup" ) ) == \
KMessageBox::Yes ) +      policy = 0;
+  } else if ( policy == 3 ) // smart
+  {
+    // window.open disabled unless from a key/mouse event
+    if (static_cast<ScriptInterpreter \
*>(exec->interpreter())->isWindowOpenAllowed()) +      policy = 0;
+  }
+  if ( policy != 0 ) {
+    return Undefined();
+  } else {
+    KParts::WindowArgs winargs;
+
+    // scan feature argument
+    v = args[2];
+    QString features;
+    if (!v.isNull()) {
+      features = v.toString(exec).qstring();
+      // specifying window params means false defaults
+      winargs.menuBarVisible = false;
+      winargs.toolBarsVisible = false;
+      winargs.statusBarVisible = false;
+      QStringList flist = QStringList::split(',', features);
+      QStringList::ConstIterator it = flist.begin();
+      while (it != flist.end()) {
+        QString s = *it++;
+        QString key, val;
+        int pos = s.find('=');
+        if (pos >= 0) {
+          key = s.left(pos).stripWhiteSpace().lower();
+          val = s.mid(pos + 1).stripWhiteSpace().lower();
+
+          int scnum = \
QApplication::desktop()->screenNumber(widget->topLevelWidget()); +
+          QRect screen = QApplication::desktop()->screenGeometry(scnum);
+          if (key == "left" || key == "screenx") {
+            winargs.x = val.toInt() + screen.x();
+            if (winargs.x < screen.x() || winargs.x > screen.right())
+              winargs.x = screen.x(); // only safe choice until size is determined
+          } else if (key == "top" || key == "screeny") {
+            winargs.y = val.toInt() + screen.y();
+            if (winargs.y < screen.y() || winargs.y > screen.bottom())
+              winargs.y = screen.y(); // only safe choice until size is determined
+          } else if (key == "height") {
+            winargs.height = val.toInt() + 2*qApp->style().pixelMetric( \
QStyle::PM_DefaultFrameWidth ) + 2; +            if (winargs.height > \
screen.height())  // should actually check workspace +              winargs.height = \
screen.height(); +            if (winargs.height < 100)
+              winargs.height = 100;
+          } else if (key == "width") {
+            winargs.width = val.toInt() + 2*qApp->style().pixelMetric( \
QStyle::PM_DefaultFrameWidth ) + 2; +            if (winargs.width > screen.width())  \
// should actually check workspace +              winargs.width = screen.width();
+            if (winargs.width < 100)
+              winargs.width = 100;
+          } else {
+            goto boolargs;
+          }
+          continue;
+        } else {
+          // leaving away the value gives true
+          key = s.stripWhiteSpace().lower();
+          val = "1";
+        }
+      boolargs:
+        if (key == "menubar")
+          winargs.menuBarVisible = (val == "1" || val == "yes");
+        else if (key == "toolbar")
+          winargs.toolBarsVisible = (val == "1" || val == "yes");
+        else if (key == "location")  // ### missing in WindowArgs
+          winargs.toolBarsVisible = (val == "1" || val == "yes");
+        else if (key == "status" || key == "statusbar")
+          winargs.statusBarVisible = (val == "1" || val == "yes");
+        else if (key == "resizable")
+          winargs.resizable = (val == "1" || val == "yes");
+        else if (key == "fullscreen")
+          winargs.fullscreen = (val == "1" || val == "yes");
+      }
+    }
+
+    // prepare arguments
+    KURL url;
+    if (!str.isEmpty())
+    {
+      KHTMLPart* p = Window::retrieveActive(exec)->m_part;
+      if ( p )
+        url = p->htmlDocument().completeURL(str).string();
+    }
+
+    KParts::URLArgs uargs;
+    KHTMLPart *p = m_part;
+    uargs.frameName = !args[1].isNull() ?
+                      args[1].toString(exec).qstring()
+                      : QString("_blank");
+    if ( uargs.frameName == "_top" )
+    {
+      while ( p->parentPart() )
+        p = p->parentPart();
+      p->scheduleRedirection(-1, url.url(), false/*don't lock history*/);
+      return Window::retrieve(p);
+    }
+    if ( uargs.frameName == "_parent" )
+    {
+      if ( p->parentPart() )
+        p = p->parentPart();
+      p->scheduleRedirection(-1, url.url(), false/*don't lock history*/);
+      return Window::retrieve(p);
+    }
+    uargs.serviceType = "text/html";
+
+    // request window (new or existing if framename is set)
+    KParts::ReadOnlyPart *newPart = 0L;
+    emit p->browserExtension()->createNewWindow("", uargs,winargs,newPart);
+    if (newPart && newPart->inherits("KHTMLPart")) {
+      KHTMLPart *khtmlpart = static_cast<KHTMLPart*>(newPart);
+      //qDebug("opener set to %p (this Window's part) in new Window %p  (this \
Window=%p)",part,win,window); +      khtmlpart->setOpener(p);
+      khtmlpart->setOpenedByJS(true);
+      if (khtmlpart->document().isNull()) {
+        khtmlpart->begin();
+        khtmlpart->write("<HTML><BODY>");
+        khtmlpart->end();
+        if ( p->docImpl() ) {
+          kdDebug(6070) << "Setting domain to " << p->docImpl()->domain().string() \
<< endl; +          khtmlpart->docImpl()->setDomain( p->docImpl()->domain());
+          khtmlpart->docImpl()->setBaseURL( p->docImpl()->baseURL() );
+        }
+      }
+      uargs.serviceType = QString::null;
+      if (uargs.frameName == "_blank")
+        uargs.frameName = QString::null;
+      if (!url.isEmpty())
+        emit khtmlpart->browserExtension()->openURLRequest(url,uargs);
+      return Window::retrieve(khtmlpart); // global object
+    } else
+      return Undefined();
+  }
+}
+
 Value WindowFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
 {
   KJS_CHECK_THIS( Window, thisObj );
@@ -1034,153 +1189,7 @@ Value WindowFunc::tryCall(ExecState *exe
     else
         return Null();
   case Window::Open:
-  {
-    KConfig *config = new KConfig("konquerorrc");
-    config->setGroup("Java/JavaScript Settings");
-    int policy = config->readUnsignedNumEntry( "WindowOpenPolicy", 0 ); // 0=allow, \
                1=ask, 2=deny, 3=smart
-    delete config;
-    if ( policy == 1 ) {
-      if ( KMessageBox::questionYesNo(widget,
-                                      i18n( "This site is trying to open up a new \
                browser "
-                                            "window using Javascript.\n"
-                                            "Do you want to allow this?" ),
-                                      i18n( "Confirmation: Javascript Popup" ) ) == \
                KMessageBox::Yes )
-        policy = 0;
-    } else if ( policy == 3 ) // smart
-    {
-      // window.open disabled unless from a key/mouse event
-      if (static_cast<ScriptInterpreter \
                *>(exec->interpreter())->isWindowOpenAllowed())
-        policy = 0;
-    }
-    if ( policy != 0 ) {
-      return Undefined();
-    } else {
-      KParts::WindowArgs winargs;
-
-      // scan feature argument
-      v = args[2];
-      QString features;
-      if (!v.isNull()) {
-        features = v.toString(exec).qstring();
-        // specifying window params means false defaults
-        winargs.menuBarVisible = false;
-        winargs.toolBarsVisible = false;
-        winargs.statusBarVisible = false;
-        QStringList flist = QStringList::split(',', features);
-        QStringList::ConstIterator it = flist.begin();
-        while (it != flist.end()) {
-          QString s = *it++;
-          QString key, val;
-          int pos = s.find('=');
-          if (pos >= 0) {
-            key = s.left(pos).stripWhiteSpace().lower();
-            val = s.mid(pos + 1).stripWhiteSpace().lower();
-
-            int scnum = \
                QApplication::desktop()->screenNumber(widget->topLevelWidget());
-
-	    QRect screen = QApplication::desktop()->screenGeometry(scnum);
-            if (key == "left" || key == "screenx") {
-              winargs.x = val.toInt() + screen.x();
-	      if (winargs.x < screen.x() || winargs.x > screen.right())
-		  winargs.x = screen.x(); // only safe choice until size is determined
-            } else if (key == "top" || key == "screeny") {
-              winargs.y = val.toInt() + screen.y();
-	      if (winargs.y < screen.y() || winargs.y > screen.bottom())
-		  winargs.y = screen.y(); // only safe choice until size is determined
-            } else if (key == "height") {
-              winargs.height = val.toInt() + 2*qApp->style().pixelMetric( \
                QStyle::PM_DefaultFrameWidth ) + 2;
-	      if (winargs.height > screen.height())  // should actually check workspace
-		  winargs.height = screen.height();
-              if (winargs.height < 100)
-		  winargs.height = 100;
-            } else if (key == "width") {
-              winargs.width = val.toInt() + 2*qApp->style().pixelMetric( \
                QStyle::PM_DefaultFrameWidth ) + 2;
-	      if (winargs.width > screen.width())    // should actually check workspace
-		  winargs.width = screen.width();
-              if (winargs.width < 100)
-		  winargs.width = 100;
-            } else {
-              goto boolargs;
-	    }
-            continue;
-          } else {
-            // leaving away the value gives true
-            key = s.stripWhiteSpace().lower();
-            val = "1";
-          }
-        boolargs:
-          if (key == "menubar")
-            winargs.menuBarVisible = (val == "1" || val == "yes");
-          else if (key == "toolbar")
-            winargs.toolBarsVisible = (val == "1" || val == "yes");
-          else if (key == "location")  // ### missing in WindowArgs
-            winargs.toolBarsVisible = (val == "1" || val == "yes");
-          else if (key == "status" || key == "statusbar")
-            winargs.statusBarVisible = (val == "1" || val == "yes");
-          else if (key == "resizable")
-            winargs.resizable = (val == "1" || val == "yes");
-          else if (key == "fullscreen")
-            winargs.fullscreen = (val == "1" || val == "yes");
-        }
-      }
-
-      // prepare arguments
-      KURL url;
-      if (!str.isEmpty())
-      {
-        KHTMLPart* p = Window::retrieveActive(exec)->m_part;
-        if ( p )
-          url = p->htmlDocument().completeURL(str).string();
-      }
-
-      KParts::URLArgs uargs;
-      uargs.frameName = !args[1].isNull() ?
-                        args[1].toString(exec).qstring()
-                        : QString("_blank");
-      if ( uargs.frameName == "_top" )
-      {
-          while ( part->parentPart() )
-              part = part->parentPart();
-          part->scheduleRedirection(-1, url.url(), false/*don't lock history*/);
-          return Window::retrieve(part);
-      }
-      if ( uargs.frameName == "_parent" )
-      {
-          if ( part->parentPart() )
-              part = part->parentPart();
-          part->scheduleRedirection(-1, url.url(), false/*don't lock history*/);
-          return Window::retrieve(part);
-      }
-      uargs.serviceType = "text/html";
-
-      // request window (new or existing if framename is set)
-      KParts::ReadOnlyPart *newPart = 0L;
-      emit part->browserExtension()->createNewWindow("", uargs,winargs,newPart);
-      if (newPart && newPart->inherits("KHTMLPart")) {
-        KHTMLPart *khtmlpart = static_cast<KHTMLPart*>(newPart);
-        //qDebug("opener set to %p (this Window's part) in new Window %p  (this \
                Window=%p)",part,win,window);
-        khtmlpart->setOpener(part);
-        khtmlpart->setOpenedByJS(true);
-        if (khtmlpart->document().isNull()) {
-          khtmlpart->begin();
-          khtmlpart->write("<HTML><BODY>");
-          khtmlpart->end();
-          if ( part->docImpl() ) {
-            kdDebug(6070) << "Setting domain to " << \
                part->docImpl()->domain().string() << endl;
-            khtmlpart->docImpl()->setDomain( part->docImpl()->domain());
-            khtmlpart->docImpl()->setBaseURL( part->docImpl()->baseURL() );
-          }
-        }
-        uargs.serviceType = QString::null;
-        if (uargs.frameName == "_blank")
-          uargs.frameName = QString::null;
-        if (!url.isEmpty())
-          emit khtmlpart->browserExtension()->openURLRequest(url,uargs);
-        return Window::retrieve(khtmlpart); // global object
-      } else
-        return Undefined();
-    }
-  }
+    return window->openWindow(exec, args);
   case Window::ScrollBy:
     if(args.size() == 2 && widget)
       widget->scrollBy(args[0].toInt32(exec), args[1].toInt32(exec));
Index: kjs_window.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/ecma/kjs_window.h,v
retrieving revision 1.83
diff -u -p -r1.83 kjs_window.h
--- kjs_window.h	2002/10/13 08:34:36	1.83
+++ kjs_window.h	2002/10/25 23:20:40
@@ -93,6 +93,7 @@ namespace KJS {
     void closeNow();
     void delayedGoHistory(int steps);
     void goHistory(int steps);
+    Value openWindow(ExecState *exec, const List &args);
     void afterScriptExecution();
     bool isSafeScript(ExecState *exec) const;
     Location *location() const;



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic