Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: Source/devtools/front_end/bindings/ResourceUtils.js

Issue 674513002: DevTools: linkify relative links in console.log(new Error().stack) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix tests Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com). 3 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com).
4 * Copyright (C) 2009 Joseph Pecoraro 4 * Copyright (C) 2009 Joseph Pecoraro
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 91
92 /** 92 /**
93 * @param {string} string 93 * @param {string} string
94 * @param {function(string,string,number=,number=):!Node} linkifier 94 * @param {function(string,string,number=,number=):!Node} linkifier
95 * @return {!DocumentFragment} 95 * @return {!DocumentFragment}
96 */ 96 */
97 WebInspector.linkifyStringAsFragmentWithCustomLinkifier = function(string, linki fier) 97 WebInspector.linkifyStringAsFragmentWithCustomLinkifier = function(string, linki fier)
98 { 98 {
99 var container = createDocumentFragment(); 99 var container = createDocumentFragment();
100 var linkStringRegEx = /(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\/\/|data:|www\.)[\w$\- _+*'=\|\/\\(){}[\]^%@&#~,:;.!?]{2,}[\w$\-_+*=\|\/\\({^%@&#~]/; 100 var linkStringRegEx = /(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\/\/|data:|www\.)[\w$\- _+*'=\|\/\\(){}[\]^%@&#~,:;.!?]{2,}[\w$\-_+*=\|\/\\({^%@&#~]/;
101 var lineColumnRegEx = /:(\d+)(:(\d+))?$/;
102 101
103 while (string) { 102 while (string) {
104 var linkString = linkStringRegEx.exec(string); 103 var linkString = linkStringRegEx.exec(string);
105 if (!linkString) 104 if (!linkString)
106 break; 105 break;
107 106
108 linkString = linkString[0]; 107 linkString = linkString[0];
109 var linkIndex = string.indexOf(linkString); 108 var linkIndex = string.indexOf(linkString);
110 var nonLink = string.substring(0, linkIndex); 109 var nonLink = string.substring(0, linkIndex);
111 container.appendChild(createTextNode(nonLink)); 110 container.appendChild(createTextNode(nonLink));
112 111
113 var title = linkString; 112 var title = linkString;
114 var realURL = (linkString.startsWith("www.") ? "http://" + linkString : linkString); 113 var realURL = (linkString.startsWith("www.") ? "http://" + linkString : linkString);
115 var lineColumnMatch = lineColumnRegEx.exec(realURL); 114 var parsedURL = new WebInspector.ParsedURL(realURL);
116 var lineNumber; 115 var splitResult = WebInspector.ParsedURL.splitLineAndColumn(parsedURL.la stPathComponent);
117 var columnNumber; 116 var linkNode;
118 if (lineColumnMatch) { 117 if (splitResult) {
119 realURL = realURL.substring(0, realURL.length - lineColumnMatch[0].l ength); 118 var link = realURL.substring(0, realURL.length - parsedURL.lastPathC omponent.length + splitResult.url.length);
120 lineNumber = parseInt(lineColumnMatch[1], 10); 119 linkNode = linkifier(title, link, splitResult.lineNumber, splitResul t.columnNumber);
121 // Immediately convert line and column to 0-based numbers. 120 } else
122 lineNumber = isNaN(lineNumber) ? undefined : lineNumber - 1; 121 linkNode = linkifier(title, realURL);
123 if (typeof(lineColumnMatch[3]) === "string") {
124 columnNumber = parseInt(lineColumnMatch[3], 10);
125 columnNumber = isNaN(columnNumber) ? undefined : columnNumber - 1;
126 }
127 }
128 122
129 var linkNode = linkifier(title, realURL, lineNumber, columnNumber);
130 container.appendChild(linkNode); 123 container.appendChild(linkNode);
131 string = string.substring(linkIndex + linkString.length, string.length); 124 string = string.substring(linkIndex + linkString.length, string.length);
132 } 125 }
133 126
134 if (string) 127 if (string)
135 container.appendChild(createTextNode(string)); 128 container.appendChild(createTextNode(string));
136 129
137 return container; 130 return container;
138 } 131 }
139 132
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 /** 221 /**
229 * @param {!WebInspector.NetworkRequest} request 222 * @param {!WebInspector.NetworkRequest} request
230 * @return {!Element} 223 * @return {!Element}
231 */ 224 */
232 WebInspector.linkifyRequestAsNode = function(request) 225 WebInspector.linkifyRequestAsNode = function(request)
233 { 226 {
234 var anchor = WebInspector.linkifyURLAsNode(request.url); 227 var anchor = WebInspector.linkifyURLAsNode(request.url);
235 anchor.requestId = request.requestId; 228 anchor.requestId = request.requestId;
236 return anchor; 229 return anchor;
237 } 230 }
OLDNEW
« no previous file with comments | « LayoutTests/inspector/console/resources/stack-with-sourceUrl.js ('k') | Source/devtools/front_end/common/ParsedURL.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698