From 1642bc22575e71f753b4721b083333dfdc56324a Mon Sep 17 00:00:00 2001 From: "pfeldman@chromium.org" Date: Fri, 13 Apr 2012 12:25:25 +0000 Subject: [PATCH] Web Inspector: introduce ParsedURL type, clean up url and displayName mess in Resource and NetworkRequest. https://bugs.webkit.org/show_bug.cgi?id=83871 Reviewed by Yury Semikhatsky. Source/WebCore: There is a number of random properties created on Resource and NetworkRequest that represent various url fragments. Display name is being based on them and sometimes requires fake Resource instance to be created. This change (officially) introduces WebInspector.ParsedURL as a type that encapsulates this complexity. This change also moves documentURL property into the Resource and NetworkRequest constructors and brushes up factory methods used to create the objects. * inspector/front-end/AuditRules.js: (WebInspector.AuditRules.GzipRule.prototype._shouldCompress): (WebInspector.AuditRules.CookieSizeRule.prototype.processCookies): * inspector/front-end/Database.js: (WebInspector.Database.prototype.get displayDomain): * inspector/front-end/JavaScriptContextManager.js: (WebInspector.FrameEvaluationContext.prototype.get displayName): * inspector/front-end/NetworkManager.js: (WebInspector.NetworkDispatcher.prototype.webSocketCreated): (WebInspector.NetworkDispatcher.prototype._createNetworkRequest): (get WebInspector): * inspector/front-end/NetworkPanel.js: (WebInspector.NetworkLogView.prototype._highlightNthMatchedRequest): (WebInspector.NetworkDataGridNode.prototype._refreshNameCell): * inspector/front-end/NetworkRequest.js: (WebInspector.NetworkRequest): (WebInspector.NetworkRequest.prototype.set url): (WebInspector.NetworkRequest.prototype.get documentURL): (WebInspector.NetworkRequest.prototype.get parsedURL): (WebInspector.NetworkRequest.prototype.get displayName): (WebInspector.NetworkRequest.prototype.get folder): * inspector/front-end/RequestHeadersView.js: (WebInspector.RequestHeadersView.prototype._refreshUrlFragment): * inspector/front-end/Resource.js: (WebInspector.Resource): (WebInspector.Resource.prototype.set url): (WebInspector.Resource.prototype.get parsedURL): (WebInspector.Resource.prototype.get frameId): (WebInspector.Resource.prototype.get loaderId): (WebInspector.Resource.prototype.get displayName): * inspector/front-end/ResourceTreeModel.js: (WebInspector.ResourceTreeModel.prototype._onRequestUpdateDropped): (WebInspector.ResourceTreeModel.prototype._addFramesRecursively): (WebInspector.ResourceTreeModel.prototype._createResourceFromFramePayload): (WebInspector.ResourceTreeFrame.prototype._addRequest): * inspector/front-end/ResourceUtils.js: (WebInspector.ParsedURL): (WebInspector.ParsedURL.prototype.get displayName): (String.prototype.asParsedURL): (WebInspector.displayDomain): (WebInspector.resourceURLForRelatedNode.callback): (WebInspector.resourceURLForRelatedNode): * inspector/front-end/ResourcesPanel.js: (WebInspector.FrameTreeElement.prototype.frameNavigated): (WebInspector.ApplicationCacheManifestTreeElement): (WebInspector.ApplicationCacheFrameTreeElement.prototype._refreshTitles): * inspector/front-end/utilities.js: LayoutTests: * inspector/debugger/raw-source-code.html: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@114117 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- LayoutTests/ChangeLog | 9 ++ .../inspector/debugger/raw-source-code.html | 2 +- Source/WebCore/ChangeLog | 62 ++++++++++++++ Source/WebCore/inspector/front-end/AuditRules.js | 6 +- Source/WebCore/inspector/front-end/Database.js | 2 +- .../front-end/JavaScriptContextManager.js | 2 +- .../WebCore/inspector/front-end/NetworkManager.js | 5 +- Source/WebCore/inspector/front-end/NetworkPanel.js | 6 +- .../WebCore/inspector/front-end/NetworkRequest.js | 61 +++++++------- .../inspector/front-end/RequestHeadersView.js | 2 +- Source/WebCore/inspector/front-end/Resource.js | 94 ++++++--------------- .../inspector/front-end/ResourceTreeModel.js | 37 ++------- .../WebCore/inspector/front-end/ResourceUtils.js | 95 +++++++++++++++++++++- .../WebCore/inspector/front-end/ResourcesPanel.js | 6 +- Source/WebCore/inspector/front-end/utilities.js | 43 ---------- 15 files changed, 241 insertions(+), 191 deletions(-) diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index 40cecee..7212179 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,5 +1,14 @@ 2012-04-13 Pavel Feldman + Web Inspector: introduce ParsedURL type, clean up url and displayName mess in Resource and NetworkRequest. + https://bugs.webkit.org/show_bug.cgi?id=83871 + + Reviewed by Yury Semikhatsky. + + * inspector/debugger/raw-source-code.html: + +2012-04-13 Pavel Feldman + Web Inspector: extracting NetworkRequest from Resource (step 3) https://bugs.webkit.org/show_bug.cgi?id=83802 diff --git a/LayoutTests/inspector/debugger/raw-source-code.html b/LayoutTests/inspector/debugger/raw-source-code.html index e6c449d..3ce1bb0 100644 --- a/LayoutTests/inspector/debugger/raw-source-code.html +++ b/LayoutTests/inspector/debugger/raw-source-code.html @@ -19,7 +19,7 @@ function test() { var requestId = ++lastRequestId + ""; WebInspector.resourceTreeModel._addFrame(new WebInspector.ResourceTreeFrame(WebInspector.resourceTreeModel, null, {id: "frame-id"})); - var request = new WebInspector.NetworkRequest(requestId, "http://fake.url", "frame-id", "loader-id"); + var request = new WebInspector.NetworkRequest(requestId, "http://fake.url", "http://fake.url", "frame-id", "loader-id"); request.type = type === "document" ? WebInspector.resourceTypes.Document : WebInspector.resourceTypes.Script; WebInspector.networkManager._dispatcher._startNetworkRequest(request); diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 7f56b0c..ba974f2 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,5 +1,67 @@ 2012-04-13 Pavel Feldman + Web Inspector: introduce ParsedURL type, clean up url and displayName mess in Resource and NetworkRequest. + https://bugs.webkit.org/show_bug.cgi?id=83871 + + Reviewed by Yury Semikhatsky. + + There is a number of random properties created on Resource and NetworkRequest that represent various url + fragments. Display name is being based on them and sometimes requires fake Resource instance to be created. + This change (officially) introduces WebInspector.ParsedURL as a type that encapsulates this complexity. + + This change also moves documentURL property into the Resource and NetworkRequest constructors and brushes up + factory methods used to create the objects. + + * inspector/front-end/AuditRules.js: + (WebInspector.AuditRules.GzipRule.prototype._shouldCompress): + (WebInspector.AuditRules.CookieSizeRule.prototype.processCookies): + * inspector/front-end/Database.js: + (WebInspector.Database.prototype.get displayDomain): + * inspector/front-end/JavaScriptContextManager.js: + (WebInspector.FrameEvaluationContext.prototype.get displayName): + * inspector/front-end/NetworkManager.js: + (WebInspector.NetworkDispatcher.prototype.webSocketCreated): + (WebInspector.NetworkDispatcher.prototype._createNetworkRequest): + (get WebInspector): + * inspector/front-end/NetworkPanel.js: + (WebInspector.NetworkLogView.prototype._highlightNthMatchedRequest): + (WebInspector.NetworkDataGridNode.prototype._refreshNameCell): + * inspector/front-end/NetworkRequest.js: + (WebInspector.NetworkRequest): + (WebInspector.NetworkRequest.prototype.set url): + (WebInspector.NetworkRequest.prototype.get documentURL): + (WebInspector.NetworkRequest.prototype.get parsedURL): + (WebInspector.NetworkRequest.prototype.get displayName): + (WebInspector.NetworkRequest.prototype.get folder): + * inspector/front-end/RequestHeadersView.js: + (WebInspector.RequestHeadersView.prototype._refreshUrlFragment): + * inspector/front-end/Resource.js: + (WebInspector.Resource): + (WebInspector.Resource.prototype.set url): + (WebInspector.Resource.prototype.get parsedURL): + (WebInspector.Resource.prototype.get frameId): + (WebInspector.Resource.prototype.get loaderId): + (WebInspector.Resource.prototype.get displayName): + * inspector/front-end/ResourceTreeModel.js: + (WebInspector.ResourceTreeModel.prototype._onRequestUpdateDropped): + (WebInspector.ResourceTreeModel.prototype._addFramesRecursively): + (WebInspector.ResourceTreeModel.prototype._createResourceFromFramePayload): + (WebInspector.ResourceTreeFrame.prototype._addRequest): + * inspector/front-end/ResourceUtils.js: + (WebInspector.ParsedURL): + (WebInspector.ParsedURL.prototype.get displayName): + (String.prototype.asParsedURL): + (WebInspector.displayDomain): + (WebInspector.resourceURLForRelatedNode.callback): + (WebInspector.resourceURLForRelatedNode): + * inspector/front-end/ResourcesPanel.js: + (WebInspector.FrameTreeElement.prototype.frameNavigated): + (WebInspector.ApplicationCacheManifestTreeElement): + (WebInspector.ApplicationCacheFrameTreeElement.prototype._refreshTitles): + * inspector/front-end/utilities.js: + +2012-04-13 Pavel Feldman + Web Inspector: extracting NetworkRequest from Resource (step 3) https://bugs.webkit.org/show_bug.cgi?id=83802 diff --git a/Source/WebCore/inspector/front-end/AuditRules.js b/Source/WebCore/inspector/front-end/AuditRules.js index 813dbc6..f1608451 100644 --- a/Source/WebCore/inspector/front-end/AuditRules.js +++ b/Source/WebCore/inspector/front-end/AuditRules.js @@ -116,7 +116,7 @@ WebInspector.AuditRules.GzipRule.prototype = { _shouldCompress: function(request) { - return request.type.isTextType() && request.domain && request.resourceSize !== undefined && request.resourceSize > 150; + return request.type.isTextType() && request.parsedURL.host && request.resourceSize !== undefined && request.resourceSize > 150; } } @@ -1225,10 +1225,10 @@ WebInspector.AuditRules.CookieSizeRule.prototype = { function collectorCallback(request, cookie) { - var cookies = cookiesPerResourceDomain[request.domain]; + var cookies = cookiesPerResourceDomain[request.parsedURL.host]; if (!cookies) { cookies = []; - cookiesPerResourceDomain[request.domain] = cookies; + cookiesPerResourceDomain[request.parsedURL.host] = cookies; } cookies.push(cookie); } diff --git a/Source/WebCore/inspector/front-end/Database.js b/Source/WebCore/inspector/front-end/Database.js index 5322baa..7fa41a9 100644 --- a/Source/WebCore/inspector/front-end/Database.js +++ b/Source/WebCore/inspector/front-end/Database.js @@ -80,7 +80,7 @@ WebInspector.Database.prototype = { /** @return {string} */ get displayDomain() { - return WebInspector.Resource.prototype.__lookupGetter__("displayDomain").call(this); + return WebInspector.displayDomain(this._domain); }, /** diff --git a/Source/WebCore/inspector/front-end/JavaScriptContextManager.js b/Source/WebCore/inspector/front-end/JavaScriptContextManager.js index 7431e9f..c818deb 100644 --- a/Source/WebCore/inspector/front-end/JavaScriptContextManager.js +++ b/Source/WebCore/inspector/front-end/JavaScriptContextManager.js @@ -107,7 +107,7 @@ WebInspector.FrameEvaluationContext.prototype = if (!this._frame.parentFrame) return ""; var name = this._frame.name || ""; - var subtitle = WebInspector.Resource.displayName(this._frame.url); + var subtitle = new WebInspector.ParsedURL(this._frame.url).displayName; if (subtitle) { if (!name) return subtitle; diff --git a/Source/WebCore/inspector/front-end/NetworkManager.js b/Source/WebCore/inspector/front-end/NetworkManager.js index 8346737..ebe65bb 100644 --- a/Source/WebCore/inspector/front-end/NetworkManager.js +++ b/Source/WebCore/inspector/front-end/NetworkManager.js @@ -410,7 +410,7 @@ WebInspector.NetworkDispatcher.prototype = { */ webSocketCreated: function(requestId, requestURL) { - var networkRequest = new WebInspector.NetworkRequest(requestId, requestURL, "", ""); + var networkRequest = new WebInspector.NetworkRequest(requestId, requestURL, "", "", ""); networkRequest.type = WebInspector.resourceTypes.WebSocket; this._startNetworkRequest(networkRequest); }, @@ -538,8 +538,7 @@ WebInspector.NetworkDispatcher.prototype = { */ _createNetworkRequest: function(requestId, frameId, loaderId, url, documentURL, initiator, stackTrace) { - var networkRequest = new WebInspector.NetworkRequest(requestId, url, frameId, loaderId); - networkRequest.documentURL = documentURL; + var networkRequest = new WebInspector.NetworkRequest(requestId, url, documentURL, frameId, loaderId); networkRequest.initiator = initiator; networkRequest.stackTrace = stackTrace; return networkRequest; diff --git a/Source/WebCore/inspector/front-end/NetworkPanel.js b/Source/WebCore/inspector/front-end/NetworkPanel.js index 3cba1da..9fb2c32 100644 --- a/Source/WebCore/inspector/front-end/NetworkPanel.js +++ b/Source/WebCore/inspector/front-end/NetworkPanel.js @@ -1126,7 +1126,7 @@ WebInspector.NetworkLogView.prototype = { return; var nameMatched = request.displayName && request.displayName.match(this._searchRegExp); - var pathMatched = request.path && request.folder.match(this._searchRegExp); + var pathMatched = request.parsedURL.path && request.folder.match(this._searchRegExp); if (!nameMatched && pathMatched && !this._largerRequestsButton.toggled) this._toggleLargerRequests(); @@ -1836,9 +1836,9 @@ WebInspector.NetworkDataGridNode.prototype = { this._nameCell.appendChild(document.createTextNode(this._fileName())); - var subtitle = this._request.displayDomain; + var subtitle = WebInspector.displayDomain(this._request.parsedURL.host); - if (this._request.path) + if (this._request.parsedURL.path) subtitle += this._request.folder; this._appendSubtitle(this._nameCell, subtitle); diff --git a/Source/WebCore/inspector/front-end/NetworkRequest.js b/Source/WebCore/inspector/front-end/NetworkRequest.js index fe031c4..96441db 100644 --- a/Source/WebCore/inspector/front-end/NetworkRequest.js +++ b/Source/WebCore/inspector/front-end/NetworkRequest.js @@ -34,13 +34,15 @@ * * @param {NetworkAgent.RequestId} requestId * @param {string} url + * @param {string} documentURL * @param {NetworkAgent.FrameId} frameId * @param {NetworkAgent.LoaderId} loaderId */ -WebInspector.NetworkRequest = function(requestId, url, frameId, loaderId) +WebInspector.NetworkRequest = function(requestId, url, documentURL, frameId, loaderId) { this._requestId = requestId; - this._url = url; + this.url = url; + this._documentURL = documentURL; this._frameId = frameId; this._loaderId = loaderId; this._startTime = -1; @@ -56,14 +58,6 @@ WebInspector.NetworkRequest = function(requestId, url, frameId, loaderId) this._content = undefined; this._contentEncoded = false; this._pendingContentCallbacks = []; - - delete this._parsedQueryParameters; - - var parsedURL = url.asParsedURL(); - this.domain = parsedURL ? parsedURL.host : ""; - this.path = parsedURL ? parsedURL.path : ""; - this.urlFragment = parsedURL ? parsedURL.fragment : ""; - this.lastPathComponent = parsedURL ? parsedURL.lastPathComponent : ""; } WebInspector.NetworkRequest.Events = { @@ -95,6 +89,29 @@ WebInspector.NetworkRequest.prototype = { return this._url; }, + set url(x) + { + if (this._url === x) + return; + + this._url = x; + this._parsedURL = new WebInspector.ParsedURL(x); + delete this._parsedQueryParameters; + }, + + /** + * @type {string} + */ + get documentURL() + { + return this._documentURL; + }, + + get parsedURL() + { + return this._parsedURL; + }, + /** * @type {NetworkAgent.FrameId} */ @@ -336,16 +353,7 @@ WebInspector.NetworkRequest.prototype = { */ get displayName() { - if (this._displayName) - return this._displayName; - this._displayName = this.lastPathComponent; - if (!this._displayName) - this._displayName = this.displayDomain; - if (!this._displayName && this.url) - this._displayName = this.url.trimURL(WebInspector.inspectedPageDomain ? WebInspector.inspectedPageDomain : ""); - if (this._displayName === "/") - this._displayName = this.url; - return this._displayName; + return this._parsedURL.displayName; }, /** @@ -353,7 +361,7 @@ WebInspector.NetworkRequest.prototype = { */ get folder() { - var path = this.path; + var path = this._parsedURL.path; var indexOfQuery = path.indexOf("?"); if (indexOfQuery !== -1) path = path.substring(0, indexOfQuery); @@ -362,17 +370,6 @@ WebInspector.NetworkRequest.prototype = { }, /** - * @type {string} - */ - get displayDomain() - { - // WebInspector.Database calls this, so don't access more than this.domain. - if (this.domain && (!WebInspector.inspectedPageDomain || (WebInspector.inspectedPageDomain && this.domain !== WebInspector.inspectedPageDomain))) - return this.domain; - return ""; - }, - - /** * @type {WebInspector.ResourceType} */ get type() diff --git a/Source/WebCore/inspector/front-end/RequestHeadersView.js b/Source/WebCore/inspector/front-end/RequestHeadersView.js index 5bfc887..3118b37 100644 --- a/Source/WebCore/inspector/front-end/RequestHeadersView.js +++ b/Source/WebCore/inspector/front-end/RequestHeadersView.js @@ -168,7 +168,7 @@ WebInspector.RequestHeadersView.prototype = { _refreshUrlFragment: function() { - var urlFragment = this._request.urlFragment; + var urlFragment = this._request.parsedURL.fragment; this._urlFragmentTreeElement.hidden = !urlFragment; if (!urlFragment) diff --git a/Source/WebCore/inspector/front-end/Resource.js b/Source/WebCore/inspector/front-end/Resource.js index 3a148e4..abca201 100644 --- a/Source/WebCore/inspector/front-end/Resource.js +++ b/Source/WebCore/inspector/front-end/Resource.js @@ -32,18 +32,23 @@ * * @param {?WebInspector.NetworkRequest} request * @param {string} url - * @param {string} frameId - * @param {?NetworkAgent.LoaderId} loaderId + * @param {string} documentURL + * @param {NetworkAgent.FrameId} frameId + * @param {NetworkAgent.LoaderId} loaderId + * @param {WebInspector.ResourceType=} type + * @param {string=} mimeType */ -WebInspector.Resource = function(request, url, frameId, loaderId) +WebInspector.Resource = function(request, url, documentURL, frameId, loaderId, type, mimeType) { this._request = request; if (this._request) this._request.setResource(this); this.url = url; - this.frameId = frameId; - this.loaderId = loaderId; - this._type = WebInspector.resourceTypes.Other; + this._documentURL = documentURL; + this._frameId = frameId; + this._loaderId = loaderId; + this._type = type || WebInspector.resourceTypes.Other; + this._mimeType = mimeType; this.history = []; this._content = undefined; @@ -51,15 +56,6 @@ WebInspector.Resource = function(request, url, frameId, loaderId) this._pendingContentCallbacks = []; } -/** - * @param {string} url - * @return {string} - */ -WebInspector.Resource.displayName = function(url) -{ - return new WebInspector.Resource(null, url, "", null).displayName; -} - WebInspector.Resource._domainModelBindings = []; /** @@ -166,14 +162,6 @@ WebInspector.Resource.prototype = { }, /** - * @return {WebInspector.Resource} - */ - resource: function() - { - return this; - }, - - /** * @type {string} */ get url() @@ -183,15 +171,13 @@ WebInspector.Resource.prototype = { set url(x) { - if (this._url === x) - return; - this._url = x; + this._parsedURL = new WebInspector.ParsedURL(x); + }, - var parsedURL = x.asParsedURL(); - this.domain = parsedURL ? parsedURL.host : ""; - this.path = parsedURL ? parsedURL.path : ""; - this.lastPathComponent = parsedURL ? parsedURL.lastPathComponent : ""; + get parsedURL() + { + return this._parsedURL; }, /** @@ -202,50 +188,28 @@ WebInspector.Resource.prototype = { return this._documentURL; }, - set documentURL(x) - { - this._documentURL = x; - }, - /** - * @type {string} + * @type {NetworkAgent.FrameId} */ - get displayName() + get frameId() { - if (this._displayName) - return this._displayName; - this._displayName = this.lastPathComponent; - if (!this._displayName) - this._displayName = this.displayDomain; - if (!this._displayName && this.url) - this._displayName = this.url.trimURL(WebInspector.inspectedPageDomain ? WebInspector.inspectedPageDomain : ""); - if (this._displayName === "/") - this._displayName = this.url; - return this._displayName; + return this._frameId; }, /** - * @type {string} + * @type {NetworkAgent.LoaderId} */ - get folder() + get loaderId() { - var path = this.path; - var indexOfQuery = path.indexOf("?"); - if (indexOfQuery !== -1) - path = path.substring(0, indexOfQuery); - var lastSlashIndex = path.lastIndexOf("/"); - return lastSlashIndex !== -1 ? path.substring(0, lastSlashIndex) : ""; + return this._loaderId; }, /** * @type {string} */ - get displayDomain() + get displayName() { - // WebInspector.Database calls this, so don't access more than this.domain. - if (this.domain && (!WebInspector.inspectedPageDomain || (WebInspector.inspectedPageDomain && this.domain !== WebInspector.inspectedPageDomain))) - return this.domain; - return ""; + return this._parsedURL.displayName; }, /** @@ -256,11 +220,6 @@ WebInspector.Resource.prototype = { return this._request ? this._request.type : this._type; }, - set type(x) - { - this._type = x; - }, - /** * @type {string} */ @@ -269,11 +228,6 @@ WebInspector.Resource.prototype = { return this._request ? this._request.mimeType : this._mimeType; }, - set mimeType(x) - { - this._mimeType = x; - }, - /** * @type {Array.} */ diff --git a/Source/WebCore/inspector/front-end/ResourceTreeModel.js b/Source/WebCore/inspector/front-end/ResourceTreeModel.js index 7d48421..80737f1 100644 --- a/Source/WebCore/inspector/front-end/ResourceTreeModel.js +++ b/Source/WebCore/inspector/front-end/ResourceTreeModel.js @@ -226,10 +226,7 @@ WebInspector.ResourceTreeModel.prototype = { if (frame._resourcesMap[url]) return; - var resource = this._createResource(url, frame.url, frameId, event.data.loaderId); - resource.type = WebInspector.resourceTypes[event.data.resourceType]; - resource.mimeType = event.data.mimeType; - resource.finished = true; + var resource = new WebInspector.Resource(null, url, frame.url, frameId, event.data.loaderId, WebInspector.resourceTypes[event.data.resourceType], event.data.mimeType); frame._addResource(resource); }, @@ -338,10 +335,7 @@ WebInspector.ResourceTreeModel.prototype = { var frame = new WebInspector.ResourceTreeFrame(this, parentFrame, framePayload); // Create frame resource. - var frameResource = this._createResourceFromFramePayload(framePayload, framePayload.url); - frameResource.mimeType = framePayload.mimeType; - frameResource.type = WebInspector.resourceTypes.Document; - frameResource.finished = true; + var frameResource = this._createResourceFromFramePayload(framePayload, framePayload.url, WebInspector.resourceTypes.Document, framePayload.mimeType); if (frame.isMainFrame()) WebInspector.inspectedPageURL = frameResource.url; @@ -358,10 +352,7 @@ WebInspector.ResourceTreeModel.prototype = { // Create frame subresources. for (var i = 0; i < frameTreePayload.resources.length; ++i) { var subresource = frameTreePayload.resources[i]; - var resource = this._createResourceFromFramePayload(framePayload, subresource.url); - resource.type = WebInspector.resourceTypes[subresource.type]; - resource.mimeType = subresource.mimeType; - resource.finished = true; + var resource = this._createResourceFromFramePayload(framePayload, subresource.url, WebInspector.resourceTypes[subresource.type], subresource.mimeType); frame._addResource(resource); } }, @@ -369,25 +360,13 @@ WebInspector.ResourceTreeModel.prototype = { /** * @param {PageAgent.Frame} frame * @param {string} url + * @param {WebInspector.ResourceType} type + * @param {string} mimeType * @return {WebInspector.Resource} */ - _createResourceFromFramePayload: function(frame, url) + _createResourceFromFramePayload: function(frame, url, type, mimeType) { - return this._createResource(url, frame.url, frame.id, frame.loaderId); - }, - - /** - * @param {string} url - * @param {string} documentURL - * @param {NetworkAgent.FrameId} frameId - * @param {NetworkAgent.LoaderId} loaderId - * @return {WebInspector.Resource} - */ - _createResource: function(url, documentURL, frameId, loaderId) - { - var resource = new WebInspector.Resource(null, url, frameId, loaderId); - resource.documentURL = documentURL; - return resource; + return new WebInspector.Resource(null, url, frame.url, frame.id, frame.loaderId, type, mimeType); } } @@ -563,7 +542,7 @@ WebInspector.ResourceTreeFrame.prototype = { // Already in the tree, we just got an extra update. return resource; } - resource = new WebInspector.Resource(request, request.url, request.frameId, request.loaderId); + resource = new WebInspector.Resource(request, request.url, request.documentURL, request.frameId, request.loaderId); this._resourcesMap[resource.url] = resource; this._model.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.ResourceAdded, resource); return resource; diff --git a/Source/WebCore/inspector/front-end/ResourceUtils.js b/Source/WebCore/inspector/front-end/ResourceUtils.js index f820b0c..cc88b36 100644 --- a/Source/WebCore/inspector/front-end/ResourceUtils.js +++ b/Source/WebCore/inspector/front-end/ResourceUtils.js @@ -29,6 +29,89 @@ */ /** + * @constructor + * @param {String|string} url + */ +WebInspector.ParsedURL = function(url) +{ + this.isValid = false; + this.url = url; + this.scheme = ""; + this.host = ""; + this.port = ""; + this.path = ""; + this.fragment = ""; + this.lastPathComponent = ""; + + // RegExp groups: + // 1 - scheme + // 2 - hostname + // 3 - ?port + // 4 - ?path + // 5 - ?fragment + var match = url.match(/^([^:]+):\/\/([^\/:]*)(?::([\d]+))?(?:(\/[^#]*)(?:#(.*))?)?$/i); + if (!match) { + if (this == "about:blank") { + this.isValid = true; + this.scheme = "about"; + this.host = "blank"; + this.path = "/"; + return; + } + return; + } + + this.isValid = true; + this.scheme = match[1].toLowerCase(); + this.host = match[2]; + this.port = match[3]; + this.path = match[4] || "/"; + this.fragment = match[5]; + + if (this.path) { + // First cut the query params. + var path = this.path; + var indexOfQuery = path.indexOf("?"); + if (indexOfQuery !== -1) + path = path.substring(0, indexOfQuery); + + // Then take last path component. + var lastSlashIndex = path.lastIndexOf("/"); + if (lastSlashIndex !== -1) { + this.firstPathComponents = path.substring(0, lastSlashIndex + 1); + this.lastPathComponent = path.substring(lastSlashIndex + 1); + } + } +} + +WebInspector.ParsedURL.prototype = { + get displayName() + { + if (this._displayName) + return this._displayName; + + this._displayName = this.lastPathComponent; + if (!this._displayName) + this._displayName = WebInspector.displayDomain(this.host); + if (!this._displayName && this.url) + this._displayName = this.url.trimURL(WebInspector.inspectedPageDomain ? WebInspector.inspectedPageDomain : ""); + if (this._displayName === "/") + this._displayName = this.url; + return this._displayName; + } +} +/** + * @return {?WebInspector.ParsedURL} + */ +String.prototype.asParsedURL = function() +{ + var parsedURL = new WebInspector.ParsedURL(this); + if (parsedURL.isValid) + return parsedURL; + return null; +} + +/** * @param {string} url * @return {?WebInspector.Resource} */ @@ -46,6 +129,16 @@ WebInspector.forAllResources = function(callback) } /** + * @param {string} host + */ +WebInspector.displayDomain = function(host) +{ + if (host && (!WebInspector.inspectedPageDomain || (WebInspector.inspectedPageDomain && host !== WebInspector.inspectedPageDomain))) + return host; + return ""; +} + +/** * @param {string} url * @return {string} */ @@ -247,7 +340,7 @@ WebInspector.resourceURLForRelatedNode = function(node, url) var resourceURL = url; function callback(resource) { - if (resource.path === url) { + if (resource.parsedURL.path === url) { resourceURL = resource.url; return true; } diff --git a/Source/WebCore/inspector/front-end/ResourcesPanel.js b/Source/WebCore/inspector/front-end/ResourcesPanel.js index b13f43d..af46d86 100644 --- a/Source/WebCore/inspector/front-end/ResourcesPanel.js +++ b/Source/WebCore/inspector/front-end/ResourcesPanel.js @@ -1081,7 +1081,7 @@ WebInspector.FrameTreeElement.prototype = { this._frameId = frame.id; this.titleText = frame.name; - this.subtitleText = WebInspector.Resource.displayName(frame.url); + this.subtitleText = new WebInspector.ParsedURL(frame.url).displayName; this._categoryElements = {}; this._treeElementForResource = {}; @@ -1922,7 +1922,7 @@ WebInspector.CookieTreeElement.prototype.__proto__ = WebInspector.BaseStorageTre */ WebInspector.ApplicationCacheManifestTreeElement = function(storagePanel, manifestURL) { - var title = WebInspector.Resource.displayName(manifestURL); + var title = new WebInspector.ParsedURL(manifestURL).displayName; WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, title, ["application-cache-storage-tree-item"]); this.tooltip = manifestURL; this._manifestURL = manifestURL; @@ -1983,7 +1983,7 @@ WebInspector.ApplicationCacheFrameTreeElement.prototype = { return; } this.titleText = frame.name; - this.subtitleText = WebInspector.Resource.displayName(frame.url); + this.subtitleText = new WebInspector.ParsedURL(frame.url).displayName; }, frameNavigated: function() diff --git a/Source/WebCore/inspector/front-end/utilities.js b/Source/WebCore/inspector/front-end/utilities.js index 7dee160..6541e74 100644 --- a/Source/WebCore/inspector/front-end/utilities.js +++ b/Source/WebCore/inspector/front-end/utilities.js @@ -453,49 +453,6 @@ String.prototype.lineEndings = function() return this._lineEndings; } -String.prototype.asParsedURL = function() -{ - // RegExp groups: - // 1 - scheme - // 2 - hostname - // 3 - ?port - // 4 - ?path - // 5 - ?fragment - var match = this.match(/^([^:]+):\/\/([^\/:]*)(?::([\d]+))?(?:(\/[^#]*)(?:#(.*))?)?$/i); - if (!match) { - if (this == "about:blank") { - return { scheme: "about", - host: "blank", - path: "/", - lastPathComponent: ""}; - } - return null; - } - var result = {}; - result.scheme = match[1].toLowerCase(); - result.host = match[2]; - result.port = match[3]; - result.path = match[4] || "/"; - result.fragment = match[5]; - - result.lastPathComponent = ""; - if (result.path) { - // First cut the query params. - var path = result.path; - var indexOfQuery = path.indexOf("?"); - if (indexOfQuery !== -1) - path = path.substring(0, indexOfQuery); - - // Then take last path component. - var lastSlashIndex = path.lastIndexOf("/"); - if (lastSlashIndex !== -1) { - result.firstPathComponents = path.substring(0, lastSlashIndex + 1); - result.lastPathComponent = path.substring(lastSlashIndex + 1); - } - } - return result; -} - String.prototype.escapeCharacters = function(chars) { var foundChar = false; -- 2.7.4