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 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
|
/*
* Copyright (C) 2013, 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.
*/
WI.FrameTreeElement = class FrameTreeElement extends WI.ResourceTreeElement
{
constructor(frame)
{
console.assert(frame instanceof WI.Frame);
super(frame.mainResource, frame);
this._frame = frame;
this._updateExpandedSetting();
frame.addEventListener(WI.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
frame.addEventListener(WI.Frame.Event.ResourceWasAdded, this._resourceWasAdded, this);
frame.addEventListener(WI.Frame.Event.ResourceWasRemoved, this._resourceWasRemoved, this);
frame.addEventListener(WI.Frame.Event.ExtraScriptAdded, this._extraScriptAdded, this);
frame.addEventListener(WI.Frame.Event.ChildFrameWasAdded, this._childFrameWasAdded, this);
frame.addEventListener(WI.Frame.Event.ChildFrameWasRemoved, this._childFrameWasRemoved, this);
this.shouldRefreshChildren = true;
this.folderSettingsKey = this._frame.url.hash;
this.registerFolderizeSettings("frames", WI.UIString("Frames"), this._frame.childFrameCollection, WI.FrameTreeElement);
this.registerFolderizeSettings("extra-scripts", WI.UIString("Extra Scripts"), this._frame.extraScriptCollection, WI.ScriptTreeElement);
function forwardingConstructor(representedObject, ...extraArguments) {
if (representedObject instanceof WI.CSSStyleSheet)
return new WI.CSSStyleSheetTreeElement(representedObject, ...extraArguments);
return new WI.ResourceTreeElement(representedObject, ...extraArguments);
}
for (let [key, value] of Object.entries(WI.Resource.Type)) {
let folderName = WI.Resource.displayNameForType(value, true);
let treeElementConstructor = forwardingConstructor;
if (value === WI.Resource.Type.WebSocket)
treeElementConstructor = WI.WebSocketResourceTreeElement;
this.registerFolderizeSettings(key, folderName, this._frame.resourceCollectionForType(value), treeElementConstructor);
}
this.updateParentStatus();
}
// Public
get frame()
{
return this._frame;
}
descendantResourceTreeElementTypeDidChange(resourceTreeElement, oldType)
{
// Called by descendant ResourceTreeElements.
// Add the tree element again, which will move it to the new location
// based on sorting and possible folder changes.
this._addTreeElement(resourceTreeElement);
}
descendantResourceTreeElementMainTitleDidChange(resourceTreeElement, oldMainTitle)
{
// Called by descendant ResourceTreeElements.
// Add the tree element again, which will move it to the new location
// based on sorting and possible folder changes.
this._addTreeElement(resourceTreeElement);
}
// Overrides from SourceCodeTreeElement.
updateSourceMapResources()
{
// Frames handle their own SourceMapResources.
if (!this.treeOutline || !this.treeOutline.includeSourceMapResourceChildren)
return;
if (!this._frame)
return;
this.updateParentStatus();
if (this.resource && this.resource.sourceMaps.length)
this.shouldRefreshChildren = true;
}
onattach()
{
// Immediate superclasses are skipped, since Frames handle their own SourceMapResources.
WI.GeneralTreeElement.prototype.onattach.call(this);
WI.cssManager.addEventListener(WI.CSSManager.Event.StyleSheetAdded, this._styleSheetAdded, this);
WI.cssManager.addEventListener(WI.CSSManager.Event.StyleSheetRemoved, this._styleSheetRemoved, this);
}
ondetach()
{
WI.cssManager.removeEventListener(WI.CSSManager.Event.StyleSheetAdded, this._styleSheetAdded, this);
WI.cssManager.removeEventListener(WI.CSSManager.Event.StyleSheetRemoved, this._styleSheetRemoved, this);
super.ondetach();
}
// Overrides from FolderizedTreeElement (Protected).
compareChildTreeElements(a, b)
{
if (a === b)
return 0;
var aIsResource = a instanceof WI.ResourceTreeElement;
var bIsResource = b instanceof WI.ResourceTreeElement;
if (aIsResource && bIsResource)
return WI.ResourceTreeElement.compareResourceTreeElements(a, b);
if (!aIsResource && !bIsResource) {
// When both components are not resources then default to base class comparison.
return super.compareChildTreeElements(a, b);
}
// Non-resources should appear before the resources.
// FIXME: There should be a better way to group the elements by their type.
return aIsResource ? 1 : -1;
}
// Overrides from TreeElement (Private).
onpopulate()
{
if (this.children.length && !this.shouldRefreshChildren)
return;
this.shouldRefreshChildren = false;
this.removeChildren();
this.updateParentStatus();
this.prepareToPopulate();
for (let frame of this._frame.childFrameCollection)
this.addChildForRepresentedObject(frame);
for (let resource of this._frame.resourceCollection)
this.addChildForRepresentedObject(resource);
var sourceMaps = this.resource && this.resource.sourceMaps;
for (var i = 0; i < sourceMaps.length; ++i) {
var sourceMap = sourceMaps[i];
for (var j = 0; j < sourceMap.resources.length; ++j)
this.addChildForRepresentedObject(sourceMap.resources[j]);
}
for (let extraScript of this._frame.extraScriptCollection) {
if (extraScript.sourceURL || extraScript.sourceMappingURL)
this.addChildForRepresentedObject(extraScript);
}
for (let styleSheet of WI.cssManager.inspectorStyleSheetsForFrame(this._frame))
this.addChildForRepresentedObject(styleSheet);
}
onexpand()
{
this._expandedSetting.value = true;
}
oncollapse()
{
// Only store the setting if we have children, since setting hasChildren to false will cause a collapse,
// and we only care about user triggered collapses.
if (this.hasChildren)
this._expandedSetting.value = false;
}
// Protected
get mainTitleText()
{
// We can't assume that `this._frame` exists since this may be called before that is set.
if (this.resource.parentFrame.name)
return WI.UIString("%s (%s)").format(this.resource.parentFrame.name, super.mainTitleText);
return super.mainTitleText;
}
// Private
_updateExpandedSetting()
{
this._expandedSetting = new WI.Setting("frame-expanded-" + this._frame.url.hash, this._frame.isMainFrame() ? true : false);
if (this._expandedSetting.value)
this.expand();
else
this.collapse();
}
_mainResourceDidChange(event)
{
this._updateResource(this._frame.mainResource);
this.updateParentStatus();
this.removeChildren();
// Change the expanded setting since the frame URL has changed. Do this before setting shouldRefreshChildren, since
// shouldRefreshChildren will call onpopulate if expanded is true.
this._updateExpandedSetting();
this.shouldRefreshChildren = true;
}
_resourceWasAdded(event)
{
this.addRepresentedObjectToNewChildQueue(event.data.resource);
}
_resourceWasRemoved(event)
{
this.removeChildForRepresentedObject(event.data.resource);
}
_extraScriptAdded(event)
{
let extraScript = event.data.script;
if (extraScript.sourceURL || extraScript.sourceMappingURL)
this.addRepresentedObjectToNewChildQueue(extraScript);
}
_childFrameWasAdded(event)
{
this.addRepresentedObjectToNewChildQueue(event.data.childFrame);
}
_childFrameWasRemoved(event)
{
this.removeChildForRepresentedObject(event.data.childFrame);
}
_styleSheetAdded(event)
{
let {styleSheet} = event.data;
if (styleSheet.origin === WI.CSSStyleSheet.Type.Author || styleSheet.injected || styleSheet.anonymous)
return;
this.addRepresentedObjectToNewChildQueue(styleSheet);
}
_styleSheetRemoved(event)
{
let {styleSheet} = event.data;
if (styleSheet.origin === WI.CSSStyleSheet.Type.Author || styleSheet.injected || styleSheet.anonymous)
return;
this.removeChildForRepresentedObject(styleSheet);
}
};
|