Skip to content

Commit

Permalink
Bug 1275662 - Close all tabs and clean up session files when "Open Ta…
Browse files Browse the repository at this point in the history
…bs" is selected in "Clear private data on exit" or "Clear private data" pref. r=JanH,sebastian

MozReview-Commit-ID: GoUQVDIzYbI

--HG--
extra : rebase_source : 13bbf3477a29cf301df72b521a0e02875bb5ef14
  • Loading branch information
cnevinc committed Dec 29, 2016
1 parent bcd1e46 commit 790b6fa
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 10 deletions.
7 changes: 7 additions & 0 deletions mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ public boolean onInterceptMotionEvent(View view, MotionEvent event) {
"CharEncoding:State",
"Settings:Show",
"Updater:Launch",
"Sanitize:OpenTabs",
null);

EventDispatcher.getInstance().registerBackgroundThreadListener(this,
Expand Down Expand Up @@ -1454,6 +1455,7 @@ public void onDestroy() {
"CharEncoding:State",
"Settings:Show",
"Updater:Launch",
"Sanitize:OpenTabs",
null);

EventDispatcher.getInstance().unregisterBackgroundThreadListener(this,
Expand Down Expand Up @@ -1914,6 +1916,11 @@ public void onClick(final DialogInterface dialog, final int which) {
settings.edit().putInt(getPackageName() + ".feedback_launch_count", 0).apply();
break;

case "Sanitize:OpenTabs":
Tabs.getInstance().closeAll();
callback.sendSuccess(null);
break;

case "Sanitize:ClearHistory":
BrowserDB.from(getProfile()).clearHistory(
getContentResolver(), message.getBoolean("clearSearchHistory", false));
Expand Down
17 changes: 10 additions & 7 deletions mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -585,17 +585,20 @@ public boolean onOptionsItemSelected(MenuItem item) {
Log.e(LOGTAG, "Error adding sanitize object", ex);
}

// If the user has opted out of session restore, and does want to clear history
// 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.has("private.data.history")) {
final String sessionRestore = getSessionRestorePreference(getSharedPreferences());
try {
try {
if (clearObj.has("private.data.openTabs")) {
res.put("dontSaveSession", true);
} else if (clearObj.has("private.data.history")) {

final String sessionRestore = getSessionRestorePreference(getSharedPreferences());
res.put("dontSaveSession", "quit".equals(sessionRestore));
} catch (JSONException ex) {
Log.e(LOGTAG, "Error adding session restore data", ex);

}
} catch (JSONException ex) {
Log.e(LOGTAG, "Error adding session restore data", ex);
}

GeckoAppShell.notifyObservers("Browser:Quit", res.toString());
// We don't call doShutdown() 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
Expand Down
6 changes: 6 additions & 0 deletions mobile/android/base/java/org/mozilla/gecko/Tabs.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public class Tabs implements BundleEventListener {
private PersistTabsRunnable mPersistTabsRunnable;
private int mPrivateClearColor;

public void closeAll() {
for (final Tab tab : mOrder) {
Tabs.getInstance().closeTab(tab, false);
}
}

private static class PersistTabsRunnable implements Runnable {
private final BrowserDB db;
private final Context context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,13 @@ public void load(LoaderManager lm, FragmentManager fm, String panelId, Bundle re
// list of panels in place.
mTabStrip.setVisibility(View.INVISIBLE);

// Load list of panels from configuration
lm.initLoader(LOADER_ID_CONFIG, null, mConfigLoaderCallbacks);
// If HomeConfigLoader already exist, force load to select the current item
if (lm.getLoader(LOADER_ID_CONFIG) != null) {
lm.getLoader(LOADER_ID_CONFIG).forceLoad();
} else {
// Load list of panels from configuration
lm.initLoader(LOADER_ID_CONFIG, null, mConfigLoaderCallbacks);
}

if (shouldAnimate) {
animator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
Expand Down
6 changes: 6 additions & 0 deletions mobile/android/chrome/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,12 @@ var BrowserApp = {
promises.push(Sanitizer.clearItem("cookies"));
promises.push(Sanitizer.clearItem("sessions"));
break;
case "openTabs":
if (aShutdown === true) {
Services.obs.notifyObservers(null, "browser:purge-session-tabs", "");
break;
}
// fall-through if aShutdown is false
default:
promises.push(Sanitizer.clearItem(key));
}
Expand Down
10 changes: 9 additions & 1 deletion mobile/android/components/SessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ SessionStore.prototype = {
observerService.addObserver(this, "domwindowopened", true);
observerService.addObserver(this, "domwindowclosed", true);
observerService.addObserver(this, "browser:purge-session-history", true);
observerService.addObserver(this, "browser:purge-session-tabs", true);
observerService.addObserver(this, "quit-application-requested", true);
observerService.addObserver(this, "quit-application-proceeding", true);
observerService.addObserver(this, "quit-application", true);
Expand Down Expand Up @@ -236,8 +237,9 @@ SessionStore.prototype = {
this._loadState = STATE_QUITTING_FLUSHED;

break;
case "browser:purge-session-tabs":
case "browser:purge-session-history": // catch sanitization
log("browser:purge-session-history");
log(aTopic);
this._clearDisk();

// Clear all data about closed tabs
Expand Down Expand Up @@ -1780,6 +1782,12 @@ SessionStore.prototype = {
},

_sendClosedTabsToJava: function ss_sendClosedTabsToJava(aWindow) {

// If the app is shutting down, we don't need to do anything.
if (this._loadState <= STATE_QUITTING) {
return;
}

if (!aWindow.__SSID) {
throw (Components.returnCode = Cr.NS_ERROR_INVALID_ARG);
}
Expand Down
20 changes: 20 additions & 0 deletions mobile/android/modules/Sanitizer.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,26 @@ Sanitizer.prototype = {
}
},

openTabs: {
clear: function ()
{
return EventDispatcher.instance.sendRequestForResult({ type: "Sanitize:OpenTabs" })
.catch(e => Cu.reportError("Java-side tab clearing failed: " + e))
.then(function() {
try {
// clear "Recently Closed" tabs in Android App
Services.obs.notifyObservers(null, "browser:purge-session-tabs", "");
}
catch (e) { }
});
},

get canClear()
{
return true;
}
},

searchHistory: {
clear: function ()
{
Expand Down

0 comments on commit 790b6fa

Please sign in to comment.