<!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>[186098] 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/186098">186098</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2015-06-29 17:27:29 -0700 (Mon, 29 Jun 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Web Inspector: iOS 8: Resources Timeline Data does not show up
https://bugs.webkit.org/show_bug.cgi?id=146433

Patch by Joseph Pecoraro &lt;pecoraro@apple.com&gt; on 2015-06-29
Reviewed by Timothy Hatcher.

There were a couple issues with initializing the legacy base timestamp
for attempting to dynamically compute monotonically increasing timestamps
for timeline events for legacy backends.

    * Sometimes legacy timestamps were in seconds since epochs,
      sometimes milliseconds. The frontend did not handle both.

    * On navigations, even while resetting the base timestamp for
      the first new record received, the main resource still had
      a will send request time computed from the previous page's
      time system. This patch re-uses the original timestamp for
      this main resource as the new base and all future records
      are computed relative to this.

* UserInterface/Controllers/FrameResourceManager.js:
(WebInspector.FrameResourceManager.prototype.resourceRequestWillBeSent):
(WebInspector.FrameResourceManager.prototype._addNewResourceToFrame):
* UserInterface/Models/Resource.js:
(WebInspector.Resource):
(WebInspector.Resource.prototype.get originalRequestWillBeSentTimestamp):
For legacy timestamp calculations, save the original request will be sent
timestamp on the Resource in case it is needed.

* UserInterface/Controllers/TimelineManager.js:
(WebInspector.TimelineManager.prototype._loadNewRecording):
When auto-starting a new recording for a navigation / reload, use the
main resource's request will be sent timestamp as the new base.

* UserInterface/Models/TimelineRecording.js:
Address legacy timeline timestamps by handling both legacy timestamps
that may be seconds / milliseconds.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebInspectorUIChangeLog">trunk/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceControllersFrameResourceManagerjs">trunk/Source/WebInspectorUI/UserInterface/Controllers/FrameResourceManager.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceControllersTimelineManagerjs">trunk/Source/WebInspectorUI/UserInterface/Controllers/TimelineManager.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceModelsResourcejs">trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceModelsTimelineRecordingjs">trunk/Source/WebInspectorUI/UserInterface/Models/TimelineRecording.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/ChangeLog (186097 => 186098)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/ChangeLog        2015-06-30 00:24:05 UTC (rev 186097)
+++ trunk/Source/WebInspectorUI/ChangeLog        2015-06-30 00:27:29 UTC (rev 186098)
</span><span class="lines">@@ -1,5 +1,44 @@
</span><span class="cx"> 2015-06-29  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Web Inspector: iOS 8: Resources Timeline Data does not show up
+        https://bugs.webkit.org/show_bug.cgi?id=146433
+
+        Reviewed by Timothy Hatcher.
+
+        There were a couple issues with initializing the legacy base timestamp
+        for attempting to dynamically compute monotonically increasing timestamps
+        for timeline events for legacy backends.
+
+            * Sometimes legacy timestamps were in seconds since epochs,
+              sometimes milliseconds. The frontend did not handle both.
+
+            * On navigations, even while resetting the base timestamp for
+              the first new record received, the main resource still had
+              a will send request time computed from the previous page's
+              time system. This patch re-uses the original timestamp for
+              this main resource as the new base and all future records
+              are computed relative to this.
+
+        * UserInterface/Controllers/FrameResourceManager.js:
+        (WebInspector.FrameResourceManager.prototype.resourceRequestWillBeSent):
+        (WebInspector.FrameResourceManager.prototype._addNewResourceToFrame):
+        * UserInterface/Models/Resource.js:
+        (WebInspector.Resource):
+        (WebInspector.Resource.prototype.get originalRequestWillBeSentTimestamp):
+        For legacy timestamp calculations, save the original request will be sent
+        timestamp on the Resource in case it is needed.
+
+        * UserInterface/Controllers/TimelineManager.js:
+        (WebInspector.TimelineManager.prototype._loadNewRecording):
+        When auto-starting a new recording for a navigation / reload, use the
+        main resource's request will be sent timestamp as the new base.
+
+        * UserInterface/Models/TimelineRecording.js:
+        Address legacy timeline timestamps by handling both legacy timestamps
+        that may be seconds / milliseconds.
+
+2015-06-29  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
+
</ins><span class="cx">         REGRESSION: Web Inspector: Jump to Definition is broken
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=146376
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceControllersFrameResourceManagerjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/FrameResourceManager.js (186097 => 186098)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Controllers/FrameResourceManager.js        2015-06-30 00:24:05 UTC (rev 186097)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/FrameResourceManager.js        2015-06-30 00:27:29 UTC (rev 186098)
</span><span class="lines">@@ -177,6 +177,13 @@
</span><span class="cx">         if (this._waitingForMainFrameResourceTreePayload)
</span><span class="cx">             return;
</span><span class="cx"> 
</span><ins>+        // COMPATIBILITY (iOS 8): Timeline timestamps for legacy backends are computed
+        // dynamically from the first backend timestamp received. For navigations we
+        // need to reset that base timestamp, and an appropriate timestamp to use is
+        // the new main resource's will be sent timestamp. So save this value on the
+        // resource in case it becomes a main resource.
+        var originalRequestWillBeSentTimestamp = timestamp;
+
</ins><span class="cx">         var elapsedTime = WebInspector.timelineManager.computeElapsedTime(timestamp);
</span><span class="cx">         var resource = this._resourceRequestIdentifierMap[requestIdentifier];
</span><span class="cx">         if (resource) {
</span><span class="lines">@@ -189,7 +196,7 @@
</span><span class="cx">         var initiatorSourceCodeLocation = this._initiatorSourceCodeLocationFromPayload(initiator);
</span><span class="cx"> 
</span><span class="cx">         // This is a new request, make a new resource and add it to the right frame.
</span><del>-        resource = this._addNewResourceToFrame(requestIdentifier, frameIdentifier, loaderIdentifier, request.url, type, request.method, request.headers, request.postData, elapsedTime, null, null, initiatorSourceCodeLocation);
</del><ins>+        resource = this._addNewResourceToFrame(requestIdentifier, frameIdentifier, loaderIdentifier, request.url, type, request.method, request.headers, request.postData, elapsedTime, null, null, initiatorSourceCodeLocation, originalRequestWillBeSentTimestamp);
</ins><span class="cx"> 
</span><span class="cx">         // Associate the resource with the requestIdentifier so it can be found in future loading events.
</span><span class="cx">         this._resourceRequestIdentifierMap[requestIdentifier] = resource;
</span><span class="lines">@@ -380,7 +387,7 @@
</span><span class="cx"> 
</span><span class="cx">     // Private
</span><span class="cx"> 
</span><del>-    _addNewResourceToFrame(requestIdentifier, frameIdentifier, loaderIdentifier, url, type, requestMethod, requestHeaders, requestData, elapsedTime, frameName, frameSecurityOrigin, initiatorSourceCodeLocation)
</del><ins>+    _addNewResourceToFrame(requestIdentifier, frameIdentifier, loaderIdentifier, url, type, requestMethod, requestHeaders, requestData, elapsedTime, frameName, frameSecurityOrigin, initiatorSourceCodeLocation, originalRequestWillBeSentTimestamp)
</ins><span class="cx">     {
</span><span class="cx">         console.assert(!this._waitingForMainFrameResourceTreePayload);
</span><span class="cx"> 
</span><span class="lines">@@ -394,12 +401,12 @@
</span><span class="cx">             else if (frame.provisionalMainResource &amp;&amp; frame.provisionalMainResource.url === url &amp;&amp; frame.provisionalLoaderIdentifier === loaderIdentifier)
</span><span class="cx">                 resource = frame.provisionalMainResource;
</span><span class="cx">             else {
</span><del>-                resource = new WebInspector.Resource(url, null, type, loaderIdentifier, requestIdentifier, requestMethod, requestHeaders, requestData, elapsedTime, initiatorSourceCodeLocation);
</del><ins>+                resource = new WebInspector.Resource(url, null, type, loaderIdentifier, requestIdentifier, requestMethod, requestHeaders, requestData, elapsedTime, initiatorSourceCodeLocation, originalRequestWillBeSentTimestamp);
</ins><span class="cx">                 this._addResourceToFrame(frame, resource);
</span><span class="cx">             }
</span><span class="cx">         } else {
</span><span class="cx">             // This is a new request for a new frame, which is always the main resource.
</span><del>-            resource = new WebInspector.Resource(url, null, type, loaderIdentifier, requestIdentifier, requestMethod, requestHeaders, requestData, elapsedTime, initiatorSourceCodeLocation);
</del><ins>+            resource = new WebInspector.Resource(url, null, type, loaderIdentifier, requestIdentifier, requestMethod, requestHeaders, requestData, elapsedTime, initiatorSourceCodeLocation, originalRequestWillBeSentTimestamp);
</ins><span class="cx">             frame = new WebInspector.Frame(frameIdentifier, frameName, frameSecurityOrigin, loaderIdentifier, resource);
</span><span class="cx">             this._frameIdentifierMap[frame.id] = frame;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceControllersTimelineManagerjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/TimelineManager.js (186097 => 186098)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Controllers/TimelineManager.js        2015-06-30 00:24:05 UTC (rev 186097)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/TimelineManager.js        2015-06-30 00:27:29 UTC (rev 186098)
</span><span class="lines">@@ -455,6 +455,18 @@
</span><span class="cx">             oldRecording.unloaded();
</span><span class="cx"> 
</span><span class="cx">         this._activeRecording = newRecording;
</span><ins>+
+        // COMPATIBILITY (iOS 8): When using Legacy timestamps, a navigation will have computed
+        // the main resource's will send request timestamp in terms of the last page's base timestamp.
+        // Now that we have navigated, we should reset the legacy base timestamp and the
+        // will send request timestamp for the new main resource. This way, all new timeline
+        // records will be computed relative to the new navigation.
+        if (this._autoCapturingMainResource &amp;&amp; WebInspector.TimelineRecording.isLegacy) {
+            console.assert(this._autoCapturingMainResource.originalRequestWillBeSentTimestamp);
+            this._activeRecording.setLegacyBaseTimestamp(this._autoCapturingMainResource.originalRequestWillBeSentTimestamp);
+            this._autoCapturingMainResource._requestSentTimestamp = 0;
+        }
+
</ins><span class="cx">         this.dispatchEventToListeners(WebInspector.TimelineManager.Event.RecordingLoaded, {oldRecording});
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceModelsResourcejs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js (186097 => 186098)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js        2015-06-30 00:24:05 UTC (rev 186097)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js        2015-06-30 00:27:29 UTC (rev 186098)
</span><span class="lines">@@ -25,7 +25,7 @@
</span><span class="cx"> 
</span><span class="cx"> WebInspector.Resource = class Resource extends WebInspector.SourceCode
</span><span class="cx"> {
</span><del>-    constructor(url, mimeType, type, loaderIdentifier, requestIdentifier, requestMethod, requestHeaders, requestData, requestSentTimestamp, initiatorSourceCodeLocation)
</del><ins>+    constructor(url, mimeType, type, loaderIdentifier, requestIdentifier, requestMethod, requestHeaders, requestData, requestSentTimestamp, initiatorSourceCodeLocation, originalRequestWillBeSentTimestamp)
</ins><span class="cx">     {
</span><span class="cx">         super();
</span><span class="cx"> 
</span><span class="lines">@@ -45,6 +45,7 @@
</span><span class="cx">         this._responseHeaders = {};
</span><span class="cx">         this._parentFrame = null;
</span><span class="cx">         this._initiatorSourceCodeLocation = initiatorSourceCodeLocation || null;
</span><ins>+        this._originalRequestWillBeSentTimestamp = originalRequestWillBeSentTimestamp || null;
</ins><span class="cx">         this._requestSentTimestamp = requestSentTimestamp || NaN;
</span><span class="cx">         this._responseReceivedTimestamp = NaN;
</span><span class="cx">         this._lastRedirectReceivedTimestamp = NaN;
</span><span class="lines">@@ -139,6 +140,11 @@
</span><span class="cx">         return this._initiatorSourceCodeLocation;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    get originalRequestWillBeSentTimestamp()
+    {
+        return this._originalRequestWillBeSentTimestamp;
+    }
+
</ins><span class="cx">     get type()
</span><span class="cx">     {
</span><span class="cx">         return this._type;
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceModelsTimelineRecordingjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Models/TimelineRecording.js (186097 => 186098)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Models/TimelineRecording.js        2015-06-30 00:24:05 UTC (rev 186097)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/TimelineRecording.js        2015-06-30 00:27:29 UTC (rev 186098)
</span><span class="lines">@@ -197,17 +197,35 @@
</span><span class="cx">         if (!timestamp || isNaN(timestamp))
</span><span class="cx">             return NaN;
</span><span class="cx"> 
</span><del>-        // COMPATIBILITY (iOS8): old backends send timestamps (milliseconds since the epoch), rather
-        // than seconds elapsed since timeline capturing started. We approximate the latter by
</del><ins>+        // COMPATIBILITY (iOS8): old backends send timestamps (seconds or milliseconds since the epoch),
+        // rather than seconds elapsed since timeline capturing started. We approximate the latter by
</ins><span class="cx">         // subtracting the start timestamp, as old versions did not use monotonic times.
</span><ins>+        if (WebInspector.TimelineRecording.isLegacy === undefined)
+            WebInspector.TimelineRecording.isLegacy = timestamp &gt; WebInspector.TimelineRecording.TimestampThresholdForLegacyRecordConversion;
+
+        if (!WebInspector.TimelineRecording.isLegacy)
+            return timestamp;
+
+        // If the record's start time is large, but not really large, then it is seconds since epoch
+        // not millseconds since epoch, so convert it to milliseconds.
+        if (timestamp &lt; WebInspector.TimelineRecording.TimestampThresholdForLegacyAssumedMilliseconds)
+            timestamp *= 1000;
+
</ins><span class="cx">         if (isNaN(this._legacyFirstRecordedTimestamp))
</span><span class="cx">             this._legacyFirstRecordedTimestamp = timestamp;
</span><span class="cx"> 
</span><del>-        // If the record's start time sems unreasonably large, treat it as a legacy timestamp.
-        if (timestamp &gt; WebInspector.TimelineRecording.TimestampThresholdForLegacyRecordConversion)
-            return (timestamp - this._legacyFirstRecordedTimestamp) / 1000.0;
</del><ins>+        // Return seconds since the first recorded value.
+        return (timestamp - this._legacyFirstRecordedTimestamp) / 1000.0;
+    }
</ins><span class="cx"> 
</span><del>-        return timestamp;
</del><ins>+    setLegacyBaseTimestamp(timestamp)
+    {
+        console.assert(isNaN(this._legacyFirstRecordedTimestamp));
+
+        if (timestamp &lt; WebInspector.TimelineRecording.TimestampThresholdForLegacyAssumedMilliseconds)
+            timestamp *= 1000;
+
+        this._legacyFirstRecordedTimestamp = timestamp;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // Private
</span><span class="lines">@@ -253,4 +271,6 @@
</span><span class="cx">     TimesUpdated: &quot;timeline-recording-times-updated&quot;
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-WebInspector.TimelineRecording.TimestampThresholdForLegacyRecordConversion = 28800000; // Date.parse(&quot;Jan 1, 1970&quot;)
</del><ins>+WebInspector.TimelineRecording.isLegacy = undefined;
+WebInspector.TimelineRecording.TimestampThresholdForLegacyRecordConversion = 10000000; // Some value not near zero.
+WebInspector.TimelineRecording.TimestampThresholdForLegacyAssumedMilliseconds = 1420099200000; // Date.parse(&quot;Jan 1, 2015&quot;). Milliseconds since epoch.
</ins></span></pre>
</div>
</div>

</body>
</html>