Changeset 69947 in webkit


Ignore:
Timestamp:
Oct 18, 2010 2:18:29 AM (14 years ago)
Author:
pfeldman@chromium.org
Message:

2010-10-16 Pavel Feldman <pfeldman@chromium.org>

Reviewed by Yury Semikhatsky.

Web Inspector: brush up URL parsing on the front-end.
https://bugs.webkit.org/show_bug.cgi?id=47772

  • inspector/InspectorResource.cpp: (WebCore::InspectorResource::updateScriptObject):
  • inspector/front-end/AuditRules.js: (WebInspector.AuditRules.getDomainToResourcesMap): (WebInspector.AuditRules.CombineExternalResourcesRule.prototype.doRun): (WebInspector.AuditRules.MinimizeDnsLookupsRule.prototype.doRun): (WebInspector.AuditRules.ParallelizeDownloadRule.prototype.doRun): (WebInspector.AuditRules.ImageDimensionsRule.prototype.doRun): (WebInspector.AuditRules.CookieSizeRule.prototype.processCookies): (WebInspector.AuditRules.StaticCookielessRule.prototype.processCookies):
  • inspector/front-end/CookieItemsView.js: (WebInspector.CookieItemsView.prototype._filterCookiesForDomain):
  • inspector/front-end/DOMAgent.js: (WebInspector.Cookies.cookieMatchesResourceURL):
  • inspector/front-end/Resource.js: (WebInspector.Resource): (WebInspector.Resource.prototype.set url): (WebInspector.Resource.prototype.get displayName):
  • inspector/front-end/ResourceCategory.js: (WebInspector.ResourceCategory.prototype.addResource):
  • inspector/front-end/ResourceView.js: (WebInspector.ResourceView):
  • inspector/front-end/inspector.js: (WebInspector.documentClick.followLink): (WebInspector.documentClick): (WebInspector.updateResource): (WebInspector.linkifyStringAsFragment): (WebInspector.resourceURLForRelatedNode): (WebInspector.completeURL):
  • inspector/front-end/utilities.js: (String.prototype.asParsedURL):
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/inspector/elements-panel-rewrite-href.html

    r67195 r69947  
    4343                continue;
    4444            }
    45             var match = href.match(WebInspector.URLRegExp);
    46             if (!match)
     45            var parsedURL = href.asParsedURL();
     46            if (!parsedURL)
    4747                testController.notifyDone("FAIL: no URL match for <" + href + ">");
    48             var split = match[4].split("/");
     48            var split = parsedURL.path.split("/");
    4949            for (var i = split.length - 1, j = 0; j < 3 && i >= 0; --i, ++j)
    5050                segments.push(split[i]);
  • trunk/WebCore/ChangeLog

    r69946 r69947  
     12010-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
    1402010-10-17  Andreas Kling  <kling@webkit.org>
    241
  • trunk/WebCore/inspector/InspectorResource.cpp

    r69763 r69947  
    263263        jsonObject->setString("url", m_requestURL.string());
    264264        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());
    268265        RefPtr<InspectorObject> requestHeaders = buildHeadersObject(m_requestHeaderFields);
    269266        jsonObject->setObject("requestHeaders", requestHeaders);
  • trunk/WebCore/inspector/front-end/AuditRules.js

    r66087 r69947  
    4343}
    4444
    45 WebInspector.AuditRules.getDomainToResourcesMap = function(resources, types, regexp, needFullResources)
     45WebInspector.AuditRules.getDomainToResourcesMap = function(resources, types, needFullResources)
    4646{
    4747    var domainToResourcesMap = {};
     
    5050        if (types && types.indexOf(resource.type) === -1)
    5151            continue;
    52         var match = resource.url.match(regexp);
    53         if (!match)
     52        var parsedURL = resource.url.asParsedURL();
     53        if (!parsedURL)
    5454            continue;
    55         var domain = match[2];
     55        var domain = parsedURL.host;
    5656        var domainResources = domainToResourcesMap[domain];
    5757        if (domainResources === undefined) {
     
    129129    doRun: function(resources, result, callback)
    130130    {
    131         var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(resources, [this._type], WebInspector.URLRegExp);
     131        var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(resources, [this._type]);
    132132        var penalizedResourceCount = 0;
    133133        // TODO: refactor according to the chosen i18n approach
     
    176176    {
    177177        var summary = result.addChild("");
    178         var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(resources, undefined, WebInspector.URLRegExp);
     178        var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(resources, undefined);
    179179        for (var domain in domainToResourcesMap) {
    180180            if (domainToResourcesMap[domain].length > 1)
    181181                continue;
    182             var match = domain.match(WebInspector.URLRegExp);
    183             if (!match)
     182            var parsedURL = domain.asParsedURL();
     183            if (!parsedURL)
    184184                continue;
    185             if (!match[2].search(WebInspector.AuditRules.IPAddressRegexp))
     185            if (!parsedURL.host.search(WebInspector.AuditRules.IPAddressRegexp))
    186186                continue; // an IP address
    187187            summary.addSnippet(match[2]);
     
    221221            resources,
    222222            [WebInspector.Resource.Type.Stylesheet, WebInspector.Resource.Type.Image],
    223             WebInspector.URLRegExp,
    224223            true);
    225224
     
    648647            const node = WebInspector.domAgent.nodeForId(imageId);
    649648            var src = node.getAttribute("src");
    650             if (!WebInspector.URLRegExp.test(src)) {
     649            if (!src.asParsedURL()) {
    651650                for (var frameOwnerCandidate = node; frameOwnerCandidate; frameOwnerCandidate = frameOwnerCandidate.parentNode) {
    652651                    if (frameOwnerCandidate.documentURL) {
     
    935934        var domainToResourcesMap = WebInspector.AuditRules.getDomainToResourcesMap(resources,
    936935                null,
    937                 WebInspector.URLRegExp,
    938936                true);
    939937        var matchingResourceData = {};
     
    999997                [WebInspector.Resource.Type.Stylesheet,
    1000998                 WebInspector.Resource.Type.Image],
    1001                 WebInspector.URLRegExp,
    1002999                true);
    10031000        var totalStaticResources = 0;
  • trunk/WebCore/inspector/front-end/CookieItemsView.js

    r56840 r69947  
    123123        for (var id in WebInspector.resources) {
    124124            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)
    127127                resourceURLsForDocumentURL.push(resource.url);
    128128        }
  • trunk/WebCore/inspector/front-end/DOMAgent.js

    r69567 r69947  
    501501WebInspector.Cookies.cookieMatchesResourceURL = function(cookie, resourceURL)
    502502{
    503     var match = resourceURL.match(WebInspector.GenericURLRegExp);
    504     if (!match)
     503    var url = resourceURL.asParsedURL();
     504    if (!url || !this.cookieDomainMatchesResourceDomain(cookie.domain, url.host))
    505505        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"));
    514509}
    515510
  • trunk/WebCore/inspector/front-end/Resource.js

    r67447 r69947  
    3030{
    3131    this.identifier = identifier;
    32     this._url = url;
     32    this.url = url;
    3333    this._startTime = -1;
    3434    this._endTime = -1;
     
    9898            return;
    9999
    100         var oldURL = this._url;
    101100        this._url = x;
    102101        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();
    108113    },
    109114
     
    120125    },
    121126
    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 
    147127    get displayName()
    148128    {
    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;
    157139    },
    158140
  • trunk/WebCore/inspector/front-end/ResourceCategory.js

    r68394 r69947  
    4848        for (var i = 0; i < resourcesLength; ++i) {
    4949            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)
    5252                    break;
    5353            else if (a.name && b.name)
  • trunk/WebCore/inspector/front-end/ResourceView.js

    r67447 r69947  
    100100    this.headersVisible = true;
    101101
    102     resource.addEventListener("url changed", this._refreshURL, this);
    103102    resource.addEventListener("requestHeaders changed", this._refreshRequestHeaders, this);
    104103    resource.addEventListener("responseHeaders changed", this._refreshResponseHeaders, this);
  • trunk/WebCore/inspector/front-end/inspector.js

    r69853 r69947  
    5757    pendingDispatches: 0,
    5858
    59     // RegExp groups:
    60     // 1 - scheme
    61     // 2 - hostname
    62     // 3 - ?port
    63     // 4 - ?path
    64     // 5 - ?fragment
    65     URLRegExp: /^(http[s]?|file):\/\/([^\/:]*)(?::([\d]+))?(?:(\/[^#]*)(?:#(.*))?)?$/i,
    66     GenericURLRegExp: /^([^:]+):\/\/([^\/:]*)(?::([\d]+))?(?:(\/[^#]*)(?:#(.*))?)?$/i,
    67 
    6859    get platform()
    6960    {
     
    771762        }
    772763
    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);
    777768                if (WebInspector.panels[panel])
    778769                    WebInspector.currentPanel = WebInspector.panels[panel];
     
    12351226
    12361227    if (payload.didRequestChange) {
    1237         resource.domain = payload.host;
    1238         resource.path = payload.path;
    1239         resource.lastPathComponent = payload.lastPathComponent;
    12401228        resource.requestHeaders = payload.requestHeaders;
    12411229        resource.mainResource = payload.mainResource;
     
    12491237            this.mainResource = resource;
    12501238
    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);
    12561243        }
    12571244    }
     
    15001487}
    15011488
    1502 WebInspector.resourceURLChanged = function(resource, oldURL)
    1503 {
    1504     delete this.resourceURLMap[oldURL];
    1505     this.resourceURLMap[resource.url] = resource;
    1506 }
    1507 
    15081489WebInspector.didCommitLoad = function()
    15091490{
     
    18391820    // documentURL not found or has bad value
    18401821    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)
    18431824            return resourceURL;
    18441825    }
     
    18481829WebInspector.completeURL = function(baseURL, href)
    18491830{
    1850     var match = baseURL.match(WebInspector.URLRegExp);
    1851     if (match) {
     1831    var parsedURL = baseURL.asParsedURL();
     1832    if (parsedURL) {
    18521833        var path = href;
    18531834        if (path.charAt(0) !== "/") {
    1854             var basePath = match[4] || "/";
     1835            var basePath = parsedURL.path;
    18551836            path = basePath.substring(0, basePath.lastIndexOf("/")) + "/" + path;
    18561837        } else if (path.length > 1 && path.charAt(1) === "/") {
    18571838            // 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;
    18611842    }
    18621843    return null;
  • trunk/WebCore/inspector/front-end/utilities.js

    r67615 r69947  
    392392        return this.indexOf(string) !== -1;
    393393    return this.match(new RegExp(string.escapeForRegExp(), "i"));
     394}
     395
     396String.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;
    394414}
    395415
Note: See TracChangeset for help on using the changeset viewer.