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

[tor-commits] [snowflake/master] Warn when WebRTC isn't detected in the webext



commit 095f4a0510213e4d61993b91d93d07e4194a296e
Author: Arlo Breault <arlolra@xxxxxxxxx>
Date:   Wed Jul 3 15:35:01 2019 +0200

    Warn when WebRTC isn't detected in the webext
    
    Trac 31067
---
 proxy/init-badge.coffee  |  4 ++++
 proxy/init-webext.coffee |  6 ++++++
 proxy/shims.coffee       |  4 ----
 proxy/util.coffee        |  2 ++
 proxy/webext/popup.js    | 14 +++++++++++---
 5 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/proxy/init-badge.coffee b/proxy/init-badge.coffee
index eead5b0..c4c9604 100644
--- a/proxy/init-badge.coffee
+++ b/proxy/init-badge.coffee
@@ -2,6 +2,10 @@
 Entry point.
 ###
 
+if (not TESTING? or not TESTING) and not Util.featureDetect()
+  console.log 'webrtc feature not detected. shutting down'
+  return
+
 snowflake = null
 
 query = Query.parse(location)
diff --git a/proxy/init-webext.coffee b/proxy/init-webext.coffee
index c2f47bf..716604f 100644
--- a/proxy/init-webext.coffee
+++ b/proxy/init-webext.coffee
@@ -17,6 +17,12 @@ log = (msg) ->
 
 dbg = (msg) -> log msg if debug
 
+if not Util.featureDetect()
+  chrome.runtime.onConnect.addListener (port) ->
+    port.postMessage
+      missingFeature: true
+  return
+
 init = () ->
   config = new Config
   ui = new WebExtUI()
diff --git a/proxy/shims.coffee b/proxy/shims.coffee
index dc7412f..8d3b979 100644
--- a/proxy/shims.coffee
+++ b/proxy/shims.coffee
@@ -31,9 +31,5 @@ else
   SessionDescription = window.RTCSessionDescription ||
     window.mozRTCSessionDescription
 
-  if typeof PeerConnection isnt 'function'
-    console.log 'webrtc feature not detected. shutting down'
-    return
-
   WebSocket = window.WebSocket
   XMLHttpRequest = window.XMLHttpRequest
diff --git a/proxy/util.coffee b/proxy/util.coffee
index 02b6024..61fe6be 100644
--- a/proxy/util.coffee
+++ b/proxy/util.coffee
@@ -34,6 +34,8 @@ class Util
       return true
     return false
 
+  @featureDetect = () ->
+    return typeof PeerConnection is 'function'
 
 class Query
   ###
diff --git a/proxy/webext/popup.js b/proxy/webext/popup.js
index 55891d4..0bf489d 100644
--- a/proxy/webext/popup.js
+++ b/proxy/webext/popup.js
@@ -3,11 +3,19 @@ const port = chrome.runtime.connect({
 });
 
 port.onMessage.addListener((m) => {
-  const active = m.active;
   const div = document.getElementById('active');
-  const img = div.querySelector('img');
-  const enabled = m.enabled
   const ps = div.querySelectorAll('p');
+  if (m.missingFeature) {
+    div.querySelector('img').src = "icons/status-off.png";
+    ps[0].innerText = "Snowflake is off";
+    ps[1].innerText = "WebRTC feature is not detected.";
+    ps[1].style.color = 'firebrick';
+    document.querySelector('.toggle').style.display = 'none';
+    return;
+  }
+  const active = m.active;
+  const img = div.querySelector('img');
+  const enabled = m.enabled;
   const clients = active ? 1 : 0;
   const enabledText = document.getElementById('toggle');
   if (enabled) {

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