Commit c7a551e4 authored by Matthew Finkel's avatar Matthew Finkel Committed by Matthew Finkel
Browse files

Bug 30573 - Sanitize old tabs and wait for tor before opening new tabs

parent 48863b82
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -1104,7 +1104,7 @@ public class BrowserApp extends GeckoApp
     *
     * mTorStatus provides synchronization across threads.
     */
    private boolean checkTorIsStarted() {
    public boolean checkTorIsStarted() {
        // When tor is started, true. Otherwise, false
        mTorStatus = false;
        BroadcastReceiver br = setupReceiveTorIsStartedAsync();
@@ -2096,6 +2096,7 @@ public class BrowserApp extends GeckoApp
                        finishAndShutdown(/* restart */ false);
                    }
                }
                super.handleMessage(event, message, callback);
                break;

            case "Sanitize:OpenTabs":
@@ -2969,6 +2970,7 @@ public class BrowserApp extends GeckoApp

                    // If we finished, then Tor bootstrapped 100%
                    mTorNeedsStart = false;
                    EventDispatcher.getInstance().dispatch("Tor:Ready", null);

                    // When bootstrapping completes, check if the Firstrun (onboarding) screens
                    // should be shown.
+54 −1
Original line number Diff line number Diff line
@@ -195,6 +195,10 @@ public abstract class GeckoApp extends GeckoActivity
    protected Menu mMenu;
    protected boolean mIsRestoringActivity;

    protected boolean mIsSanitizeTabsEnabled = false;
    protected boolean mIsSanitizeCompleted = false;
    protected Object mIsSanitizeCompletedLock = new Object();

    /** Tells if we're aborting app launch, e.g. if this is an unsupported device configuration. */
    protected boolean mIsAbortingAppLaunch;

@@ -606,6 +610,12 @@ public abstract class GeckoApp extends GeckoActivity
        for (final String clear : clearSet) {
            clearObj.putBoolean(clear, true);
        }

        synchronized (mIsSanitizeCompletedLock) {
            mIsSanitizeTabsEnabled = clearSet.contains("private.data.openTabs");
            mIsSanitizeCompleted = false;
        }

        return clearObj;
    }

@@ -790,6 +800,11 @@ public abstract class GeckoApp extends GeckoActivity
                notifyAll();
            }

        } else if ("Sanitize:Finished".equals(event)) {
            synchronized (mIsSanitizeCompletedLock) {
                mIsSanitizeCompleted = true;
            }

        } else if ("SystemUI:Visibility".equals(event)) {
            if (message.getBoolean("visible", true)) {
                mMainLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
@@ -1618,9 +1633,47 @@ public abstract class GeckoApp extends GeckoActivity
                        loadStartupTab(Tabs.LOADURL_NEW_TAB, action);
                    } else {
                        final int flags = getNewTabFlags();
                        final BrowserApp browserApp = (BrowserApp) GeckoApp.this;

                        synchronized (mIsSanitizeCompletedLock) {
                            // If OpenTabs will be sanitized, then load the tab after Sanitize:Finished
                            // is received. If Tor isn't started, then load tabs after Tor:Ready, too. And
                            // if Gecko isn't loaded, then wait until the profile is loaded (avoiding the race
                            // between loading the page and checking if |browser.privatebrowsing.autoStart| is true.
                            EventDispatcher.getInstance().registerUiThreadListener(new BundleEventListener() {
                                // isSanitized is true if Sanitizing is enable and it is completed or if Sanitizing is disabled.
                                private boolean isSanitized = (mIsSanitizeTabsEnabled && mIsSanitizeCompleted) || !mIsSanitizeTabsEnabled;
                                private boolean isTorReady = browserApp.checkTorIsStarted();
                                private boolean isGeckoReady = GeckoThread.isRunning();

                                @Override
                                public void handleMessage(String event, GeckoBundle message, EventCallback callback) {
                                    if ("Sanitize:Finished".equals(event)) {
                                        EventDispatcher.getInstance().unregisterUiThreadListener(this, "Sanitize:Finished");
                                        isSanitized = true;

                                    } else if ("Tor:Ready".equals(event)) {
                                        EventDispatcher.getInstance().unregisterUiThreadListener(this, "Tor:Ready");
                                        isTorReady = true;
                                    } else if ("Gecko:Ready".equals(event)) {
                                        EventDispatcher.getInstance().unregisterUiThreadListener(this, "Gecko:Ready");
                                        isGeckoReady = true;
                                    } else if ("Tor:CheckIfReady".equals(event)) {
                                        EventDispatcher.getInstance().unregisterUiThreadListener(this, "Tor:CheckIfReady");
                                    }

                                    if (isSanitized && isTorReady && isGeckoReady) {
                                        loadStartupTab(passedUri, intent, flags);
                                    }
                                }
                            }, "Sanitize:Finished", "Tor:Ready", "Tor:CheckIfReady", "Gecko:Ready");

                            // Run the event callback now, just in case Tor:Ready and Sanitize:Finished were
                            // dispatched before the listener was created.
                            EventDispatcher.getInstance().dispatch("Tor:CheckIfReady", null);
                        }
                    }
                }
            });
        } else {
            if (!mIsRestoringActivity) {