php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37927 NewWindow2 event not firing
Submitted: 2006-06-27 13:47 UTC Modified: 2007-02-02 15:51 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: massimiliano_ciceri at it dot ibm dot com Assigned: wharmby (profile)
Status: Closed Package: COM related
PHP Version: 5.1.4 OS: windows 2000
Private report: No CVE-ID: None
 [2006-06-27 13:47 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-27 13:56 UTC] 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.
 [2007-01-23 16:47 UTC] 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.
 [2007-01-25 17:34 UTC] wharmby at uk dot ibm dot com
I will take a look at this one next.
 [2007-01-25 19:46 UTC] 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-26 16:48 UTC] wharmby at uk dot ibm dot com
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.
 [2007-02-02 08:48 UTC] wharmby@php.net
Issue with NewWindow2 event now fixed in HEAD. Will send patch to Ilia for approval for drop into 5.2
 [2007-02-02 10:31 UTC] wharmby at uk dot ibm dot com
PHP 5.2 patch sent to Ilia for approval.
 [2007-02-02 15:51 UTC] wharmby@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Fix now in PHP_5_2 branch
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC