Changeset 126426 in webkit


Ignore:
Timestamp:
Aug 23, 2012 8:08:29 AM (12 years ago)
Author:
pfeldman@chromium.org
Message:

Web Inspector: extract ParsedURL into a separate file.
https://bugs.webkit.org/show_bug.cgi?id=94817

Reviewed by Alexander Pavlov.

  • WebCore.gypi:
  • WebCore.vcproj/WebCore.vcproj:
  • inspector/compile-front-end.py:
  • inspector/front-end/AuditRules.js:

(WebInspector.AuditRules.ImageDimensionsRule.prototype.doRun):
(WebInspector.AuditRules.CssInHeadRule.prototype.doRun.externalStylesheetsReceived):
(WebInspector.AuditRules.StylesScriptsOrderRule.prototype.doRun.cssBeforeInlineReceived):

  • inspector/front-end/DefaultTextEditor.js:

(WebInspector.TextEditorMainPanel.prototype._rewriteHref):

  • inspector/front-end/ParsedURL.js: Added.

(WebInspector.ParsedURL):
(WebInspector.ParsedURL.completeURL):
(WebInspector.ParsedURL.prototype.get displayName):
(String.prototype.asParsedURL):

  • inspector/front-end/ResourceUtils.js:

(WebInspector.resourceURLForRelatedNode):

  • inspector/front-end/StylesSidebarPane.js:

(WebInspector.StylePropertyTreeElement.prototype.updateTitle.linkifyURL):

  • inspector/front-end/WebKit.qrc:
  • inspector/front-end/inspector.html:
Location:
trunk
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/inspector/styles/styles-url-linkify.html

    r124590 r126426  
    1111    function completeURL(baseURL, href)
    1212    {
    13         InspectorTest.addResult(WebInspector.completeURL(baseURL, href));
     13        InspectorTest.addResult(WebInspector.ParsedURL.completeURL(baseURL, href));
    1414    }
    1515
  • trunk/Source/WebCore/ChangeLog

    r126425 r126426  
     12012-08-23  Pavel Feldman  <pfeldman@chromium.org>
     2
     3        Web Inspector: extract ParsedURL into a separate file.
     4        https://bugs.webkit.org/show_bug.cgi?id=94817
     5
     6        Reviewed by Alexander Pavlov.
     7
     8        * WebCore.gypi:
     9        * WebCore.vcproj/WebCore.vcproj:
     10        * inspector/compile-front-end.py:
     11        * inspector/front-end/AuditRules.js:
     12        (WebInspector.AuditRules.ImageDimensionsRule.prototype.doRun):
     13        (WebInspector.AuditRules.CssInHeadRule.prototype.doRun.externalStylesheetsReceived):
     14        (WebInspector.AuditRules.StylesScriptsOrderRule.prototype.doRun.cssBeforeInlineReceived):
     15        * inspector/front-end/DefaultTextEditor.js:
     16        (WebInspector.TextEditorMainPanel.prototype._rewriteHref):
     17        * inspector/front-end/ParsedURL.js: Added.
     18        (WebInspector.ParsedURL):
     19        (WebInspector.ParsedURL.completeURL):
     20        (WebInspector.ParsedURL.prototype.get displayName):
     21        (String.prototype.asParsedURL):
     22        * inspector/front-end/ResourceUtils.js:
     23        (WebInspector.resourceURLForRelatedNode):
     24        * inspector/front-end/StylesSidebarPane.js:
     25        (WebInspector.StylePropertyTreeElement.prototype.updateTitle.linkifyURL):
     26        * inspector/front-end/WebKit.qrc:
     27        * inspector/front-end/inspector.html:
     28
    1292012-08-23  Pavel Feldman  <pfeldman@chromium.org>
    230
  • trunk/Source/WebCore/WebCore.gypi

    r126425 r126426  
    63486348            'inspector/front-end/Panel.js',
    63496349            'inspector/front-end/PanelEnablerView.js',
     6350            'inspector/front-end/ParsedURL.js',
    63506351            'inspector/front-end/Placard.js',
    63516352            'inspector/front-end/Popover.js',
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r126425 r126426  
    7619176191                                </File>
    7619276192                                <File
     76193                                        RelativePath="..\inspector\front-end\ParsedURL.js"
     76194                                        >
     76195                                </File>
     76196                                <File
    7619376197                                        RelativePath="..\inspector\front-end\panelEnablerView.css"
    7619476198                                        >
  • trunk/Source/WebCore/inspector/compile-front-end.py

    r126425 r126426  
    4646            "Color.js",
    4747            "Object.js",
     48            "ParsedURL.js",
    4849            "Settings.js",
    4950            "UIString.js",
  • trunk/Source/WebCore/inspector/front-end/AuditRules.js

    r125399 r126426  
    719719                for (var frameOwnerCandidate = node; frameOwnerCandidate; frameOwnerCandidate = frameOwnerCandidate.parentNode) {
    720720                    if (frameOwnerCandidate.documentURL) {
    721                         var completeSrc = WebInspector.completeURL(frameOwnerCandidate.documentURL, src);
     721                        var completeSrc = WebInspector.ParsedURL.completeURL(frameOwnerCandidate.documentURL, src);
    722722                        break;
    723723                    }
     
    859859                for (var j = 0; j < externalStylesheetNodeIds.length; ++j) {
    860860                    var linkNode = WebInspector.domAgent.nodeForId(externalStylesheetNodeIds[j]);
    861                     var completeHref = WebInspector.completeURL(linkNode.ownerDocument.documentURL, linkNode.getAttribute("href"));
     861                    var completeHref = WebInspector.ParsedURL.completeURL(linkNode.ownerDocument.documentURL, linkNode.getAttribute("href"));
    862862                    externalStylesheetHrefs.push(completeHref || "<empty>");
    863863                }
     
    940940                for (var i = 0; i < lateStyleIds.length; ++i) {
    941941                    var lateStyleNode = WebInspector.domAgent.nodeForId(lateStyleIds[i]);
    942                     var completeHref = WebInspector.completeURL(lateStyleNode.ownerDocument.documentURL, lateStyleNode.getAttribute("href"));
     942                    var completeHref = WebInspector.ParsedURL.completeURL(lateStyleNode.ownerDocument.documentURL, lateStyleNode.getAttribute("href"));
    943943                    lateStyleUrls.push(completeHref || "<empty>");
    944944                }
  • trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js

    r126210 r126426  
    21112111        if (!this._url || !hrefValue || hrefValue.indexOf("://") > 0)
    21122112            return hrefValue;
    2113         return WebInspector.completeURL(this._url, hrefValue);
     2113        return WebInspector.ParsedURL.completeURL(this._url, hrefValue);
    21142114    },
    21152115
  • trunk/Source/WebCore/inspector/front-end/ResourceUtils.js

    r124792 r126426  
    3030
    3131/**
    32  * @constructor
    33  * @param {string} url
    34  */
    35 WebInspector.ParsedURL = function(url)
    36 {
    37     this.isValid = false;
    38     this.url = url;
    39     this.scheme = "";
    40     this.host = "";
    41     this.port = "";
    42     this.path = "";
    43     this.queryParams = "";
    44     this.fragment = "";
    45     this.folderPathComponents = "";
    46     this.lastPathComponent = "";
    47 
    48     // RegExp groups:
    49     // 1 - scheme
    50     // 2 - hostname
    51     // 3 - ?port
    52     // 4 - ?path
    53     // 5 - ?fragment
    54     var match = url.match(/^([^:]+):\/\/([^\/:]*)(?::([\d]+))?(?:(\/[^#]*)(?:#(.*))?)?$/i);
    55     if (match) {
    56         this.isValid = true;
    57         this.scheme = match[1].toLowerCase();
    58         this.host = match[2];
    59         this.port = match[3];
    60         this.path = match[4] || "/";
    61         this.fragment = match[5];
    62     } else {
    63         if (this.url.startsWith("data:")) {
    64             this.scheme = "data";
    65             return;
    66         }
    67         if (this.url === "about:blank") {
    68             this.scheme = "about";
    69             return;
    70         }
    71         this.path = this.url;
    72     }
    73 
    74     if (this.path) {
    75         // First cut the query params.
    76         var path = this.path;
    77         var indexOfQuery = path.indexOf("?");
    78         if (indexOfQuery !== -1) {
    79             this.queryParams = path.substring(indexOfQuery + 1)
    80             path = path.substring(0, indexOfQuery);
    81         }
    82 
    83         // Then take last path component.
    84         var lastSlashIndex = path.lastIndexOf("/");
    85         if (lastSlashIndex !== -1) {
    86             this.folderPathComponents = path.substring(0, lastSlashIndex);
    87             this.lastPathComponent = path.substring(lastSlashIndex + 1);
    88         } else
    89             this.lastPathComponent = path;
    90     }
    91 }
    92 
    93 WebInspector.ParsedURL.prototype = {
    94     get displayName()
    95     {
    96         if (this._displayName)
    97             return this._displayName;
    98 
    99         if (this.scheme === "data") {
    100             this._displayName = this.url.trimEnd(20);
    101             return this._displayName;
    102         }
    103 
    104         if (this.url === "about:blank")
    105             return this.url;
    106 
    107         this._displayName = this.lastPathComponent;
    108         if (!this._displayName)
    109             this._displayName = WebInspector.displayDomain(this.host);
    110         if (!this._displayName && this.url)
    111             this._displayName = this.url.trimURL(WebInspector.inspectedPageDomain ? WebInspector.inspectedPageDomain : "");
    112         if (this._displayName === "/")
    113             this._displayName = this.url;
    114         return this._displayName;
    115     }
    116 }
    117 /**
    118  * @return {?WebInspector.ParsedURL}
    119  */
    120 String.prototype.asParsedURL = function()
    121 {
    122     var parsedURL = new WebInspector.ParsedURL(this.toString());
    123     if (parsedURL.isValid)
    124         return parsedURL;
    125     return null;
    126 }
    127 
    128 /**
    12932 * @param {string} url
    13033 * @return {?WebInspector.Resource}
     
    348251    for (var frameOwnerCandidate = node; frameOwnerCandidate; frameOwnerCandidate = frameOwnerCandidate.parentNode) {
    349252        if (frameOwnerCandidate.documentURL) {
    350             var result = WebInspector.completeURL(frameOwnerCandidate.documentURL, url);
     253            var result = WebInspector.ParsedURL.completeURL(frameOwnerCandidate.documentURL, url);
    351254            if (result)
    352255                return result;
     
    367270    return resourceURL;
    368271}
    369 
    370 /**
    371  * @param {string} baseURL
    372  * @param {string} href
    373  * @return {?string}
    374  */
    375 WebInspector.completeURL = function(baseURL, href)
    376 {
    377     if (href) {
    378         // Return absolute URLs as-is.
    379         var parsedHref = href.asParsedURL();
    380         if (parsedHref && parsedHref.scheme)
    381             return href;
    382 
    383         // Return special URLs as-is.
    384         var trimmedHref = href.trim();
    385         if (trimmedHref.startsWith("data:") || trimmedHref.startsWith("javascript:") || trimmedHref.startsWith("blob:"))
    386             return href;
    387     }
    388 
    389     var parsedURL = baseURL.asParsedURL();
    390     if (parsedURL) {
    391         var path = href;
    392         if (path.charAt(0) !== "/") {
    393             var basePath = parsedURL.path;
    394 
    395             // Trim off the query part of the basePath.
    396             var questionMarkIndex = basePath.indexOf("?");
    397             if (questionMarkIndex > 0)
    398                 basePath = basePath.substring(0, questionMarkIndex);
    399             // A href of "?foo=bar" implies "basePath?foo=bar".
    400             // With "basePath?a=b" and "?foo=bar" we should get "basePath?foo=bar".
    401             var prefix;
    402             if (path.charAt(0) === "?") {
    403                 var basePathCutIndex = basePath.indexOf("?");
    404                 if (basePathCutIndex !== -1)
    405                     prefix = basePath.substring(0, basePathCutIndex);
    406                 else
    407                     prefix = basePath;
    408             } else
    409                 prefix = basePath.substring(0, basePath.lastIndexOf("/")) + "/";
    410 
    411             path = prefix + path;
    412         } else if (path.length > 1 && path.charAt(1) === "/") {
    413             // href starts with "//" which is a full URL with the protocol dropped (use the baseURL protocol).
    414             return parsedURL.scheme + ":" + path;
    415         }
    416         return parsedURL.scheme + "://" + parsedURL.host + (parsedURL.port ? (":" + parsedURL.port) : "") + path;
    417     }
    418     return null;
    419 }
  • trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js

    r125965 r126426  
    17181718                container.appendChild(document.createTextNode("url("));
    17191719                if (self._styleRule.sourceURL)
    1720                     hrefUrl = WebInspector.completeURL(self._styleRule.sourceURL, hrefUrl);
     1720                    hrefUrl = WebInspector.ParsedURL.completeURL(self._styleRule.sourceURL, hrefUrl);
    17211721                else if (this._parentPane.node)
    17221722                    hrefUrl = WebInspector.resourceURLForRelatedNode(this._parentPane.node, hrefUrl);
  • trunk/Source/WebCore/inspector/front-end/WebKit.qrc

    r126425 r126426  
    118118    <file>Panel.js</file>
    119119    <file>PanelEnablerView.js</file>
     120    <file>ParsedURL.js</file>
    120121    <file>Placard.js</file>
    121122    <file>Popover.js</file>
  • trunk/Source/WebCore/inspector/front-end/inspector.html

    r126425 r126426  
    7575    <script type="text/javascript" src="NetworkLog.js"></script>
    7676    <script type="text/javascript" src="ResourceTreeModel.js"></script>
     77    <script type="text/javascript" src="ParsedURL.js"></script>
    7778    <script type="text/javascript" src="ResourceUtils.js"></script>
    7879    <script type="text/javascript" src="ResourceType.js"></script>
Note: See TracChangeset for help on using the changeset viewer.