- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / tabs / connect / echo.js
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
5 // Content script that echoes back all messages.
6 // Posting a message with "GET" returns the name and # of connections opened.
7 var connections = 0;
8
9 chrome.runtime.onConnect.addListener(function onConnect(port) {
10   connections++;
11   port.onMessage.addListener(function onMessage(msg) {
12     if (msg == "GET") {
13       port.postMessage({"name": port.name, "connections": connections});
14     } else {
15       port.postMessage(msg);
16     }
17   });
18 });
19
20 chrome.extension.onRequest.addListener(function(request, sender, respond) {
21   respond(request);
22 });