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

Bug 317163

Summary: Browser.java dispatching to platform specific implementation has room for improvment
Product: [Eclipse Project] Platform Reporter: Christian Campo <christian.campo>
Component: SWTAssignee: Grant Gayed <grant_gayed>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: juergen.becker
Version: 3.6   
Target Milestone: 3.7 M2   
Hardware: All   
OS: All   
Whiteboard:

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