[tor-commits] [flashproxy/js] Add a FlashProxy.disable method.

dcf at torproject.org dcf at torproject.org
Thu Apr 5 07:11:47 UTC 2012


commit f6a8d1b64ec373dc3a287bb1d7bfe54022ce94d3
Author: David Fifield <david at bamsoftware.com>
Date:   Wed Apr 4 22:40:56 2012 -0700

    Add a FlashProxy.disable method.
    
    Turn the badge gray to show that it's disabled. Use this instead of
    having a separate DummyFlashProxy class.
---
 flashproxy.js |   37 +++++++++++++++----------------------
 1 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/flashproxy.js b/flashproxy.js
index 8c29d82..02a564f 100644
--- a/flashproxy.js
+++ b/flashproxy.js
@@ -421,29 +421,23 @@ function FlashProxy()
         this.badge.proxy_begin();
     };
 
+    /* Cease all network operations and prevent any future ones. */
+    this.disable = function() {
+        puts("disabling");
+        this.proxy_main = function() { };
+        this.make_proxy_pair = function(client_addr, relay_addr) { };
+        while (this.proxy_pairs.length > 0)
+            this.proxy_pairs.pop().close();
+        this.badge.set_color("#777");
+        this.badge.refresh();
+    };
+
     this.die = function() {
         puts("die");
         this.badge.set_color("#111");
     };
 }
 
-/* This is the non-functional badge that occupies space when
-   flashproxy_should_disable decides that the proxy shouldn't run. */
-function DummyFlashProxy()
-{
-    var img;
-
-    img = document.createElement("img");
-    img.setAttribute("src", "https://crypto.stanford.edu/flashproxy/badge.png");
-    img.setAttribute("border", 0);
-    img.setAttribute("id", "flashproxy-badge");
-
-    this.badge_elem = img;
-
-    this.start = function() {
-    };
-}
-
 /* An instance of a client-relay connection. */
 function ProxyPair(client_addr, relay_addr, rate_limit)
 {
@@ -771,13 +765,12 @@ function flashproxy_should_disable()
 
 function flashproxy_badge_insert()
 {
+    var fp;
     var e;
 
-    if (flashproxy_should_disable()) {
-        fp = new DummyFlashProxy();
-    } else {
-        fp = new FlashProxy();
-    }
+    fp = new FlashProxy();
+    if (flashproxy_should_disable())
+        fp.disable();
 
     /* http://intertwingly.net/blog/2006/11/10/Thats-Not-Write for this trick to
        insert right after the <script> element in the DOM. */





More information about the tor-commits mailing list