| OLD | NEW |
| 1 <script> | 1 <script> |
| 2 window.onload = function() { | 2 window.onload = function() { |
| 3 chrome.extension.onConnect.addListener(function(port) { | 3 chrome.extension.onConnect.addListener(function(port) { |
| 4 console.log('onConnect'); | 4 console.log('onConnect'); |
| 5 port.onMessage.addListener(function(msg) { | 5 port.onMessage.addListener(function(msg) { |
| 6 console.log('got message'); | 6 console.log('got message'); |
| 7 if (msg.testPostMessageFromTab) { | 7 if (msg.testPostMessageFromTab) { |
| 8 port.postMessage({success: true, portName: port.name}); | 8 port.postMessage({success: true, portName: port.name}); |
| 9 console.log('sent success'); | 9 console.log('sent success'); |
| 10 } | 10 } |
| 11 // Ignore other messages since they are from us. | 11 // Ignore other messages since they are from us. |
| 12 }); | 12 }); |
| 13 }); | 13 }); |
| 14 chrome.extension.onConnectExternal.addListener(function(port) { |
| 15 port.onMessage.addListener(function(msg) { |
| 16 if (msg.testConnectExternal) { |
| 17 port.postMessage({success: true, senderId: port.sender.id}); |
| 18 } |
| 19 }); |
| 20 }); |
| 14 }; | 21 }; |
| 15 | 22 |
| 16 // Tests that postMessage to the tab and its response works. | 23 // Tests that postMessage to the tab and its response works. |
| 17 function testPostMessage() { | 24 function testPostMessage() { |
| 18 chrome.tabs.getSelected(null, function(tab) { | 25 chrome.tabs.getSelected(null, function(tab) { |
| 19 var port = chrome.tabs.connect(tab.id); | 26 var port = chrome.tabs.connect(tab.id); |
| 20 console.log('connect to ' + tab.id); | 27 console.log('connect to ' + tab.id); |
| 21 port.postMessage({testPostMessage: true}); | 28 port.postMessage({testPostMessage: true}); |
| 22 port.onMessage.addListener(function(msg) { | 29 port.onMessage.addListener(function(msg) { |
| 23 window.domAutomationController.send(msg.success); | 30 window.domAutomationController.send(msg.success); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 chrome.tabs.getSelected(null, function(tab) { | 78 chrome.tabs.getSelected(null, function(tab) { |
| 72 var port = chrome.tabs.connect(tab.id); | 79 var port = chrome.tabs.connect(tab.id); |
| 73 console.log('connect to ' + tab.id); | 80 console.log('connect to ' + tab.id); |
| 74 port.postMessage({testDisconnectOnClose: true}); | 81 port.postMessage({testDisconnectOnClose: true}); |
| 75 port.onDisconnect.addListener(function() { | 82 port.onDisconnect.addListener(function() { |
| 76 window.domAutomationController.send(true); | 83 window.domAutomationController.send(true); |
| 77 }); | 84 }); |
| 78 }); | 85 }); |
| 79 } | 86 } |
| 80 </script> | 87 </script> |
| OLD | NEW |