Bug 30520

Summary: Enable creation of custom SidebarTreeElements for different ProfileTypes
Product: WebKit Reporter: Alexander Pavlov (apavlov) <apavlov>
Component: Web Inspector (Deprecated)Assignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, pfeldman, timothy
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
patch
timothy: review-
patch (fixed)
pfeldman: review-
patch (rename field) none

Alexander Pavlov (apavlov)
Reported 2009-10-19 10:16:05 PDT
Currently ProfileSidebarTreeElement is always created as the sidebar tree node for profiles. This is too limiting for some types of profiles which would rather provide their own tree elements (e.g. they require non-empty subtitles).
Attachments
patch (5.10 KB, patch)
2009-10-19 11:17 PDT, Alexander Pavlov (apavlov)
timothy: review-
patch (fixed) (4.41 KB, patch)
2009-10-20 03:20 PDT, Alexander Pavlov (apavlov)
pfeldman: review-
patch (rename field) (4.45 KB, patch)
2009-10-21 03:30 PDT, Alexander Pavlov (apavlov)
no flags
Alexander Pavlov (apavlov)
Comment 1 2009-10-19 11:17:41 PDT
Timothy Hatcher
Comment 2 2009-10-19 11:40:48 PDT
Comment on attachment 41433 [details] patch > + sidebarTreeElementForProfile: function(profile) > + { > + return new WebInspector.ProfileSidebarTreeElement(profile); > + }, Why does this return a new tree element each time? Shouldn't this return the same one each time? If not, then this function needs a "create" prefix. > + createView: function(profile) > + { > + return undefined; > + }, > + > + sidebarTreeElementForProfile: function(profile) > + { > + return undefined; > + }, It is better to use null in cases like this. But why do these exist? > + viewForProfile: function(profile) > + { > + if (!profile._profileView) > + profile._profileView = this.createView(profile); > + return profile._profileView; > } I am confused why there are multiple versions of these functions. Also this clearly calls "this.createView", which just returns undefined. Can you explain this? I don't think the functions that just return "undefined" are needed or useful. > + _parseKey: function(key) > + { > + var match = key.match(/^([^\/]+)\/([^\/]+)$/); > + if (match) > + return [unescape(match[1]), unescape(match[2])]; > + return undefined; > + }, Better to return null. > + _viewForProfile: function(profile) > + { > + for (var key in this._profilesIdMap) { > + if (this._profilesIdMap[key] === profile) { > + var parsedKey = this._parseKey(key); > + if (parsedKey) > + return this.getProfileType(parsedKey[1]).viewForProfile(profile); > + } > + } > + return undefined; > + }, Better to return null. r-. This needs clerified and not have functions that do nothing but return undefined. (Or explained with good comments.)
Pavel Feldman
Comment 3 2009-10-19 11:49:30 PDT
> + _viewForProfile: function(profile) > + { > + for (var key in this._profilesIdMap) { > + if (this._profilesIdMap[key] === profile) { > + var parsedKey = this._parseKey(key); > + if (parsedKey) > + return this.getProfileType(parsedKey[1]).viewForProfile(profile); This sounds much more complex than "profile.type.viewForProfile(profile)". Should we make profile have this property in order to get rid of key parsing?
Alexander Pavlov (apavlov)
Comment 4 2009-10-19 13:10:55 PDT
(In reply to comment #3) > > + _viewForProfile: function(profile) > > + { > > + for (var key in this._profilesIdMap) { > > + if (this._profilesIdMap[key] === profile) { > > + var parsedKey = this._parseKey(key); > > + if (parsedKey) > > + return this.getProfileType(parsedKey[1]).viewForProfile(profile); > > This sounds much more complex than "profile.type.viewForProfile(profile)". > Should we make profile have this property in order to get rid of key parsing? Good point. I was trying to decrease coupling as much as possible but this one seems fine.
Timothy Hatcher
Comment 5 2009-10-19 13:22:10 PDT
Comment on attachment 41433 [details] patch I understand this design better now. You should add comments to each function that the ProfileType subclasses should implement. I also think ProfileType.sidebarTreeElementForProfile should be ProfileType.createSidebarTreeElementForProfile to show it returns a new instance each time.
Alexander Pavlov (apavlov)
Comment 6 2009-10-20 03:20:56 PDT
Created attachment 41493 [details] patch (fixed)
Pavel Feldman
Comment 7 2009-10-20 15:47:13 PDT
Comment on attachment 41493 [details] patch (fixed) > + // Must be implemented by subclasses. > + createView: function(profile) Nit, can be done in subsequent patch: usually abstract methods that are implemented in concrete classes are named as doCreateSomething*. Otherwise it is easy to get confused on what should be overriden and what not. > + { > + throw new Error("Needs implemented."); > + }, "Not implemented" ? > > + profile._type = profileType; This looks like a hack: what if concrete profile object already has this property? Either declare it a hack and name it "__profilesPanelProfileType" or make profile define "type" getter and put it into docs.
Timothy Hatcher
Comment 8 2009-10-20 17:04:25 PDT
(In reply to comment #7) > (From update of attachment 41493 [details]) > > + // Must be implemented by subclasses. > > + createView: function(profile) > > Nit, can be done in subsequent patch: usually abstract methods that are > implemented in concrete classes are named as doCreateSomething*. > Otherwise it is easy to get confused on what should be overriden and what not. This is not something we normally do in WebKit. I think the normal names are better.
Alexander Pavlov (apavlov)
Comment 9 2009-10-21 03:25:59 PDT
(In reply to comment #7) > (From update of attachment 41493 [details]) > > + // Must be implemented by subclasses. > > + createView: function(profile) > > Nit, can be done in subsequent patch: usually abstract methods that are > implemented in concrete classes are named as doCreateSomething*. > Otherwise it is easy to get confused on what should be overriden and what not. Timothy has commented on this one. > > + { > > + throw new Error("Needs implemented."); > > + }, > > "Not implemented" ? This is fine, as in "Has a comment that points out this needs implemented when network headers are added" (WebCore/ChangeLog, 2008-05-13) or at the bottom of Comment #2. And, it was suggested by Timothy. > > > > + profile._type = profileType; > > This looks like a hack: what if concrete profile object already has this > property? > Either declare it a hack and name it "__profilesPanelProfileType" or make > profile define "type" getter and put it into docs. Profiles should be definitely ProfileType-agnostic since ProfileTypes deal with visual representation of profiles, and they are bound only at the point of the addProfileHeader() invocation. That's why I was parsing the keys (which was cleaner than "caching" ProfileTypes inside profiles) rather than using an explicit association. I will stick to "__profilesPanelProfileType".
Alexander Pavlov (apavlov)
Comment 10 2009-10-21 03:30:55 PDT
Created attachment 41560 [details] patch (rename field) Renamed the "cached" ProfileType field inside profiles.
WebKit Commit Bot
Comment 11 2009-10-21 06:57:20 PDT
Comment on attachment 41560 [details] patch (rename field) Clearing flags on attachment: 41560 Committed r49905: <http://trac.webkit.org/changeset/49905>
WebKit Commit Bot
Comment 12 2009-10-21 06:57:25 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.