Hello,
My extension will need to send data from the toolstrip area to the
content_scripts running within the page currently displayed when the
toolstrip button is clicked.
The way to handle the ports seems a bit tricky, specially when dealing
with a page containing iframes / frames.
If I understood properly, a content_script will run for each frame in
my page, provided that the frame's url matches the required pattern.
Each of these scripts will need to open a communication channel.
In order to get a message passed to all of the content scripts, my
toolstrip view will need to keep track of the ports opened and then
cycle through all of them to send a message.
toolstrip snippet :
var myPorts=[];
chrome.self.onConnect.addListener(function(port) {
myPorts.push(port); // I need to add some code here to filter ports
coming from other tabs
});
function sendMsg(msg){
myPorts.forEach(p){
p.postMessage(msg);
}
}
Is this the proper way to do this ?
If any of my iframes gets replaced by another url, or is reloaded, I
will get a new port registered, but I will also have an invalid port
left in my list.
If I may suggest, it would be interesting to get the API to provide us
the list of active ports opened relative to a specific page.
A broadcasting mechanism could come handy as well.
Also, is it a fair assumption that content_script will open only one
connection per frame ?
Or will we get the possibility to provide an ID when creating ports ?
Each port could be dedicated to a specific task.
Something like :
content_script:
var port = chrome.extension.connect
( { "id":"XMLCommunicationChannel" } );
View :
chrome.self.onConnect.addListener(function(port) {
if(port.id==="XMLCommunicationChannel"){
port.onMessage.addListener( _fReceiveXMLFromScript );
port.postMessage("<XML><BLAHBLAH/></XML>");
}
});
Thanks,
Yo
--~--~---------~--~----~------------~-------~--~----~
Chromium Discussion mailing list: [email protected]
View archives, change email options, or unsubscribe:
http://groups.google.com/group/chromium-discuss
-~----------~----~----~----~------~----~------~--~---