Web Inspector: Save and restore tab state on reload and between sessions
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 26 Apr 2015 01:26:41 +0000 (01:26 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 26 Apr 2015 01:26:41 +0000 (01:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=144202

Reviewed by Joseph Pecoraro.

* UserInterface/Base/Main.js:
(WebInspector.contentLoaded):
(WebInspector._mainResourceDidChange):
(WebInspector._provisionalLoadStarted):
(WebInspector._restoreCookieForOpenTabs):
(WebInspector._saveCookieForOpenTabs):
(WebInspector._pageHidden):
* UserInterface/Views/TabContentView.js:
(WebInspector.TabContentView):
(WebInspector.TabContentView.prototype.restoreStateFromCookie):
(WebInspector.TabContentView.prototype.saveStateToCookie):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183340 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Base/Main.js
Source/WebInspectorUI/UserInterface/Views/TabContentView.js

index 0d64218..0e8c68d 100644 (file)
@@ -1,5 +1,24 @@
 2015-04-25  Timothy Hatcher  <timothy@apple.com>
 
+        Web Inspector: Save and restore tab state on reload and between sessions
+        https://bugs.webkit.org/show_bug.cgi?id=144202
+
+        Reviewed by Joseph Pecoraro.
+
+        * UserInterface/Base/Main.js:
+        (WebInspector.contentLoaded):
+        (WebInspector._mainResourceDidChange):
+        (WebInspector._provisionalLoadStarted):
+        (WebInspector._restoreCookieForOpenTabs):
+        (WebInspector._saveCookieForOpenTabs):
+        (WebInspector._pageHidden):
+        * UserInterface/Views/TabContentView.js:
+        (WebInspector.TabContentView):
+        (WebInspector.TabContentView.prototype.restoreStateFromCookie):
+        (WebInspector.TabContentView.prototype.saveStateToCookie):
+
+2015-04-25  Timothy Hatcher  <timothy@apple.com>
+
         Web Inspector: Split search from ResourceSidebarPanel into a Search tab and sidebar
         https://bugs.webkit.org/show_bug.cgi?id=144197
 
index 48a1043..94c42d6 100644 (file)
@@ -332,6 +332,8 @@ WebInspector.contentLoaded = function()
         this.tabBrowser.addTabForContentView(tabContentView, true);
     }
 
+    this._restoreCookieForOpenTabs();
+
     this.tabBar.selectedTabBarItem = this._selectedTabIndexSetting.value;
 
     if (!this.tabBar.selectedTabBarItem)
@@ -997,6 +999,8 @@ WebInspector._mainResourceDidChange = function(event)
 
     this._inProvisionalLoad = false;
 
+    this._restoreCookieForOpenTabs();
+
     this._updateDownloadToolbarButton();
 
     this.updateWindowTitle();
@@ -1007,9 +1011,27 @@ WebInspector._provisionalLoadStarted = function(event)
     if (!event.target.isMainFrame())
         return;
 
+    this._saveCookieForOpenTabs();
+
     this._inProvisionalLoad = true;
 };
 
+WebInspector._restoreCookieForOpenTabs = function(causedByReload)
+{
+    for (var tabBarItem of this.tabBar.tabBarItems) {
+        var tabContentView = tabBarItem.representedObject;
+        tabContentView.restoreStateFromCookie(causedByReload);
+    }
+};
+
+WebInspector._saveCookieForOpenTabs = function()
+{
+    for (var tabBarItem of this.tabBar.tabBarItems) {
+        var tabContentView = tabBarItem.representedObject;
+        tabContentView.saveStateToCookie();
+    }
+};
+
 WebInspector._windowFocused = function(event)
 {
     if (event.target.document.nodeType !== Node.DOCUMENT_NODE || this.docked)
@@ -1065,7 +1087,7 @@ WebInspector._mouseMoved = function(event)
 
 WebInspector._pageHidden = function(event)
 {
-    // FIXME: Save inspector state.
+    this._saveCookieForOpenTabs();
 };
 
 WebInspector._undock = function(event)
index b9f4002..2d8df17 100644 (file)
@@ -49,6 +49,8 @@ WebInspector.TabContentView = function(identifier, styleClassNames, tabBarItem,
 
     this._detailsSidebarCollapsedSetting = new WebInspector.Setting(identifier + "-details-sidebar-collapsed", true);
     this._detailsSidebarSelectedPanelSetting = new WebInspector.Setting(identifier + "-details-sidebar-selected-panel", null);
+
+    this._cookieSetting = new WebInspector.Setting(identifier + "-tab-cookie", {});
 };
 
 WebInspector.TabContentView.prototype = {
@@ -105,6 +107,28 @@ WebInspector.TabContentView.prototype = {
         return false;
     },
 
+    restoreStateFromCookie: function(causedByReload)
+    {
+        if (!this.navigationSidebarPanel)
+            return;
+
+        var matchTypeOnlyDelayForReload = 2000;
+        var matchTypeOnlyDelayForReopen = 1000;
+
+        var relaxMatchDelay = causedByReload ? matchTypeOnlyDelayForReload : matchTypeOnlyDelayForReopen;
+        this.navigationSidebarPanel.restoreStateFromCookie(this._cookieSetting.value || {}, relaxMatchDelay);
+    },
+
+    saveStateToCookie: function()
+    {
+        if (!this.navigationSidebarPanel)
+            return;
+
+        var cookie = this._cookieSetting.value || {};
+        this.navigationSidebarPanel.saveStateToCookie(cookie);
+        this._cookieSetting.value = cookie;
+    },
+
     get navigationSidebarPanel()
     {
         return this._navigationSidebarPanel;