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 @@