Skip to content

Commit

Permalink
Get rid of the horrible global and pass tab_port so updates always go…
Browse files Browse the repository at this point in the history
… to the right place
  • Loading branch information
Alex Bennee committed Dec 21, 2009
1 parent 6dcf2ac commit a642737
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions xmlcomms.js
Expand Up @@ -5,8 +5,6 @@
*
*/

var reply_port = null;

// This is the edit server address
var urlPrefix = "http://127.0.0.1:9292/"

Expand All @@ -20,7 +18,7 @@ chrome.browserAction.onClicked.addListener(function(tab) {
// Handle and edit request coming from the content page script
//
// Package up the text to be edited and send it to the edit server
function handleContentMessages(msg)
function handleContentMessages(msg, tab_port)
{
console.log("handleContentMessages called:"+msg);
var cmd = msg.cmd;
Expand All @@ -31,6 +29,8 @@ function handleContentMessages(msg)
var url = urlPrefix + cmd + "/";
url = url + id;

console.log(" page URL:"+tab_port.tab.url);
console.log(" tab_port:"+tab_port.portId_);
console.log(" request URL:"+url);

xhr.open("POST", url, true);
Expand All @@ -46,7 +46,7 @@ function handleContentMessages(msg)
};

//port.postMessage(tab.id, update_msg);
reply_port.postMessage(update_msg);
tab_port.postMessage(update_msg);
}
}

Expand All @@ -56,9 +56,9 @@ function handleContentMessages(msg)

function contentTalking(port)
{
console.log("contentTalking:"+port);
reply_port = port;// will this cause a problem with multiple tabs connecting at once?
port.onMessage.addListener(handleContentMessages);
port.onMessage.addListener(function(msg, port) {
handleContentMessages(msg,port);
});
}

// Hook up whenever someone connects to the extension comms port
Expand Down

0 comments on commit a642737

Please sign in to comment.