Title: [98840] trunk/Source/WebCore
Revision
98840
Author
[email protected]
Date
2011-10-31 02:18:30 -0700 (Mon, 31 Oct 2011)

Log Message

Web Inspector: factor out ResourceUtils, clean up externs.
https://bugs.webkit.org/show_bug.cgi?id=71192

Patch by Pavel Feldman <[email protected]> on 2011-10-31
Reviewed by Yury Semikhatsky.

* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* inspector/compile-front-end.sh:
* inspector/front-end/ConsoleMessage.js:
(WebInspector.ConsoleMessageImpl.prototype._linkifyLocation):
* inspector/front-end/DebuggerPresentationModel.js:
* inspector/front-end/ProfilesPanel.js:
* inspector/front-end/Resource.js:
(WebInspector.Resource.displayName):
* inspector/front-end/ResourceTreeModel.js:
(WebInspector.ResourceTreeModel.prototype._createResource):
* inspector/front-end/ResourceUtils.js: Added.
(WebInspector.resourceForURL):
(WebInspector.forAllResources):
(WebInspector.displayNameForURL):
(WebInspector.linkifyStringAsFragmentWithCustomLinkifier):
(WebInspector.registerLinkifierPlugin):
(WebInspector.linkifyStringAsFragment):
(WebInspector.linkifyURLAsNode):
(WebInspector.linkifyURL):
(WebInspector.formatLinkText):
(WebInspector.linkifyResourceAsNode):
(WebInspector.resourceURLForRelatedNode.callback):
(WebInspector.resourceURLForRelatedNode):
(WebInspector.populateHrefContextMenu):
(WebInspector.completeURL):
* inspector/front-end/StylesSidebarPane.js:
(WebInspector.StylePropertyTreeElement.prototype.selectElement):
* inspector/front-end/WebKit.qrc:
* inspector/front-end/externs.js:
* inspector/front-end/inspector.html:
* inspector/front-end/inspector.js:
(WebInspector.networkResourceById):
* inspector/front-end/utilities.js:
(setupPrototypeUtilities.Element.prototype.selectionLeftOffset):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (98839 => 98840)


--- trunk/Source/WebCore/ChangeLog	2011-10-31 08:37:32 UTC (rev 98839)
+++ trunk/Source/WebCore/ChangeLog	2011-10-31 09:18:30 UTC (rev 98840)
@@ -1,3 +1,46 @@
+2011-10-31  Pavel Feldman  <[email protected]>
+
+        Web Inspector: factor out ResourceUtils, clean up externs.
+        https://bugs.webkit.org/show_bug.cgi?id=71192
+
+        Reviewed by Yury Semikhatsky.
+
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * inspector/compile-front-end.sh:
+        * inspector/front-end/ConsoleMessage.js:
+        (WebInspector.ConsoleMessageImpl.prototype._linkifyLocation):
+        * inspector/front-end/DebuggerPresentationModel.js:
+        * inspector/front-end/ProfilesPanel.js:
+        * inspector/front-end/Resource.js:
+        (WebInspector.Resource.displayName):
+        * inspector/front-end/ResourceTreeModel.js:
+        (WebInspector.ResourceTreeModel.prototype._createResource):
+        * inspector/front-end/ResourceUtils.js: Added.
+        (WebInspector.resourceForURL):
+        (WebInspector.forAllResources):
+        (WebInspector.displayNameForURL):
+        (WebInspector.linkifyStringAsFragmentWithCustomLinkifier):
+        (WebInspector.registerLinkifierPlugin):
+        (WebInspector.linkifyStringAsFragment):
+        (WebInspector.linkifyURLAsNode):
+        (WebInspector.linkifyURL):
+        (WebInspector.formatLinkText):
+        (WebInspector.linkifyResourceAsNode):
+        (WebInspector.resourceURLForRelatedNode.callback):
+        (WebInspector.resourceURLForRelatedNode):
+        (WebInspector.populateHrefContextMenu):
+        (WebInspector.completeURL):
+        * inspector/front-end/StylesSidebarPane.js:
+        (WebInspector.StylePropertyTreeElement.prototype.selectElement):
+        * inspector/front-end/WebKit.qrc:
+        * inspector/front-end/externs.js:
+        * inspector/front-end/inspector.html:
+        * inspector/front-end/inspector.js:
+        (WebInspector.networkResourceById):
+        * inspector/front-end/utilities.js:
+        (setupPrototypeUtilities.Element.prototype.selectionLeftOffset):
+
 2011-10-28  Alexander Pavlov  <[email protected]>
 
         Web Inspector: Using keyboard to increment/decrement units is inconsistent

Modified: trunk/Source/WebCore/WebCore.gypi (98839 => 98840)


--- trunk/Source/WebCore/WebCore.gypi	2011-10-31 08:37:32 UTC (rev 98839)
+++ trunk/Source/WebCore/WebCore.gypi	2011-10-31 09:18:30 UTC (rev 98840)
@@ -6350,6 +6350,7 @@
             'inspector/front-end/ResourceResponseView.js',
             'inspector/front-end/ResourceTimingView.js',
             'inspector/front-end/ResourceTreeModel.js',
+            'inspector/front-end/ResourceUtils.js',
             'inspector/front-end/ResourceView.js',
             'inspector/front-end/ResourcesPanel.js',
             'inspector/front-end/ResourcePreviewView.js',

Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (98839 => 98840)


--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2011-10-31 08:37:32 UTC (rev 98839)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2011-10-31 09:18:30 UTC (rev 98840)
@@ -68937,6 +68937,10 @@
 					>
 				</File>
 				<File
+					RelativePath="..\inspector\front-end\ResourceUtils.js"
+					>
+				</File>
+				<File
 					RelativePath="..\inspector\front-end\ResourceView.js"
 					>
 				</File>

Modified: trunk/Source/WebCore/inspector/compile-front-end.sh (98839 => 98840)


--- trunk/Source/WebCore/inspector/compile-front-end.sh	2011-10-31 08:37:32 UTC (rev 98839)
+++ trunk/Source/WebCore/inspector/compile-front-end.sh	2011-10-31 09:18:30 UTC (rev 98840)
@@ -31,7 +31,7 @@
 
 python Source/WebCore/inspector/generate-protocol-externs -o Source/WebCore/inspector/front-end/protocol-externs.js Source/WebCore/inspector/Inspector.json
 
-java -jar ~/closure/compiler.jar --compilation_level SIMPLE_OPTIMIZATIONS --warning_level VERBOSE --language_in ECMASCRIPT5 --accept_const_keyword \
+java -jar ~/closure/compiler.jar --summary_detail_level 3 --compilation_level SIMPLE_OPTIMIZATIONS --warning_level VERBOSE --language_in ECMASCRIPT5 --accept_const_keyword \
     --externs Source/WebCore/inspector/front-end/externs.js \
     --externs Source/WebCore/inspector/front-end/protocol-externs.js \
     --module jsmodule_util:2 \
@@ -108,7 +108,7 @@
         --js Source/WebCore/inspector/front-end/UIUtils.js \
         --js Source/WebCore/inspector/front-end/View.js \
         --js Source/WebCore/inspector/front-end/WelcomeView.js \
-    --module jsmodule_components:15:jsmodule_sdk,jsmodule_ui \
+    --module jsmodule_components:16:jsmodule_sdk,jsmodule_ui \
         --js Source/WebCore/inspector/front-end/ConsoleMessage.js \
         --js Source/WebCore/inspector/front-end/BreakpointsSidebarPane.js \
         --js Source/WebCore/inspector/front-end/DOMBreakpointsSidebarPane.js \
@@ -119,6 +119,7 @@
         --js Source/WebCore/inspector/front-end/_javascript_ContextManager.js \
         --js Source/WebCore/inspector/front-end/ObjectPopoverHelper.js \
         --js Source/WebCore/inspector/front-end/ObjectPropertiesSection.js \
+        --js Source/WebCore/inspector/front-end/ResourceUtils.js \
         --js Source/WebCore/inspector/front-end/SourceFrame.js \
         --js Source/WebCore/inspector/front-end/SourceTokenizer.js \
         --js Source/WebCore/inspector/front-end/TimelineAgent.js \

Modified: trunk/Source/WebCore/inspector/front-end/ConsoleMessage.js (98839 => 98840)


--- trunk/Source/WebCore/inspector/front-end/ConsoleMessage.js	2011-10-31 08:37:32 UTC (rev 98839)
+++ trunk/Source/WebCore/inspector/front-end/ConsoleMessage.js	2011-10-31 09:18:30 UTC (rev 98840)
@@ -194,7 +194,7 @@
     _linkifyLocation: function(url, lineNumber, columnNumber)
     {
         // FIXME(62725): stack trace line/column numbers are one-based.
-        lineNumber = lineNumber ? lineNumber - 1 : undefined;
+        lineNumber = lineNumber ? lineNumber - 1 : 0;
         columnNumber = columnNumber ? columnNumber - 1 : 0;
         return this._linkifier.linkifyLocation(url, lineNumber, columnNumber, "console-message-url");
     },

Modified: trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js (98839 => 98840)


--- trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js	2011-10-31 08:37:32 UTC (rev 98839)
+++ trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js	2011-10-31 09:18:30 UTC (rev 98840)
@@ -906,7 +906,7 @@
 WebInspector.DebuggerPresentationModel.Linkifier.prototype = {
     /**
      * @param {string} sourceURL
-     * @param {number=} lineNumber
+     * @param {number} lineNumber
      * @param {number=} columnNumber
      * @param {string=} classes
      */
@@ -921,7 +921,7 @@
 
     /**
      * @param {string} sourceURL
-     * @param {number=} lineNumber
+     * @param {number} lineNumber
      * @param {string=} classes
      */
     linkifyResource: function(sourceURL, lineNumber, classes)

Modified: trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js (98839 => 98840)


--- trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js	2011-10-31 08:37:32 UTC (rev 98839)
+++ trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js	2011-10-31 09:18:30 UTC (rev 98840)
@@ -88,6 +88,14 @@
     }
 }
 
+WebInspector.registerLinkifierPlugin(function(title)
+{
+    var profileStringMatches = WebInspector.ProfileType.URLRegExp.exec(title);
+    if (profileStringMatches)
+        title = WebInspector.panels.profiles.displayTitleForProfileLink(profileStringMatches[2], profileStringMatches[1]);
+    return title;
+});
+
 WebInspector.ProfilesPanel = function()
 {
     WebInspector.Panel.call(this, "profiles");

Modified: trunk/Source/WebCore/inspector/front-end/Resource.js (98839 => 98840)


--- trunk/Source/WebCore/inspector/front-end/Resource.js	2011-10-31 08:37:32 UTC (rev 98839)
+++ trunk/Source/WebCore/inspector/front-end/Resource.js	2011-10-31 09:18:30 UTC (rev 98840)
@@ -69,7 +69,7 @@
  * @constructor
  * @extends {WebInspector.Object}
  *
- * @param {?NetworkAgent.RequestId} requestId
+ * @param {NetworkAgent.RequestId} requestId
  * @param {string} url
  * @param {?string} frameId
  * @param {?NetworkAgent.LoaderId} loaderId
@@ -95,7 +95,7 @@
 
 WebInspector.Resource.displayName = function(url)
 {
-    return new WebInspector.Resource(null, url, null, null).displayName;
+    return new WebInspector.Resource("fake-transient-resource", url, null, null).displayName;
 }
 
 // Keep these in sync with WebCore::InspectorResource::Type

Modified: trunk/Source/WebCore/inspector/front-end/ResourceTreeModel.js (98839 => 98840)


--- trunk/Source/WebCore/inspector/front-end/ResourceTreeModel.js	2011-10-31 08:37:32 UTC (rev 98839)
+++ trunk/Source/WebCore/inspector/front-end/ResourceTreeModel.js	2011-10-31 09:18:30 UTC (rev 98840)
@@ -393,7 +393,7 @@
      */
     _createResource: function(frame, url)
     {
-        var resource = new WebInspector.Resource(null, url, frame.id, frame.loaderId);
+        var resource = new WebInspector.Resource("", url, frame.id, frame.loaderId);
         resource.documentURL = frame.url;
         resource.mimeType = frame.mimeType;
         return resource;
@@ -443,3 +443,8 @@
  * @type {WebInspector.ResourceTreeModel}
  */
 WebInspector.resourceTreeModel = null;
+
+/**
+ * @type {WebInspector.Resource}
+ */
+WebInspector.mainResource = null;

Added: trunk/Source/WebCore/inspector/front-end/ResourceUtils.js (0 => 98840)


--- trunk/Source/WebCore/inspector/front-end/ResourceUtils.js	                        (rev 0)
+++ trunk/Source/WebCore/inspector/front-end/ResourceUtils.js	2011-10-31 09:18:30 UTC (rev 98840)
@@ -0,0 +1,311 @@
+/*
+ * Copyright (C) 2006, 2007, 2008 Apple Inc.  All rights reserved.
+ * Copyright (C) 2007 Matt Lilek ([email protected]).
+ * Copyright (C) 2009 Joseph Pecoraro
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @param {string} url
+ * @return {?WebInspector.Resource}
+ */
+WebInspector.resourceForURL = function(url)
+{
+    return WebInspector.resourceTreeModel.resourceForURL(url);
+}
+
+/**
+ * @param {function(WebInspector.Resource)} callback
+ */
+WebInspector.forAllResources = function(callback)
+{
+     WebInspector.resourceTreeModel.forAllResources(callback);
+}
+
+/**
+ * @param {string} url
+ * @return {string}
+ */
+WebInspector.displayNameForURL = function(url)
+{
+    if (!url)
+        return "";
+
+    var resource = WebInspector.resourceForURL(url);
+    if (resource)
+        return resource.displayName;
+
+    if (!WebInspector.mainResource)
+        return url.trimURL("");
+
+    var lastPathComponent = WebInspector.mainResource.lastPathComponent;
+    var index = WebInspector.mainResource.url.indexOf(lastPathComponent);
+    if (index !== -1 && index + lastPathComponent.length === WebInspector.mainResource.url.length) {
+        var baseURL = WebInspector.mainResource.url.substring(0, index);
+        if (url.indexOf(baseURL) === 0)
+            return url.substring(index);
+    }
+
+    return url.trimURL(WebInspector.mainResource.domain);
+}
+
+/**
+ * @param {string} string
+ * @param {function(string,string,string=):Node} linkifier
+ * @return {DocumentFragment}
+ */
+WebInspector.linkifyStringAsFragmentWithCustomLinkifier = function(string, linkifier)
+{
+    var container = document.createDocumentFragment();
+    var linkStringRegEx = /(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\/\/|www\.)[\w$\-_+*'=\|\/\\(){}[\]%@&#~,:;.!?]{2,}[\w$\-_+*=\|\/\\({%@&#~]/;
+    var lineColumnRegEx = /:(\d+)(:(\d+))?$/;
+
+    while (string) {
+        var linkString = linkStringRegEx.exec(string);
+        if (!linkString)
+            break;
+
+        linkString = linkString[0];
+        var linkIndex = string.indexOf(linkString);
+        var nonLink = string.substring(0, linkIndex);
+        container.appendChild(document.createTextNode(nonLink));
+
+        var title = linkString;
+        var realURL = (linkString.indexOf("www.") === 0 ? "http://" + linkString : linkString);
+        var lineColumnMatch = lineColumnRegEx.exec(realURL);
+        if (lineColumnMatch)
+            realURL = realURL.substring(0, realURL.length - lineColumnMatch[0].length);
+
+        var linkNode = linkifier(title, realURL, lineColumnMatch ? lineColumnMatch[1] : undefined);
+        container.appendChild(linkNode);
+        string = string.substring(linkIndex + linkString.length, string.length);
+    }
+
+    if (string)
+        container.appendChild(document.createTextNode(string));
+
+    return container;
+}
+
+WebInspector._linkifierPlugins = [];
+
+/**
+ * @param {function(string):string} plugin
+ */
+WebInspector.registerLinkifierPlugin = function(plugin)
+{
+    WebInspector._linkifierPlugins.push(plugin);
+}
+
+/**
+ * @param {string} string
+ * @return {DocumentFragment}
+ */
+WebInspector.linkifyStringAsFragment = function(string)
+{
+    function linkifier(title, url, lineNumber)
+    {
+        for (var i = 0; i < WebInspector._linkifierPlugins.length; ++i)
+            title = WebInspector._linkifierPlugins[i](title);
+
+        var isExternal = !WebInspector.resourceForURL(url);
+        var urlNode = WebInspector.linkifyURLAsNode(url, title, undefined, isExternal);
+        if (typeof(lineNumber) !== "undefined") {
+            urlNode.setAttribute("line_number", lineNumber);
+            urlNode.setAttribute("preferred_panel", "scripts");
+        }
+        
+        return urlNode; 
+    }
+    
+    return WebInspector.linkifyStringAsFragmentWithCustomLinkifier(string, linkifier);
+}
+
+/**
+ * @param {string} url
+ * @param {string=} linkText
+ * @param {string=} classes
+ * @param {boolean=} isExternal
+ * @param {string=} tooltipText
+ * @return {Element}
+ */
+WebInspector.linkifyURLAsNode = function(url, linkText, classes, isExternal, tooltipText)
+{
+    if (!linkText)
+        linkText = url;
+    classes = (classes ? classes + " " : "");
+    classes += isExternal ? "webkit-html-external-link" : "webkit-html-resource-link";
+
+    var a = document.createElement("a");
+    a.href = ""
+    a.className = classes;
+    if (typeof tooltipText === "undefined")
+        a.title = url;
+    else if (typeof tooltipText !== "string" || tooltipText.length)
+        a.title = tooltipText;
+    a.textContent = linkText;
+    a.style.maxWidth = "100%";
+    if (isExternal)
+        a.setAttribute("target", "_blank");
+
+    return a;
+}
+
+/**
+ * @param {string} url
+ * @param {string=} linkText
+ * @param {string=} classes
+ * @param {boolean=} isExternal
+ * @param {string=} tooltipText
+ * @return {string}
+ * @deprecated
+ */
+WebInspector.linkifyURL = function(url, linkText, classes, isExternal, tooltipText)
+{
+    // Use the DOM version of this function so as to avoid needing to escape attributes.
+    // FIXME:  Get rid of linkifyURL entirely.
+    return WebInspector.linkifyURLAsNode(url, linkText, classes, isExternal, tooltipText).outerHTML;
+}
+
+/**
+ * @param {string} url
+ * @param {number=} lineNumber
+ * @return {string}
+ */
+WebInspector.formatLinkText = function(url, lineNumber)
+{
+    var text = WebInspector.displayNameForURL(url);
+    if (typeof lineNumber === "number")
+        text += ":" + (lineNumber + 1);
+    return text;
+}
+
+/**
+ * @param {string} url
+ * @param {number} lineNumber
+ * @param {string=} classes
+ * @param {string=} tooltipText
+ * @return {Element}
+ */
+WebInspector.linkifyResourceAsNode = function(url, lineNumber, classes, tooltipText)
+{
+    var linkText = WebInspector.formatLinkText(url, lineNumber);
+    var anchor = WebInspector.linkifyURLAsNode(url, linkText, classes, false, tooltipText);
+    anchor.setAttribute("preferred_panel", "resources");
+    anchor.setAttribute("line_number", lineNumber);
+    return anchor;
+}
+
+WebInspector.resourceURLForRelatedNode = function(node, url)
+{
+    if (!url || url.indexOf("://") > 0)
+        return url;
+
+    for (var frameOwnerCandidate = node; frameOwnerCandidate; frameOwnerCandidate = frameOwnerCandidate.parentNode) {
+        if (frameOwnerCandidate.documentURL) {
+            var result = WebInspector.completeURL(frameOwnerCandidate.documentURL, url);
+            if (result)
+                return result;
+            break;
+        }
+    }
+
+    // documentURL not found or has bad value
+    var resourceURL = url;
+    function callback(resource)
+    {
+        if (resource.path === url) {
+            resourceURL = resource.url;
+            return true;
+        }
+    }
+    WebInspector.forAllResources(callback);
+    return resourceURL;
+}
+
+/**
+ * @param {WebInspector.ContextMenu} contextMenu
+ * @param {Node} contextNode
+ * @param {Event} event
+ */
+WebInspector.populateHrefContextMenu = function(contextMenu, contextNode, event)
+{
+    var anchorElement = event.target.enclosingNodeOrSelfWithClass("webkit-html-resource-link") || event.target.enclosingNodeOrSelfWithClass("webkit-html-external-link");
+    if (!anchorElement)
+        return false;
+
+    var resourceURL = WebInspector.resourceURLForRelatedNode(contextNode, anchorElement.href);
+    if (!resourceURL)
+        return false;
+
+    // Add resource-related actions.
+    contextMenu.appendItem(WebInspector.openLinkExternallyLabel(), WebInspector.openResource.bind(WebInspector, resourceURL, false));
+    if (WebInspector.resourceForURL(resourceURL))
+        contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Open link in Resources panel" : "Open Link in Resources Panel"), WebInspector.openResource.bind(null, resourceURL, true));
+    contextMenu.appendItem(WebInspector.copyLinkAddressLabel(), InspectorFrontendHost.copyText.bind(InspectorFrontendHost, resourceURL));
+    return true;
+}
+
+/**
+ * @param {string} baseURL
+ * @param {string} href
+ * @return {?string}
+ */
+WebInspector.completeURL = function(baseURL, href)
+{
+    if (href) {
+        // Return absolute URLs as-is.
+        var parsedHref = href.asParsedURL();
+        if ((parsedHref && parsedHref.scheme) || href.indexOf("data:") === 0)
+            return href;
+    }
+
+    var parsedURL = baseURL.asParsedURL();
+    if (parsedURL) {
+        var path = href;
+        if (path.charAt(0) !== "/") {
+            var basePath = parsedURL.path;
+            // A href of "?foo=bar" implies "basePath?foo=bar".
+            // With "basePath?a=b" and "?foo=bar" we should get "basePath?foo=bar".
+            var prefix;
+            if (path.charAt(0) === "?") {
+                var basePathCutIndex = basePath.indexOf("?");
+                if (basePathCutIndex !== -1)
+                    prefix = basePath.substring(0, basePathCutIndex);
+                else
+                    prefix = basePath;
+            } else
+                prefix = basePath.substring(0, basePath.lastIndexOf("/")) + "/";
+
+            path = prefix + path;
+        } else if (path.length > 1 && path.charAt(1) === "/") {
+            // href starts with "//" which is a full URL with the protocol dropped (use the baseURL protocol).
+            return parsedURL.scheme + ":" + path;
+        }
+        return parsedURL.scheme + "://" + parsedURL.host + (parsedURL.port ? (":" + parsedURL.port) : "") + path;
+    }
+    return null;
+}
Property changes on: trunk/Source/WebCore/inspector/front-end/ResourceUtils.js
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js (98839 => 98840)


--- trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js	2011-10-31 08:37:32 UTC (rev 98839)
+++ trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js	2011-10-31 09:18:30 UTC (rev 98840)
@@ -1857,7 +1857,7 @@
         {
             // FIXME: the ":"/";" detection does not work for non-US layouts due to the event being keydown rather than keypress.
             var isFieldInputTerminated = (event.keyCode === WebInspector.KeyboardShortcut.Keys.Semicolon.code) &&
-                (isEditingName ? event.shiftKey : (!event.shiftKey && shouldCommitValueSemicolon(event.target.textContent, event.target.selectionLeftOffset)));
+                (isEditingName ? event.shiftKey : (!event.shiftKey && shouldCommitValueSemicolon(event.target.textContent, event.target.selectionLeftOffset())));
             if (isEnterKey(event) || isFieldInputTerminated) {
                 // Enter or colon (for name)/semicolon outside of string (for value).
                 event.preventDefault();

Modified: trunk/Source/WebCore/inspector/front-end/WebKit.qrc (98839 => 98840)


--- trunk/Source/WebCore/inspector/front-end/WebKit.qrc	2011-10-31 08:37:32 UTC (rev 98839)
+++ trunk/Source/WebCore/inspector/front-end/WebKit.qrc	2011-10-31 09:18:30 UTC (rev 98840)
@@ -101,6 +101,7 @@
     <file>ResourceResponseView.js</file>
     <file>ResourceTimingView.js</file>
     <file>ResourceTreeModel.js</file>
+    <file>ResourceUtils.js</file>
     <file>ResourceView.js</file>
     <file>ResourcesPanel.js</file>
     <file>ScopeChainSidebarPane.js</file>

Modified: trunk/Source/WebCore/inspector/front-end/externs.js (98839 => 98840)


--- trunk/Source/WebCore/inspector/front-end/externs.js	2011-10-31 08:37:32 UTC (rev 98839)
+++ trunk/Source/WebCore/inspector/front-end/externs.js	2011-10-31 09:18:30 UTC (rev 98840)
@@ -40,52 +40,6 @@
 var WebInspector = {}
 
 /**
- * @param {string} url
- * @param {string=} linkText
- * @param {string=} classes
- * @param {boolean=} isExternal
- * @param {string=} tooltipText
- */
-WebInspector.linkifyURLAsNode = function(url, linkText, classes, isExternal, tooltipText) {}
-
-/**
- * @param {string} url
- * @param {string=} linkText
- * @param {string=} classes
- * @param {boolean=} isExternal
- * @param {string=} tooltipText
- */
-WebInspector.linkifyURL = function(url, linkText, classes, isExternal, tooltipText) {}
-
-/** @param {string} url */
-WebInspector.linkifyStringAsFragment = function(url) {}
-/** @param {string} url */
-WebInspector.linkifyStringAsFragmentWithCustomLinkifier = function(url, linkifier) {}
-
-/**
- * @param {string=} classes
- * @param {string=} tooltipText
- */
-WebInspector.linkifyResourceAsNode = function(url, lineNumber, classes, tooltipText) {}
-
-/**
- * @param {string} url
- * @param {number=} lineNumber
- */
-WebInspector.formatLinkText = function(url, lineNumber) {}
-
-/**
- * @param {string} url
- */
-WebInspector.displayNameForURL = function(url) {}
-
-/**
- * @param {string} url
- * @param {string} href
- */
-WebInspector.completeURL = function(url, href) {}
-
-/**
  * @param {string} str
  * @param {...*} varArgs
  */
@@ -107,12 +61,6 @@
 Element.prototype.scrollIntoViewIfNeeded = function(param) {}
 
 /**
- * @return {number}
- */
-Element.prototype.selectionLeftOffset = function() {}
-
-
-/**
  * @param {boolean=} onlyFirst
  */
 Array.prototype.remove = function(obj, onlyFirst) {}
@@ -125,12 +73,6 @@
 WebInspector.extensionServer.notifyPanelHidden = function(panel) {}
 WebInspector.extensionServer.notifyObjectSelected = function(object) {}
 
-/**
- * @param {string} url
- * @return {?WebInspector.Resource}
- */
-WebInspector.resourceForURL = function(url) {}
-
 WebInspector.debuggerPresentationModel = {
     linkifyLocation: function(url, lineNumber, columnNumber, className) {}
 }
@@ -144,15 +86,6 @@
 }
 
 /**
- * @param {WebInspector.ContextMenu} contextMenu
- * @param {Node} contextNode
- * @param {Event} event
- */
-WebInspector.populateHrefContextMenu = function(contextMenu, contextNode, event)
-{
-}
-
-/**
  * @return {boolean}
  */
 WebInspector.useLowerCaseMenuTitles = function()
@@ -220,8 +153,6 @@
  */
 WebInspector.log = function(message, messageLevel, showConsole) {}
 
-WebInspector.resourceURLForRelatedNode = function(node, url) {}
-
 WebInspector.addMainEventListeners = function(doc) {}
 
 WebInspector.openResource = function(url, external) {}

Modified: trunk/Source/WebCore/inspector/front-end/inspector.html (98839 => 98840)


--- trunk/Source/WebCore/inspector/front-end/inspector.html	2011-10-31 08:37:32 UTC (rev 98839)
+++ trunk/Source/WebCore/inspector/front-end/inspector.html	2011-10-31 09:18:30 UTC (rev 98840)
@@ -67,6 +67,7 @@
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
+    <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""

Modified: trunk/Source/WebCore/inspector/front-end/inspector.js (98839 => 98840)


--- trunk/Source/WebCore/inspector/front-end/inspector.js	2011-10-31 08:37:32 UTC (rev 98839)
+++ trunk/Source/WebCore/inspector/front-end/inspector.js	2011-10-31 09:18:30 UTC (rev 98840)
@@ -402,16 +402,6 @@
     networkResourceById: function(id)
     {
         return this.panels.network.resourceById(id);
-    },
-
-    forAllResources: function(callback)
-    {
-        WebInspector.resourceTreeModel.forAllResources(callback);
-    },
-
-    resourceForURL: function(url)
-    {
-        return this.resourceTreeModel.resourceForURL(url);
     }
 }
 
@@ -1021,29 +1011,6 @@
     this.panels.elements.revealAndSelectNode(nodeId);
 }
 
-WebInspector.displayNameForURL = function(url)
-{
-    if (!url)
-        return "";
-
-    var resource = this.resourceForURL(url);
-    if (resource)
-        return resource.displayName;
-
-    if (!WebInspector.mainResource)
-        return url.trimURL("");
-
-    var lastPathComponent = WebInspector.mainResource.lastPathComponent;
-    var index = WebInspector.mainResource.url.indexOf(lastPathComponent);
-    if (index !== -1 && index + lastPathComponent.length === WebInspector.mainResource.url.length) {
-        var baseURL = WebInspector.mainResource.url.substring(0, index);
-        if (url.indexOf(baseURL) === 0)
-            return url.substring(index);
-    }
-
-    return url.trimURL(WebInspector.mainResource.domain);
-}
-
 WebInspector._showAnchorLocation = function(anchor)
 {
     if (WebInspector.openAnchorLocationRegistry.dispatch(anchor))
@@ -1075,193 +1042,12 @@
     return true;
 }
 
-WebInspector.linkifyStringAsFragmentWithCustomLinkifier = function(string, linkifier)
-{
-    var container = document.createDocumentFragment();
-    var linkStringRegEx = /(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\/\/|www\.)[\w$\-_+*'=\|\/\\(){}[\]%@&#~,:;.!?]{2,}[\w$\-_+*=\|\/\\({%@&#~]/;
-    var lineColumnRegEx = /:(\d+)(:(\d+))?$/;
-
-    while (string) {
-        var linkString = linkStringRegEx.exec(string);
-        if (!linkString)
-            break;
-
-        linkString = linkString[0];
-        var linkIndex = string.indexOf(linkString);
-        var nonLink = string.substring(0, linkIndex);
-        container.appendChild(document.createTextNode(nonLink));
-
-        var title = linkString;
-        var realURL = (linkString.indexOf("www.") === 0 ? "http://" + linkString : linkString);
-        var lineColumnMatch = lineColumnRegEx.exec(realURL);
-        if (lineColumnMatch)
-            realURL = realURL.substring(0, realURL.length - lineColumnMatch[0].length);
-
-        var linkNode = linkifier(title, realURL, lineColumnMatch ? lineColumnMatch[1] : undefined);
-        container.appendChild(linkNode);
-        string = string.substring(linkIndex + linkString.length, string.length);
-    }
-
-    if (string)
-        container.appendChild(document.createTextNode(string));
-
-    return container;
-}
-
-WebInspector.linkifyStringAsFragment = function(string)
-{
-    function linkifier(title, url, lineNumber)
-    {
-        var profileStringMatches = WebInspector.ProfileType.URLRegExp.exec(title);
-        if (profileStringMatches)
-            title = WebInspector.panels.profiles.displayTitleForProfileLink(profileStringMatches[2], profileStringMatches[1]);
-
-        var isExternal = !WebInspector.resourceForURL(url);
-        var urlNode = WebInspector.linkifyURLAsNode(url, title, null, isExternal);
-        if (typeof(lineNumber) !== "undefined") {
-            urlNode.setAttribute("line_number", lineNumber);
-            urlNode.setAttribute("preferred_panel", "scripts");
-        }
-        
-        return urlNode; 
-    }
-    
-    return WebInspector.linkifyStringAsFragmentWithCustomLinkifier(string, linkifier);
-}
-
 WebInspector.showProfileForURL = function(url)
 {
     WebInspector.showPanel("profiles");
     WebInspector.panels.profiles.showProfileForURL(url);
 }
 
-WebInspector.linkifyURLAsNode = function(url, linkText, classes, isExternal, tooltipText)
-{
-    if (!linkText)
-        linkText = url;
-    classes = (classes ? classes + " " : "");
-    classes += isExternal ? "webkit-html-external-link" : "webkit-html-resource-link";
-
-    var a = document.createElement("a");
-    a.href = ""
-    a.className = classes;
-    if (typeof tooltipText === "undefined")
-        a.title = url;
-    else if (typeof tooltipText !== "string" || tooltipText.length)
-        a.title = tooltipText;
-    a.textContent = linkText;
-    a.style.maxWidth = "100%";
-    if (isExternal)
-        a.setAttribute("target", "_blank");
-
-    return a;
-}
-
-WebInspector.linkifyURL = function(url, linkText, classes, isExternal, tooltipText)
-{
-    // Use the DOM version of this function so as to avoid needing to escape attributes.
-    // FIXME:  Get rid of linkifyURL entirely.
-    return WebInspector.linkifyURLAsNode(url, linkText, classes, isExternal, tooltipText).outerHTML;
-}
-
-WebInspector.formatLinkText = function(url, lineNumber)
-{
-    var text = WebInspector.displayNameForURL(url);
-    if (lineNumber !== undefined)
-        text += ":" + (lineNumber + 1);
-    return text;
-}
-
-WebInspector.linkifyResourceAsNode = function(url, lineNumber, classes, tooltipText)
-{
-    var linkText = this.formatLinkText(url, lineNumber);
-    var anchor = this.linkifyURLAsNode(url, linkText, classes, false, tooltipText);
-    anchor.setAttribute("preferred_panel", "resources");
-    anchor.setAttribute("line_number", lineNumber);
-    return anchor;
-}
-
-WebInspector.resourceURLForRelatedNode = function(node, url)
-{
-    if (!url || url.indexOf("://") > 0)
-        return url;
-
-    for (var frameOwnerCandidate = node; frameOwnerCandidate; frameOwnerCandidate = frameOwnerCandidate.parentNode) {
-        if (frameOwnerCandidate.documentURL) {
-            var result = WebInspector.completeURL(frameOwnerCandidate.documentURL, url);
-            if (result)
-                return result;
-            break;
-        }
-    }
-
-    // documentURL not found or has bad value
-    var resourceURL = url;
-    function callback(resource)
-    {
-        if (resource.path === url) {
-            resourceURL = resource.url;
-            return true;
-        }
-    }
-    WebInspector.forAllResources(callback);
-    return resourceURL;
-}
-
-WebInspector.populateHrefContextMenu = function(contextMenu, contextNode, event)
-{
-    var anchorElement = event.target.enclosingNodeOrSelfWithClass("webkit-html-resource-link") || event.target.enclosingNodeOrSelfWithClass("webkit-html-external-link");
-    if (!anchorElement)
-        return false;
-
-    var resourceURL = WebInspector.resourceURLForRelatedNode(contextNode, anchorElement.href);
-    if (!resourceURL)
-        return false;
-
-    // Add resource-related actions.
-    contextMenu.appendItem(WebInspector.openLinkExternallyLabel(), WebInspector.openResource.bind(WebInspector, resourceURL, false));
-    if (WebInspector.resourceForURL(resourceURL))
-        contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Open link in Resources panel" : "Open Link in Resources Panel"), WebInspector.openResource.bind(null, resourceURL, true));
-    contextMenu.appendItem(WebInspector.copyLinkAddressLabel(), InspectorFrontendHost.copyText.bind(InspectorFrontendHost, resourceURL));
-    return true;
-}
-
-WebInspector.completeURL = function(baseURL, href)
-{
-    if (href) {
-        // Return absolute URLs as-is.
-        var parsedHref = href.asParsedURL();
-        if ((parsedHref && parsedHref.scheme) || href.indexOf("data:") === 0)
-            return href;
-    }
-
-    var parsedURL = baseURL.asParsedURL();
-    if (parsedURL) {
-        var path = href;
-        if (path.charAt(0) !== "/") {
-            var basePath = parsedURL.path;
-            // A href of "?foo=bar" implies "basePath?foo=bar".
-            // With "basePath?a=b" and "?foo=bar" we should get "basePath?foo=bar".
-            var prefix;
-            if (path.charAt(0) === "?") {
-                var basePathCutIndex = basePath.indexOf("?");
-                if (basePathCutIndex !== -1)
-                    prefix = basePath.substring(0, basePathCutIndex);
-                else
-                    prefix = basePath;
-            } else
-                prefix = basePath.substring(0, basePath.lastIndexOf("/")) + "/";
-
-            path = prefix + path;
-        } else if (path.length > 1 && path.charAt(1) === "/") {
-            // href starts with "//" which is a full URL with the protocol dropped (use the baseURL protocol).
-            return parsedURL.scheme + ":" + path;
-        }
-        return parsedURL.scheme + "://" + parsedURL.host + (parsedURL.port ? (":" + parsedURL.port) : "") + path;
-    }
-    return null;
-}
-
 WebInspector.addMainEventListeners = function(doc)
 {
     doc.addEventListener("focus", this.focusChanged.bind(this), true);

Modified: trunk/Source/WebCore/inspector/front-end/utilities.js (98839 => 98840)


--- trunk/Source/WebCore/inspector/front-end/utilities.js	2011-10-31 08:37:32 UTC (rev 98839)
+++ trunk/Source/WebCore/inspector/front-end/utilities.js	2011-10-31 09:18:30 UTC (rev 98840)
@@ -343,7 +343,8 @@
     return this;
 }
 
-Element.prototype.__defineGetter__("selectionLeftOffset", function() {
+Element.prototype.selectionLeftOffset = function()
+{
     // Calculate selection offset relative to the current element.
 
     var selection = window.getSelection();
@@ -362,7 +363,7 @@
     }
 
     return leftOffset;
-});
+}
 
 String.prototype.hasSubstring = function(string, caseInsensitive)
 {
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to