private void _initJSErrorHook() { // nsIWebBrowser wb = (nsIWebBrowser) m_browser.getWebBrowser(); Mozilla mz = Mozilla.getInstance(); nsIServiceManager sm = mz.getServiceManager(); nsIConsoleService con = (nsIConsoleService) sm.getServiceByContractID( "@mozilla.org/consoleservice;1", nsIConsoleService.NS_ICONSOLESERVICE_IID); nsIConsoleListener lis = new nsIConsoleListener() { public nsISupports queryInterface(String uuid) { if (!uuid.equals(NS_ISUPPORTS_IID) && !uuid.equals(nsIConsoleListener.NS_ICONSOLELISTENER_IID)) { throw new XPCOMException(IXPCOMError.NS_ERROR_NOT_IMPLEMENTED); } return this; } public void observe(nsIConsoleMessage aMsg) { // JavaScript Error System.out.println("console -> " + aMsg.getMessage()); } }; con.registerListener(lis); }
/** @see com.aptana.ide.editors.unified.ContributedBrowser#dispose() */ public void dispose() { browser.dispose(); if (hand != null && !hand.isDisposed()) { hand.dispose(); } errors.dispose(); nsIConsoleService service = (nsIConsoleService) Mozilla.getInstance() .getServiceManager() .getServiceByContractID( "@mozilla.org/consoleservice;1", nsIConsoleService.NS_ICONSOLESERVICE_IID); // $NON-NLS-1$ service.unregisterListener(errorListener); }
/** * @see * com.aptana.ide.editors.unified.ContributedBrowser#createControl(org.eclipse.swt.widgets.Composite) */ public void createControl(Composite parent) { browser = createSWTBrowser(parent); browser.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); errors = new Composite(parent, SWT.NONE); GridLayout eLayout = new GridLayout(2, false); eLayout.marginHeight = 1; eLayout.marginWidth = 1; eLayout.horizontalSpacing = 2; errors.setLayout(eLayout); errors.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); hand = new Cursor(errors.getDisplay(), SWT.CURSOR_HAND); errorIcon = new Label(errors, SWT.LEFT); errorIcon.setCursor(hand); MouseAdapter showConsole = new MouseAdapter() { public void mouseDown(MouseEvent e) { ConsolePlugin.getDefault() .getConsoleManager() .showConsoleView(FirefoxConsole.getConsole()); } }; errorIcon.setLayoutData(new GridData(SWT.END, SWT.FILL, true, true)); errorIcon.addMouseListener(showConsole); errorLabel = new Label(errors, SWT.LEFT); errorLabel.setCursor(hand); errorLabel.addMouseListener(showConsole); errorLabel.setForeground(errorLabel.getDisplay().getSystemColor(SWT.COLOR_DARK_RED)); errorLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, true)); nsIConsoleService service = (nsIConsoleService) Mozilla.getInstance() .getServiceManager() .getServiceByContractID( "@mozilla.org/consoleservice;1", nsIConsoleService.NS_ICONSOLESERVICE_IID); // $NON-NLS-1$ service.registerListener(errorListener); // Hook console FirefoxConsole.getConsole(); }