Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 317163 - Browser.java dispatching to platform specific implementation has room for improvment
Summary: Browser.java dispatching to platform specific implementation has room for imp...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.7 M2   Edit
Assignee: Grant Gayed CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-17 08:15 EDT by Christian Campo CLA
Modified: 2010-08-20 15:38 EDT (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 Christian Campo CLA 2010-06-17 08:15:46 EDT
Currently the Browser class has a gigantic "if" to detect the Browser class of choice that connects the actual platform specific Browser implementation:

	if ((style & SWT.MOZILLA) != 0) {
		className = "org.eclipse.swt.browser.Mozilla"; //$NON-NLS-1$
	} else {
		if ("win32".equals (platform) || "wpf".equals (platform)) { //$NON-NLS-1$ $NON-NLS-2$
			className = "org.eclipse.swt.browser.IE"; //$NON-NLS-1$
		} else if ("motif".equals (platform)) { //$NON-NLS-1$
			className = "org.eclipse.swt.browser.Mozilla"; //$NON-NLS-1$
		} else if ("gtk".equals (platform)) { //$NON-NLS-1$
			className = "org.eclipse.swt.browser.Mozilla"; //$NON-NLS-1$
		} else if ("carbon".equals (platform) || "cocoa".equals (platform)) { //$NON-NLS-1$
			className = "org.eclipse.swt.browser.Safari"; //$NON-NLS-1$
		} else if ("photon".equals (platform)) { //$NON-NLS-1$
			className = "org.eclipse.swt.browser.Voyager"; //$NON-NLS-1$
		} else {
			dispose ();
			SWT.error (SWT.ERROR_NO_HANDLES);
		}
	}
	
This design makes it unbearable hard for new platforms to add their implementation (and its a pretty bad design anyway). Also using strings and reflection to find a class is the second bad idea that I see here.

I propose to use a class BrowserFactory with a single static method createBrowser() which returns an instance of of WebBrowser and then every platform can easily implement its own version of BrowserFactory to retrieve the implementation.
Comment 1 Grant Gayed CLA 2010-08-20 15:38:34 EDT
agreed, fixed > 20100820