[tor-commits] [flashproxy/master] Add HEADLESS global indicating whether we have a DOM.

dcf at torproject.org dcf at torproject.org
Wed Jul 31 00:19:47 UTC 2013


commit 7a8278c91effb41a97c3141b875e7ef0bae53a80
Author: David Fifield <david at bamsoftware.com>
Date:   Sun Jun 23 19:04:24 2013 -0700

    Add HEADLESS global indicating whether we have a DOM.
---
 proxy/flashproxy.js |   24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/proxy/flashproxy.js b/proxy/flashproxy.js
index cb36247..4367eff 100644
--- a/proxy/flashproxy.js
+++ b/proxy/flashproxy.js
@@ -84,14 +84,21 @@ var OPT_IN_COOKIE = "flashproxy-allow";
 var WebSocket = window.WebSocket || window.MozWebSocket;
 
 var query = parse_query_string(window.location.search.substr(1));
-var cookies = parse_cookie_string(document.cookie);
 var DEBUG = get_param_boolean(query, "debug", false);
 var SAFE_LOGGING = !get_param_boolean(query, "unsafe_logging", false);
 var debug_div;
-
-if (DEBUG) {
-    debug_div = document.createElement("pre");
-    debug_div.className = "debug";
+/* HEADLESS is true if we are running not in a browser with a DOM. */
+var HEADLESS = typeof(document) === "undefined";
+
+var cookies;
+if (HEADLESS) {
+    cookies = {};
+} else {
+    cookies = parse_cookie_string(document.cookie);
+    if (DEBUG) {
+        debug_div = document.createElement("pre");
+        debug_div.className = "debug";
+    }
 }
 
 function puts(s) {
@@ -459,13 +466,16 @@ function make_websocket(addr) {
 }
 
 function FlashProxy() {
-    if (DEBUG) {
+    if (HEADLESS) {
+        /* No badge. */
+    } else if (DEBUG) {
         this.badge_elem = debug_div;
     } else {
         this.badge = new Badge();
         this.badge_elem = this.badge.elem;
     }
-    this.badge_elem.setAttribute("id", "flashproxy-badge");
+    if (this.badge_elem)
+        this.badge_elem.setAttribute("id", "flashproxy-badge");
 
     this.proxy_pairs = [];
 





More information about the tor-commits mailing list