<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[183713] trunk/Source/WebInspectorUI</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/183713">183713</a></dd>
<dt>Author</dt> <dd>timothy@apple.com</dd>
<dt>Date</dt> <dd>2015-05-02 02:36:12 -0700 (Sat, 02 May 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Web Inspector: REGRESSION: Resources section doesn't update after changes are made to a local file
https://bugs.webkit.org/show_bug.cgi?id=144512

The content view was being associated with the wrong represented object. This caused the code to use
the old main resource when showing the frame again.

Reviewed by Joseph Pecoraro.

* UserInterface/Base/Main.js:
(WebInspector._frameWasAdded.delayedWork):
(WebInspector._frameWasAdded):
With the changes in ResourceSidebarPanel, we need to delay showing the frame.

* UserInterface/Views/ContentBrowserTabContentView.js:
(WebInspector.ContentBrowserTabContentView.prototype.showRepresentedObject):
Avoid restoring state by calling cancelRestoringState(). Not fully related to this bug,
but it was preventing testing the cases.

* UserInterface/Views/ContentViewContainer.js:
(WebInspector.ContentViewContainer.prototype.contentViewForRepresentedObject):
This fixes the bug. Don't associate the content view with the Frame, associate it with
the Resource that we actually show.

* UserInterface/Views/NavigationSidebarPanel.js:
(WebInspector.NavigationSidebarPanel.prototype.cancelRestoringState): Added.

* UserInterface/Views/ResourceSidebarPanel.js:
(WebInspector.ResourceSidebarPanel): Remove unused _waitingForInitialMainFrame.
(WebInspector.ResourceSidebarPanel.prototype.treeElementForRepresentedObject):
(WebInspector.ResourceSidebarPanel.prototype._mainResourceDidChange):
(WebInspector.ResourceSidebarPanel.prototype._mainFrameDidChange):
(WebInspector.ResourceSidebarPanel.prototype._mainFrameMainResourceDidChange.delayedWork):
(WebInspector.ResourceSidebarPanel.prototype._mainFrameMainResourceDidChange):
Clean up how we show the main frame in the sidebar. This was a two step mess before.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebInspectorUIChangeLog">trunk/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceBaseMainjs">trunk/Source/WebInspectorUI/UserInterface/Base/Main.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsContentBrowserTabContentViewjs">trunk/Source/WebInspectorUI/UserInterface/Views/ContentBrowserTabContentView.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsContentViewContainerjs">trunk/Source/WebInspectorUI/UserInterface/Views/ContentViewContainer.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsNavigationSidebarPaneljs">trunk/Source/WebInspectorUI/UserInterface/Views/NavigationSidebarPanel.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsResourceSidebarPaneljs">trunk/Source/WebInspectorUI/UserInterface/Views/ResourceSidebarPanel.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/ChangeLog (183712 => 183713)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/ChangeLog        2015-05-02 06:09:47 UTC (rev 183712)
+++ trunk/Source/WebInspectorUI/ChangeLog        2015-05-02 09:36:12 UTC (rev 183713)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2015-05-02  Timothy Hatcher  &lt;timothy@apple.com&gt;
+
+        Web Inspector: REGRESSION: Resources section doesn't update after changes are made to a local file
+        https://bugs.webkit.org/show_bug.cgi?id=144512
+
+        The content view was being associated with the wrong represented object. This caused the code to use
+        the old main resource when showing the frame again.
+
+        Reviewed by Joseph Pecoraro.
+
+        * UserInterface/Base/Main.js:
+        (WebInspector._frameWasAdded.delayedWork):
+        (WebInspector._frameWasAdded):
+        With the changes in ResourceSidebarPanel, we need to delay showing the frame.
+
+        * UserInterface/Views/ContentBrowserTabContentView.js:
+        (WebInspector.ContentBrowserTabContentView.prototype.showRepresentedObject):
+        Avoid restoring state by calling cancelRestoringState(). Not fully related to this bug,
+        but it was preventing testing the cases.
+
+        * UserInterface/Views/ContentViewContainer.js:
+        (WebInspector.ContentViewContainer.prototype.contentViewForRepresentedObject):
+        This fixes the bug. Don't associate the content view with the Frame, associate it with
+        the Resource that we actually show.
+
+        * UserInterface/Views/NavigationSidebarPanel.js:
+        (WebInspector.NavigationSidebarPanel.prototype.cancelRestoringState): Added.
+
+        * UserInterface/Views/ResourceSidebarPanel.js:
+        (WebInspector.ResourceSidebarPanel): Remove unused _waitingForInitialMainFrame.
+        (WebInspector.ResourceSidebarPanel.prototype.treeElementForRepresentedObject):
+        (WebInspector.ResourceSidebarPanel.prototype._mainResourceDidChange):
+        (WebInspector.ResourceSidebarPanel.prototype._mainFrameDidChange):
+        (WebInspector.ResourceSidebarPanel.prototype._mainFrameMainResourceDidChange.delayedWork):
+        (WebInspector.ResourceSidebarPanel.prototype._mainFrameMainResourceDidChange):
+        Clean up how we show the main frame in the sidebar. This was a two step mess before.
+
</ins><span class="cx"> 2015-04-29  Timothy Hatcher  &lt;timothy@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Inspector: Remove FrameContentView.js
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceBaseMainjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Main.js (183712 => 183713)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Base/Main.js        2015-05-02 06:09:47 UTC (rev 183712)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Main.js        2015-05-02 09:36:12 UTC (rev 183713)
</span><span class="lines">@@ -1092,7 +1092,14 @@
</span><span class="cx">     if (frame.id !== this._frameIdentifierToShowSourceCodeWhenAvailable)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    this.showSourceCodeForFrame(frame.id);
</del><ins>+    function delayedWork()
+    {
+        this.showSourceCodeForFrame(frame.id);
+    }
+
+    // Delay showing the frame since FrameWasAdded is called before MainFrameChanged.
+    // Calling showSourceCodeForFrame before MainFrameChanged will show the frame then close it.
+    setTimeout(delayedWork.bind(this));
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> WebInspector._mainFrameDidChange = function(event)
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsContentBrowserTabContentViewjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ContentBrowserTabContentView.js (183712 => 183713)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Views/ContentBrowserTabContentView.js        2015-05-02 06:09:47 UTC (rev 183712)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ContentBrowserTabContentView.js        2015-05-02 09:36:12 UTC (rev 183713)
</span><span class="lines">@@ -180,6 +180,8 @@
</span><span class="cx"> 
</span><span class="cx">     showRepresentedObject: function(representedObject, cookie)
</span><span class="cx">     {
</span><ins>+        if (this.navigationSidebarPanel)
+            this.navigationSidebarPanel.cancelRestoringState();
</ins><span class="cx">         this.contentBrowser.showContentViewForRepresentedObject(representedObject, cookie);
</span><span class="cx">     },
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsContentViewContainerjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ContentViewContainer.js (183712 => 183713)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Views/ContentViewContainer.js        2015-05-02 06:09:47 UTC (rev 183712)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ContentViewContainer.js        2015-05-02 09:36:12 UTC (rev 183713)
</span><span class="lines">@@ -114,6 +114,11 @@
</span><span class="cx">         if (!contentView)
</span><span class="cx">             return null;
</span><span class="cx"> 
</span><ins>+        // The representedObject can change in the constructor for ContentView. Remember the
+        // contentViews on the real representedObject and not the one originally supplied.
+        // The main case for this is a Frame being passed in and the main Resource being used.
+        representedObject = contentView.representedObject;
+
</ins><span class="cx">         // Remember this content view for future calls.
</span><span class="cx">         if (!representedObject.__contentViews)
</span><span class="cx">             representedObject.__contentViews = [];
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsNavigationSidebarPaneljs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/NavigationSidebarPanel.js (183712 => 183713)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Views/NavigationSidebarPanel.js        2015-05-02 06:09:47 UTC (rev 183712)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/NavigationSidebarPanel.js        2015-05-02 09:36:12 UTC (rev 183713)
</span><span class="lines">@@ -139,6 +139,15 @@
</span><span class="cx">         return this._restoringState;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    cancelRestoringState()
+    {
+        if (!this._finalAttemptToRestoreViewStateTimeout)
+            return;
+
+        clearTimeout(this._finalAttemptToRestoreViewStateTimeout);
+        this._finalAttemptToRestoreViewStateTimeout = undefined;
+    }
+
</ins><span class="cx">     createContentTreeOutline(dontHideByDefault, suppressFiltering)
</span><span class="cx">     {
</span><span class="cx">         var contentTreeOutlineElement = document.createElement(&quot;ol&quot;);
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsResourceSidebarPaneljs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ResourceSidebarPanel.js (183712 => 183713)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Views/ResourceSidebarPanel.js        2015-05-02 06:09:47 UTC (rev 183712)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ResourceSidebarPanel.js        2015-05-02 09:36:12 UTC (rev 183713)
</span><span class="lines">@@ -33,7 +33,7 @@
</span><span class="cx"> 
</span><span class="cx">         this.filterBar.placeholder = WebInspector.UIString(&quot;Filter Resource List&quot;);
</span><span class="cx"> 
</span><del>-        this._waitingForInitialMainFrame = true;
</del><ins>+        WebInspector.Frame.addEventListener(WebInspector.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
</ins><span class="cx"> 
</span><span class="cx">         WebInspector.frameResourceManager.addEventListener(WebInspector.FrameResourceManager.Event.MainFrameDidChange, this._mainFrameDidChange, this);
</span><span class="cx"> 
</span><span class="lines">@@ -110,8 +110,10 @@
</span><span class="cx">             return treeElement;
</span><span class="cx"> 
</span><span class="cx">         // Only special case Script objects.
</span><del>-        if (!(representedObject instanceof WebInspector.Script))
</del><ins>+        if (!(representedObject instanceof WebInspector.Script)) {
+            console.error(&quot;Didn't find a TreeElement for representedObject&quot;, representedObject);
</ins><span class="cx">             return null;
</span><ins>+        }
</ins><span class="cx"> 
</span><span class="cx">         // If the Script has a URL we should have found it earlier.
</span><span class="cx">         if (representedObject.url) {
</span><span class="lines">@@ -139,21 +141,36 @@
</span><span class="cx"> 
</span><span class="cx">     // Private
</span><span class="cx"> 
</span><ins>+    _mainResourceDidChange(event)
+    {
+        if (!event.target.isMainFrame())
+            return;
+
+        this._mainFrameMainResourceDidChange(event.target);
+    }
+
</ins><span class="cx">     _mainFrameDidChange(event)
</span><span class="cx">     {
</span><ins>+        this._mainFrameMainResourceDidChange(WebInspector.frameResourceManager.mainFrame);
+    }
+
+    _mainFrameMainResourceDidChange(mainFrame)
+    {
+        this.contentBrowser.contentViewContainer.closeAllContentViews();
+
</ins><span class="cx">         if (this._mainFrameTreeElement) {
</span><del>-            this._mainFrameTreeElement.frame.removeEventListener(WebInspector.Frame.Event.MainResourceDidChange, this._mainFrameMainResourceDidChange, this);
</del><span class="cx">             this.contentTreeOutline.removeChild(this._mainFrameTreeElement);
</span><span class="cx">             this._mainFrameTreeElement = null;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        var newFrame = WebInspector.frameResourceManager.mainFrame;
-        if (newFrame) {
-            newFrame.addEventListener(WebInspector.Frame.Event.MainResourceDidChange, this._mainFrameMainResourceDidChange, this);
-            this._mainFrameTreeElement = new WebInspector.FrameTreeElement(newFrame);
-            this.contentTreeOutline.insertChild(this._mainFrameTreeElement, 0);
</del><ins>+        if (!mainFrame)
+            return;
</ins><span class="cx"> 
</span><del>-            // Select a tree element by default. Allow onselect if we aren't showing a content view.
</del><ins>+        this._mainFrameTreeElement = new WebInspector.FrameTreeElement(mainFrame);
+        this.contentTreeOutline.insertChild(this._mainFrameTreeElement, 0);
+
+        function delayedWork()
+        {
</ins><span class="cx">             if (!this.contentTreeOutline.selectedTreeElement) {
</span><span class="cx">                 var currentContentView = this.contentBrowser.currentContentView;
</span><span class="cx">                 var treeElement = currentContentView ? this.treeElementForRepresentedObject(currentContentView.representedObject) : null;
</span><span class="lines">@@ -163,40 +180,11 @@
</span><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        // The navigation path needs update when the main frame changes, since all resources are under the main frame.
-        this.contentBrowser.updateHierarchicalPathForCurrentContentView();
-
-        // We only care about the first time the main frame changes.
-        if (!this._waitingForInitialMainFrame)
-            return;
-
-        // Only if there is a main frame.
-        if (!newFrame)
-            return;
-
-        this._waitingForInitialMainFrame = false;
</del><ins>+        // Cookie restoration will attempt to re-select the resource we were showing.
+        // Give it time to do that before selecting the main frame resource.
+        setTimeout(delayedWork.bind(this));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    _mainFrameMainResourceDidChange(event)
-    {
-        this.contentBrowser.contentViewContainer.closeAllContentViews();
-
-        function delayedWork()
-        {
-            // Show the main frame since there is no content view showing.
-            // Cookie restoration will attempt to re-select the resource we were showing.
-            if (!this.contentBrowser.currentContentView) {
-                // NOTE: This selection, during provisional loading, won't be saved, so it is
-                // safe to do and not-clobber cookie restoration.
-                this.showDefaultContentViewForTreeElement(this._mainFrameTreeElement);
-            }
-        }
-
-        // Delay this work because other listeners of this event might not have fired yet. So selecting the main frame
-        // before those listeners do their work might cause the content of the old page to show instead of the new page.
-        setTimeout(delayedWork.bind(this), 0);
-    }
-
</del><span class="cx">     _scriptWasAdded(event)
</span><span class="cx">     {
</span><span class="cx">         var script = event.data.script;
</span></span></pre>
</div>
</div>

</body>
</html>