commit 57d56c82322c313e90ee86bf2a3abcc62ad06606 Author: Chang Lan clan@eecs.berkeley.edu Date: Fri Apr 18 15:10:25 2014 -0700
Remove debug info. --- chrome/app/background.js | 37 +++++++++++++++++++------------------ chrome/extension/background.js | 18 +++++++++++------- 2 files changed, 30 insertions(+), 25 deletions(-)
diff --git a/chrome/app/background.js b/chrome/app/background.js index 77ad0da..e9d7711 100644 --- a/chrome/app/background.js +++ b/chrome/app/background.js @@ -1,7 +1,8 @@ -// attempt to keep app from going inactive +const DEBUG = false;
-chrome.alarms.create("ping", {when: 5000, periodInMinutes: 1 }); -chrome.alarms.onAlarm.addListener(function(alarm) { console.info("alarm name = " + alarm.name); }); +function debug(str) { + if (DEBUG) { console.info(str); } +}
const IP = "127.0.0.1"; const PORT = 7000; @@ -26,7 +27,7 @@ chrome.runtime.onMessageExternal.addListener( );
function listenAndAccept(socketId) { - console.log("listenAndAccept " + socketId); + debug("listenAndAccept " + socketId); chrome.sockets.tcpServer.listen(socketId, IP, PORT, function(resultCode) { onListenCallback(socketId, resultCode) @@ -34,25 +35,25 @@ function listenAndAccept(socketId) { }
function onListenCallback(socketId, resultCode) { - console.log("onListenCallback " + socketId); + debug("onListenCallback " + socketId); if (resultCode < 0) { - console.log("Error listening:" + + debug("Error listening:" + chrome.runtime.lastError.message); return; } serverSocketId = socketId; chrome.sockets.tcpServer.onAccept.addListener(onAccept); chrome.sockets.tcpServer.onAcceptError.addListener(function(info) { - console.log("onAcceptError " + JSON.stringify(info)); + debug("onAcceptError " + JSON.stringify(info)); }); chrome.sockets.tcp.onReceive.addListener(onReceive); chrome.sockets.tcp.onReceiveError.addListener(function(info) { - console.log("onReceiveError " + JSON.stringify(info)); + debug("onReceiveError " + JSON.stringify(info)); }); }
function onAccept(info) { - console.log("onAccept " + JSON.stringify(info)); + debug("onAccept " + JSON.stringify(info)); if (info.socketId != serverSocketId) return;
@@ -60,7 +61,7 @@ function onAccept(info) { }
function readIntoBuf(data) { - console.log("readIntoBuf " + "bytesToRead: " + bytesToRead + ", datalen: " + data.byteLength + ", buflen: " + buf.length); + debug("readIntoBuf " + "bytesToRead: " + bytesToRead + ", datalen: " + data.byteLength + ", buflen: " + buf.length); var n = Math.min(data.byteLength, bytesToRead); buf.set(new Uint8Array(data.slice(0, n)), buf.length - bytesToRead); bytesToRead -= n; @@ -68,7 +69,7 @@ function readIntoBuf(data) { }
function onReceive(info) { - console.log("onReceive " + JSON.stringify(info) + " len: " + info.data.byteLength); + debug("onReceive " + JSON.stringify(info) + " len: " + info.data.byteLength); var data = info.data; switch (state) { case STATE_READING_LENGTH: @@ -78,7 +79,7 @@ function onReceive(info) {
var b = buf; bytesToRead = (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]; - console.log(bytesToRead); + debug(bytesToRead); buf = new Uint8Array(bytesToRead); state = STATE_READING_OBJECT;
@@ -88,7 +89,7 @@ function onReceive(info) { return;
var str = ab2str(buf); - console.log(str); + debug(str); var request = JSON.parse(str); makeRequest(request, info.socketId);
@@ -99,7 +100,7 @@ function onReceive(info) { }
function makeRequest(request, socketId) { - console.log("makeRequest " + JSON.stringify(request)); + debug("makeRequest " + JSON.stringify(request));
port = chrome.runtime.connect(EXTENSION_ID); port.onMessage.addListener(function(response) { @@ -107,13 +108,13 @@ function makeRequest(request, socketId) { port.disconnect(); }); port.onDisconnect.addListener(function() { - console.log("onDisconnect"); + debug("onDisconnect"); }); port.postMessage(request); }
function returnResponse(response, socketId) { - console.log("returnResponse " + JSON.stringify(response)); + debug("returnResponse " + JSON.stringify(response)); var str = JSON.stringify(response); var b = str2ab(str);
@@ -126,9 +127,9 @@ function returnResponse(response, socketId) { buf.set(new Uint8Array(b), 4);
chrome.sockets.tcp.send(socketId, buf.buffer, function(info) { - console.log("send " + socketId); + debug("send " + socketId); if (info.resultCode != 0) - console.log("Send failed " + info.resultCode); + debug("Send failed " + info.resultCode); }); }
diff --git a/chrome/extension/background.js b/chrome/extension/background.js index 8acd9e8..836f022 100644 --- a/chrome/extension/background.js +++ b/chrome/extension/background.js @@ -1,4 +1,8 @@ -// attempt to keep app from going inactive +const DEBUG = false; + +function debug(str) { + if (DEBUG) { console.info(str); } +}
chrome.alarms.create("heartbeat", {when: 5000, periodInMinutes: 1 }); chrome.alarms.onAlarm.addListener(function(alarm) { @@ -34,9 +38,9 @@ function onBeforeSendHeadersCallback(details) { }
chrome.runtime.onConnectExternal.addListener(function(port) { - console.log("onConnectExternal"); + debug("onConnectExternal"); port.onMessage.addListener(function(request) { - console.log("onMessage"); + debug("onMessage"); var timeout = 2000; var xhr = new XMLHttpRequest(); xhr.responseType = "arraybuffer"; @@ -50,14 +54,14 @@ chrome.runtime.onConnectExternal.addListener(function(port) { sendResponse(response); }; xhr.onload = function() { - console.log("onload " + xhr.response.byteLength); + debug("onload " + xhr.response.byteLength); chrome.webRequest.onBeforeSendHeaders.removeListener(onBeforeSendHeadersCallback); var response = { status: xhr.status, body: _arrayBufferToBase64(xhr.response) }; port.postMessage(response); - console.log("postMessage " + JSON.stringify(response)); + debug("postMessage " + JSON.stringify(response)); }; var requestMethod = request.method; var url = request.url; @@ -75,7 +79,7 @@ chrome.runtime.onConnectExternal.addListener(function(port) { if (request.body != undefined) { body = _base64ToArrayBuffer(request.body); xhr.overrideMimeType("Content-Type", "application/octet-stream"); - console.log(body); + debug(body); }
chrome.webRequest.onBeforeSendHeaders.addListener(onBeforeSendHeadersCallback, { @@ -99,7 +103,7 @@ function _base64ToArrayBuffer(base64) {
function _arrayBufferToBase64(buf) { var bytes = new Uint8Array(buf); - console.log(JSON.stringify(buf)); + debug(JSON.stringify(buf)); var base64 = ''; var encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
tor-commits@lists.torproject.org