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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/components/Linkifier.js

Issue 2512873002: [DevTools] Do not use external links for resources anymore. (Closed)
Patch Set: Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 * @param {?SDK.Target} target 225 * @param {?SDK.Target} target
226 * @param {?string} scriptId 226 * @param {?string} scriptId
227 * @param {string} sourceURL 227 * @param {string} sourceURL
228 * @param {number} lineNumber 228 * @param {number} lineNumber
229 * @param {number=} columnNumber 229 * @param {number=} columnNumber
230 * @param {string=} classes 230 * @param {string=} classes
231 * @return {?Element} 231 * @return {?Element}
232 */ 232 */
233 maybeLinkifyScriptLocation(target, scriptId, sourceURL, lineNumber, columnNumb er, classes) { 233 maybeLinkifyScriptLocation(target, scriptId, sourceURL, lineNumber, columnNumb er, classes) {
234 var fallbackAnchor = 234 var fallbackAnchor =
235 sourceURL ? Components.linkifyResourceAsNode(sourceURL, lineNumber, colu mnNumber, classes) : null; 235 sourceURL ? Components.Linkifier.linkifyURL(sourceURL, undefined, classe s, lineNumber, columnNumber) : null;
236 if (!target || target.isDisposed()) 236 if (!target || target.isDisposed())
237 return fallbackAnchor; 237 return fallbackAnchor;
238 var debuggerModel = SDK.DebuggerModel.fromTarget(target); 238 var debuggerModel = SDK.DebuggerModel.fromTarget(target);
239 if (!debuggerModel) 239 if (!debuggerModel)
240 return fallbackAnchor; 240 return fallbackAnchor;
241 241
242 var rawLocation = 242 var rawLocation =
243 (scriptId ? debuggerModel.createRawLocationByScriptId(scriptId, lineNumb er, columnNumber || 0) : null) || 243 (scriptId ? debuggerModel.createRawLocationByScriptId(scriptId, lineNumb er, columnNumber || 0) : null) ||
244 debuggerModel.createRawLocationByURL(sourceURL, lineNumber, columnNumber || 0); 244 debuggerModel.createRawLocationByURL(sourceURL, lineNumber, columnNumber || 0);
245 if (!rawLocation) 245 if (!rawLocation)
(...skipping 14 matching lines...) Expand all
260 * @param {?SDK.Target} target 260 * @param {?SDK.Target} target
261 * @param {?string} scriptId 261 * @param {?string} scriptId
262 * @param {string} sourceURL 262 * @param {string} sourceURL
263 * @param {number} lineNumber 263 * @param {number} lineNumber
264 * @param {number=} columnNumber 264 * @param {number=} columnNumber
265 * @param {string=} classes 265 * @param {string=} classes
266 * @return {!Element} 266 * @return {!Element}
267 */ 267 */
268 linkifyScriptLocation(target, scriptId, sourceURL, lineNumber, columnNumber, c lasses) { 268 linkifyScriptLocation(target, scriptId, sourceURL, lineNumber, columnNumber, c lasses) {
269 return this.maybeLinkifyScriptLocation(target, scriptId, sourceURL, lineNumb er, columnNumber, classes) || 269 return this.maybeLinkifyScriptLocation(target, scriptId, sourceURL, lineNumb er, columnNumber, classes) ||
270 Components.linkifyResourceAsNode(sourceURL, lineNumber, columnNumber, cl asses); 270 Components.Linkifier.linkifyURL(sourceURL, undefined, classes, lineNumbe r, columnNumber);
271 } 271 }
272 272
273 /** 273 /**
274 * @param {!SDK.DebuggerModel.Location} rawLocation 274 * @param {!SDK.DebuggerModel.Location} rawLocation
275 * @param {string} fallbackUrl 275 * @param {string} fallbackUrl
276 * @param {string=} classes 276 * @param {string=} classes
277 * @return {!Element} 277 * @return {!Element}
278 */ 278 */
279 linkifyRawLocation(rawLocation, fallbackUrl, classes) { 279 linkifyRawLocation(rawLocation, fallbackUrl, classes) {
280 return this.linkifyScriptLocation( 280 return this.linkifyScriptLocation(
(...skipping 16 matching lines...) Expand all
297 * @param {!SDK.Target} target 297 * @param {!SDK.Target} target
298 * @param {!Protocol.Runtime.StackTrace} stackTrace 298 * @param {!Protocol.Runtime.StackTrace} stackTrace
299 * @param {string=} classes 299 * @param {string=} classes
300 * @return {!Element} 300 * @return {!Element}
301 */ 301 */
302 linkifyStackTraceTopFrame(target, stackTrace, classes) { 302 linkifyStackTraceTopFrame(target, stackTrace, classes) {
303 console.assert(stackTrace.callFrames && stackTrace.callFrames.length); 303 console.assert(stackTrace.callFrames && stackTrace.callFrames.length);
304 304
305 var topFrame = stackTrace.callFrames[0]; 305 var topFrame = stackTrace.callFrames[0];
306 var fallbackAnchor = 306 var fallbackAnchor =
307 Components.linkifyResourceAsNode(topFrame.url, topFrame.lineNumber, topF rame.columnNumber, classes); 307 Components.Linkifier.linkifyURL(topFrame.url, undefined, classes, topFra me.lineNumber, topFrame.columnNumber);
308 if (target.isDisposed()) 308 if (target.isDisposed())
309 return fallbackAnchor; 309 return fallbackAnchor;
310 310
311 var debuggerModel = SDK.DebuggerModel.fromTarget(target); 311 var debuggerModel = SDK.DebuggerModel.fromTarget(target);
312 var rawLocations = debuggerModel.createRawLocationsByStackTrace(stackTrace); 312 var rawLocations = debuggerModel.createRawLocationsByStackTrace(stackTrace);
313 if (rawLocations.length === 0) 313 if (rawLocations.length === 0)
314 return fallbackAnchor; 314 return fallbackAnchor;
315 315
316 var anchor = this._createAnchor(classes); 316 var anchor = this._createAnchor(classes);
317 var liveLocation = Bindings.debuggerWorkspaceBinding.createStackTraceTopFram eLiveLocation( 317 var liveLocation = Bindings.debuggerWorkspaceBinding.createStackTraceTopFram eLiveLocation(
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 } 440 }
441 441
442 /** 442 /**
443 * @param {string} url 443 * @param {string} url
444 * @param {string=} text 444 * @param {string=} text
445 * @param {string=} className 445 * @param {string=} className
446 * @param {number=} lineNumber 446 * @param {number=} lineNumber
447 * @param {number=} columnNumber 447 * @param {number=} columnNumber
448 * @return {!Element} 448 * @return {!Element}
449 */ 449 */
450 static linkifyURLAsNode(url, text, className, lineNumber, columnNumber) { 450 static linkifyURL(url, text, className, lineNumber, columnNumber) {
451 var isExternal = !Bindings.resourceForURL(url) && !Workspace.workspace.uiSou rceCodeForURL(url); 451 if (!url) {
452 if (isExternal) { 452 var element = createElementWithClass('span', className);
453 var link = UI.createExternalLink(url, text, className); 453 element.textContent = text || Common.UIString('(unknown)');
454 link.lineNumber = lineNumber; 454 return element;
455 link.columnNumber = columnNumber;
456 return link;
457 } 455 }
458 return Components.linkifyResourceAsNode(url, lineNumber, columnNumber, class Name, undefined, text); 456
457 var linkText = text || Bindings.displayNameForURL(url);
458 if (typeof lineNumber === 'number' && !text)
459 linkText += ':' + (lineNumber + 1);
460
461 var anchor = createElementWithClass('a', className);
462 if (!url.trim().toLowerCase().startsWith('javascript:')) {
463 anchor.href = url;
464 anchor.classList.add('webkit-html-resource-link');
465 }
466 anchor.title = linkText !== url ? url : '';
467 anchor.textContent = linkText.trimMiddle(150);
468 anchor.lineNumber = lineNumber;
469 anchor.columnNumber = columnNumber;
470 return anchor;
459 } 471 }
460 }; 472 };
461 473
462 /** @type {!Set<!Components.Linkifier>} */ 474 /** @type {!Set<!Components.Linkifier>} */
463 Components.Linkifier._instances = new Set(); 475 Components.Linkifier._instances = new Set();
464 /** @type {?Components.LinkDecorator} */ 476 /** @type {?Components.LinkDecorator} */
465 Components.Linkifier._decorator = null; 477 Components.Linkifier._decorator = null;
466 478
467 Components.Linkifier._iconSymbol = Symbol('Linkifier.iconSymbol'); 479 Components.Linkifier._iconSymbol = Symbol('Linkifier.iconSymbol');
468 Components.Linkifier._enableDecoratorSymbol = Symbol('Linkifier.enableIconsSymbo l'); 480 Components.Linkifier._enableDecoratorSymbol = Symbol('Linkifier.enableIconsSymbo l');
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 */ 575 */
564 Components.linkifyStringAsFragment = function(string) { 576 Components.linkifyStringAsFragment = function(string) {
565 /** 577 /**
566 * @param {string} title 578 * @param {string} title
567 * @param {string} url 579 * @param {string} url
568 * @param {number=} lineNumber 580 * @param {number=} lineNumber
569 * @param {number=} columnNumber 581 * @param {number=} columnNumber
570 * @return {!Node} 582 * @return {!Node}
571 */ 583 */
572 function linkifier(title, url, lineNumber, columnNumber) { 584 function linkifier(title, url, lineNumber, columnNumber) {
573 return Components.Linkifier.linkifyURLAsNode(url, title, undefined, lineNumb er, columnNumber); 585 return Components.Linkifier.linkifyURL(url, title, undefined, lineNumber, co lumnNumber);
574 } 586 }
575 587
576 return Components.linkifyStringAsFragmentWithCustomLinkifier(string, linkifier ); 588 return Components.linkifyStringAsFragmentWithCustomLinkifier(string, linkifier );
577 }; 589 };
578
579 /**
580 * @param {string} url
581 * @param {number=} lineNumber
582 * @param {number=} columnNumber
583 * @param {string=} classes
584 * @param {string=} tooltipText
585 * @param {string=} urlDisplayName
586 * @return {!Element}
587 */
588 Components.linkifyResourceAsNode = function(url, lineNumber, columnNumber, class es, tooltipText, urlDisplayName) {
589 if (!url) {
590 var element = createElementWithClass('span', classes);
591 element.textContent = urlDisplayName || Common.UIString('(unknown)');
592 return element;
593 }
594 var linkText = urlDisplayName || Bindings.displayNameForURL(url);
595 if (typeof lineNumber === 'number' && !urlDisplayName)
596 linkText += ':' + (lineNumber + 1);
597
598 var anchor = createElementWithClass('a', classes);
599 if (!url.trim().toLowerCase().startsWith('javascript:')) {
600 anchor.href = url;
601 anchor.classList.add('webkit-html-resource-link');
602 }
603 anchor.title = tooltipText || (linkText !== url ? url : '');
604 anchor.textContent = linkText.trimMiddle(150);
605 anchor.lineNumber = lineNumber;
606 anchor.columnNumber = columnNumber;
607 return anchor;
608 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698