diff -r 000000000000 -r 615c4158fbbb ide/debugger/src/main/java/org/apidesign/bck2brwsr/debugger/DebugBck2Brwsr.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ide/debugger/src/main/java/org/apidesign/bck2brwsr/debugger/DebugBck2Brwsr.java Sat Mar 30 07:55:27 2013 +0100 @@ -0,0 +1,101 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.debugger; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.net.MalformedURLException; +import java.net.URL; +import org.netbeans.api.debugger.Session; +import org.netbeans.api.project.Project; +import org.netbeans.modules.web.browser.api.BrowserSupport; +import org.netbeans.modules.web.browser.api.WebBrowser; +import org.netbeans.modules.web.browser.api.WebBrowsers; +import org.netbeans.modules.web.webkit.debugging.api.WebKitDebugging; +import org.netbeans.modules.web.webkit.debugging.spi.netbeansdebugger.NetBeansJavaScriptDebuggerFactory; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionRegistration; +import org.openide.awt.HtmlBrowser; +import org.openide.util.Exceptions; +import org.openide.util.Lookup; + +/** + * + * @author Jaroslav Tulach + */ +@ActionID(category = "Debug", id = "org.apidesign.bck2brwsr.Debug") +@ActionRegistration(displayName = "Bck2brwsr debugger", asynchronous = true) +@ActionReference(path = "Menu/DebugProject", position = 33333) +public final class DebugBck2Brwsr implements ActionListener { + private final Project project; + + public DebugBck2Brwsr(Project p) { + this.project = p; + } + + + @Override + public void actionPerformed(ActionEvent e) { + try { + URL url = new URL("http://localhost:8383/HTML5Application/index.html"); + BrowserSupport.getDefaultEmbedded().load(url, project.getProjectDirectory()); + /* + for (WebBrowser web : WebBrowsers.getInstance().getAll(true)) { + HtmlBrowser.Impl impl = web.getHtmlBrowserFactory().createHtmlBrowserImpl(); + WebKitDebugging wkd = impl.getLookup().lookup(WebKitDebugging.class); + if (wkd != null) { + impl.setURL(url); + Session session = startSession(wkd, project.getLookup()); + System.err.println("debugging : " + session.getCurrentLanguage()); + return; + } + // Collection res = pane.getLookup().lookupAll(Object.class); + System.err.println("res: " + wkd); + } + */ + } catch (MalformedURLException ex) { + Exceptions.printStackTrace(ex); + } + } + + private static Session startSession(WebKitDebugging wkd, Lookup context) { + final String sevenThree = "org.netbeans.modules.web.webkit.debugging.spi.netbeansdebugger.NetBeansJavaScriptDebuggerFactory"; + final String sevenFour = "org.netbeans.modules.web.webkit.debugging.spi.JavaScriptDebuggerFactory"; + + Class cls; + try { + cls = Class.forName(sevenFour); + } catch (ClassNotFoundException ex1) { + try { + cls = Class.forName(sevenThree); + } catch (ClassNotFoundException ex) { + throw new IllegalStateException("Can't start debug session", ex); + } + } + + Object inst = Lookup.getDefault().lookup(cls); + + try { + java.lang.reflect.Method m = cls.getMethod("createDebuggingSession", WebKitDebugging.class, Lookup.class); + return (Session)m.invoke(inst, wkd, context); + } catch (Exception ex) { + throw new IllegalStateException(ex); + } + } +}