1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
/*
* Copyright (C) 2015 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
WebInspector.NetworkSidebarPanel = class NetworkSidebarPanel extends WebInspector.NavigationSidebarPanel
{
constructor(contentBrowser)
{
super("network", WebInspector.UIString("Network"), true);
this.contentBrowser = contentBrowser;
this.filterBar.placeholder = WebInspector.UIString("Filter Resource List");
this._navigationBar = new WebInspector.NavigationBar;
this.addSubview(this._navigationBar);
this._resourcesTitleBarElement = document.createElement("div");
this._resourcesTitleBarElement.textContent = WebInspector.UIString("Name");
this._resourcesTitleBarElement.classList.add("title-bar");
this.element.appendChild(this._resourcesTitleBarElement);
var scopeItemPrefix = "network-sidebar-";
var scopeBarItems = [];
scopeBarItems.push(new WebInspector.ScopeBarItem(scopeItemPrefix + "type-all", WebInspector.UIString("All Resources"), true));
for (var key in WebInspector.Resource.Type) {
var value = WebInspector.Resource.Type[key];
var scopeBarItem = new WebInspector.ScopeBarItem(scopeItemPrefix + value, WebInspector.Resource.displayNameForType(value, true));
scopeBarItem[WebInspector.NetworkSidebarPanel.ResourceTypeSymbol] = value;
scopeBarItems.push(scopeBarItem);
}
this._scopeBar = new WebInspector.ScopeBar("network-sidebar-scope-bar", scopeBarItems, scopeBarItems[0], true);
this._scopeBar.addEventListener(WebInspector.ScopeBar.Event.SelectionChanged, this._scopeBarSelectionDidChange, this);
this._navigationBar.addNavigationItem(this._scopeBar);
this.contentTreeOutline.element.classList.add("network-grid");
this.contentTreeOutline.disclosureButtons = false;
this.contentBrowser.addEventListener(WebInspector.ContentBrowser.Event.CurrentContentViewDidChange, this._contentBrowserCurrentContentViewDidChange, this);
var networkTimeline = WebInspector.timelineManager.persistentNetworkTimeline;
networkTimeline.addEventListener(WebInspector.Timeline.Event.Reset, this._networkTimelineReset, this);
this._networkGridView = new WebInspector.NetworkGridContentView(null, {networkSidebarPanel: this});
}
// Public
get minimumWidth()
{
return this._navigationBar.minimumWidth;
}
closed()
{
super.closed();
WebInspector.frameResourceManager.removeEventListener(null, null, this);
}
showDefaultContentView()
{
this.contentBrowser.showContentView(this._networkGridView);
}
canShowDifferentContentView()
{
if (this._clickedTreeElementGoToArrow)
return true;
if (this.contentBrowser.currentContentView instanceof WebInspector.NetworkGridContentView)
return false;
return !this.restoringState || !this._restoredShowingNetworkGridContentView;
}
// Protected
saveStateToCookie(cookie)
{
console.assert(cookie);
cookie[WebInspector.NetworkSidebarPanel.ShowingNetworkGridContentViewCookieKey] = this.contentBrowser.currentContentView instanceof WebInspector.NetworkGridContentView;
super.saveStateToCookie(cookie);
}
restoreStateFromCookie(cookie, relaxedMatchDelay)
{
console.assert(cookie);
// Don't call NavigationSidebarPanel.restoreStateFromCookie, because it tries to match based
// on type selected tree element. This would cause the grid to be deselected.
if (cookie[WebInspector.NetworkSidebarPanel.ShowingNetworkGridContentViewCookieKey])
return;
super.restoreStateFromCookie(cookie, relaxedMatchDelay);
}
hasCustomFilters()
{
console.assert(this._scopeBar.selectedItems.length === 1);
var selectedScopeBarItem = this._scopeBar.selectedItems[0];
return selectedScopeBarItem && !selectedScopeBarItem.exclusive;
}
matchTreeElementAgainstCustomFilters(treeElement, flags)
{
console.assert(this._scopeBar.selectedItems.length === 1);
var selectedScopeBarItem = this._scopeBar.selectedItems[0];
// Show everything if there is no selection or "All Resources" is selected (the exclusive item).
if (!selectedScopeBarItem || selectedScopeBarItem.exclusive)
return true;
function match()
{
if (treeElement instanceof WebInspector.FrameTreeElement)
return selectedScopeBarItem[WebInspector.NetworkSidebarPanel.ResourceTypeSymbol] === WebInspector.Resource.Type.Document;
console.assert(treeElement instanceof WebInspector.ResourceTreeElement, "Unknown treeElement", treeElement);
if (!(treeElement instanceof WebInspector.ResourceTreeElement))
return false;
return treeElement.resource.type === selectedScopeBarItem[WebInspector.NetworkSidebarPanel.ResourceTypeSymbol];
}
var matched = match();
if (matched)
flags.expandTreeElement = true;
return matched;
}
treeElementAddedOrChanged(treeElement)
{
if (treeElement.status || !treeElement.treeOutline)
return;
var fragment = document.createDocumentFragment();
var closeButton = new WebInspector.TreeElementStatusButton(useSVGSymbol("Images/Close.svg", null, WebInspector.UIString("Close resource view")));
closeButton.element.classList.add("close");
closeButton.addEventListener(WebInspector.TreeElementStatusButton.Event.Clicked, this._treeElementCloseButtonClicked, this);
fragment.appendChild(closeButton.element);
var goToButton = new WebInspector.TreeElementStatusButton(WebInspector.createGoToArrowButton());
goToButton[WebInspector.NetworkSidebarPanel.TreeElementSymbol] = treeElement;
goToButton.addEventListener(WebInspector.TreeElementStatusButton.Event.Clicked, this._treeElementGoToArrowWasClicked, this);
fragment.appendChild(goToButton.element);
treeElement.status = fragment;
}
// Private
_networkTimelineReset(event)
{
this.contentBrowser.contentViewContainer.closeAllContentViews();
this.showDefaultContentView();
}
_contentBrowserCurrentContentViewDidChange(event)
{
var didShowNetworkGridContentView = this.contentBrowser.currentContentView instanceof WebInspector.NetworkGridContentView;
this.element.classList.toggle("network-grid-content-view-showing", didShowNetworkGridContentView);
}
_treeElementGoToArrowWasClicked(event)
{
this._clickedTreeElementGoToArrow = true;
let treeElement = event.target[WebInspector.NetworkSidebarPanel.TreeElementSymbol];
console.assert(treeElement instanceof WebInspector.TreeElement);
treeElement.select(true, true);
this._clickedTreeElementGoToArrow = false;
}
_treeElementCloseButtonClicked(event)
{
// Say we are processing a selection change to avoid the selected tree element
// from being deselected when the default content view is shown.
this.contentTreeOutline.processingSelectionChange = true;
this.showDefaultContentView();
this.contentTreeOutline.processingSelectionChange = false;
}
_scopeBarSelectionDidChange(event)
{
this.updateFilter();
}
};
WebInspector.NetworkSidebarPanel.ResourceTypeSymbol = Symbol("resource-type");
WebInspector.NetworkSidebarPanel.TreeElementSymbol = Symbol("tree-element");
WebInspector.NetworkSidebarPanel.ShowingNetworkGridContentViewCookieKey = "network-sidebar-panel-showing-network-grid-content-view";
|