Web Inspector: Tab Restoration incorrectly makes ContentViews "shown" in background...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 May 2015 19:53:28 +0000 (19:53 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 May 2015 19:53:28 +0000 (19:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=145080

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2015-05-18
Reviewed by Timothy Hatcher.

Many tabs have their own content browser / navigation sidebar. During
state restoration, each tab would immediately try to restore an
appropriate ContentView after the load / navigation. However, in doing
so, we weren't respecting whether or not the Tab the ContentBrowser
was in was hidden or not, so ContentViews in background tags were
still being treated as shown/visible.

This patch changes state restoration to only affect the foreground
tab, and be delayed on all background tabs until that tab is shown.
This reduces the amount of work on load and navigation to just a
single tab instead of all tabs. Most importantly, it avoids having
performing work on ContentBrowsers that are non-visible, so state
restoration only happens for visible ContentBrowsers.

For simplicity, in the case of a delayed tab restoration triggered
by the user switching tabs, we don't try twice (like we occasionally
do on load/reload). We could add back some hueristic here if needed.

* UserInterface/Base/Main.js:
(WebInspector.contentLoaded):
(WebInspector.activateExtraDomains):
(WebInspector._mainResourceDidChange):
(WebInspector._restoreCookieForOpenTabs):
* UserInterface/Views/NavigationSidebarPanel.js:

* UserInterface/Views/TabContentView.js:
(WebInspector.TabContentView.prototype.shown):
(WebInspector.TabContentView.prototype.restoreStateFromCookie):
(WebInspector.TabContentView.prototype.saveStateToCookie):
When asked to restore state, save that logic until the next time the tab is shown.

* UserInterface/Views/TextEditor.js:
(WebInspector.TextEditor.prototype.get visible):
* UserInterface/Views/SourceCodeTextEditor.js:
(WebInspector.SourceCodeTextEditor.prototype.editingControllerDidStartEditing):
(WebInspector.SourceCodeTextEditor.prototype._setTypeTokenAnnotatorEnabledState): Deleted.
Although this didn't actually catch the issue, it could potentially
catch other issues in the future. We don't want to enable the annotators
in a non-visible text editor, as it could be a performance issue.

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Base/Main.js
Source/WebInspectorUI/UserInterface/Views/NavigationSidebarPanel.js
Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js
Source/WebInspectorUI/UserInterface/Views/TabContentView.js
Source/WebInspectorUI/UserInterface/Views/TextEditor.js

index 6ad0a32..718760d 100644 (file)
@@ -1,3 +1,50 @@
+2015-05-18  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Tab Restoration incorrectly makes ContentViews "shown" in background tabs
+        https://bugs.webkit.org/show_bug.cgi?id=145080
+
+        Reviewed by Timothy Hatcher.
+
+        Many tabs have their own content browser / navigation sidebar. During
+        state restoration, each tab would immediately try to restore an
+        appropriate ContentView after the load / navigation. However, in doing
+        so, we weren't respecting whether or not the Tab the ContentBrowser
+        was in was hidden or not, so ContentViews in background tags were
+        still being treated as shown/visible.
+
+        This patch changes state restoration to only affect the foreground
+        tab, and be delayed on all background tabs until that tab is shown.
+        This reduces the amount of work on load and navigation to just a
+        single tab instead of all tabs. Most importantly, it avoids having
+        performing work on ContentBrowsers that are non-visible, so state
+        restoration only happens for visible ContentBrowsers.
+
+        For simplicity, in the case of a delayed tab restoration triggered
+        by the user switching tabs, we don't try twice (like we occasionally
+        do on load/reload). We could add back some hueristic here if needed.
+
+        * UserInterface/Base/Main.js:
+        (WebInspector.contentLoaded):
+        (WebInspector.activateExtraDomains):
+        (WebInspector._mainResourceDidChange):
+        (WebInspector._restoreCookieForOpenTabs):
+        * UserInterface/Views/NavigationSidebarPanel.js:
+
+        * UserInterface/Views/TabContentView.js:
+        (WebInspector.TabContentView.prototype.shown):
+        (WebInspector.TabContentView.prototype.restoreStateFromCookie):
+        (WebInspector.TabContentView.prototype.saveStateToCookie):
+        When asked to restore state, save that logic until the next time the tab is shown.
+
+        * UserInterface/Views/TextEditor.js:
+        (WebInspector.TextEditor.prototype.get visible):
+        * UserInterface/Views/SourceCodeTextEditor.js:
+        (WebInspector.SourceCodeTextEditor.prototype.editingControllerDidStartEditing):
+        (WebInspector.SourceCodeTextEditor.prototype._setTypeTokenAnnotatorEnabledState): Deleted.
+        Although this didn't actually catch the issue, it could potentially
+        catch other issues in the future. We don't want to enable the annotators
+        in a non-visible text editor, as it could be a performance issue.
+
 2015-05-15  Matt Baker  <mattbaker@apple.com>
 
         Web Inspector: empty timeline should not use previous timeline's zoom interval
index 6561d21..33579b6 100644 (file)
@@ -41,6 +41,12 @@ WebInspector.DebuggableType = {
 WebInspector.SelectedSidebarPanelCookieKey = "selected-sidebar-panel";
 WebInspector.TypeIdentifierCookieKey = "represented-object-type";
 
+WebInspector.StateRestorationType = {
+    Load: "state-restoration-load",
+    Navigation: "state-restoration-navigation",
+    Delayed: "state-restoration-delayed",
+};
+
 WebInspector.loaded = function()
 {
     // Initialize WebSocket to communication.
@@ -343,7 +349,7 @@ WebInspector.contentLoaded = function()
         this.tabBrowser.addTabForContentView(tabContentView, true);
     }
 
-    this._restoreCookieForOpenTabs();
+    this._restoreCookieForOpenTabs(WebInspector.StateRestorationType.Load);
 
     this.tabBar.selectedTabBarItem = this._selectedTabIndexSetting.value;
 
@@ -508,7 +514,7 @@ WebInspector.activateExtraDomains = function(domains)
 
         this.tabBrowser.addTabForContentView(tabContentView, true);
 
-        tabContentView.restoreStateFromCookie();
+        tabContentView.restoreStateFromCookie(WebInspector.StateRestorationType.Load);
     }
 
     this._pendingOpenTabTypes = stillPendingOpenTabTypes;
@@ -1129,7 +1135,7 @@ WebInspector._mainResourceDidChange = function(event)
 
     // Run cookie restoration after we are sure all of the Tabs and NavigationSidebarPanels
     // have updated with respect to the main resource change.
-    setTimeout(this._restoreCookieForOpenTabs.bind(this, true));
+    setTimeout(this._restoreCookieForOpenTabs.bind(this, WebInspector.StateRestorationType.Navigation));
 
     this._updateDownloadToolbarButton();
 
@@ -1146,13 +1152,13 @@ WebInspector._provisionalLoadStarted = function(event)
     this._inProvisionalLoad = true;
 };
 
-WebInspector._restoreCookieForOpenTabs = function(causedByNavigation)
+WebInspector._restoreCookieForOpenTabs = function(restorationType)
 {
     for (var tabBarItem of this.tabBar.tabBarItems) {
         var tabContentView = tabBarItem.representedObject;
         if (!(tabContentView instanceof WebInspector.TabContentView))
             continue;
-        tabContentView.restoreStateFromCookie(causedByNavigation);
+        tabContentView.restoreStateFromCookie(restorationType);
     }
 };
 
index 9acee9f..07b9e52 100644 (file)
@@ -235,6 +235,9 @@ WebInspector.NavigationSidebarPanel = class NavigationSidebarPanel extends WebIn
         if (this._finalAttemptToRestoreViewStateTimeout)
             clearTimeout(this._finalAttemptToRestoreViewStateTimeout);
 
+        if (relaxedMatchDelay === 0)
+            return;
+
         function finalAttemptToRestoreViewStateFromCookie()
         {
             delete this._finalAttemptToRestoreViewStateTimeout;
index 3ff2cda..77f5e40 100644 (file)
@@ -1648,6 +1648,8 @@ WebInspector.SourceCodeTextEditor = class SourceCodeTextEditor extends WebInspec
             return;
 
         if (shouldActivate) {
+            console.assert(this.visible, "Annotators should not be enabled if the TextEditor is not visible");
+
             RuntimeAgent.enableTypeProfiler();
 
             this._typeTokenAnnotator.reset();
index 02207b9..8645073 100644 (file)
@@ -107,15 +107,30 @@ WebInspector.TabContentView.prototype = {
         return false;
     },
 
-    restoreStateFromCookie: function(causedByNavigation)
+    shown: function()
+    {
+        if (this._shouldRestoreStateWhenShown)
+            this.restoreStateFromCookie(WebInspector.StateRestorationType.Delayed);
+    },
+
+    restoreStateFromCookie: function(restorationType)
     {
         if (!this.navigationSidebarPanel)
             return;
 
-        var matchTypeOnlyDelayForNavigation = 2000;
-        var matchTypeOnlyDelayForReopen = 1000;
+        if (!this.visible) {
+            this._shouldRestoreStateWhenShown = true;
+            return;
+        }
+
+        this._shouldRestoreStateWhenShown = false;
+
+        var relaxMatchDelay = 0;
+        if (restorationType === WebInspector.StateRestorationType.Load)
+            relaxMatchDelay = 1000;
+        else if (restorationType === WebInspector.StateRestorationType.Navigation)
+            relaxMatchDelay = 2000;
 
-        var relaxMatchDelay = causedByNavigation ? matchTypeOnlyDelayForNavigation : matchTypeOnlyDelayForReopen;
         this.navigationSidebarPanel.restoreStateFromCookie(this._cookieSetting.value || {}, relaxMatchDelay);
     },
 
@@ -124,6 +139,9 @@ WebInspector.TabContentView.prototype = {
         if (!this.navigationSidebarPanel)
             return;
 
+        if (this._shouldRestoreStateWhenShown)
+            return;
+
         var cookie = {};
         this.navigationSidebarPanel.saveStateToCookie(cookie);
         this._cookieSetting.value = cookie;
index 1965410..d335743 100644 (file)
@@ -76,6 +76,11 @@ WebInspector.TextEditor = class TextEditor extends WebInspector.Object
         return this._element;
     }
 
+    get visible()
+    {
+        return this._visible;
+    }
+
     get string()
     {
         return this._codeMirror.getValue();