[tbb-commits] [tor-browser/tor-browser-52.7.2esr-8.0-1] Orfox: queue URL Intents and Tab:Load events when Orbot is not yet started

gk at torproject.org gk at torproject.org
Tue Mar 20 11:26:34 UTC 2018


commit 7b8e8ea0d5ead3c243bd8f73b07ed815eaa3369d
Author: Hans-Christoph Steiner <hans at eds.org>
Date:   Wed Sep 2 16:43:33 2015 +0200

    Orfox: queue URL Intents and Tab:Load events when Orbot is not yet started
    
    Instead of failing when opening a URL and Tor is not ready, queue those
    Intents, then send them once we get STATUS_ON from Orbot.  Tab:Load events
    seem to be the main way that URLs are sent to the browser engine.
    Trying to migrate these changes to 45, this might end up breaking it, not sure.
    
    Squash with 64604feef6326ed44101bde31edb666ffbf21352
    
    Signed-off-by: Amogh Pradeep <amoghbl1 at gmail.com>
---
 .../base/java/org/mozilla/gecko/BrowserApp.java    | 21 +++++----------
 .../main/java/org/mozilla/gecko/GeckoAppShell.java | 31 ++++++++++++++++++++++
 2 files changed, 37 insertions(+), 15 deletions(-)

diff --git a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
index 984f04eaf52c..b57fe27705fb 100644
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -1077,21 +1077,12 @@ public class BrowserApp extends GeckoApp
         @Override
         public void onReceive(Context context, Intent intent) {
             if (TextUtils.equals(intent.getAction(), OrbotHelper.ACTION_STATUS)) {
-                Log.i(LOGTAG, getPackageName() + " received intent : " + intent.getAction() + " " + intent.getPackage());
-                String status = intent.getStringExtra(OrbotHelper.EXTRA_STATUS) + " (" + intent.getStringExtra(OrbotHelper.EXTRA_PACKAGE_NAME) + ")";
-                Log.i(LOGTAG, status);
-
-                boolean enabled = (intent.getStringExtra(OrbotHelper.EXTRA_STATUS).equals(OrbotHelper.STATUS_ON));
-                // TODO
-                /*
-                   if(enabled) {
-                   if (intent.hasExtra(OrbotHelper.EXTRA_PROXY_PORT_HTTP))
-                   Log.i(LOGTAG, "HTTP PROXY: " + intent.getIntExtra(OrbotHelper.EXTRA_PROXY_PORT_HTTP, -1));
-
-                   if (intent.hasExtra(OrbotHelper.EXTRA_PROXY_PORT_SOCKS))
-                   Log.i(LOGTAG, "SOCKS PROXY: " + intent.getIntExtra(OrbotHelper.EXTRA_PROXY_PORT_SOCKS, -1));
-                   }
-                 */
+                String status = intent.getStringExtra(OrbotHelper.EXTRA_STATUS);
+                Tabs.getInstance().setTorStatus(status);
+
+                if (status.equals(OrbotHelper.STATUS_ON)) {
+                    GeckoAppShell.sendPendingUrlIntents(BrowserApp.this);
+                }
             }
         }
     };
diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
index a802126395b4..9f28742c02d7 100644
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
@@ -21,9 +21,12 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Queue;
 import java.util.StringTokenizer;
 import java.util.TreeMap;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
 
 import android.annotation.SuppressLint;
 import org.mozilla.gecko.annotation.JNITarget;
@@ -44,6 +47,8 @@ import org.mozilla.gecko.util.NativeJSObject;
 import org.mozilla.gecko.util.ProxySelector;
 import org.mozilla.gecko.util.ThreadUtils;
 
+import info.guardianproject.netcipher.proxy.OrbotHelper;
+
 import android.Manifest;
 import android.app.Activity;
 import android.app.ActivityManager;
@@ -110,6 +115,8 @@ public class GeckoAppShell
     // We have static members only.
     private GeckoAppShell() { }
 
+    private static String torStatus;
+
     private static final CrashHandler CRASH_HANDLER = new CrashHandler() {
         @Override
         protected String getAppPackageName() {
@@ -187,6 +194,8 @@ public class GeckoAppShell
     static private int sDensityDpi;
     static private int sScreenDepth;
 
+    static final Queue<Intent> PENDING_URL_INTENTS = new ConcurrentLinkedQueue<Intent>();
+
     /* Is the value in sVibrationEndTime valid? */
     private static boolean sVibrationMaybePlaying;
 
@@ -254,6 +263,17 @@ public class GeckoAppShell
         return sLayerView;
     }
 
+    static void sendPendingUrlIntents() {
+        try {
+            Context context = getContext();
+            while (!PENDING_URL_INTENTS.isEmpty()) {
+                final Intent intent = PENDING_URL_INTENTS.poll();
+                context.startActivity(intent);
+            }
+        } catch (NoSuchElementException e) {}
+    }
+
+
     /**
      * Sends an asynchronous request to Gecko.
      *
@@ -2236,4 +2256,15 @@ public class GeckoAppShell
         }
         return sScreenSize;
     }
+
+    public static void setTorStatus(Intent intent) {
+        torStatus = intent.getStringExtra(OrbotHelper.EXTRA_STATUS);
+        if (OrbotHelper.STATUS_ON.equals(torStatus)) {
+            sendPendingUrlIntents();
+        }
+    }
+
+    public static String getTorStatus() {
+        return torStatus;
+    }
 }





More information about the tbb-commits mailing list