Skip to content

Commit dd6f2e6

Browse files
committed
Use mount point instead of remote path on Chrome Extension
1 parent 24ffa5e commit dd6f2e6

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

extensions/chrome/js/background.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var tabInfo = {};
1+
var sessions = {};
22
var ports = {};
33

44
initPanelMessage();
@@ -14,8 +14,8 @@ function panelMessage(tabId, type, msg) {
1414
}
1515
}
1616

17-
function sendSessionId(tabId) {
18-
panelMessage(tabId, 'session-id', { sessionId: tabInfo[tabId].sessionId });
17+
function sendSession(tabId) {
18+
panelMessage(tabId, 'update-session', sessions[tabId]);
1919
}
2020

2121
function removeConsole(tabId) {
@@ -26,8 +26,8 @@ function initPanelMessage() {
2626
chrome.runtime.onConnect.addListener(onConnect);
2727

2828
function handleMessage(msg) {
29-
if (msg.type === 'session-id') {
30-
sendSessionId(msg.tabId);
29+
if (msg.type === 'session') {
30+
sendSession(msg.tabId);
3131
}
3232
}
3333

@@ -52,7 +52,7 @@ function initReqRes() {
5252

5353
function handleMessage(req, sender, sendResponse) {
5454
if (req.type === 'request') {
55-
var url = tabInfo[req.tabId].remoteHost + '/' + req.url;
55+
var url = sessions[req.tabId].remoteHost + '/' + req.url;
5656
REPLConsole.request(req.method, url, req.params, function(xhr) {
5757
sendResponse(extractProps(xhr));
5858
});
@@ -85,8 +85,9 @@ function initHttpListener() {
8585
var headers = getHeaders(details);
8686
var sessionId;
8787
if (sessionId = headers['X-Web-Console-Session-Id']) {
88-
tabInfo[details.tabId] = {
88+
sessions[details.tabId] = {
8989
sessionId: sessionId,
90+
mountPoint: headers['X-Web-Console-Mount-Point'],
9091
remoteHost: details.url.match(/([^:]+:\/\/[^\/]+)\/?/)[1]
9192
};
9293
}
@@ -97,12 +98,12 @@ function initNavListener() {
9798
// Fired when a document is completely loaded and initialized.
9899
chrome.webNavigation.onCompleted.addListener(function(details) {
99100
if (filter(details)) {
100-
sendSessionId(details.tabId);
101+
sendSession(details.tabId);
101102
removeConsole(details.tabId);
102103
}
103104
});
104105

105106
function filter(details) {
106-
return details.frameId === 0 && tabInfo[details.tabId];
107+
return details.frameId === 0 && sessions[details.tabId];
107108
}
108109
}

extensions/chrome/js/panel.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,20 @@ REPLConsole.request = function(method, url, params, callback) {
1515

1616
// Handle messages from the background script.
1717
port.onMessage.addListener(function(msg) {
18-
if (msg.type === 'session-id') {
19-
updateRemotePath(msg.sessionId);
18+
if (msg.type === 'update-session') {
19+
updateSession(msg);
2020
} else if (msg.type === 'remove-console') {
2121
removeConsole();
2222
}
2323
});
2424

25-
function updateRemotePath(sessionId) {
26-
var remotePath = '__web_console/repl_sessions/' + sessionId;
25+
function updateSession(info) {
2726
if (repl) {
28-
repl.remotePath = remotePath;
27+
repl.sessionId = info.sessionId;
28+
repl.mountPoint = info.mountPoint;
2929
} else {
30-
repl = REPLConsole.installInto('console', { remotePath: remotePath });
30+
var options = { sessionId: info.sessionId, mountPoint: info.mountPoint };
31+
repl = REPLConsole.installInto('console', options);
3132
}
3233
}
3334

@@ -36,5 +37,5 @@ function removeConsole() {
3637
chrome.devtools.inspectedWindow.eval(script);
3738
}
3839

39-
port.postMessage({ type: 'session-id', tabId: tabId });
40+
port.postMessage({ type: 'session', tabId: tabId });
4041
removeConsole();

0 commit comments

Comments
 (0)