Bug 722661 - Part 3: Include private browsing session with restore. r=mfinkle
authorBrian Nicholson <bnicholson@mozilla.com>
Mon, 29 Oct 2012 16:34:29 -0700
changeset 111850 619ac2cecd1e2b3b30d6779ad925bc4ffe83cfca
parent 111849 a9579b178f216fae79e3d151c40303c5e6e770e3
child 111851 ba32bc11b66f85dbdc2f56e2c04bf6273d3bf798
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersmfinkle
bugs722661
milestone19.0a1
Bug 722661 - Part 3: Include private browsing session with restore. r=mfinkle
mobile/android/base/GeckoApp.java
mobile/android/components/SessionStore.js
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -1643,30 +1643,34 @@ abstract public class GeckoApp
                     SessionParser parser = new SessionParser() {
                         @Override
                         public void onTabRead(SessionTab sessionTab) {
                             JSONObject tabObject = sessionTab.getTabObject();
 
                             int flags = Tabs.LOADURL_NEW_TAB;
                             flags |= ((isExternalURL || !sessionTab.isSelected()) ? Tabs.LOADURL_DELAY_LOAD : 0);
                             flags |= (tabObject.optBoolean("desktopMode") ? Tabs.LOADURL_DESKTOP : 0);
+                            flags |= (tabObject.optBoolean("isPrivate") ? Tabs.LOADURL_PRIVATE : 0);
 
                             Tab tab = Tabs.getInstance().loadUrl(sessionTab.getSelectedUrl(), flags);
                             tab.updateTitle(sessionTab.getSelectedTitle());
 
                             try {
                                 tabObject.put("tabId", tab.getId());
                             } catch (JSONException e) {
                                 Log.e(LOGTAG, "JSON error", e);
                             }
                             tabs.put(tabObject);
                         }
                     };
 
                     parser.parse(sessionString);
+                    if (mPrivateBrowsingSession != null) {
+                        parser.parse(mPrivateBrowsingSession);
+                    }
 
                     if (tabs.length() > 0) {
                         sessionString = new JSONObject().put("windows", new JSONArray().put(new JSONObject().put("tabs", tabs))).toString();
                     } else {
                         throw new Exception("No tabs could be read from session file");
                     }
                 }
 
@@ -1804,21 +1808,16 @@ abstract public class GeckoApp
             setLaunchState(GeckoApp.LaunchState.GeckoRunning);
             Tab selectedTab = Tabs.getInstance().getSelectedTab();
             if (selectedTab != null)
                 Tabs.getInstance().selectTab(selectedTab.getId());
             connectGeckoLayerClient();
             GeckoAppShell.setLayerClient(mLayerView.getLayerClient());
             GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Viewport:Flush", null));
         }
-
-        if (mPrivateBrowsingSession != null) {
-            GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent(
-                    "PrivateBrowsing:Restore", mPrivateBrowsingSession));
-        }
     }
 
     public GeckoProfile getProfile() {
         // fall back to default profile if we didn't load a specific one
         if (mProfile == null) {
             mProfile = GeckoProfile.get(this);
         }
         return mProfile;
--- a/mobile/android/components/SessionStore.js
+++ b/mobile/android/components/SessionStore.js
@@ -133,17 +133,16 @@ SessionStore.prototype = {
         observerService.addObserver(this, "final-ui-startup", true);
         observerService.addObserver(this, "domwindowopened", true);
         observerService.addObserver(this, "domwindowclosed", true);
         observerService.addObserver(this, "browser-lastwindow-close-granted", true);
         observerService.addObserver(this, "browser:purge-session-history", true);
         observerService.addObserver(this, "quit-application-requested", true);
         observerService.addObserver(this, "quit-application-granted", true);
         observerService.addObserver(this, "quit-application", true);
-        observerService.addObserver(this, "PrivateBrowsing:Restore", true);
         break;
       case "final-ui-startup":
         observerService.removeObserver(this, "final-ui-startup");
         this.init();
         break;
       case "domwindowopened":
         let window = aSubject;
         window.addEventListener("load", function() {
@@ -199,17 +198,16 @@ SessionStore.prototype = {
           this._sessionFile.moveTo(null, this._sessionFileBackup.leafName);
 
         observerService.removeObserver(this, "domwindowopened");
         observerService.removeObserver(this, "domwindowclosed");
         observerService.removeObserver(this, "browser-lastwindow-close-granted");
         observerService.removeObserver(this, "quit-application-requested");
         observerService.removeObserver(this, "quit-application-granted");
         observerService.removeObserver(this, "quit-application");
-        observerService.removeObserver(this, "PrivateBrowsing:Restore");
 
         // If a save has been queued, kill the timer and save state now
         if (this._saveTimer) {
           this._saveTimer.cancel();
           this._saveTimer = null;
           this.saveState();
         }
         break;
@@ -233,25 +231,16 @@ SessionStore.prototype = {
 
         Services.obs.notifyObservers(null, "sessionstore-state-purge-complete", "");
         break;
       case "timer-callback":
         // Timer call back for delayed saving
         this._saveTimer = null;
         this.saveState();
         break;
-      case "PrivateBrowsing:Restore":
-        let session;
-        try {
-          session = JSON.parse(aData);
-          this._restoreWindow(session, session.windows[0].selected != null);
-        } catch (e) {
-          Cu.reportError("SessionStore: Could not restore browser session: " + e);
-        }
-        break;
     }
   },
 
   handleEvent: function ss_handleEvent(aEvent) {
     let window = aEvent.currentTarget.ownerDocument.defaultView;
     switch (aEvent.type) {
       case "TabOpen": {
         let browser = aEvent.target;