| Summary: | Browser.java dispatching to platform specific implementation has room for improvment | ||
|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Christian Campo <christian.campo> |
| Component: | SWT | Assignee: | 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: | |||
agreed, fixed > 20100820 |
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.