Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 338602

Summary: IBrowserRidget - API to intercept and prevent URL changes
Product: [RT] Riena Reporter: Elias Volanakis <elias>
Component: ridgetAssignee: Elias Volanakis <elias>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: 3.0.0   
Hardware: PC   
OS: Windows Vista   
Whiteboard:

Description Elias Volanakis CLA 2011-03-01 18:31:41 EST
For the IBrowserRidget we need API to intercept and prevent URL changes.

This should be possible using SWTs LocationListener / LocationEvent. The proposed API will be based on that, but toolkit independent.
Comment 1 Elias Volanakis CLA 2011-03-01 18:36:03 EST
Committing 1st implementation.

Example Snippet:

  	      browserRidget.addLocationListener(new ILocationListener() {
				public boolean locationChanging(final LocationEvent event) {
					System.out.println(event);
					final String msg = String.format("Go to:\n\n'%s' ?", event.getLocation());
					return MessageDialog.openQuestion(shell, "Confirm Change", msg);
				}
			});

Technical notes:

- The listener cannot prevent _some_ changes. For example: clicks that trigger javascripts (dom changes) or that open urls with <a href="" target="_blank"> do not fire events and therefore cannot be caught
- Per design - changing the URL via API calls (i.e. setUrl(...), setText(...)) does not fire events or notify the listener. This is constintent with SWT patterns, to avoid endless listener-event-listener loops.
- Per design - rebinding the ridget to another browser widget does not notify the listeners. (though this could be discussed)
Comment 2 Elias Volanakis CLA 2011-03-07 20:11:40 EST
Notes:

- added LocationEvent.isAllowed() flag - this can be used to check if another listener has already vetoed the change.
- added ILocationListener.locationChanged() to receive notification of successful url changes - this is equivalent to browserRidget.addPropertyListener(IBrowserRidget.PROPERTY_URL, lsnr);

Resolved.