[tor-commits] [tor-browser/tor-browser-68.1.0esr-9.0-1] Orfox: hook up default panic trigger to "quit and clear"

gk at torproject.org gk at torproject.org
Sat Aug 31 19:46:16 UTC 2019


commit bd41c7cefcc3e36c45d780b8c03f1d369f8ad4e1
Author: Hans-Christoph Steiner <hans at eds.org>
Date:   Sat Nov 21 00:24:09 2015 +0100

    Orfox: hook up default panic trigger to "quit and clear"
    
    Signed-off-by: Amogh Pradeep <amoghbl1 at gmail.com>
    
    Also:
    Bug 28507: Implement fallback to delete private data in the browser startup
    
    When the TBA is forcefully closed, its private data is not deleted,
    even if the history.clear_on_exit is set.
    
    As fallback, this patch calls the Sanitize:ClearData event in the
    browser startup to clean the private data if needed.
---
 mobile/android/base/AndroidManifest.xml.in         |  7 +++
 .../base/java/org/mozilla/gecko/GeckoApp.java      | 72 ++++++++++++++--------
 2 files changed, 52 insertions(+), 27 deletions(-)

diff --git a/mobile/android/base/AndroidManifest.xml.in b/mobile/android/base/AndroidManifest.xml.in
index e61a3411b2e0..48809195dc57 100644
--- a/mobile/android/base/AndroidManifest.xml.in
+++ b/mobile/android/base/AndroidManifest.xml.in
@@ -171,6 +171,13 @@
                 <data android:pathPattern=".*\\.xpi" />
             </intent-filter>
 
+            <!-- receive triggers from panickit apps -->
+            <intent-filter>
+                <action android:name="info.guardianproject.panic.action.TRIGGER" />
+
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+
 #ifdef MOZ_ANDROID_BEAM
             <intent-filter>
                 <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
diff --git a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
index 9143536400e3..c988923e960f 100644
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -139,6 +139,7 @@ public abstract class GeckoApp extends GeckoActivity
     public static final String ACTION_INIT_PW              = "org.mozilla.gecko.INIT_PW";
     public static final String ACTION_SWITCH_TAB           = "org.mozilla.gecko.SWITCH_TAB";
     public static final String ACTION_SHUTDOWN             = "org.mozilla.gecko.SHUTDOWN";
+    public static final String ACTION_PANIC_TRIGGER        = "info.guardianproject.panic.action.TRIGGER";
 
     public static final String INTENT_REGISTER_STUMBLER_LISTENER = "org.mozilla.gecko.STUMBLER_REGISTER_LOCAL_LISTENER";
 
@@ -581,42 +582,50 @@ public abstract class GeckoApp extends GeckoActivity
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
         if (item.getItemId() == R.id.quit) {
-            // Make sure the Guest Browsing notification goes away when we quit.
-            GuestSession.hideNotification(this);
+            quitAndClear();
+            return true;
+        }
 
-            final SharedPreferences prefs = getSharedPreferencesForProfile();
-            final Set<String> clearSet = PrefUtils.getStringSet(
-                    prefs, ClearOnShutdownPref.PREF, new HashSet<String>());
+        return super.onOptionsItemSelected(item);
+    }
 
-            final GeckoBundle clearObj = new GeckoBundle(clearSet.size());
-            for (final String clear : clearSet) {
-                clearObj.putBoolean(clear, true);
-            }
+    private GeckoBundle createSanitizeData() {
+        final SharedPreferences prefs = getSharedPreferencesForProfile();
+        final Set<String> clearSet = PrefUtils.getStringSet(
+            prefs, ClearOnShutdownPref.PREF, new HashSet<String>());
 
-            final GeckoBundle res = new GeckoBundle(2);
-            res.putBundle("sanitize", clearObj);
+        final GeckoBundle clearObj = new GeckoBundle(clearSet.size());
+        for (final String clear : clearSet) {
+            clearObj.putBoolean(clear, true);
+        }
+        return clearObj;
+    }
 
-            // If the user wants to clear open tabs, or else has opted out of session
-            // restore and does want to clear history, we also want to prevent the current
-            // session info from being saved.
-            if (clearObj.containsKey("private.data.openTabs")) {
-                res.putBoolean("dontSaveSession", true);
-            } else if (clearObj.containsKey("private.data.history")) {
+    private void quitAndClear() {
+        // Make sure the Guest Browsing notification goes away when we quit.
+        GuestSession.hideNotification(this);
 
-                final String sessionRestore =
-                        getSessionRestorePreference(getSharedPreferences());
-                res.putBoolean("dontSaveSession", "quit".equals(sessionRestore));
-            }
+        final GeckoBundle clearObj = createSanitizeData();
+        final GeckoBundle res = new GeckoBundle(2);
+        res.putBundle("sanitize", clearObj);
 
-            EventDispatcher.getInstance().dispatch("Browser:Quit", res);
+        // If the user wants to clear open tabs, or else has opted out of session
+        // restore and does want to clear history, we also want to prevent the current
+        // session info from being saved.
+        if (clearObj.containsKey("private.data.openTabs")) {
+            res.putBoolean("dontSaveSession", true);
+        } else if (clearObj.containsKey("private.data.history")) {
 
-            // We don't call shutdown here because this creates a race condition which
-            // can cause the clearing of private data to fail. Instead, we shut down the
-            // UI only after we're done sanitizing.
-            return true;
+            final String sessionRestore =
+                    getSessionRestorePreference(getSharedPreferences());
+            res.putBoolean("dontSaveSession", "quit".equals(sessionRestore));
         }
 
-        return super.onOptionsItemSelected(item);
+        EventDispatcher.getInstance().dispatch("Browser:Quit", res);
+
+        // We don't call shutdown here because this creates a race condition which
+        // can cause the clearing of private data to fail. Instead, we shut down the
+        // UI only after we're done sanitizing.
     }
 
     @Override
@@ -1160,6 +1169,13 @@ public abstract class GeckoApp extends GeckoActivity
         mTextSelection.create();
 
         final Bundle finalSavedInstanceState = savedInstanceState;
+
+        // When the browser is forcefully closed, its private data is not
+        // deleted, even if the history.clear_on_exit is set. Here we are calling
+        // the Sanitize:ClearData in the startup to make sure the private
+        // data was cleared.
+        EventDispatcher.getInstance().dispatch("Sanitize:ClearData", createSanitizeData());
+
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override
             public void run() {
@@ -1602,6 +1618,8 @@ public abstract class GeckoApp extends GeckoActivity
             // Copy extras.
             settingsIntent.putExtras(intent.getUnsafe());
             startActivity(settingsIntent);
+        } else if (ACTION_PANIC_TRIGGER.equals(action)) {
+            quitAndClear();
         }
 
         mPromptService = new PromptService(this, getAppEventDispatcher());





More information about the tor-commits mailing list