Changeset 69947 in webkit
- Timestamp:
- Oct 18, 2010 2:18:29 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/inspector/elements-panel-rewrite-href.html
r67195 r69947 43 43 continue; 44 44 } 45 var match = href.match(WebInspector.URLRegExp);46 if (! match)45 var parsedURL = href.asParsedURL(); 46 if (!parsedURL) 47 47 testController.notifyDone("FAIL: no URL match for <" + href + ">"); 48 var split = match[4].split("/");48 var split = parsedURL.path.split("/"); 49 49 for (var i = split.length - 1, j = 0; j < 3 && i >= 0; --i, ++j) 50 50 segments.push(split[i]); -
trunk/WebCore/ChangeLog
r69946 r69947 1 2010-10-16 Pavel Feldman <pfeldman@chromium.org> 2 3 Reviewed by Yury Semikhatsky. 4 5 Web Inspector: brush up URL parsing on the front-end. 6 https://bugs.webkit.org/show_bug.cgi?id=47772 7 8 * inspector/InspectorResource.cpp: 9 (WebCore::InspectorResource::updateScriptObject): 10 * inspector/front-end/AuditRules.js: 11 (WebInspector.AuditRules.getDomainToResourcesMap): 12 (WebInspector.AuditRules.CombineExternalResourcesRule.prototype.doRun): 13 (WebInspector.AuditRules.MinimizeDnsLookupsRule.prototype.doRun): 14 (WebInspector.AuditRules.ParallelizeDownloadRule.prototype.doRun): 15 (WebInspector.AuditRules.ImageDimensionsRule.prototype.doRun): 16 (WebInspector.AuditRules.CookieSizeRule.prototype.processCookies): 17 (WebInspector.AuditRules.StaticCookielessRule.prototype.processCookies): 18 * inspector/front-end/CookieItemsView.js: 19 (WebInspector.CookieItemsView.prototype._filterCookiesForDomain): 20 * inspector/front-end/DOMAgent.js: 21 (WebInspector.Cookies.cookieMatchesResourceURL): 22 * inspector/front-end/Resource.js: 23 (WebInspector.Resource): 24 (WebInspector.Resource.prototype.set url): 25 (WebInspector.Resource.prototype.get displayName): 26 * inspector/front-end/ResourceCategory.js: 27 (WebInspector.ResourceCategory.prototype.addResource): 28 * inspector/front-end/ResourceView.js: 29 (WebInspector.ResourceView): 30 * inspector/front-end/inspector.js: 31 (WebInspector.documentClick.followLink): 32 (WebInspector.documentClick): 33 (WebInspector.updateResource): 34 (WebInspector.linkifyStringAsFragment): 35 (WebInspector.resourceURLForRelatedNode): 36 (WebInspector.completeURL): 37 * inspector/front-end/utilities.js: 38 (String.prototype.asParsedURL): 39 1 40 2010-10-17 Andreas Kling <kling@webkit.org> 2 41 -
trunk/WebCore/inspector/InspectorResource.cpp
r69763 r69947 263 263 jsonObject->setString("url", m_requestURL.string()); 264 264 jsonObject->setString("documentURL", m_documentURL.string()); 265 jsonObject->setString("host", m_requestURL.host());266 jsonObject->setString("path", m_requestURL.path());267 jsonObject->setString("lastPathComponent", m_requestURL.lastPathComponent());268 265 RefPtr<InspectorObject> requestHeaders = buildHeadersObject(m_requestHeaderFields); 269 266 jsonObject->setObject("requestHeaders", requestHeaders); -
trunk/WebCore/inspector/front-end/AuditRules.js
r66087 r69947 43 43 } 44 44 45 WebInspector.AuditRules.getDomainToResourcesMap = function(resources, types, regexp,needFullResources)45 WebInspector.AuditRules.getDomainToResourcesMap = function(resources, types, needFullResources) 46 46 { 47 47 var domainToResourcesMap = {}; … … 50 50 if (types && types.indexOf(resource.type) === -1) 51 51 continue; 52 var match = resource.url.match(regexp);53 if (! match)52 var parsedURL = resource.url.asParsedURL(); 53 if (!parsedURL) 54 54 continue; 55 var domain = match[2];55 var domain = parsedURL.host; 56 56 var domainResources = domainToResourcesMap[domain]; 57 57 if (domainResources === undefined) { … … 129 129 doRun: function(resources, result, callback) 130 130 { 131 var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(resources, [this._type] , WebInspector.URLRegExp);131 var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(resources, [this._type]); 132 132 var penalizedResourceCount = 0; 133 133 // TODO: refactor according to the chosen i18n approach … … 176 176 { 177 177 var summary = result.addChild(""); 178 var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(resources, undefined , WebInspector.URLRegExp);178 var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(resources, undefined); 179 179 for (var domain in domainToResourcesMap) { 180 180 if (domainToResourcesMap[domain].length > 1) 181 181 continue; 182 var match = domain.match(WebInspector.URLRegExp);183 if (! match)182 var parsedURL = domain.asParsedURL(); 183 if (!parsedURL) 184 184 continue; 185 if (! match[2].search(WebInspector.AuditRules.IPAddressRegexp))185 if (!parsedURL.host.search(WebInspector.AuditRules.IPAddressRegexp)) 186 186 continue; // an IP address 187 187 summary.addSnippet(match[2]); … … 221 221 resources, 222 222 [WebInspector.Resource.Type.Stylesheet, WebInspector.Resource.Type.Image], 223 WebInspector.URLRegExp,224 223 true); 225 224 … … 648 647 const node = WebInspector.domAgent.nodeForId(imageId); 649 648 var src = node.getAttribute("src"); 650 if (! WebInspector.URLRegExp.test(src)) {649 if (!src.asParsedURL()) { 651 650 for (var frameOwnerCandidate = node; frameOwnerCandidate; frameOwnerCandidate = frameOwnerCandidate.parentNode) { 652 651 if (frameOwnerCandidate.documentURL) { … … 935 934 var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(resources, 936 935 null, 937 WebInspector.URLRegExp,938 936 true); 939 937 var matchingResourceData = {}; … … 999 997 [WebInspector.Resource.Type.Stylesheet, 1000 998 WebInspector.Resource.Type.Image], 1001 WebInspector.URLRegExp,1002 999 true); 1003 1000 var totalStaticResources = 0; -
trunk/WebCore/inspector/front-end/CookieItemsView.js
r56840 r69947 123 123 for (var id in WebInspector.resources) { 124 124 var resource = WebInspector.resources[id]; 125 var match = resource.documentURL.match(WebInspector.GenericURLRegExp);126 if ( match && match[2] === this._cookieDomain)125 var url = resource.documentURL.asParsedURL(); 126 if (url && url.host == this._cookieDomain) 127 127 resourceURLsForDocumentURL.push(resource.url); 128 128 } -
trunk/WebCore/inspector/front-end/DOMAgent.js
r69567 r69947 501 501 WebInspector.Cookies.cookieMatchesResourceURL = function(cookie, resourceURL) 502 502 { 503 var match = resourceURL.match(WebInspector.GenericURLRegExp);504 if (! match)503 var url = resourceURL.asParsedURL(); 504 if (!url || !this.cookieDomainMatchesResourceDomain(cookie.domain, url.host)) 505 505 return false; 506 // See WebInspector.URLRegExp for definitions of the group index constants. 507 if (!this.cookieDomainMatchesResourceDomain(cookie.domain, match[2])) 508 return false; 509 var resourcePort = match[3] ? match[3] : undefined; 510 var resourcePath = match[4] ? match[4] : '/'; 511 return (resourcePath.indexOf(cookie.path) === 0 512 && (!cookie.port || resourcePort == cookie.port) 513 && (!cookie.secure || match[1].toLowerCase() === 'https')); 506 return (url.path.indexOf(cookie.path) === 0 507 && (!cookie.port || url.port == cookie.port) 508 && (!cookie.secure || url.scheme === "https")); 514 509 } 515 510 -
trunk/WebCore/inspector/front-end/Resource.js
r67447 r69947 30 30 { 31 31 this.identifier = identifier; 32 this. _url = url;32 this.url = url; 33 33 this._startTime = -1; 34 34 this._endTime = -1; … … 98 98 return; 99 99 100 var oldURL = this._url;101 100 this._url = x; 102 101 delete this._parsedQueryParameters; 103 // FIXME: We should make the WebInspector object listen for the "url changed" event. 104 // Then resourceURLChanged can be removed. 105 WebInspector.resourceURLChanged(this, oldURL); 106 107 this.dispatchEventToListeners("url changed"); 102 103 var parsedURL = x.asParsedURL(); 104 this.domain = parsedURL ? parsedURL.host : ""; 105 this.path = parsedURL ? parsedURL.path : ""; 106 this.lastPathComponent = ""; 107 if (parsedURL && parsedURL.path) { 108 var lastSlashIndex = parsedURL.path.lastIndexOf("/"); 109 if (lastSlashIndex !== -1) 110 this.lastPathComponent = parsedURL.path.substring(lastSlashIndex + 1); 111 } 112 this.lastPathComponentLowerCase = this.lastPathComponent.toLowerCase(); 108 113 }, 109 114 … … 120 125 }, 121 126 122 get domain()123 {124 return this._domain;125 },126 127 set domain(x)128 {129 if (this._domain === x)130 return;131 this._domain = x;132 },133 134 get lastPathComponent()135 {136 return this._lastPathComponent;137 },138 139 set lastPathComponent(x)140 {141 if (this._lastPathComponent === x)142 return;143 this._lastPathComponent = x;144 this._lastPathComponentLowerCase = x ? x.toLowerCase() : null;145 },146 147 127 get displayName() 148 128 { 149 var title = this.lastPathComponent; 150 if (!title) 151 title = this.displayDomain; 152 if (!title && this.url) 153 title = this.url.trimURL(WebInspector.mainResource ? WebInspector.mainResource.domain : ""); 154 if (title === "/") 155 title = this.url; 156 return title; 129 if (this._displayName) 130 return this._displayName; 131 this._displayName = this.lastPathComponent; 132 if (!this._displayName) 133 this._displayName = this.displayDomain; 134 if (!this._displayName && this.url) 135 this._displayName = this.url.trimURL(WebInspector.mainResource ? WebInspector.mainResource.domain : ""); 136 if (this._displayName === "/") 137 this._displayName = this.url; 138 return this._displayName; 157 139 }, 158 140 -
trunk/WebCore/inspector/front-end/ResourceCategory.js
r68394 r69947 48 48 for (var i = 0; i < resourcesLength; ++i) { 49 49 var b = this.resources[i]; 50 if (a. _lastPathComponentLowerCase && b._lastPathComponentLowerCase)51 if (a. _lastPathComponentLowerCase < b._lastPathComponentLowerCase)50 if (a.lastPathComponentLowerCase && b.lastPathComponentLowerCase) 51 if (a.lastPathComponentLowerCase < b.lastPathComponentLowerCase) 52 52 break; 53 53 else if (a.name && b.name) -
trunk/WebCore/inspector/front-end/ResourceView.js
r67447 r69947 100 100 this.headersVisible = true; 101 101 102 resource.addEventListener("url changed", this._refreshURL, this);103 102 resource.addEventListener("requestHeaders changed", this._refreshRequestHeaders, this); 104 103 resource.addEventListener("responseHeaders changed", this._refreshResponseHeaders, this); -
trunk/WebCore/inspector/front-end/inspector.js
r69853 r69947 57 57 pendingDispatches: 0, 58 58 59 // RegExp groups:60 // 1 - scheme61 // 2 - hostname62 // 3 - ?port63 // 4 - ?path64 // 5 - ?fragment65 URLRegExp: /^(http[s]?|file):\/\/([^\/:]*)(?::([\d]+))?(?:(\/[^#]*)(?:#(.*))?)?$/i,66 GenericURLRegExp: /^([^:]+):\/\/([^\/:]*)(?::([\d]+))?(?:(\/[^#]*)(?:#(.*))?)?$/i,67 68 59 get platform() 69 60 { … … 771 762 } 772 763 773 const urlMatch = WebInspector.GenericURLRegExp.exec(anchor.href);774 if ( urlMatch && urlMatch[1]=== "webkit-link-action") {775 if ( urlMatch[2]=== "show-panel") {776 const panel = urlMatch[4].substring(1);764 var parsedURL = anchor.href.asParsedURL(); 765 if (parsedURL && parsedURL.scheme === "webkit-link-action") { 766 if (parsedURL.host === "show-panel") { 767 var panel = parsedURL.path.substring(1); 777 768 if (WebInspector.panels[panel]) 778 769 WebInspector.currentPanel = WebInspector.panels[panel]; … … 1235 1226 1236 1227 if (payload.didRequestChange) { 1237 resource.domain = payload.host;1238 resource.path = payload.path;1239 resource.lastPathComponent = payload.lastPathComponent;1240 1228 resource.requestHeaders = payload.requestHeaders; 1241 1229 resource.mainResource = payload.mainResource; … … 1249 1237 this.mainResource = resource; 1250 1238 1251 var match = payload.documentURL.match(WebInspector.GenericURLRegExp); 1252 if (match) { 1253 var protocol = match[1].toLowerCase(); 1254 this._addCookieDomain(match[2]); 1255 this._addAppCacheDomain(match[2]); 1239 var parsedURL = payload.documentURL.asParsedURL(); 1240 if (parsedURL) { 1241 this._addCookieDomain(parsedURL.host); 1242 this._addAppCacheDomain(parsedURL.host); 1256 1243 } 1257 1244 } … … 1500 1487 } 1501 1488 1502 WebInspector.resourceURLChanged = function(resource, oldURL)1503 {1504 delete this.resourceURLMap[oldURL];1505 this.resourceURLMap[resource.url] = resource;1506 }1507 1508 1489 WebInspector.didCommitLoad = function() 1509 1490 { … … 1839 1820 // documentURL not found or has bad value 1840 1821 for (var resourceURL in WebInspector.resourceURLMap) { 1841 var match = resourceURL.match(WebInspector.URLRegExp);1842 if ( match && match[4]=== url)1822 var parsedURL = resourceURL.asParsedURL(); 1823 if (parsedURL && parsedURL.path === url) 1843 1824 return resourceURL; 1844 1825 } … … 1848 1829 WebInspector.completeURL = function(baseURL, href) 1849 1830 { 1850 var match = baseURL.match(WebInspector.URLRegExp);1851 if ( match) {1831 var parsedURL = baseURL.asParsedURL(); 1832 if (parsedURL) { 1852 1833 var path = href; 1853 1834 if (path.charAt(0) !== "/") { 1854 var basePath = match[4] || "/";1835 var basePath = parsedURL.path; 1855 1836 path = basePath.substring(0, basePath.lastIndexOf("/")) + "/" + path; 1856 1837 } else if (path.length > 1 && path.charAt(1) === "/") { 1857 1838 // href starts with "//" which is a full URL with the protocol dropped (use the baseURL protocol). 1858 return match[1]+ ":" + path;1859 } 1860 return match[1] + "://" + match[2] + (match[3] ? (":" + match[3]) : "") + path;1839 return parsedURL.scheme + ":" + path; 1840 } 1841 return parsedURL.scheme + "://" + parsedURL.host + (parsedURL.port ? (":" + parsedURL.port) : "") + path; 1861 1842 } 1862 1843 return null; -
trunk/WebCore/inspector/front-end/utilities.js
r67615 r69947 392 392 return this.indexOf(string) !== -1; 393 393 return this.match(new RegExp(string.escapeForRegExp(), "i")); 394 } 395 396 String.prototype.asParsedURL = function() 397 { 398 // RegExp groups: 399 // 1 - scheme 400 // 2 - hostname 401 // 3 - ?port 402 // 4 - ?path 403 // 5 - ?fragment 404 var match = this.match(/^([^:]+):\/\/([^\/:]*)(?::([\d]+))?(?:(\/[^#]*)(?:#(.*))?)?$/i); 405 if (!match) 406 return null; 407 var result = {}; 408 result.scheme = match[1].toLowerCase(); 409 result.host = match[2]; 410 result.port = match[3]; 411 result.path = match[4] || "/"; 412 result.fragment = match[5]; 413 return result; 394 414 } 395 415
Note: See TracChangeset
for help on using the changeset viewer.