Bug 57068 - [browser] Curious behaviour on target=_blank links
Summary: [browser] Curious behaviour on target=_blank links
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Christophe Cornu CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-04-01 13:21 EST by Benjamin Pasero CLA
Modified: 2005-01-26 16:38 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Pasero CLA 2004-04-01 13:21:01 EST
Hi,

I am using the SWT browser widget to display HTML and let the user navigate 
through the WWW in my application. 

Earlier the browser ignored clicking on links that would open in a new window 
(with having target="_blank").

I've now found out the OpenWindowListener which could solve my problem. Playing 
around with it, I came up to this snippet, which shows a very strange behaviour:

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setText("Main Window");
		shell.setLayout(new FillLayout());
		Browser browser = new Browser(shell, SWT.NONE);
		initialize(display, browser);
		shell.open();
		browser.setUrl("C:/index.html");
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}

	static void initialize(final Display display, Browser browser) {
		browser.addOpenWindowListener(new OpenWindowListener() {
			public void open(WindowEvent event) {
				event.browser.getUrl();	//Comment / Uncomment 
this line!
			}
		});
	}

The file "index.html" is a local HTML file with a simple link that uses 
target="_blank".

Having the "event.browser.getUrl();" commented, nothing happens. But when 
uncommented, after clicking on the URL it opens in my system default browser 
(IE). 

I am also wondering, why the WindowEvent event does not provide information 
about the URL that the new browser-window will load?

Regards,
Ben
Comment 1 Christophe Cornu CLA 2004-04-02 18:40:28 EST
Thanks for reporting this!

The WindowEvent fired in a VisibilityWindowListener.show contains the location 
of the new window. If your application needs to handle new windows, you should 
handle all OpenWindowListener/VisibilityWindowListener/CloseWindowListener as 
indicated in the WindowEvent javadoc.
Comment 2 Steven Wasleski CLA 2004-05-14 15:10:48 EDT
So Christophe, it sounds like this is working how it is suppose to work and 
that Ben just has some more work to do to handle some more events.  Am I 
reading this correctly?  If so, please resolve this bug report as invalid.  If 
not, please advise on the status of this bug.
Comment 3 Benjamin Pasero CLA 2004-05-15 08:46:44 EDT
Hi Steven,

I just tried the snippet again with SWT 3.050 and experienced the same curious 
behaviour: When calling "event.browser.getUrl();" in OpenWindowListener the 
target="_blank" link in the index.html causes the IE to open the link into. 
Having that line commented, nothing happens.

Please correct me if I am wrong, but I dont think this behaviour is wanted?

Regards,
Ben
Comment 4 Christophe Cornu CLA 2004-05-18 13:24:19 EDT
Steven, this PR is to investigate further the strange IE behaviour 
demonstrated by Benjamin's snippet when getUrl is called from within 
OpenWindowListener.open. Comment 2 describes how to actually get the location 
of the new window.  The snippet exhibits an unexpected behaviour. Is this 
problem blocking you?
Comment 5 Steven Wasleski CLA 2004-05-18 17:20:12 EDT
It is not blocking me nor the product team that first brought it to my 
attention.  As for Ben and his project, I will leave it to him to evaluate how 
critical this one is.
Comment 6 Benjamin Pasero CLA 2004-05-19 04:01:59 EDT
Well this problem is not critical for my project, it was never. I just wanted 
to report this problem to Eclipse, after I've noticed it.
Comment 7 Christophe Cornu CLA 2004-10-29 16:07:49 EDT
At long last, here is the key to this mystery.

. event.browser is null (as defined in the javadoc of OpenWindowListener.open -
 this field is to be set by the listener) - so it's wrong to access it!
.event.browser.getUrl() triggers an NPE.

The code should be using ((Browser)event.widget).getUrl()

bug 4811 is going to improve the way exceptions are thrown from within DND and 
OLE callbacks. In that case, it was silently caught deep inside our OLE 
binding and leaving IE to a default mode of opening the window into a new 
window.
Comment 8 Christophe Cornu CLA 2005-01-26 16:38:15 EST
v>20050126 - setting appropriate default value expected by IE before 
application code has a chance at throwing exception. Previously, IE would 
assume the event was not handled and would bring a new instance in while the 
JVM throws an exception.