Diff
Modified: trunk/LayoutTests/inspector/elements/elements-panel-rewrite-href-expected.txt (126571 => 126572)
--- trunk/LayoutTests/inspector/elements/elements-panel-rewrite-href-expected.txt 2012-08-24 11:47:54 UTC (rev 126571)
+++ trunk/LayoutTests/inspector/elements/elements-panel-rewrite-href-expected.txt 2012-08-24 12:10:49 UTC (rev 126572)
@@ -1,5 +1,6 @@
Tests that src and href element targets are rewritten properly.
+null
,bogusSheet1.css
inspector,elements,bogusSheet2.css
tests,inspector,inspector-test.js
Modified: trunk/LayoutTests/inspector/elements/elements-panel-rewrite-href.html (126571 => 126572)
--- trunk/LayoutTests/inspector/elements/elements-panel-rewrite-href.html 2012-08-24 11:47:54 UTC (rev 126571)
+++ trunk/LayoutTests/inspector/elements/elements-panel-rewrite-href.html 2012-08-24 12:10:49 UTC (rev 126572)
@@ -19,7 +19,7 @@
var node = innerMapping[nodeId];
if (node.nodeName() === "LINK" || node.nodeName() === "SCRIPT") {
var segments = [];
- var href = "" node.getAttribute("src") || node.getAttribute("href"));
+ var href = "" || node.getAttribute("href"));
if (!href) {
segments.push("<empty>");
continue;
@@ -32,6 +32,8 @@
segments.push(split[i]);
InspectorTest.addResult(segments.reverse());
}
+ if (node.nodeName() === "A")
+ InspectorTest.addResult(node.resolveURL(node.getAttribute("href")));
}
InspectorTest.completeTest();
}
@@ -45,5 +47,7 @@
Tests that src and href element targets are rewritten properly.
</p>
+<a style="display:none" href="" _javascript_:alert('foo') "></a>
+
</body>
</html>
Modified: trunk/LayoutTests/inspector/styles/styles-url-linkify-expected.txt (126571 => 126572)
--- trunk/LayoutTests/inspector/styles/styles-url-linkify-expected.txt 2012-08-24 11:47:54 UTC (rev 126571)
+++ trunk/LayoutTests/inspector/styles/styles-url-linkify-expected.txt 2012-08-24 12:10:49 UTC (rev 126572)
@@ -19,7 +19,6 @@
http://example.com/cat.jpeg
http://example.com/cat.jpeg
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEIAAABCAgMAAACeOuh7AAAABGdBTUEAAK/INwWK6QAAAAlQTFRF////AAAA////fu+PTwAAAAF0Uk5TAEDm2GYAAACHSURBVDjLxdLbDYAgDAVQGELn0R3oEHYf2KGdUqtE46OFRCP3oyTng1xCnWsaD5JRRtCkQ2YmkBkHRXqWJBn0j0TICbrsWVoWhRShCdcGyZCtHxMaUnVPRZ9KSbmBJdsX2vJVnwqRD0Rb4rpzgIbE/AI5NTnWAMvy5l0dXrfuLh5OCe5BmmYGXhTUxlQ5xJ8AAAAASUVORK5CYII=
-_javascript_:alert('foo');
null
blob:http%3A//example.com/f91b7b00-00-0000-0000-3b7c87055d7a
blob:http%3A//example.com/f91b7b00-00-0000-0000-3b7c87055d7a
Modified: trunk/LayoutTests/inspector/styles/styles-url-linkify.html (126571 => 126572)
--- trunk/LayoutTests/inspector/styles/styles-url-linkify.html 2012-08-24 11:47:54 UTC (rev 126571)
+++ trunk/LayoutTests/inspector/styles/styles-url-linkify.html 2012-08-24 12:10:49 UTC (rev 126572)
@@ -35,9 +35,8 @@
const blobURL = "blob:http%3A//example.com/f91b7b00-00-0000-0000-3b7c87055d7a";
completeURL("https://example.com/foo", dataURL);
completeURL("http://example.com/foo", "_javascript_:alert('foo');");
- InspectorTest.addResult(WebInspector.resourceURLForRelatedNode(null, " _javascript_:alert('foo'); "));
completeURL("http://example.com/foo", blobURL);
- InspectorTest.addResult(WebInspector.resourceURLForRelatedNode(null, blobURL));
+ InspectorTest.addResult(WebInspector.ParsedURL.completeURL(blobURL));
function dumpHref(dumpLinkClass)
{
Modified: trunk/Source/WebCore/ChangeLog (126571 => 126572)
--- trunk/Source/WebCore/ChangeLog 2012-08-24 11:47:54 UTC (rev 126571)
+++ trunk/Source/WebCore/ChangeLog 2012-08-24 12:10:49 UTC (rev 126572)
@@ -1,3 +1,36 @@
+2012-08-24 Pavel Feldman <[email protected]>
+
+ Web Inspector: resolve URLs upon creation, get rid of populateHrefContextMenu
+ https://bugs.webkit.org/show_bug.cgi?id=94900
+
+ Reviewed by Vsevolod Vlasov.
+
+ - This change makes sure we resolve URLs upon adding the to the UI. Then we treat them as absolute links in context menu, etc.
+ - There is no need to override context menu for links anymore - system menu will do.
+
+ * inspector/front-end/AuditResultView.js:
+ (WebInspector.AuditResultView):
+ * inspector/front-end/ConsoleView.js:
+ * inspector/front-end/DOMAgent.js:
+ (WebInspector.DOMNode.prototype.descendantUserPropertyCount):
+ (WebInspector.DOMNode.prototype.resolveURL):
+ * inspector/front-end/ElementsPanel.js:
+ * inspector/front-end/ElementsTreeOutline.js:
+ (WebInspector.ElementsTreeOutline.prototype.populateContextMenu):
+ (WebInspector.ElementsTreeElement.prototype._buildAttributeDOM):
+ * inspector/front-end/HandlerRegistry.js:
+ (WebInspector.HandlerRegistry.prototype.appendApplicableItems):
+ (WebInspector.HandlerRegistry.prototype._appendContentProviderItems):
+ (WebInspector.HandlerRegistry.prototype._appendHrefItems):
+ * inspector/front-end/ParsedURL.js:
+ (WebInspector.ParsedURL.completeURL):
+ * inspector/front-end/ResourceUtils.js:
+ (WebInspector.linkifyRequestAsNode):
+ * inspector/front-end/StylesSidebarPane.js:
+ (WebInspector.StylesSidebarPane):
+ (WebInspector.StylePropertyTreeElement.prototype.updateTitle.linkifyURL):
+ * inspector/front-end/UIUtils.js:
+
2012-08-24 Xan Lopez <[email protected]>
[GTK] Use the new 'feature_defines' variable to generate DOM bindings
Modified: trunk/Source/WebCore/inspector/front-end/AdvancedSearchController.js (126571 => 126572)
--- trunk/Source/WebCore/inspector/front-end/AdvancedSearchController.js 2012-08-24 11:47:54 UTC (rev 126571)
+++ trunk/Source/WebCore/inspector/front-end/AdvancedSearchController.js 2012-08-24 12:10:49 UTC (rev 126572)
@@ -500,7 +500,7 @@
{
var anchor = document.createElement("a");
anchor.preferredPanel = "scripts";
- anchor.href = ""
+ anchor.href = ""
anchor.uiSourceCode = uiSourceCode;
anchor.lineNumber = lineNumber;
return anchor;
Modified: trunk/Source/WebCore/inspector/front-end/AuditFormatters.js (126571 => 126572)
--- trunk/Source/WebCore/inspector/front-end/AuditFormatters.js 2012-08-24 11:47:54 UTC (rev 126571)
+++ trunk/Source/WebCore/inspector/front-end/AuditFormatters.js 2012-08-24 12:10:49 UTC (rev 126572)
@@ -60,7 +60,7 @@
url: function(url, displayText, allowExternalNavigation)
{
var a = document.createElement("a");
- a.href = ""
+ a.href = ""
a.title = url;
a.textContent = displayText || url;
if (allowExternalNavigation)
Modified: trunk/Source/WebCore/inspector/front-end/AuditResultView.js (126571 => 126572)
--- trunk/Source/WebCore/inspector/front-end/AuditResultView.js 2012-08-24 11:47:54 UTC (rev 126571)
+++ trunk/Source/WebCore/inspector/front-end/AuditResultView.js 2012-08-24 12:10:49 UTC (rev 126572)
@@ -43,17 +43,9 @@
categoryResults.sort(categorySorter);
for (var i = 0; i < categoryResults.length; ++i)
this.element.appendChild(new WebInspector.AuditCategoryResultPane(categoryResults[i]).element);
-
- this.element.addEventListener("contextmenu", this._contextMenuEventFired.bind(this), true);
}
WebInspector.AuditResultView.prototype = {
- _contextMenuEventFired: function(event)
- {
- var contextMenu = new WebInspector.ContextMenu();
- if (WebInspector.populateHrefContextMenu(contextMenu, null, event))
- contextMenu.show(event);
- }
}
WebInspector.AuditResultView.prototype.__proto__ = WebInspector.View.prototype;
Modified: trunk/Source/WebCore/inspector/front-end/ConsoleView.js (126571 => 126572)
--- trunk/Source/WebCore/inspector/front-end/ConsoleView.js 2012-08-24 11:47:54 UTC (rev 126571)
+++ trunk/Source/WebCore/inspector/front-end/ConsoleView.js 2012-08-24 12:10:49 UTC (rev 126572)
@@ -550,11 +550,11 @@
return;
}
+ if (event.target.enclosingNodeOrSelfWithNodeName("a"))
+ return;
+
var contextMenu = new WebInspector.ContextMenu();
- if (WebInspector.populateHrefContextMenu(contextMenu, null, event))
- contextMenu.appendSeparator();
-
function monitoringXHRItemAction()
{
WebInspector.settings.monitoringXHREnabled.set(!WebInspector.settings.monitoringXHREnabled.get());
Modified: trunk/Source/WebCore/inspector/front-end/DOMAgent.js (126571 => 126572)
--- trunk/Source/WebCore/inspector/front-end/DOMAgent.js 2012-08-24 11:47:54 UTC (rev 126571)
+++ trunk/Source/WebCore/inspector/front-end/DOMAgent.js 2012-08-24 12:10:49 UTC (rev 126572)
@@ -736,6 +736,22 @@
descendantUserPropertyCount: function(name)
{
return this._descendantUserPropertyCounters && this._descendantUserPropertyCounters[name] ? this._descendantUserPropertyCounters[name] : 0;
+ },
+
+ /**
+ * @param {string} url
+ * @return {?string}
+ */
+ resolveURL: function(url)
+ {
+ if (!url)
+ return url;
+ for (var frameOwnerCandidate = this; frameOwnerCandidate; frameOwnerCandidate = frameOwnerCandidate.parentNode) {
+ if (frameOwnerCandidate.documentURL)
+ return WebInspector.ParsedURL.completeURL(frameOwnerCandidate.documentURL, url);
+ }
+ console.error("Could not resolve DOM URL: " + url);
+ return null;
}
}
Modified: trunk/Source/WebCore/inspector/front-end/ElementsPanel.js (126571 => 126572)
--- trunk/Source/WebCore/inspector/front-end/ElementsPanel.js 2012-08-24 11:47:54 UTC (rev 126571)
+++ trunk/Source/WebCore/inspector/front-end/ElementsPanel.js 2012-08-24 12:10:49 UTC (rev 126572)
@@ -336,8 +336,7 @@
var contextMenu = new WebInspector.ContextMenu();
var populated = this.treeOutline.populateContextMenu(contextMenu, event);
- if (populated)
- contextMenu.appendSeparator();
+ contextMenu.appendSeparator();
contextMenu.appendCheckboxItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Word wrap" : "Word Wrap"), toggleWordWrap.bind(this), WebInspector.settings.domWordWrap.get());
contextMenu.show(event);
Modified: trunk/Source/WebCore/inspector/front-end/ElementsTreeOutline.js (126571 => 126572)
--- trunk/Source/WebCore/inspector/front-end/ElementsTreeOutline.js 2012-08-24 11:47:54 UTC (rev 126571)
+++ trunk/Source/WebCore/inspector/front-end/ElementsTreeOutline.js 2012-08-24 12:10:49 UTC (rev 126572)
@@ -483,25 +483,17 @@
if (textNode && textNode.hasStyleClass("bogus"))
textNode = null;
var commentNode = event.target.enclosingNodeOrSelfWithClass("webkit-html-comment");
- var populated = WebInspector.populateHrefContextMenu(contextMenu, this.selectedDOMNode(), event);
- if (textNode && treeElement._populateTextContextMenu) {
- if (populated)
- contextMenu.appendSeparator();
+ contextMenu.appendApplicableItems(event.target);
+ if (textNode) {
+ contextMenu.appendSeparator();
treeElement._populateTextContextMenu(contextMenu, textNode);
- populated = true;
- } else if (isTag && treeElement._populateTagContextMenu) {
- if (populated)
- contextMenu.appendSeparator();
+ } else if (isTag) {
+ contextMenu.appendSeparator();
treeElement._populateTagContextMenu(contextMenu, event);
- populated = true;
- } else if (commentNode && treeElement._populateNodeContextMenu) {
- if (populated)
- contextMenu.appendSeparator();
+ } else if (commentNode) {
+ contextMenu.appendSeparator();
treeElement._populateNodeContextMenu(contextMenu, textNode);
- populated = true;
}
-
- return populated;
},
adjustCollapsedRange: function()
@@ -1664,7 +1656,7 @@
attrSpanElement.appendChild(document.createTextNode("=\u200B\""));
if (linkify && (name === "src" || name === "href")) {
- var rewrittenHref = WebInspector.resourceURLForRelatedNode(node, value);
+ var rewrittenHref = node.resolveURL(value);
value = value.replace(/([\/;:\)\]\}])/g, "$1\u200B");
if (rewrittenHref === null) {
var attrValueElement = attrSpanElement.createChild("span", "webkit-html-attribute-value");
Modified: trunk/Source/WebCore/inspector/front-end/HandlerRegistry.js (126571 => 126572)
--- trunk/Source/WebCore/inspector/front-end/HandlerRegistry.js 2012-08-24 11:47:54 UTC (rev 126571)
+++ trunk/Source/WebCore/inspector/front-end/HandlerRegistry.js 2012-08-24 12:10:49 UTC (rev 126572)
@@ -96,6 +96,16 @@
*/
appendApplicableItems: function(contextMenu, target)
{
+ this._appendContentProviderItems(contextMenu, target);
+ this._appendHrefItems(contextMenu, target);
+ },
+
+ /**
+ * @param {WebInspector.ContextMenu} contextMenu
+ * @param {Object} target
+ */
+ _appendContentProviderItems: function(contextMenu, target)
+ {
if (!(target instanceof WebInspector.UISourceCode || target instanceof WebInspector.Resource || target instanceof WebInspector.NetworkRequest))
return;
var contentProvider = /** @type {WebInspector.ContentProvider} */ target;
@@ -140,6 +150,31 @@
contextMenu.appendSeparator();
contextMenu.appendItem(WebInspector.UIString("Save"), save.bind(this, false));
contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Save as..." : "Save As..."), save.bind(this, true));
+ },
+
+ /**
+ * @param {WebInspector.ContextMenu} contextMenu
+ * @param {Object} target
+ */
+ _appendHrefItems: function(contextMenu, target)
+ {
+ if (!(target instanceof Node))
+ return;
+ var targetNode = /** @type {Node} */ target;
+
+ var anchorElement = targetNode.enclosingNodeOrSelfWithClass("webkit-html-resource-link") || targetNode.enclosingNodeOrSelfWithClass("webkit-html-external-link");
+ if (!anchorElement)
+ return;
+
+ var resourceURL = anchorElement.href;
+ if (!resourceURL)
+ return;
+
+ // 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));
}
}
Modified: trunk/Source/WebCore/inspector/front-end/Linkifier.js (126571 => 126572)
--- trunk/Source/WebCore/inspector/front-end/Linkifier.js 2012-08-24 11:47:54 UTC (rev 126571)
+++ trunk/Source/WebCore/inspector/front-end/Linkifier.js 2012-08-24 12:10:49 UTC (rev 126572)
@@ -97,7 +97,7 @@
_updateAnchor: function(anchor, uiLocation)
{
anchor.preferredPanel = "scripts";
- anchor.href = ""
+ anchor.href = ""
anchor.uiSourceCode = uiLocation.uiSourceCode;
anchor.lineNumber = uiLocation.lineNumber;
this._formatter.formatLiveAnchor(anchor, uiLocation);
Modified: trunk/Source/WebCore/inspector/front-end/ParsedURL.js (126571 => 126572)
--- trunk/Source/WebCore/inspector/front-end/ParsedURL.js 2012-08-24 11:47:54 UTC (rev 126571)
+++ trunk/Source/WebCore/inspector/front-end/ParsedURL.js 2012-08-24 12:10:49 UTC (rev 126572)
@@ -96,17 +96,20 @@
WebInspector.ParsedURL.completeURL = function(baseURL, href)
{
if (href) {
- // Return absolute URLs as-is.
- var parsedHref = href.asParsedURL();
- if (parsedHref && parsedHref.scheme)
- return href;
-
// Return special URLs as-is.
var trimmedHref = href.trim();
- if (trimmedHref.startsWith("data:") || trimmedHref.startsWith("_javascript_:") || trimmedHref.startsWith("blob:"))
+ if (trimmedHref.startsWith("data:") || trimmedHref.startsWith("blob:"))
return href;
- }
+ if (!sanitizeHref(trimmedHref))
+ return null; // Sanitize _javascript_ URLs from content
+ // Return absolute URLs as-is.
+ var parsedHref = trimmedHref.asParsedURL();
+ if (parsedHref && parsedHref.scheme)
+ return trimmedHref;
+ } else
+ return baseURL;
+
var parsedURL = baseURL.asParsedURL();
if (parsedURL) {
var path = href;
Modified: trunk/Source/WebCore/inspector/front-end/ResourceUtils.js (126571 => 126572)
--- trunk/Source/WebCore/inspector/front-end/ResourceUtils.js 2012-08-24 11:47:54 UTC (rev 126571)
+++ trunk/Source/WebCore/inspector/front-end/ResourceUtils.js 2012-08-24 12:10:49 UTC (rev 126572)
@@ -181,7 +181,7 @@
classes += isExternal ? "webkit-html-external-link" : "webkit-html-resource-link";
var a = document.createElement("a");
- a.href = ""
+ a.href = ""
a.className = classes;
if (typeof tooltipText === "undefined")
a.title = url;
@@ -236,36 +236,3 @@
anchor.requestId = request.requestId;
return anchor;
}
-
-/**
- * @return {?string} null if the specified resource MUST NOT have a URL (e.g. "_javascript_:...")
- */
-WebInspector.resourceURLForRelatedNode = function(node, url)
-{
- if (!url || url.indexOf("://") > 0)
- return url;
-
- if (url.trim().startsWith("_javascript_:"))
- return null; // Do not provide a resource URL for security.
-
- for (var frameOwnerCandidate = node; frameOwnerCandidate; frameOwnerCandidate = frameOwnerCandidate.parentNode) {
- if (frameOwnerCandidate.documentURL) {
- var result = WebInspector.ParsedURL.completeURL(frameOwnerCandidate.documentURL, url);
- if (result)
- return result;
- break;
- }
- }
-
- // documentURL not found or has bad value
- var resourceURL = url;
- function callback(resource)
- {
- if (resource.parsedURL.path === url) {
- resourceURL = resource.url;
- return true;
- }
- }
- WebInspector.forAllResources(callback);
- return resourceURL;
-}
Modified: trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js (126571 => 126572)
--- trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js 2012-08-24 11:47:54 UTC (rev 126571)
+++ trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js 2012-08-24 12:10:49 UTC (rev 126572)
@@ -134,9 +134,11 @@
WebInspector.StylesSidebarPane.prototype = {
_contextMenuEventFired: function(event)
{
+ // We start editing upon click -> default navigation to resources panel is not available
+ // Hence we add a soft context menu for hrefs.
var contextMenu = new WebInspector.ContextMenu();
- if (WebInspector.populateHrefContextMenu(contextMenu, this.node, event))
- contextMenu.show(event);
+ contextMenu.appendApplicableItems(event.target);
+ contextMenu.show(event);
},
get _forcedPseudoClasses()
@@ -1719,7 +1721,7 @@
if (self._styleRule.sourceURL)
hrefUrl = WebInspector.ParsedURL.completeURL(self._styleRule.sourceURL, hrefUrl);
else if (this._parentPane.node)
- hrefUrl = WebInspector.resourceURLForRelatedNode(this._parentPane.node, hrefUrl);
+ hrefUrl = this._parentPane.node.resolveURL(hrefUrl);
var hasResource = !!WebInspector.resourceForURL(hrefUrl);
// FIXME: WebInspector.linkifyURLAsNode() should really use baseURI.
container.appendChild(WebInspector.linkifyURLAsNode(hrefUrl, url, undefined, !hasResource));
Modified: trunk/Source/WebCore/inspector/front-end/UIUtils.js (126571 => 126572)
--- trunk/Source/WebCore/inspector/front-end/UIUtils.js 2012-08-24 11:47:54 UTC (rev 126571)
+++ trunk/Source/WebCore/inspector/front-end/UIUtils.js 2012-08-24 12:10:49 UTC (rev 126572)
@@ -1079,29 +1079,6 @@
}
}
-/**
- * @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;
-}
-
WebInspector._coalescingLevel = 0;
WebInspector.startBatchUpdate = function()
Modified: trunk/Source/WebCore/inspector/front-end/utilities.js (126571 => 126572)
--- trunk/Source/WebCore/inspector/front-end/utilities.js 2012-08-24 11:47:54 UTC (rev 126571)
+++ trunk/Source/WebCore/inspector/front-end/utilities.js 2012-08-24 12:10:49 UTC (rev 126572)
@@ -133,6 +133,15 @@
return result;
}
+/**
+ * @param {string} href
+ * @return {string}
+ */
+function sanitizeHref(href)
+{
+ return href && href.trim().toLowerCase().startsWith("_javascript_:") ? "" : href;
+}
+
String.prototype.removeURLFragment = function()
{
var fragmentIndex = this.indexOf("#");