Title: [117581] trunk
Revision
117581
Author
[email protected]
Date
2012-05-18 06:30:40 -0700 (Fri, 18 May 2012)

Log Message

Web Inspector: remove unnecessary indirection from profile types
https://bugs.webkit.org/show_bug.cgi?id=86845

Reviewed by Pavel Feldman.

Source/WebCore:

Introduced CSSProfileHeader and CPUProfileHeader, moved view creation from
the type to corresponding profile headers. Removed some inderection and
private fields assigned in random places. Added type annotations.

* inspector/front-end/CPUProfileView.js:
(WebInspector.CPUProfileType.prototype.createTemporaryProfile):
(WebInspector.CPUProfileType.prototype.createProfile):
(WebInspector.CPUProfileHeader):
(WebInspector.CPUProfileHeader.prototype.createSidebarTreeElement):
(WebInspector.CPUProfileHeader.prototype.createView):
* inspector/front-end/CSSSelectorProfileView.js:
(WebInspector.CSSSelectorProfileType.prototype.stopRecordingProfile):
(WebInspector.CSSSelectorProfileType.prototype.createTemporaryProfile):
(WebInspector.CSSSelectorProfileType.prototype.createProfile):
(WebInspector.CSSProfileHeader):
(WebInspector.CSSProfileHeader.prototype.createSidebarTreeElement):
(WebInspector.CSSProfileHeader.prototype.createView):
* inspector/front-end/HeapSnapshotView.js:
(WebInspector.HeapSnapshotProfileType.prototype.createTemporaryProfile):
(WebInspector.HeapSnapshotProfileType.prototype.createProfile):
(WebInspector.HeapProfileHeader):
(WebInspector.HeapProfileHeader.prototype.createSidebarTreeElement):
(WebInspector.HeapProfileHeader.prototype.createView):
(WebInspector.HeapProfileHeader.prototype.load):
(WebInspector.HeapProfileHeader.prototype.saveToFile):
* inspector/front-end/ProfileLauncherView.js:
(WebInspector.ProfileLauncherView):
(WebInspector.ProfileLauncherView.prototype.addProfileType):
(WebInspector.ProfileLauncherView.prototype._profileTypeChanged):
* inspector/front-end/ProfilesPanel.js:
(WebInspector.ProfileType):
(WebInspector.ProfileHeader):
(WebInspector.ProfileHeader.prototype.profileType):
(WebInspector.ProfileHeader.prototype.createSidebarTreeElement):
(WebInspector.ProfileHeader.prototype.existingView):
(WebInspector.ProfileHeader.prototype.view):
(WebInspector.ProfileHeader.prototype.createView):
(WebInspector.ProfilesPanel.prototype._reset):
(WebInspector.ProfilesPanel.prototype.addProfileHeader):
(WebInspector.ProfilesPanel.prototype._removeProfileHeader):
(WebInspector.ProfilesPanel.prototype.showProfile):
(WebInspector.ProfilesPanel.prototype.getProfiles):
(WebInspector.ProfilesPanel.prototype.findTemporaryProfile):
(WebInspector.ProfilesPanel.prototype._searchableViews):
* inspector/front-end/View.js:
(WebInspector.View._assert):

LayoutTests:

* inspector/profiler/heap-snapshot-test.js:
(initialize_HeapSnapshotTest):

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (117580 => 117581)


--- trunk/LayoutTests/ChangeLog	2012-05-18 12:42:53 UTC (rev 117580)
+++ trunk/LayoutTests/ChangeLog	2012-05-18 13:30:40 UTC (rev 117581)
@@ -1,3 +1,13 @@
+2012-05-18  Yury Semikhatsky  <[email protected]>
+
+        Web Inspector: remove unnecessary indirection from profile types
+        https://bugs.webkit.org/show_bug.cgi?id=86845
+
+        Reviewed by Pavel Feldman.
+
+        * inspector/profiler/heap-snapshot-test.js:
+        (initialize_HeapSnapshotTest):
+
 2012-05-18  Zoltan Arvai  <[email protected]>
 
         [Qt][WK2] Cleaning skip list. Unskip passing tests.

Modified: trunk/LayoutTests/inspector/profiler/heap-snapshot-test.js (117580 => 117581)


--- trunk/LayoutTests/inspector/profiler/heap-snapshot-test.js	2012-05-18 12:42:53 UTC (rev 117580)
+++ trunk/LayoutTests/inspector/profiler/heap-snapshot-test.js	2012-05-18 13:30:40 UTC (rev 117581)
@@ -513,7 +513,12 @@
     callback = InspectorTest.safeWrap(callback);
     var uid = InspectorTest._nextUid++;
     var snapshot = generator();
-    var profile = "" WebInspector.HeapProfileHeader(UserInitiatedProfileName + "." + uid, uid, snapshot.maxJSObjectId);
+    var profileType = WebInspector.panels.profiles.getProfileType(WebInspector.HeapSnapshotProfileType.TypeId);
+    var profile = ""
+        title: UserInitiatedProfileName + "." + uid,
+        uid: uid,
+        maxJSObjectId: snapshot.maxJSObjectId
+    });
     delete snapshot.maxJSObjectId;
     function pushGeneratedSnapshot(typeId, uid)
     {
@@ -525,8 +530,6 @@
     }
     InspectorTest.override(ProfilerAgent, "getProfile", pushGeneratedSnapshot);
     InspectorTest._takeAndOpenSnapshotCallback = callback;
-    var profileType = WebInspector.panels.profiles.getProfileType(profile.typeId);
-    profile = ""
     WebInspector.panels.profiles.addProfileHeader(profile);
     WebInspector.panels.profiles.showProfile(profile);
 };

Modified: trunk/Source/WebCore/ChangeLog (117580 => 117581)


--- trunk/Source/WebCore/ChangeLog	2012-05-18 12:42:53 UTC (rev 117580)
+++ trunk/Source/WebCore/ChangeLog	2012-05-18 13:30:40 UTC (rev 117581)
@@ -1,3 +1,57 @@
+2012-05-18  Yury Semikhatsky  <[email protected]>
+
+        Web Inspector: remove unnecessary indirection from profile types
+        https://bugs.webkit.org/show_bug.cgi?id=86845
+
+        Reviewed by Pavel Feldman.
+
+        Introduced CSSProfileHeader and CPUProfileHeader, moved view creation from
+        the type to corresponding profile headers. Removed some inderection and
+        private fields assigned in random places. Added type annotations.
+
+        * inspector/front-end/CPUProfileView.js:
+        (WebInspector.CPUProfileType.prototype.createTemporaryProfile):
+        (WebInspector.CPUProfileType.prototype.createProfile):
+        (WebInspector.CPUProfileHeader):
+        (WebInspector.CPUProfileHeader.prototype.createSidebarTreeElement):
+        (WebInspector.CPUProfileHeader.prototype.createView):
+        * inspector/front-end/CSSSelectorProfileView.js:
+        (WebInspector.CSSSelectorProfileType.prototype.stopRecordingProfile):
+        (WebInspector.CSSSelectorProfileType.prototype.createTemporaryProfile):
+        (WebInspector.CSSSelectorProfileType.prototype.createProfile):
+        (WebInspector.CSSProfileHeader):
+        (WebInspector.CSSProfileHeader.prototype.createSidebarTreeElement):
+        (WebInspector.CSSProfileHeader.prototype.createView):
+        * inspector/front-end/HeapSnapshotView.js:
+        (WebInspector.HeapSnapshotProfileType.prototype.createTemporaryProfile):
+        (WebInspector.HeapSnapshotProfileType.prototype.createProfile):
+        (WebInspector.HeapProfileHeader):
+        (WebInspector.HeapProfileHeader.prototype.createSidebarTreeElement):
+        (WebInspector.HeapProfileHeader.prototype.createView):
+        (WebInspector.HeapProfileHeader.prototype.load):
+        (WebInspector.HeapProfileHeader.prototype.saveToFile):
+        * inspector/front-end/ProfileLauncherView.js:
+        (WebInspector.ProfileLauncherView):
+        (WebInspector.ProfileLauncherView.prototype.addProfileType):
+        (WebInspector.ProfileLauncherView.prototype._profileTypeChanged):
+        * inspector/front-end/ProfilesPanel.js:
+        (WebInspector.ProfileType):
+        (WebInspector.ProfileHeader):
+        (WebInspector.ProfileHeader.prototype.profileType):
+        (WebInspector.ProfileHeader.prototype.createSidebarTreeElement):
+        (WebInspector.ProfileHeader.prototype.existingView):
+        (WebInspector.ProfileHeader.prototype.view):
+        (WebInspector.ProfileHeader.prototype.createView):
+        (WebInspector.ProfilesPanel.prototype._reset):
+        (WebInspector.ProfilesPanel.prototype.addProfileHeader):
+        (WebInspector.ProfilesPanel.prototype._removeProfileHeader):
+        (WebInspector.ProfilesPanel.prototype.showProfile):
+        (WebInspector.ProfilesPanel.prototype.getProfiles):
+        (WebInspector.ProfilesPanel.prototype.findTemporaryProfile):
+        (WebInspector.ProfilesPanel.prototype._searchableViews):
+        * inspector/front-end/View.js:
+        (WebInspector.View._assert):
+
 2012-05-18  Kentaro Hara  <[email protected]>
 
         [V8][Refactoring] Remove V8Proxy::throwError(const char*, ErrorType, v8::Isolate*=0)

Modified: trunk/Source/WebCore/inspector/front-end/CPUProfileView.js (117580 => 117581)


--- trunk/Source/WebCore/inspector/front-end/CPUProfileView.js	2012-05-18 12:42:53 UTC (rev 117580)
+++ trunk/Source/WebCore/inspector/front-end/CPUProfileView.js	2012-05-18 13:30:40 UTC (rev 117581)
@@ -100,7 +100,7 @@
 
     this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.DefaultFormatter(30));
 
-    ProfilerAgent.getProfile(this.profile.typeId, this.profile.uid, profileCallback.bind(this));
+    ProfilerAgent.getProfile(this.profile.profileType().id, this.profile.uid, profileCallback.bind(this));
 }
 
 WebInspector.CPUProfileView._TypeTree = "Tree";
@@ -612,16 +612,6 @@
         this._recording = isProfiling;
     },
 
-    createSidebarTreeElementForProfile: function(profile)
-    {
-        return new WebInspector.ProfileSidebarTreeElement(profile, WebInspector.UIString("Profile %d"), "profile-sidebar-tree-item");
-    },
-
-    createView: function(profile)
-    {
-        return new WebInspector.CPUProfileView(profile);
-    },
-
     /**
      * @override
      * @param {string=} title
@@ -630,7 +620,7 @@
     createTemporaryProfile: function(title)
     {
         title = title || WebInspector.UIString("Recording\u2026");
-        return new WebInspector.ProfileHeader(WebInspector.CPUProfileType.TypeId, title);
+        return new WebInspector.CPUProfileHeader(this, title);
     },
 
     /**
@@ -640,8 +630,40 @@
      */
     createProfile: function(profile)
     {
-        return new WebInspector.ProfileHeader(profile.typeId, profile.title, profile.uid);
+        return new WebInspector.CPUProfileHeader(this, profile.title, profile.uid);
     }
 }
 
 WebInspector.CPUProfileType.prototype.__proto__ = WebInspector.ProfileType.prototype;
+
+/**
+ * @constructor
+ * @extends {WebInspector.ProfileHeader}
+ * @param {WebInspector.CPUProfileType} type
+ * @param {string} title
+ * @param {number=} uid
+ */
+WebInspector.CPUProfileHeader = function(type, title, uid)
+{
+    WebInspector.ProfileHeader.call(this, type, title, uid);
+}
+
+WebInspector.CPUProfileHeader.prototype = {
+    /**
+     * @override
+     */
+    createSidebarTreeElement: function()
+    {
+        return new WebInspector.ProfileSidebarTreeElement(this, WebInspector.UIString("Profile %d"), "profile-sidebar-tree-item");
+    },
+
+    /**
+     * @override
+     */
+    createView: function()
+    {
+        return new WebInspector.CPUProfileView(this);
+    }
+}
+
+WebInspector.CPUProfileHeader.prototype.__proto__ = WebInspector.ProfileHeader.prototype;

Modified: trunk/Source/WebCore/inspector/front-end/CSSSelectorProfileView.js (117580 => 117581)


--- trunk/Source/WebCore/inspector/front-end/CSSSelectorProfileView.js	2012-05-18 12:42:53 UTC (rev 117580)
+++ trunk/Source/WebCore/inspector/front-end/CSSSelectorProfileView.js	2012-05-18 13:30:40 UTC (rev 117581)
@@ -27,6 +27,7 @@
  * @constructor
  * @extends WebInspector.DataGridNode
  * @param {WebInspector.CSSSelectorProfileView} profileView
+ * @param {CSSAgent.SelectorProfile} data
  */
 WebInspector.CSSSelectorDataGridNode = function(profileView, data)
 {
@@ -332,15 +333,19 @@
 
     stopRecordingProfile: function()
     {
+        /**
+         * @param {?Protocol.Error} error
+         * @param {CSSAgent.SelectorProfile} profile
+         */
         function callback(error, profile)
         {
             if (error)
                 return;
 
-            profile.uid = this._profileUid++;
-            profile.title = WebInspector.UIString("Profile %d", profile.uid) + String.sprintf(" (%s)", Number.secondsToString(profile.totalTime / 1000));
-            profile.typeId = WebInspector.CSSSelectorProfileType.TypeId;
-            WebInspector.panels.profiles.addProfileHeader(profile);
+            var uid = this._profileUid++;
+            var title = WebInspector.UIString("Profile %d", uid) + String.sprintf(" (%s)", Number.secondsToString(profile.totalTime / 1000));
+            var profileHeader = new WebInspector.CSSProfileHeader(this, title, uid, profile);
+            WebInspector.panels.profiles.addProfileHeader(profileHeader);
             WebInspector.panels.profiles.setRecordingProfile(WebInspector.CSSSelectorProfileType.TypeId, false);
         }
 
@@ -348,16 +353,6 @@
         CSSAgent.stopSelectorProfiler(callback.bind(this));
     },
 
-    createSidebarTreeElementForProfile: function(profile)
-    {
-        return new WebInspector.ProfileSidebarTreeElement(profile, profile.title, "profile-sidebar-tree-item");
-    },
-
-    createView: function(profile)
-    {
-        return new WebInspector.CSSSelectorProfileView(profile);
-    },
-
     /**
      * @override
      * @param {string=} title
@@ -366,18 +361,54 @@
     createTemporaryProfile: function(title)
     {
         title = title || WebInspector.UIString("Recording\u2026");
-        return new WebInspector.ProfileHeader(WebInspector.CSSSelectorProfileType.TypeId, title);
+        return new WebInspector.CSSProfileHeader(this, title);
     },
 
     /**
      * @override
-     * @param {ProfilerAgent.ProfileHeader} profile
+     * @param {CSSAgent.SelectorProfile} profile
      * @return {WebInspector.ProfileHeader}
      */
     createProfile: function(profile)
     {
-        return new WebInspector.ProfileHeader(profile.typeId, profile.title, profile.uid);
+        throw new Error("Unreachable");
     }
 }
 
 WebInspector.CSSSelectorProfileType.prototype.__proto__ = WebInspector.ProfileType.prototype;
+
+
+/**
+ * @constructor
+ * @extends {WebInspector.ProfileHeader}
+ * @param {WebInspector.CSSSelectorProfileType} type
+ * @param {string} title
+ * @param {number=} uid
+ * @param {CSSAgent.SelectorProfile=} protocolData
+ */
+WebInspector.CSSProfileHeader = function(type, title, uid, protocolData)
+{
+    WebInspector.ProfileHeader.call(this, type, title, uid);
+    this._protocolData = protocolData;
+}
+
+WebInspector.CSSProfileHeader.prototype = {
+    /**
+     * @override
+     */
+    createSidebarTreeElement: function()
+    {
+        return new WebInspector.ProfileSidebarTreeElement(this, this.title, "profile-sidebar-tree-item");
+    },
+
+    /**
+     * @override
+     */
+    createView: function()
+    {
+        var profile = "" @type {CSSAgent.SelectorProfile} */this._protocolData;
+        return new WebInspector.CSSSelectorProfileView(profile);
+    }
+}
+
+WebInspector.CSSProfileHeader.prototype.__proto__ = WebInspector.ProfileHeader.prototype;

Modified: trunk/Source/WebCore/inspector/front-end/HeapSnapshotView.js (117580 => 117581)


--- trunk/Source/WebCore/inspector/front-end/HeapSnapshotView.js	2012-05-18 12:42:53 UTC (rev 117580)
+++ trunk/Source/WebCore/inspector/front-end/HeapSnapshotView.js	2012-05-18 13:30:40 UTC (rev 117581)
@@ -756,16 +756,6 @@
         return WebInspector.UIString("Heap snapshot profiles show memory distribution among your page's _javascript_ objects and related DOM nodes.");
     },
 
-    createSidebarTreeElementForProfile: function(profile)
-    {
-        return new WebInspector.ProfileSidebarTreeElement(profile, WebInspector.UIString("Snapshot %d"), "heap-snapshot-sidebar-tree-item");
-    },
-
-    createView: function(profile)
-    {
-        return new WebInspector.HeapSnapshotView(WebInspector.panels.profiles, profile);
-    },
-
     /**
      * @override
      * @param {string=} title
@@ -774,7 +764,7 @@
     createTemporaryProfile: function(title)
     {
         title = title || WebInspector.UIString("Snapshotting\u2026");
-        return new WebInspector.HeapProfileHeader(title);
+        return new WebInspector.HeapProfileHeader(this, title);
     },
 
     /**
@@ -784,7 +774,7 @@
      */
     createProfile: function(profile)
     {
-        return new WebInspector.HeapProfileHeader(profile.title, profile.uid, profile.maxJSObjectId || 0);
+        return new WebInspector.HeapProfileHeader(this, profile.title, profile.uid, profile.maxJSObjectId || 0);
     }
 }
 
@@ -793,13 +783,14 @@
 /**
  * @constructor
  * @extends {WebInspector.ProfileHeader}
+ * @param {WebInspector.HeapSnapshotProfileType} type
  * @param {string} title
  * @param {number=} uid
  * @param {number=} maxJSObjectId
  */
-WebInspector.HeapProfileHeader = function(title, uid, maxJSObjectId)
+WebInspector.HeapProfileHeader = function(type, title, uid, maxJSObjectId)
 {
-    WebInspector.ProfileHeader.call(this, WebInspector.HeapSnapshotProfileType.TypeId, title, uid);
+    WebInspector.ProfileHeader.call(this, type, title, uid);
     this.maxJSObjectId = maxJSObjectId;
     /**
      * @type {WebInspector.HeapSnapshotLoaderProxy}
@@ -813,6 +804,22 @@
 }
 
 WebInspector.HeapProfileHeader.prototype = {
+    /**
+     * @override
+     */
+    createSidebarTreeElement: function()
+    {
+        return new WebInspector.ProfileSidebarTreeElement(this, WebInspector.UIString("Snapshot %d"), "heap-snapshot-sidebar-tree-item");
+    },
+
+    /**
+     * @override
+     */
+    createView: function()
+    {
+        return new WebInspector.HeapSnapshotView(WebInspector.panels.profiles, this);
+    },
+
     snapshotProxy: function()
     {
         return this._snapshotProxy;
@@ -835,7 +842,7 @@
         if (this._loaderProxy.startLoading(callback)) {
             this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026");
             this.sidebarElement.wait = true;
-            ProfilerAgent.getProfile(this.typeId, this.uid);
+            ProfilerAgent.getProfile(this.profileType().id, this.uid);
         }
     },
 
@@ -929,7 +936,7 @@
             this._savedChunksCount = 0;
             WebInspector.fileManager.removeEventListener(WebInspector.FileManager.EventTypes.SavedURL, startSavingSnapshot, this);
             WebInspector.fileManager.addEventListener(WebInspector.FileManager.EventTypes.AppendedToURL, this._saveStatusUpdate, this);
-            ProfilerAgent.getProfile(this.typeId, this.uid);
+            ProfilerAgent.getProfile(this.profileType().id, this.uid);
         }
 
         this._fileName = this._fileName || "Heap-" + new Date().toISO8601Compact() + ".heapsnapshot";

Modified: trunk/Source/WebCore/inspector/front-end/ProfileLauncherView.js (117580 => 117581)


--- trunk/Source/WebCore/inspector/front-end/ProfileLauncherView.js	2012-05-18 12:42:53 UTC (rev 117580)
+++ trunk/Source/WebCore/inspector/front-end/ProfileLauncherView.js	2012-05-18 13:30:40 UTC (rev 117581)
@@ -38,7 +38,6 @@
 
     this._panel = profilesPanel;
     this._profileRunning = false;
-    this._optionIdPrefix = "profile-type-";
 
     this.element.addStyleClass("profile-launcher-view");
     this.element.addStyleClass("panel-enabler-view");
@@ -53,8 +52,6 @@
     this._profileTypeSelectorForm = this._contentElement.createChild("form");
     this._contentElement.createChild("div", "flexible-space");
 
-    this._boundProfileTypeChangeListener = this._profileTypeChanged.bind(this);
-
     this._controlButton = this._contentElement.createChild("button", "control-profiling");
     this._controlButton.addEventListener("click", this._controlButtonClicked.bind(this), false);
     this._updateControls();
@@ -71,6 +68,9 @@
         this._panel.addEventListener(WebInspector.ProfilesPanel.EventTypes.ProfileFinished, this._onProfileFinished, this);
     },
 
+    /**
+     * @param {WebInspector.ProfileType} profileType
+     */
     addProfileType: function(profileType)
     {
         var checked = !this._profileTypeSelectorForm.children.length;
@@ -80,13 +80,11 @@
         labelElement.insertBefore(optionElement, labelElement.firstChild);
         optionElement.type = "radio";
         optionElement.name = "profile-type";
-        var optionId = this._optionIdPrefix + profileType.id;
-        optionElement.id = optionId;
         if (checked) {
             optionElement.checked = checked;
             this.dispatchEventToListeners(WebInspector.ProfileLauncherView.EventTypes.ProfileTypeSelected, profileType);
         }
-        optionElement.addEventListener("change", this._boundProfileTypeChangeListener, false);
+        optionElement.addEventListener("change", this._profileTypeChanged.bind(this, profileType), false);
         var descriptionElement = labelElement.createChild("p");
         descriptionElement.textContent = profileType.description;
     },
@@ -109,10 +107,12 @@
         }
     },
 
-    _profileTypeChanged: function(event)
+    /**
+     * @param {WebInspector.ProfileType} profileType
+     */
+    _profileTypeChanged: function(profileType, event)
     {
-        var selectedProfileType = this._panel.getProfileType(event.target.id.substring(this._optionIdPrefix.length));
-        this.dispatchEventToListeners(WebInspector.ProfileLauncherView.EventTypes.ProfileTypeSelected, selectedProfileType);
+        this.dispatchEventToListeners(WebInspector.ProfileLauncherView.EventTypes.ProfileTypeSelected, profileType);
     },
 
     _onProfileStarted: function(event)

Modified: trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js (117580 => 117581)


--- trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js	2012-05-18 12:42:53 UTC (rev 117580)
+++ trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js	2012-05-18 13:30:40 UTC (rev 117581)
@@ -32,6 +32,10 @@
 {
     this._id = id;
     this._name = name;
+    /**
+     * @type {WebInspector.SidebarSectionTreeElement}
+     */
+    this.treeElement = null;
 }
 
 WebInspector.ProfileType.URLRegExp = /webkit-profile:\/\/(.+)\/(.+)#([0-9]+)/;
@@ -65,13 +69,6 @@
         return false;
     },
 
-    viewForProfile: function(profile)
-    {
-        if (!profile._profileView)
-            profile._profileView = this.createView(profile);
-        return profile._profileView;
-    },
-
     reset: function()
     {
     },
@@ -82,18 +79,6 @@
     },
 
     // Must be implemented by subclasses.
-    createView: function(profile)
-    {
-        throw new Error("Needs implemented.");
-    },
-
-    // Must be implemented by subclasses.
-    createSidebarTreeElementForProfile: function(profile)
-    {
-        throw new Error("Needs implemented.");
-    },
-
-    // Must be implemented by subclasses.
     /**
      * @param {string=} title
      * @return {WebInspector.ProfileHeader}
@@ -124,13 +109,13 @@
 
 /**
  * @constructor
- * @param {string} profileType
+ * @param {WebInspector.ProfileType} profileType
  * @param {string} title
  * @param {number=} uid
  */
 WebInspector.ProfileHeader = function(profileType, title, uid)
 {
-    this.typeId = profileType,
+    this._profileType = profileType;
     this.title = title;
     if (uid === undefined) {
         this.uid = -1;
@@ -143,7 +128,38 @@
 }
 
 WebInspector.ProfileHeader.prototype = {
+    profileType: function()
+    {
+        return this._profileType;
+    },
+
     /**
+     * Must be implemented by subclasses.
+     * @return {WebInspector.ProfileSidebarTreeElement}
+     */
+    createSidebarTreeElement: function()
+    {
+        throw new Error("Needs implemented.");
+    },
+
+    existingView: function()
+    {
+        return this._view;
+    },
+
+    view: function()
+    {
+        if (!this._view)
+            this._view = this.createView();
+        return this._view;
+    },
+
+    createView: function()
+    {
+        throw new Error("Not implemented.");
+    },
+
+    /**
      * @param {Function} callback
      */
     load: function(callback) { },
@@ -334,14 +350,12 @@
         WebInspector.Panel.prototype.reset.call(this);
 
         for (var i = 0; i < this._profiles.length; ++i) {
-            var view = this._profiles[i]._profileView;
+            var view = this._profiles[i].existingView();
             if (view) {
                 view.detach();
                 if ("dispose" in view)
                     view.dispose();
             }
-
-            delete this._profiles[i]._profileView;
         }
         delete this.visibleView;
 
@@ -443,16 +457,15 @@
      */
     addProfileHeader: function(profile)
     {
-        this._removeTemporaryProfile(profile.typeId);
+        this._removeTemporaryProfile(profile.profileType().id);
 
-        var typeId = profile.typeId;
-        var profileType = this.getProfileType(typeId);
+        var profileType = profile.profileType();
+        var typeId = profileType.id;
         var sidebarParent = profileType.treeElement;
         sidebarParent.hidden = false;
         var small = false;
         var alternateTitle;
 
-        profile.__profilesPanelProfileType = profileType;
         this._profiles.push(profile);
         this._profilesIdMap[this._makeKey(profile.uid, typeId)] = profile;
 
@@ -492,7 +505,7 @@
             }
         }
 
-        var profileTreeElement = profileType.createSidebarTreeElementForProfile(profile);
+        var profileTreeElement = profile.createSidebarTreeElement();
         profile.sidebarElement = profileTreeElement;
         profileTreeElement.small = small;
         if (alternateTitle)
@@ -512,9 +525,7 @@
      */
     _removeProfileHeader: function(profile)
     {
-        var typeId = profile.typeId;
-        var profileType = this.getProfileType(typeId);
-        var sidebarParent = profileType.treeElement;
+        var sidebarParent = profile.profileType().treeElement;
 
         for (var i = 0; i < this._profiles.length; ++i) {
             if (this._profiles[i].uid === profile.uid) {
@@ -523,15 +534,15 @@
                 break;
             }
         }
-        delete this._profilesIdMap[this._makeKey(profile.uid, typeId)];
+        delete this._profilesIdMap[this._makeKey(profile.uid, profile.profileType().id)];
 
-        var profileTitleKey = this._makeTitleKey(profile.title, typeId);
+        var profileTitleKey = this._makeTitleKey(profile.title, profile.profileType().id);
         delete this._profileGroups[profileTitleKey];
 
         sidebarParent.removeChild(profile._profilesTreeElement);
 
         if (!profile.isTemporary)
-            ProfilerAgent.removeProfile(profile.typeId, profile.uid);
+            ProfilerAgent.removeProfile(profile.profileType().id, profile.uid);
 
         // No other item will be selected if there aren't any other profiles, so
         // make sure that view gets cleared when the last profile is removed.
@@ -549,7 +560,7 @@
 
         this.closeVisibleView();
 
-        var view = profile.__profilesPanelProfileType.viewForProfile(profile);
+        var view = profile.view();
 
         view.show(this.profileViews);
 
@@ -577,7 +588,7 @@
         var profilesCount = this._profiles.length;
         for (var i = 0; i < profilesCount; ++i) {
             var profile = ""
-            if (!profile.isTemporary && profile.typeId === typeId)
+            if (!profile.isTemporary && profile.profileType().id === typeId)
                 result.push(profile);
         }
         return result;
@@ -595,8 +606,8 @@
             // TODO: allow to choose snapshot if there are several options.
             if (profile.maxJSObjectId >= snapshotObjectId) {
                 this.showProfile(profile);
-                profile._profileView.changeView(viewName, function() {
-                    profile._profileView.dataGrid.highlightObjectByHeapSnapshotId(snapshotObjectId);
+                profile.view().changeView(viewName, function() {
+                    profile.view().dataGrid.highlightObjectByHeapSnapshotId(snapshotObjectId);
                 });
                 break;
             }
@@ -611,7 +622,7 @@
     {
         var profilesCount = this._profiles.length;
         for (var i = 0; i < profilesCount; ++i)
-            if (this._profiles[i].typeId === typeId && this._profiles[i].isTemporary)
+            if (this._profiles[i].profileType().id === typeId && this._profiles[i].isTemporary)
                 return this._profiles[i];
         return null;
     },
@@ -627,7 +638,7 @@
     },
 
     /**
-     * @param {WebInspector.ProfileHeader} profile
+     * @param {ProfilerAgent.ProfileHeader} profile
      */
     hasProfile: function(profile)
     {
@@ -876,7 +887,7 @@
         var profilesLength = this._profiles.length;
         for (var i = 0; i < profilesLength; ++i) {
             var profile = ""
-            var view = profile.__profilesPanelProfileType.viewForProfile(profile);
+            var view = profile.view();
             if (!view.performSearch || view === visibleView)
                 continue;
             views.push(view);
@@ -976,6 +987,10 @@
         if (!this._profilerEnabled || this._profilesWereRequested)
             return;
 
+        /**
+         * @param {?string} error
+         * @param {Array.<ProfilerAgent.ProfileHeader>} profileHeaders
+         */
         function populateCallback(error, profileHeaders) {
             if (error)
                 return;

Modified: trunk/Source/WebCore/inspector/front-end/View.js (117580 => 117581)


--- trunk/Source/WebCore/inspector/front-end/View.js	2012-05-18 12:42:53 UTC (rev 117580)
+++ trunk/Source/WebCore/inspector/front-end/View.js	2012-05-18 13:30:40 UTC (rev 117581)
@@ -396,6 +396,7 @@
 {
     if (!condition) {
         console.trace();
+        console.error("assert: " + new Error().stack);
         throw new Error(message);
     }
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to