2 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
26 WebInspector.ResourceTimelineDataGridNode = function(resourceTimelineRecord, graphOnly, graphDataSource)
28 WebInspector.TimelineDataGridNode.call(this, graphOnly, graphDataSource);
30 this._resource = resourceTimelineRecord.resource;
31 this._record = resourceTimelineRecord;
33 this._record.addEventListener(WebInspector.TimelineRecord.Event.Updated, graphOnly ? this._timelineRecordUpdated : this._needsRefresh, this);
36 this._resource.addEventListener(WebInspector.Resource.Event.URLDidChange, this._needsRefresh, this);
37 this._resource.addEventListener(WebInspector.Resource.Event.TypeDidChange, this._needsRefresh, this);
38 this._resource.addEventListener(WebInspector.Resource.Event.LoadingDidFinish, this._needsRefresh, this);
39 this._resource.addEventListener(WebInspector.Resource.Event.LoadingDidFail, this._needsRefresh, this);
40 this._resource.addEventListener(WebInspector.Resource.Event.SizeDidChange, this._needsRefresh, this);
41 this._resource.addEventListener(WebInspector.Resource.Event.TransferSizeDidChange, this._needsRefresh, this);
45 // FIXME: Move to a WebInspector.Object subclass and we can remove this.
46 WebInspector.Object.deprecatedAddConstructorFunctions(WebInspector.ResourceTimelineDataGridNode);
48 WebInspector.ResourceTimelineDataGridNode.IconStyleClassName = "icon";
49 WebInspector.ResourceTimelineDataGridNode.ErrorStyleClassName = "error";
51 WebInspector.ResourceTimelineDataGridNode.prototype = {
52 constructor: WebInspector.ResourceTimelineDataGridNode,
53 __proto__: WebInspector.TimelineDataGridNode.prototype,
59 return [this._record];
64 return this._resource;
70 return this._cachedData;
72 var resource = this._resource;
75 if (!this._graphOnly) {
76 var zeroTime = this.graphDataSource ? this.graphDataSource.zeroTime : 0;
78 data.domain = WebInspector.displayNameForHost(resource.urlComponents.host);
79 data.scheme = resource.urlComponents.scheme ? resource.urlComponents.scheme.toUpperCase() : "";
80 data.method = resource.requestMethod;
81 data.type = resource.type;
82 data.statusCode = resource.statusCode;
83 data.cached = resource.cached;
84 data.size = resource.size;
85 data.transferSize = resource.transferSize;
86 data.requestSent = resource.requestSentTimestamp - zeroTime;
87 data.duration = resource.receiveDuration;
88 data.latency = resource.latency;
91 data.graph = this._record.startTime;
93 this._cachedData = data;
97 createCellContent: function(columnIdentifier, cell)
99 var resource = this._resource;
101 if (resource.failed || resource.canceled || resource.statusCode >= 400)
102 cell.classList.add(WebInspector.ResourceTimelineDataGridNode.ErrorStyleClassName);
104 const emptyValuePlaceholderString = "\u2014";
105 var value = this.data[columnIdentifier];
107 switch (columnIdentifier) {
109 return WebInspector.Resource.displayNameForType(value);
112 cell.title = resource.statusText || "";
113 return value || emptyValuePlaceholderString;
116 return value ? WebInspector.UIString("Yes") : WebInspector.UIString("No");
119 var fragment = document.createDocumentFragment();
121 var goToButton = WebInspector.createGoToArrowButton();
122 goToButton.addEventListener("click", this._goToResource.bind(this));
123 fragment.appendChild(goToButton);
125 var text = document.createTextNode(value || emptyValuePlaceholderString);
126 fragment.appendChild(text);
132 return isNaN(value) ? emptyValuePlaceholderString : Number.bytesToString(value, true);
137 return isNaN(value) ? emptyValuePlaceholderString : Number.secondsToString(value, true);
140 return WebInspector.TimelineDataGridNode.prototype.createCellContent.call(this, columnIdentifier, cell);
145 if (this._scheduledRefreshIdentifier) {
146 cancelAnimationFrame(this._scheduledRefreshIdentifier);
147 delete this._scheduledRefreshIdentifier;
150 delete this._cachedData;
152 WebInspector.TimelineDataGridNode.prototype.refresh.call(this);
157 _needsRefresh: function()
159 if (this.dataGrid instanceof WebInspector.TimelineDataGrid) {
160 this.dataGrid.dataGridNodeNeedsRefresh(this);
164 if (this._scheduledRefreshIdentifier)
167 this._scheduledRefreshIdentifier = requestAnimationFrame(this.refresh.bind(this));
170 _goToResource: function(event)
172 WebInspector.resourceSidebarPanel.showSourceCode(this._resource);
175 _timelineRecordUpdated: function(event)
177 if (this.isRecordVisible(this._record))
178 this.needsGraphRefresh();