[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake/master] Add toggle functionality to web extension



commit 799a13d3853c26b51bb2ed3c05690f6650cebec2
Author: Cecylia Bocovich <cohosh@xxxxxxxxxxxxxx>
Date:   Wed Jun 26 20:21:44 2019 -0400

    Add toggle functionality to web extension
---
 proxy/init-webext.coffee   | 12 ++++++++++++
 proxy/ui.coffee            |  8 ++++++++
 proxy/webext/manifest.json |  3 ++-
 proxy/webext/popup.html    |  4 ++--
 proxy/webext/popup.js      | 13 +++++++++++++
 5 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/proxy/init-webext.coffee b/proxy/init-webext.coffee
index 1ba6391..104384d 100644
--- a/proxy/init-webext.coffee
+++ b/proxy/init-webext.coffee
@@ -4,6 +4,9 @@ Entry point.
 
 debug = false
 snowflake = null
+config = null
+broker = null
+ui = null
 
 # Log to both console and UI if applicable.
 # Requires that the snowflake and UI objects are hooked up in order to
@@ -21,8 +24,17 @@ init = () ->
   snowflake = new Snowflake config, ui, broker
 
   log '== snowflake proxy =='
+
+update = () ->
+  if !ui.enabled
+    # Do not activate the proxy if any number of conditions are true.
+    snowflake.disable()
+    log 'Currently not active.'
+    return
+
   # Otherwise, begin setting up WebRTC and acting as a proxy.
   dbg 'Contacting Broker at ' + broker.url
+  log 'Starting snowflake'
   snowflake.setRelayAddr config.relayAddr
   snowflake.beginWebRTC()
 
diff --git a/proxy/ui.coffee b/proxy/ui.coffee
index 505fa45..fa45823 100644
--- a/proxy/ui.coffee
+++ b/proxy/ui.coffee
@@ -4,6 +4,7 @@ All of Snowflake's DOM manipulation and inputs.
 
 class UI
   active: false
+  enabled: false
 
   setStatus: (msg) ->
 
@@ -74,10 +75,17 @@ class WebExtUI extends UI
       total: @stats.reduce ((t, c) ->
         t + c
       ), 0
+      enabled: @enabled
 
   onConnect: (port) =>
     @port = port
     port.onDisconnect.addListener @onDisconnect
+    port.onMessage.addListener @onMessage
+    @postActive()
+  
+  onMessage: (m) =>
+    @enabled = m.enabled
+    update()
     @postActive()
 
   onDisconnect: (port) =>
diff --git a/proxy/webext/manifest.json b/proxy/webext/manifest.json
index cd7d250..8cf43ae 100644
--- a/proxy/webext/manifest.json
+++ b/proxy/webext/manifest.json
@@ -13,5 +13,6 @@
 		},
 		"default_title": "Snowflake",
 		"default_popup": "popup.html"
-	}
+	},
+        "permissions": ["cookies", "https://snowflake.torproject.org/";]
 }
diff --git a/proxy/webext/popup.html b/proxy/webext/popup.html
index 8149232..c32a5f8 100644
--- a/proxy/webext/popup.html
+++ b/proxy/webext/popup.html
@@ -12,9 +12,9 @@
                         <p></p>
                 </div>
                 <div class="b toggle">
-                        <label>Turn Off</label>
+                        <label id=toggle>Turn On</label>
                         <label class="switch">
-                                <input type="checkbox" checked>
+                                <input id="enabled" type="checkbox"/>
                                 <span class="slider round"></span>
                         </label>
                 </div>
diff --git a/proxy/webext/popup.js b/proxy/webext/popup.js
index 3869a5f..f02bdff 100644
--- a/proxy/webext/popup.js
+++ b/proxy/webext/popup.js
@@ -11,4 +11,17 @@ port.onMessage.addListener((m) => {
 	const clients = active ? 1 : 0;
 	ps[0].innerText = `${clients} client${(clients !== 1) ? 's' : ''} connected.`;
 	ps[1].innerText = `Your snowflake has helped ${m.total} user${(m.total !== 1) ? 's' : ''} circumvent censorship in the last 24 hours.`;
+        const enabled = m.enabled
+        const enabledText = document.getElementById('toggle');
+        if (enabled) {
+            document.getElementById('enabled').checked = true;
+            enabledText.innerText = 'Turn Off';
+        } else {
+            document.getElementById('enabled').checked = false;
+            enabledText.innerText = 'Turn On';
+        }
 });
+
+document.addEventListener('change', (event) => {
+    port.postMessage({enabled: event.target.checked});
+})



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits