ID: 37927 Comment by: wharmby at uk dot ibm dot com Reported By: massimiliano_ciceri at it dot ibm dot com Status: Assigned Bug Type: COM related Operating System: windows 2000 PHP Version: 5.1.4 Assigned To: wez New Comment:
Patch for issue with DWebBrowserEvents2::NewWindow2 event handler not getting called posted on internals list for review. You will need the fix for defect 34564 as well to enable you to cancel any navigation though. As for probelms with DWebBrowserEvents::NewWindow I believe these are IE related and the DWebBrowserEvents interface should no longer be used; the MSDN page which describes it does say its obsolete and to use DWebBrowserEvents2 instead. During my investigation I found 2 problems with the DWebBrowserEvents interface which appear IE related and not issues in the COM extension itself: (1) The interface defines NewWindow as an event that takes just 2 arguments. However it appears to actually takes 6 !!. The COM trace shows: [7060] T=00001de4 [7060] PHP:IEEventSinker InvokeEx [7060] T=00001de4 [7060] -- Invoke: 107 newwindow [9] flags=00000001 args=6 [7060] T=00001de4 [7060] alloc zval for arg 0 VT=00000008 [7060] T=00001de4 [7060] alloc zval for arg 1 VT=00000003 [7060] T=00001de4 [7060] alloc zval for arg 2 VT=00000008 [7060] T=00001de4 [7060] alloc zval for arg 3 VT=0000400c [7060] T=00001de4 [7060] alloc zval for arg 4 VT=00000008 [7060] T=00001de4 [7060] alloc zval for arg 5 VT=0000400b [7060] T=00001de4 [7060] arguments processed, prepare to do some work [7060] T=00001de4 [7060] function called ok So defining the event handler as described on the MSDN site will result in unpredictable behaviour; certainly navigation will not be prevented with the supplied testcase. The 6th argument is of type VT_VOOL so I am guessing that's the "cancel" argument. By adding dummy arguments to the event handler as follows: function NewWindow(&$dum1, $dum2, $dum3, $dum4, $dum5, &$Cancel) { $this->newWindowOpened = true; echo "NewWindow event was fired.\n"; variant_set($Cancel,true); return; } and with the fix for defect 345764 applied then the NewWindow event is fired the first time its tried and navigation is cancelled. However any subsequent attempt to open any link in a new window is also prevented even though not all attempts result in a NewWindow event being reported and occasionally I am unable to close down IE so perhaps my guess at what the 6th argument does is invalid!!. Everything is fine when DWebBrowserEvents2 interface is used. (2) The supplied testcase defines the "OnQuit" event which is, according to MSDN, defined by the DWebBrowserEvents interface. Alas not !! Or at least not using IE Version 6. The actual event name appears to be "Quit" and not "OnQuit". Again here is the COM trace of the event reported using the supplied test case: [6012] PHP:IEEventSinker InvokeEx [6012] T=00000ff0 [6012] -- Invoke: 103 quit [4] flags=00000001 args=1 [6012] T=00000ff0 [6012] alloc zval for arg 0 VT=0000000b [6012] T=00000ff0 [6012] arguments processed, prepare to do some work [6012] T=00000ff0 [6012] failed to call func This clearly shows the event is named "quit" and so the call to the any handler named "onQuit" fails. Modifying the testcase to define a method "Quit" and the user defined method fires OK. Previous Comments: ------------------------------------------------------------------------ [2007-01-25 19:46:46] wharmby at uk dot ibm dot com I have recreated the issue with NewWindow2 event and I believe I have identified the issue; problem in COM code processing in/out arguments of type VT_DISPATCH|VT_BYREF. Will check out fix tomorrow and post patch to internals list if its OK. ------------------------------------------------------------------------ [2007-01-25 17:34:27] wharmby at uk dot ibm dot com I will take a look at this one next. ------------------------------------------------------------------------ [2007-01-23 16:47:39] wharmby at uk dot ibm dot com I suspect the 2nd problem reported here, i.e "IE automation object NewWindow event cannot be cancelled." is the same issue has reported in defect 34564 for which I am currently working on a fix. ------------------------------------------------------------------------ [2006-06-27 13:56:18] massimiliano_ciceri at it dot ibm dot com $testcase value should be set to 1 for the first test as i mean in the source description... thanks to all of you. ------------------------------------------------------------------------ [2006-06-27 13:47:31] massimiliano_ciceri at it dot ibm dot com Description: ------------ Problem with: 1. IE automation object NewWindow2 event does not trigger. 2. IE automation object NewWindow event cannot be cancelled. This has been tested on PHP 5.1.4 and PHP 6 CVS and also on PHP 5 CSV. Regards, Massimiliano Reproduce code: --------------- <?php // 21.06.2006 reproducing bugs for NewWindow2 & NewWindow // instruction : // 1. run this with PHP cli 5.1.4 or PHP 6 CSV // 2. when the PHP home page completed in IExplore, try open a link in a new window // problem (1): the NewWindow2 event will not trigger as espected... // 3. try switch var testcase value to 2 to simulate second problem // problem (2): the NewWindow event trigger but you are not able to Cancel // it... A new page will be created and opened on the target url // you clicked on. $testcase = 2; // switch test code from case=1 to case=2 class IEEventSinker { var $terminated = false; var $newWindowOpened = false; function NewWindow(&$ppDisp, &$Cancel) { $this->newWindowOpened = true; echo "<1>NewWindow event was fired.\n"; // $Cancel=true; // php 4 style ... variant_set($Cancel,true); // php 5 style ... echo "trying cancelling NewWindow event...\n"; return; } function NewWindow2(&$ppDisp, &$Cancel) { $this->newWindowOpened = true; echo "<2>NewWindow2 event was fired.\n"; // $Cancel=true; variant_set($Cancel,true); return; } function OnQuit() { $this->terminated = true; print "Browser Quit...\n"; } } $ie = new COM("InternetExplorer.Application"); if ($testcase==1) { // reproduce NewWindow2 problem $sink1 = new IEEventSinker(); com_event_sink($ie, $sink1, "DWebBrowserEvents2"); } if ($testcase==2) { // reproduce NewWindow problem $sink2 = new IEEventSinker(); com_event_sink($ie, $sink2, "DWebBrowserEvents"); } $ie->Visible = true; $ie->Navigate2("http://www.php.net",0); if ($testcase==1) { // reproduce NewWindow2 problem while(!$sink1->terminated) { com_message_pump(1280); } } if ($testcase==2) { // reproduce NewWindow problem while(!$sink2->terminated) { com_message_pump(1280); } } unset($ie); ?> Expected result: ---------------- NewWindow2 event received by the sink class. At least be able to cancel the event NewWindow. Actual result: -------------- 1) NewWindow2 event not triggered at all. 2) NewWindow event trigger but cannot cancel it. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=37927&edit=1