2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.bck2brwsr.debugger;
20 import java.awt.event.ActionEvent;
21 import java.awt.event.ActionListener;
22 import java.net.MalformedURLException;
24 import org.netbeans.api.debugger.Session;
25 import org.netbeans.api.project.Project;
26 import org.netbeans.modules.web.browser.api.BrowserSupport;
27 import org.netbeans.modules.web.browser.api.WebBrowser;
28 import org.netbeans.modules.web.browser.api.WebBrowsers;
29 import org.netbeans.modules.web.webkit.debugging.api.WebKitDebugging;
30 import org.netbeans.modules.web.webkit.debugging.spi.netbeansdebugger.NetBeansJavaScriptDebuggerFactory;
31 import org.openide.awt.ActionID;
32 import org.openide.awt.ActionReference;
33 import org.openide.awt.ActionRegistration;
34 import org.openide.awt.HtmlBrowser;
35 import org.openide.util.Exceptions;
36 import org.openide.util.Lookup;
40 * @author Jaroslav Tulach <jtulach@netbeans.org>
42 @ActionID(category = "Debug", id = "org.apidesign.bck2brwsr.Debug")
43 @ActionRegistration(displayName = "Bck2brwsr debugger", asynchronous = true)
44 @ActionReference(path = "Menu/DebugProject", position = 33333)
45 public final class DebugBck2Brwsr implements ActionListener {
46 private final Project project;
48 public DebugBck2Brwsr(Project p) {
54 public void actionPerformed(ActionEvent e) {
56 URL url = new URL("http://localhost:8383/HTML5Application/index.html");
57 BrowserSupport.getDefaultEmbedded().load(url, project.getProjectDirectory());
59 for (WebBrowser web : WebBrowsers.getInstance().getAll(true)) {
60 HtmlBrowser.Impl impl = web.getHtmlBrowserFactory().createHtmlBrowserImpl();
61 WebKitDebugging wkd = impl.getLookup().lookup(WebKitDebugging.class);
64 Session session = startSession(wkd, project.getLookup());
65 System.err.println("debugging : " + session.getCurrentLanguage());
68 // Collection<? extends Object> res = pane.getLookup().lookupAll(Object.class);
69 System.err.println("res: " + wkd);
72 } catch (MalformedURLException ex) {
73 Exceptions.printStackTrace(ex);
77 private static Session startSession(WebKitDebugging wkd, Lookup context) {
78 final String sevenThree = "org.netbeans.modules.web.webkit.debugging.spi.netbeansdebugger.NetBeansJavaScriptDebuggerFactory";
79 final String sevenFour = "org.netbeans.modules.web.webkit.debugging.spi.JavaScriptDebuggerFactory";
83 cls = Class.forName(sevenFour);
84 } catch (ClassNotFoundException ex1) {
86 cls = Class.forName(sevenThree);
87 } catch (ClassNotFoundException ex) {
88 throw new IllegalStateException("Can't start debug session", ex);
92 Object inst = Lookup.getDefault().lookup(cls);
95 java.lang.reflect.Method m = cls.getMethod("createDebuggingSession", WebKitDebugging.class, Lookup.class);
96 return (Session)m.invoke(inst, wkd, context);
97 } catch (Exception ex) {
98 throw new IllegalStateException(ex);