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

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: Created 6 years, 2 months 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 * @param {string} string 94 * @param {string} string
95 * @param {function(string,string,number=,number=):!Node} linkifier 95 * @param {function(string,string,number=,number=):!Node} linkifier
96 * @return {!DocumentFragment} 96 * @return {!DocumentFragment}
97 * // FIXME: remove this suppression (crbug.com/425498). 97 * // FIXME: remove this suppression (crbug.com/425498).
98 * @suppressGlobalPropertiesCheck 98 * @suppressGlobalPropertiesCheck
99 */ 99 */
100 WebInspector.linkifyStringAsFragmentWithCustomLinkifier = function(string, linki fier) 100 WebInspector.linkifyStringAsFragmentWithCustomLinkifier = function(string, linki fier)
101 { 101 {
102 var container = document.createDocumentFragment(); 102 var container = document.createDocumentFragment();
103 var linkStringRegEx = /(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\/\/|data:|www\.)[\w$\- _+*'=\|\/\\(){}[\]^%@&#~,:;.!?]{2,}[\w$\-_+*=\|\/\\({^%@&#~]/; 103 var linkStringRegEx = /(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\/\/|data:|www\.)[\w$\- _+*'=\|\/\\(){}[\]^%@&#~,:;.!?]{2,}[\w$\-_+*=\|\/\\({^%@&#~]/;
104 var lineColumnRegEx = /:(\d+)(:(\d+))?$/;
105 104
106 while (string) { 105 while (string) {
107 var linkString = linkStringRegEx.exec(string); 106 var linkString = linkStringRegEx.exec(string);
108 if (!linkString) 107 if (!linkString)
109 break; 108 break;
110 109
111 linkString = linkString[0]; 110 linkString = linkString[0];
112 var linkIndex = string.indexOf(linkString); 111 var linkIndex = string.indexOf(linkString);
113 var nonLink = string.substring(0, linkIndex); 112 var nonLink = string.substring(0, linkIndex);
114 container.appendChild(document.createTextNode(nonLink)); 113 container.appendChild(document.createTextNode(nonLink));
115 114
116 var title = linkString; 115 var title = linkString;
117 var realURL = (linkString.startsWith("www.") ? "http://" + linkString : linkString); 116 var realURL = (linkString.startsWith("www.") ? "http://" + linkString : linkString);
118 var parsedURL = new WebInspector.ParsedURL(realURL); 117 var parsedURL = new WebInspector.ParsedURL(realURL);
119 var lineColumnMatch = lineColumnRegEx.exec(parsedURL.lastPathComponent); 118 var splitResult = WebInspector.ParsedURL.splitLineAndColumn(parsedURL.la stPathComponent);
120 var lineNumber; 119 var linkNode;
121 var columnNumber; 120 if (splitResult) {
122 if (lineColumnMatch) { 121 var link = realURL.substring(0, realURL.length - parsedURL.lastPathC omponent.length + splitResult.url.length);
123 realURL = realURL.substring(0, realURL.length - lineColumnMatch[0].l ength); 122 linkNode = linkifier(title, splitResult.url, splitResult.lineNumber, splitResult.columnNumber);
124 lineNumber = parseInt(lineColumnMatch[1], 10); 123 } else
aandrey 2014/10/23 17:51:30 { .. }
125 // Immediately convert line and column to 0-based numbers. 124 linkNode = linkifier(title, realURL);
126 lineNumber = isNaN(lineNumber) ? undefined : lineNumber - 1;
127 if (typeof(lineColumnMatch[3]) === "string") {
128 columnNumber = parseInt(lineColumnMatch[3], 10);
129 columnNumber = isNaN(columnNumber) ? undefined : columnNumber - 1;
130 }
131 }
132 125
133 var linkNode = linkifier(title, realURL, lineNumber, columnNumber);
134 container.appendChild(linkNode); 126 container.appendChild(linkNode);
135 string = string.substring(linkIndex + linkString.length, string.length); 127 string = string.substring(linkIndex + linkString.length, string.length);
136 } 128 }
137 129
138 if (string) 130 if (string)
139 container.appendChild(document.createTextNode(string)); 131 container.appendChild(document.createTextNode(string));
140 132
141 return container; 133 return container;
142 } 134 }
143 135
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 /** 203 /**
212 * @param {!WebInspector.NetworkRequest} request 204 * @param {!WebInspector.NetworkRequest} request
213 * @return {!Element} 205 * @return {!Element}
214 */ 206 */
215 WebInspector.linkifyRequestAsNode = function(request) 207 WebInspector.linkifyRequestAsNode = function(request)
216 { 208 {
217 var anchor = WebInspector.linkifyURLAsNode(request.url); 209 var anchor = WebInspector.linkifyURLAsNode(request.url);
218 anchor.requestId = request.requestId; 210 anchor.requestId = request.requestId;
219 return anchor; 211 return anchor;
220 } 212 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698