From a6f4142fb3e24838becea3ecb3a5719141ded17a Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sat, 21 Nov 2015 00:24:09 +0100 Subject: [PATCH] Orfox: hook up default panic trigger to "quit and clear" Signed-off-by: Amogh Pradeep 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 95cdedb0f7761..00e26babd2aca 100644 --- a/mobile/android/base/AndroidManifest.xml.in +++ b/mobile/android/base/AndroidManifest.xml.in @@ -182,6 +182,13 @@ + + + + + + + #ifdef MOZ_ANDROID_BEAM diff --git a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java index 2770e7a098131..026982f50d703 100644 --- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java +++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java @@ -138,6 +138,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"; @@ -583,42 +584,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 clearSet = PrefUtils.getStringSet( - prefs, ClearOnShutdownPref.PREF, new HashSet()); + 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 clearSet = PrefUtils.getStringSet( + prefs, ClearOnShutdownPref.PREF, new HashSet()); - 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 @@ -1150,6 +1159,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() { @@ -1592,6 +1608,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()); -- GitLab