diff --git a/extensions/chrome/js/background.js b/extensions/chrome/js/background.js index 96da3c3b..11054243 100644 --- a/extensions/chrome/js/background.js +++ b/extensions/chrome/js/background.js @@ -1,4 +1,4 @@ -var tabInfo = {}; +var sessions = {}; var ports = {}; initPanelMessage(); @@ -14,8 +14,8 @@ function panelMessage(tabId, type, msg) { } } -function sendSessionId(tabId) { - panelMessage(tabId, 'session-id', { sessionId: tabInfo[tabId].sessionId }); +function sendSession(tabId) { + panelMessage(tabId, 'update-session', sessions[tabId]); } function removeConsole(tabId) { @@ -26,8 +26,8 @@ function initPanelMessage() { chrome.runtime.onConnect.addListener(onConnect); function handleMessage(msg) { - if (msg.type === 'session-id') { - sendSessionId(msg.tabId); + if (msg.type === 'session') { + sendSession(msg.tabId); } } @@ -52,7 +52,7 @@ function initReqRes() { function handleMessage(req, sender, sendResponse) { if (req.type === 'request') { - var url = tabInfo[req.tabId].remoteHost + '/' + req.url; + var url = sessions[req.tabId].remoteHost + '/' + req.url; REPLConsole.request(req.method, url, req.params, function(xhr) { sendResponse(extractProps(xhr)); }); @@ -85,8 +85,9 @@ function initHttpListener() { var headers = getHeaders(details); var sessionId; if (sessionId = headers['X-Web-Console-Session-Id']) { - tabInfo[details.tabId] = { + sessions[details.tabId] = { sessionId: sessionId, + mountPoint: headers['X-Web-Console-Mount-Point'], remoteHost: details.url.match(/([^:]+:\/\/[^\/]+)\/?/)[1] }; } @@ -97,12 +98,12 @@ function initNavListener() { // Fired when a document is completely loaded and initialized. chrome.webNavigation.onCompleted.addListener(function(details) { if (filter(details)) { - sendSessionId(details.tabId); + sendSession(details.tabId); removeConsole(details.tabId); } }); function filter(details) { - return details.frameId === 0 && tabInfo[details.tabId]; + return details.frameId === 0 && sessions[details.tabId]; } } diff --git a/extensions/chrome/js/panel.js b/extensions/chrome/js/panel.js index 818ea71b..bc48839c 100644 --- a/extensions/chrome/js/panel.js +++ b/extensions/chrome/js/panel.js @@ -15,19 +15,20 @@ REPLConsole.request = function(method, url, params, callback) { // Handle messages from the background script. port.onMessage.addListener(function(msg) { - if (msg.type === 'session-id') { - updateRemotePath(msg.sessionId); + if (msg.type === 'update-session') { + updateSession(msg); } else if (msg.type === 'remove-console') { removeConsole(); } }); -function updateRemotePath(sessionId) { - var remotePath = '__web_console/repl_sessions/' + sessionId; +function updateSession(info) { if (repl) { - repl.remotePath = remotePath; + repl.sessionId = info.sessionId; + repl.mountPoint = info.mountPoint; } else { - repl = REPLConsole.installInto('console', { remotePath: remotePath }); + var options = { sessionId: info.sessionId, mountPoint: info.mountPoint }; + repl = REPLConsole.installInto('console', options); } } @@ -36,5 +37,5 @@ function removeConsole() { chrome.devtools.inspectedWindow.eval(script); } -port.postMessage({ type: 'session-id', tabId: tabId }); +port.postMessage({ type: 'session', tabId: tabId }); removeConsole();