| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 1 // Content script that echoes back all messages. | 5 // Content script that echoes back all messages. |
| 2 // Posting a message with "GET" returns the name and # of connections opened. | 6 // Posting a message with "GET" returns the name and # of connections opened. |
| 3 var connections = 0; | 7 var connections = 0; |
| 4 | 8 |
| 5 chrome.extension.onConnect.addListener(function onConnect(port) { | 9 chrome.runtime.onConnect.addListener(function onConnect(port) { |
| 6 connections++; | 10 connections++; |
| 7 port.onMessage.addListener(function onMessage(msg) { | 11 port.onMessage.addListener(function onMessage(msg) { |
| 8 if (msg == "GET") { | 12 if (msg == "GET") { |
| 9 port.postMessage({"name": port.name, "connections": connections}); | 13 port.postMessage({"name": port.name, "connections": connections}); |
| 10 } else { | 14 } else { |
| 11 port.postMessage(msg); | 15 port.postMessage(msg); |
| 12 } | 16 } |
| 13 }); | 17 }); |
| 14 }); | 18 }); |
| 15 | 19 |
| 16 chrome.extension.onRequest.addListener(function(request, sender, respond) { | 20 chrome.extension.onRequest.addListener(function(request, sender, respond) { |
| 17 respond(request); | 21 respond(request); |
| 18 }); | 22 }); |
| OLD | NEW |