1 // Copyright (c) 2012 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 var scriptMessageEvent;
5 var pageToScriptTunnel;
6 var scriptToPageTunnel;
8 function setStatus(status) {
9 document.getElementById('status').innerText = status;
12 function setupScriptTunnel() {
13 scriptMessageEvent = document.createEvent("Event");
14 scriptMessageEvent.initEvent('scriptMessage', true, true);
16 pageToScriptTunnel = document.getElementById("pageToScriptTunnel");
17 scriptToPageTunnel = document.getElementById("scriptToPageTunnel");
19 scriptToPageTunnel.addEventListener("scriptMessage", function() {
20 var data = JSON.parse(scriptToPageTunnel.innerText);
21 window[data.name](data.args);
25 function messageData(data) {
27 for (var i = 0; i < data.length; i++) {
31 'name': data.callee.name.replace(/notify/g, "on"),
36 function notifyBackgroundPageResponded() {
37 pageToScriptTunnel.innerText = JSON.stringify(messageData(arguments));
38 pageToScriptTunnel.dispatchEvent(scriptMessageEvent);
41 function notifyBackgroundPageLoaded() {
42 pageToScriptTunnel.innerText = JSON.stringify(messageData(arguments));
43 pageToScriptTunnel.dispatchEvent(scriptMessageEvent);
46 function notifyBackgroundPagePermissionDenied() {
47 pageToScriptTunnel.innerText = JSON.stringify(messageData(arguments));
48 pageToScriptTunnel.dispatchEvent(scriptMessageEvent);
51 function notifyCounterError() {
52 pageToScriptTunnel.innerText = JSON.stringify(messageData(arguments));
53 pageToScriptTunnel.dispatchEvent(scriptMessageEvent);
56 function notifyBackgroundPageClosing() {
57 pageToScriptTunnel.innerText = JSON.stringify(messageData(arguments));
58 pageToScriptTunnel.dispatchEvent(scriptMessageEvent);
61 function notifyBackgroundPageClosed() {
62 pageToScriptTunnel.innerText = JSON.stringify(messageData(arguments));
63 pageToScriptTunnel.dispatchEvent(scriptMessageEvent);