Commit 7b8e8ea0 authored by eighthave's avatar eighthave Committed by Georg Koppen
Browse files

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: default avatarAmogh Pradeep <amoghbl1@gmail.com>
parent a9dbc810
Loading
Loading
Loading
Loading
+6 −15
Original line number Diff line number Diff line
@@ -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);
                String status = intent.getStringExtra(OrbotHelper.EXTRA_STATUS);
                Tabs.getInstance().setTorStatus(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));
                if (status.equals(OrbotHelper.STATUS_ON)) {
                    GeckoAppShell.sendPendingUrlIntents(BrowserApp.this);
                }
                 */
            }
        }
    };
+31 −0
Original line number Diff line number Diff line
@@ -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;
    }
}