diff --git a/WicketSourceForChrome/background.js b/WicketSourceForChrome/background.js new file mode 100644 index 0000000..91df8dc --- /dev/null +++ b/WicketSourceForChrome/background.js @@ -0,0 +1,32 @@ +chrome.runtime.onMessage.addListener(function(request, sender, callback) { + function getServer() { + if (localStorage["server"]) { + return localStorage["server"]; + } + return "localhost"; + } + function getPort() { + if (localStorage["port"]) { + return localStorage["port"]; + } + return "9123"; + } + function getPassword() { + if (localStorage["password"]) { + return localStorage["password"]; + } + return ""; + } + + if (request.method == "getWicketsourceSidebarUrl") { + var url = "sidebar.html?ws=" + encodeURIComponent(request.wicketsourceString) + + "&wid=" + encodeURIComponent(request.wicketIdString) + + "&server=" + encodeURIComponent(getServer()) + + "&port=" + encodeURIComponent(getPort()) + + "&p=" + encodeURIComponent(getPassword()); + callback(url); + } + else { + callback(null); + } +}); diff --git a/WicketSourceForChrome/devtools.js b/WicketSourceForChrome/devtools.js index 7a387d3..3960f5c 100644 --- a/WicketSourceForChrome/devtools.js +++ b/WicketSourceForChrome/devtools.js @@ -6,26 +6,7 @@ chrome.devtools.panels.elements.createSidebarPane("WicketSource", function(sideb function Message() { this.message = "Select a node with a wicketsource attribute to see details."; } - - function getServer() { - if (localStorage["server"]) { - return localStorage["server"]; - } - return "localhost"; - } - function getPort() { - if (localStorage["port"]) { - return localStorage["port"]; - } - return "9123"; - } - function getPassword() { - if (localStorage["password"]) { - return localStorage["password"]; - } - return ""; - } - + // Listener event callback initiates "inspected-page context" data retrieval // (which understands currently selected node in the Inspect Element tab). function update() { @@ -34,35 +15,39 @@ chrome.devtools.panels.elements.createSidebarPane("WicketSource", function(sideb } function wicketIdEval(result, isException) { - if (!isException) { - this.wicketIdString = result; - } else { + if (isException) { this.wicketIdString = null; + } else { + this.wicketIdString = result; } } function wicketsourceEval(result, isException) { - if (!isException) { - this.wicketsourceString = result; + if (isException) { + this.wicketsourceString = null; } else { - this.wicketsourceString = null; + this.wicketsourceString = result; } displaySidebar(); } function displaySidebar() { if (this.wicketsourceString == null) { - var msg = new Message(); + var msg = new Message(); sidebar.setObject(msg); return; } - sidebar.setPage("sidebar.html?ws=" + encodeURIComponent(this.wicketsourceString) - + "&wid=" + encodeURIComponent(this.wicketIdString) - + "&server=" + encodeURIComponent(getServer()) - + "&port=" + encodeURIComponent(getPort()) - + "&p=" + encodeURIComponent(getPassword()) - ); - } + chrome.runtime.sendMessage( + { + method: "getWicketsourceSidebarUrl", + wicketsourceString: this.wicketsourceString, + wicketIdString: this.wicketIdString + }, + function(url) { + sidebar.setPage(url); + } + ); + } // On the way in the first time, show an instructional message. diff --git a/WicketSourceForChrome/manifest.json b/WicketSourceForChrome/manifest.json index 11f2e40..c3c9630 100644 --- a/WicketSourceForChrome/manifest.json +++ b/WicketSourceForChrome/manifest.json @@ -5,7 +5,10 @@ "description": "Adds a Developer Tools sidebar with Wicket source code location for the selected DOM element.", "devtools_page": "devtools.html", "options_page": "options.html", - "icons": { + "background": { + "scripts": ["background.js"] + }, + "icons": { "16": "go_icon.png", "48": "icon48.png", "64": "icon64.png",