public BrowserExample(org.eclipse.swt.widgets.Composite parent, boolean top) { this.parent = parent; try { browser = new org.eclipse.swt.browser.Browser(parent, SWT.BORDER); } catch (org.eclipse.swt.SWTError e) { error = e; parent.setLayout(new org.eclipse.swt.layout.FillLayout()); org.eclipse.swt.widgets.Label label = new org.eclipse.swt.widgets.Label(parent, SWT.CENTER | SWT.WRAP); label.setText(getResourceString("BrowserNotCreated")); parent.layout(true); return; } initResources(); final org.eclipse.swt.widgets.Display display = parent.getDisplay(); browser.setData("org.eclipse.swt.examples.browserexample.BrowserApplication", this); browser.addOpenWindowListener( new org.eclipse.swt.browser.OpenWindowListener() { public void open(org.eclipse.swt.browser.WindowEvent event) { org.eclipse.swt.widgets.Shell shell = new org.eclipse.swt.widgets.Shell(display); if (icon != null) { shell.setImage(icon); } shell.setLayout(new org.eclipse.swt.layout.FillLayout()); org.eclipse.swt.examples.browserexample.BrowserExample app = new org.eclipse.swt.examples.browserexample.BrowserExample(shell, false); app.setShellDecoration(icon, true); event.browser = app.getBrowser(); } }); if (top) { browser.setUrl(getResourceString("Startup")); show(false, null, null, true, true, true, true); } else { browser.addVisibilityWindowListener( new org.eclipse.swt.browser.VisibilityWindowListener() { public void hide(org.eclipse.swt.browser.WindowEvent e) {} public void show(org.eclipse.swt.browser.WindowEvent e) { org.eclipse.swt.browser.Browser browser = (org.eclipse.swt.browser.Browser) e.widget; org.eclipse.swt.examples.browserexample.BrowserExample app = (org.eclipse.swt.examples.browserexample.BrowserExample) browser.getData("org.eclipse.swt.examples.browserexample.BrowserApplication"); app.show(true, e.location, e.size, e.addressBar, e.menuBar, e.statusBar, e.toolBar); } }); browser.addCloseWindowListener( new org.eclipse.swt.browser.CloseWindowListener() { public void close(org.eclipse.swt.browser.WindowEvent event) { org.eclipse.swt.browser.Browser browser = (org.eclipse.swt.browser.Browser) event.widget; org.eclipse.swt.widgets.Shell shell = browser.getShell(); shell.close(); } }); } }
public static boolean test1(String url) { if (verbose) System.out.println( "javascript window.open with location and size parameters - args: " + url + "\n Expected Event Sequence: Visibility.show"); passed = false; final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Browser browser = new Browser(shell, SWT.NONE); browser.addOpenWindowListener( new OpenWindowListener() { public void open(WindowEvent event) { if (verbose) System.out.println("OpenWindow " + index); Shell newShell = new Shell(display); newShell.setLayout(new FillLayout()); Browser browser = new Browser(newShell, SWT.NONE); browser.setData("index", new Integer(index)); browser.addVisibilityWindowListener( new VisibilityWindowListener() { public void hide(WindowEvent event) {} public void show(WindowEvent event) { Browser browser = (Browser) event.widget; Shell parent = browser.getShell(); Point location = event.location; Point size = event.size; if (location != null) parent.setLocation(location); if (size != null) parent.setSize(size); int index = ((Integer) browser.getData("index")).intValue(); parent.setText("SWT Browser shell " + index); parent.open(); if (index < 0) { /* Certain browsers fire multiple show events for no good reason. Further show events * are considered 'legal' as long as they don't contain size and location information. */ if (location != null || size != null) { if (verbose) System.out.println( "Failure - Browser " + index + " is receiving multiple show events"); passed = false; shell.close(); } else { if (verbose) System.out.println( "Unnecessary (but harmless) visibility.show event Browser " + index); } } else { if (verbose) System.out.println( "Visibility.show browser " + index + " location " + location + " size " + size); browser.setData("index", new Integer(-100 - index)); /* Certain browsers include decorations in addition to the expected size. * Accept sizes that are greater than or equal to the expected size. * Certain browsers invent size or location when some parameters are missing. * If we expect null for one of size or location, also accept non null answers. */ Point expectedLocation = regressionBounds[index][0]; Point expectedSize = regressionBounds[index][1]; if (verbose) System.out.println( "Expected location " + expectedLocation + " size " + expectedSize); boolean checkLocation = (location == null && expectedLocation == null) || (location != null && location.equals(expectedLocation) || (location != null && expectedLocation == null)); boolean checkSize = (size == null && expectedSize == null) || (size != null && size.equals(expectedSize)) || (size != null && expectedSize == null) || (size != null && size.x >= expectedSize.x && size.y >= expectedSize.y); if (!checkSize || !checkLocation) { if (verbose) System.out.println(" Failure "); passed = false; shell.close(); return; } else cntPassed++; } } }); browser.addCloseWindowListener( new CloseWindowListener() { public void close(WindowEvent event) { cntClosed++; if (verbose) System.out.println("Close"); Browser browser = (Browser) event.widget; browser.getShell().close(); if (cntPassed == regressionBounds.length) passed = true; if (cntClosed == regressionBounds.length) { shell.close(); return; } } }); event.browser = browser; index++; } }); shell.open(); browser.setUrl(url); boolean timeout = runLoopTimer(display, shell, 600); if (timeout) passed = false; display.dispose(); return passed; }
private Browser createSWTBrowser(Composite parent) { try { if (System.getProperty(XULRUNNER_ENV) == null) { Bundle bundle = null; if (CoreUIUtils.onWindows) { bundle = Platform.getBundle(XULRUNNER_WIN32_PLUGIN); } else if (CoreUIUtils.onMacOSX) { bundle = Platform.getBundle(XULRUNNER_MAC_PLUGIN); } if (bundle != null) { URL xulrunner = bundle.getEntry(XULRUNNER_PATH); if (xulrunner != null) { try { xulrunner = FileLocator.toFileURL(xulrunner); if (xulrunner != null) { File xulrunnerFolder = new File(xulrunner.getFile()); String message = MessageFormat.format( Messages.getString("FirefoxBrowser.Setting_Path_To"), // $NON-NLS-1$ new Object[] {xulrunnerFolder.getAbsolutePath()}); System.setProperty(XULRUNNER_ENV, xulrunnerFolder.getAbsolutePath()); IdeLog.logInfo(Activator.getDefault(), message); } } catch (IOException e) { IdeLog.logError( Activator.getDefault(), Messages.getString("FirefoxBrowser.Error_Setting_Path"), e); //$NON-NLS-1$ } } } } } catch (Exception e) { IdeLog.logError( Activator.getDefault(), Messages.getString("FirefoxBrowser.Error_Setting_Path"), e); //$NON-NLS-1$ } browser = new Browser(parent, SWT.MOZILLA); browser.addProgressListener(progressListener); browser.addOpenWindowListener(openWindowListener); // Disable Java nsIPrefService prefService = (nsIPrefService) Mozilla.getInstance() .getServiceManager() .getServiceByContractID( "@mozilla.org/preferences-service;1", nsIPrefService.NS_IPREFSERVICE_IID); // $NON-NLS-1$ nsIPrefBranch prefBranch = prefService.getBranch(""); // $NON-NLS-1$ prefBranch.setBoolPref("security.enable_java", 0); // $NON-NLS-1$ if (Platform.OS_MACOSX.equals(Platform.getOS())) { nsIWebBrowserSetup webBrowserSetup = (nsIWebBrowserSetup) internalGetWebBrowser().queryInterface(nsIWebBrowserSetup.NS_IWEBBROWSERSETUP_IID); if (webBrowserSetup != null) { webBrowserSetup.setProperty(nsIWebBrowserSetup.SETUP_ALLOW_PLUGINS, 0); } } return browser; }