Web Inspector: Remove dead code in FrameTreeElement
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Views / FrameTreeElement.js
index 6b99937..9bc6db4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * 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
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-WebInspector.FrameTreeElement = function(frame, representedObject)
+WebInspector.FrameTreeElement = class FrameTreeElement extends WebInspector.ResourceTreeElement
 {
-    console.assert(frame instanceof WebInspector.Frame);
-
-    WebInspector.ResourceTreeElement.call(this, frame.mainResource, representedObject || frame);
+    constructor(frame, representedObject)
+    {
+        console.assert(frame instanceof WebInspector.Frame);
 
-    this._frame = frame;
+        super(frame.mainResource, representedObject || frame);
 
-    this._updateExpandedSetting();
+        this._frame = frame;
 
-    frame.addEventListener(WebInspector.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
-    frame.addEventListener(WebInspector.Frame.Event.ResourceWasAdded, this._resourceWasAdded, this);
-    frame.addEventListener(WebInspector.Frame.Event.ResourceWasRemoved, this._resourceWasRemoved, this);
-    frame.addEventListener(WebInspector.Frame.Event.ChildFrameWasAdded, this._childFrameWasAdded, this);
-    frame.addEventListener(WebInspector.Frame.Event.ChildFrameWasRemoved, this._childFrameWasRemoved, this);
+        this._updateExpandedSetting();
 
-    frame.domTree.addEventListener(WebInspector.DOMTree.Event.ContentFlowWasAdded, this._childContentFlowWasAdded, this);
-    frame.domTree.addEventListener(WebInspector.DOMTree.Event.ContentFlowWasRemoved, this._childContentFlowWasRemoved, this);
-    frame.domTree.addEventListener(WebInspector.DOMTree.Event.RootDOMNodeInvalidated, this._rootDOMNodeInvalidated, this);
+        frame.addEventListener(WebInspector.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
+        frame.addEventListener(WebInspector.Frame.Event.ResourceWasAdded, this._resourceWasAdded, this);
+        frame.addEventListener(WebInspector.Frame.Event.ResourceWasRemoved, this._resourceWasRemoved, this);
+        frame.addEventListener(WebInspector.Frame.Event.ExtraScriptAdded, this._extraScriptAdded, this);
+        frame.addEventListener(WebInspector.Frame.Event.ChildFrameWasAdded, this._childFrameWasAdded, this);
+        frame.addEventListener(WebInspector.Frame.Event.ChildFrameWasRemoved, this._childFrameWasRemoved, this);
 
-    if (this._frame.isMainFrame())
-        this._downloadingPage = false;
+        frame.domTree.addEventListener(WebInspector.DOMTree.Event.ContentFlowWasAdded, this._childContentFlowWasAdded, this);
+        frame.domTree.addEventListener(WebInspector.DOMTree.Event.ContentFlowWasRemoved, this._childContentFlowWasRemoved, this);
+        frame.domTree.addEventListener(WebInspector.DOMTree.Event.RootDOMNodeInvalidated, this._rootDOMNodeInvalidated, this);
 
-    this.shouldRefreshChildren = true;
-    this.folderSettingsKey = this._frame.url.hash;
+        this.shouldRefreshChildren = true;
+        this.folderSettingsKey = this._frame.url.hash;
 
-    this.registerFolderizeSettings("frames", WebInspector.UIString("Frames"),
-        function(representedObject) { return representedObject instanceof WebInspector.Frame; },
-        function() { return this.frame.childFrames.length; }.bind(this),
-        WebInspector.FrameTreeElement
-    );
+        this.registerFolderizeSettings("frames", WebInspector.UIString("Frames"),
+            (representedObject) => representedObject instanceof WebInspector.Frame,
+            () => this.frame.childFrames.length,
+            WebInspector.FrameTreeElement
+        );
 
-    this.registerFolderizeSettings("flows", WebInspector.UIString("Flows"),
-        function(representedObject) { return representedObject instanceof WebInspector.ContentFlow; },
-        function() { return this.frame.domTree.flowsCount; }.bind(this),
-        WebInspector.ContentFlowTreeElement
-    );
+        this.registerFolderizeSettings("flows", WebInspector.UIString("Flows"),
+            (representedObject) => representedObject instanceof WebInspector.ContentFlow,
+            () => this.frame.domTree.flowsCount,
+            WebInspector.ContentFlowTreeElement
+        );
 
-    function makeValidateCallback(resourceType) {
-        return function(representedObject) {
-            return representedObject instanceof WebInspector.Resource && representedObject.type === resourceType;
-        };
-    }
+        this.registerFolderizeSettings("extra-scripts", WebInspector.UIString("Extra Scripts"),
+            (representedObject) => representedObject instanceof WebInspector.Script && representedObject.dynamicallyAddedScriptElement,
+            () => this.frame.extraScripts.length,
+            WebInspector.ScriptTreeElement
+        );
 
-    function makeChildCountCallback(frame, resourceType) {
-        return function() {
-            return frame.resourcesWithType(resourceType).length;
-        };
-    }
+        function makeValidateCallback(resourceType) {
+            return function(representedObject) {
+                return representedObject instanceof WebInspector.Resource && representedObject.type === resourceType;
+            };
+        }
 
-    for (var key in WebInspector.Resource.Type) {
-        var value = WebInspector.Resource.Type[key];
-        var folderName = WebInspector.Resource.displayNameForType(value, true);
-        this.registerFolderizeSettings(key, folderName,
-            makeValidateCallback(value),
-            makeChildCountCallback(this.frame, value),
-            WebInspector.ResourceTreeElement
-        );
-    }
+        function makeChildCountCallback(frame, resourceType) {
+            return function() {
+                return frame.resourcesWithType(resourceType).length;
+            };
+        }
 
-    this.updateParentStatus();
-};
+        for (var key in WebInspector.Resource.Type) {
+            var value = WebInspector.Resource.Type[key];
+            var folderName = WebInspector.Resource.displayNameForType(value, true);
+            this.registerFolderizeSettings(key, folderName,
+                makeValidateCallback(value),
+                makeChildCountCallback(this.frame, value),
+                WebInspector.ResourceTreeElement
+            );
+        }
 
-WebInspector.FrameTreeElement.prototype = {
-    constructor: WebInspector.FrameTreeElement,
-    __proto__: WebInspector.ResourceTreeElement.prototype,
+        this.updateParentStatus();
+    }
 
     // Public
 
     get frame()
     {
         return this._frame;
-    },
+    }
 
-    descendantResourceTreeElementTypeDidChange: function(resourceTreeElement, oldType)
+    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: function(resourceTreeElement, oldMainTitle)
+    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: function()
+    updateSourceMapResources()
     {
         // Frames handle their own SourceMapResources.
 
@@ -131,32 +133,19 @@ WebInspector.FrameTreeElement.prototype = {
 
         if (this.resource && this.resource.sourceMaps.length)
             this.shouldRefreshChildren = true;
-    },
+    }
 
-    onattach: function()
+    onattach()
     {
         // Immediate superclasses are skipped, since Frames handle their own SourceMapResources.
         WebInspector.GeneralTreeElement.prototype.onattach.call(this);
 
-        if (this._frame.isMainFrame()) {
-            WebInspector.notifications.addEventListener(WebInspector.Notification.PageArchiveStarted, this._pageArchiveStarted, this);
-            WebInspector.notifications.addEventListener(WebInspector.Notification.PageArchiveEnded, this._pageArchiveEnded, this);
-        }
-    },
-
-    ondetach: function()
-    {
-        WebInspector.ResourceTreeElement.prototype.ondetach.call(this);
-
-        if (this._frame.isMainFrame()) {
-            WebInspector.notifications.removeEventListener(WebInspector.Notification.PageArchiveStarted, this._pageArchiveStarted, this);
-            WebInspector.notifications.removeEventListener(WebInspector.Notification.PageArchiveEnded, this._pageArchiveEnded, this);
-        }
-    },
+        this.element.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this));
+    }
 
     // Overrides from FolderizedTreeElement (Protected).
 
-    compareChildTreeElements: function(a, b)
+    compareChildTreeElements(a, b)
     {
         if (a === b)
             return 0;
@@ -169,63 +158,17 @@ WebInspector.FrameTreeElement.prototype = {
 
         if (!aIsResource && !bIsResource) {
             // When both components are not resources then default to base class comparison.
-            return WebInspector.ResourceTreeElement.prototype.compareChildTreeElements.call(this, a, b);
+            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;
-    },
-
-    // Called from ResourceTreeElement.
-
-    updateStatusForMainFrame: function()
-    {
-        function loadedImages()
-        {
-            if (!this._reloadButton || !this._downloadButton)
-                return;
-
-            var fragment = document.createDocumentFragment("div");
-            fragment.appendChild(this._downloadButton.element);
-            fragment.appendChild(this._reloadButton.element);
-            this.status = fragment;
-
-            delete this._loadingMainFrameButtons;
-        }
-
-        if (this._reloadButton && this._downloadButton) {
-            loadedImages.call(this);
-            return;
-        }
-
-        if (!this._loadingMainFrameButtons) {
-            this._loadingMainFrameButtons = true;
-
-            var tooltip;
-            if (WebInspector.debuggableType === WebInspector.DebuggableType.JavaScript)
-                tooltip = WebInspector.UIString("Restart (%s)").format(WebInspector._reloadPageKeyboardShortcut.displayName);
-            else
-                tooltip = WebInspector.UIString("Reload page (%s)\nReload ignoring cache (%s)").format(WebInspector._reloadPageKeyboardShortcut.displayName, WebInspector._reloadPageIgnoringCacheKeyboardShortcut.displayName);
-
-            wrappedSVGDocument(platformImagePath("Reload.svg"), null, tooltip, function(element) {
-                this._reloadButton = new WebInspector.TreeElementStatusButton(element);
-                this._reloadButton.addEventListener(WebInspector.TreeElementStatusButton.Event.Clicked, this._reloadPageClicked, this);
-                loadedImages.call(this);
-            }.bind(this));
-
-            wrappedSVGDocument(platformImagePath("DownloadArrow.svg"), null, WebInspector.UIString("Download Web Archive"), function(element) {
-                this._downloadButton = new WebInspector.TreeElementStatusButton(element);
-                this._downloadButton.addEventListener(WebInspector.TreeElementStatusButton.Event.Clicked, this._downloadButtonClicked, this);
-                this._updateDownloadButton();
-                loadedImages.call(this);
-            }.bind(this));
-        }
-    },
+    }
 
     // Overrides from TreeElement (Private).
 
-    onpopulate: function()
+    onpopulate()
     {
         if (this.children.length && !this.shouldRefreshChildren)
             return;
@@ -252,34 +195,38 @@ WebInspector.FrameTreeElement.prototype = {
         for (var flowKey in flowMap)
             this.addChildForRepresentedObject(flowMap[flowKey]);
 
-    },
+        for (let extraScript of this._frame.extraScripts) {
+            if (extraScript.sourceURL || extraScript.sourceMappingURL)
+                this.addChildForRepresentedObject(extraScript);
+        }
+    }
 
-    onexpand: function()
+    onexpand()
     {
         this._expandedSetting.value = true;
         this._frame.domTree.requestContentFlowList();
-    },
+    }
 
-    oncollapse: function()
+    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;
-    },
+    }
 
     // Private
 
-    _updateExpandedSetting: function()
+    _updateExpandedSetting()
     {
         this._expandedSetting = new WebInspector.Setting("frame-expanded-" + this._frame.url.hash, this._frame.isMainFrame() ? true : false);
         if (this._expandedSetting.value)
             this.expand();
         else
             this.collapse();
-    },
+    }
 
-    _mainResourceDidChange: function(event)
+    _mainResourceDidChange(event)
     {
         this._updateResource(this._frame.mainResource);
 
@@ -290,87 +237,49 @@ WebInspector.FrameTreeElement.prototype = {
         // shouldRefreshChildren will call onpopulate if expanded is true.
         this._updateExpandedSetting();
 
-        if (this._frame.isMainFrame())
-            this._updateDownloadButton();
-
         this.shouldRefreshChildren = true;
-    },
+    }
 
-    _resourceWasAdded: function(event)
+    _resourceWasAdded(event)
     {
         this.addRepresentedObjectToNewChildQueue(event.data.resource);
-    },
+    }
 
-    _resourceWasRemoved: function(event)
+    _resourceWasRemoved(event)
     {
         this.removeChildForRepresentedObject(event.data.resource);
-    },
+    }
+
+    _extraScriptAdded(event)
+    {
+        let extraScript = event.data.script;
+        if (extraScript.sourceURL || extraScript.sourceMappingURL)
+            this.addRepresentedObjectToNewChildQueue(extraScript);
+    }
 
-    _childFrameWasAdded: function(event)
+    _childFrameWasAdded(event)
     {
         this.addRepresentedObjectToNewChildQueue(event.data.childFrame);
-    },
+    }
 
-    _childFrameWasRemoved: function(event)
+    _childFrameWasRemoved(event)
     {
         this.removeChildForRepresentedObject(event.data.childFrame);
-    },
+    }
 
-    _childContentFlowWasAdded: function(event)
+    _childContentFlowWasAdded(event)
     {
         this.addRepresentedObjectToNewChildQueue(event.data.flow);
-    },
+    }
 
-    _childContentFlowWasRemoved: function(event)
+    _childContentFlowWasRemoved(event)
     {
         this.removeChildForRepresentedObject(event.data.flow);
-    },
+    }
 
-    _rootDOMNodeInvalidated: function()
+    _rootDOMNodeInvalidated()
     {
         if (this.expanded)
             this._frame.domTree.requestContentFlowList();
-    },
-
-    _reloadPageClicked: function(event)
-    {
-        // Ignore cache when the shift key is pressed.
-        PageAgent.reload(event.data.shiftKey);
-    },
-
-    _downloadButtonClicked: function(event)
-    {
-        WebInspector.archiveMainFrame();
-    },
-
-    _updateDownloadButton: function()
-    {
-        console.assert(this._frame.isMainFrame());
-        if (!this._downloadButton)
-            return;
-
-        if (!PageAgent.archive || WebInspector.debuggableType !== WebInspector.DebuggableType.Web) {
-            this._downloadButton.hidden = true;
-            return;
-        }
-
-        if (this._downloadingPage) {
-            this._downloadButton.enabled = false;
-            return;
-        }
-
-        this._downloadButton.enabled = WebInspector.canArchiveMainFrame();
-    },
-
-    _pageArchiveStarted: function(event)
-    {
-        this._downloadingPage = true;
-        this._updateDownloadButton();
-    },
-
-    _pageArchiveEnded: function(event)
-    {
-        this._downloadingPage = false;
-        this._updateDownloadButton();
     }
 };