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

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

Issue 2571713005: DevTools: untruncate links on console export (Closed)
Patch Set: rebase Created 3 years, 11 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
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 20 matching lines...) Expand all
31 /** 31 /**
32 * @implements {SDK.TargetManager.Observer} 32 * @implements {SDK.TargetManager.Observer}
33 * @unrestricted 33 * @unrestricted
34 */ 34 */
35 Components.Linkifier = class { 35 Components.Linkifier = class {
36 /** 36 /**
37 * @param {number=} maxLengthForDisplayedURLs 37 * @param {number=} maxLengthForDisplayedURLs
38 * @param {boolean=} useLinkDecorator 38 * @param {boolean=} useLinkDecorator
39 */ 39 */
40 constructor(maxLengthForDisplayedURLs, useLinkDecorator) { 40 constructor(maxLengthForDisplayedURLs, useLinkDecorator) {
41 this._maxLength = maxLengthForDisplayedURLs || Components.Linkifier.MaxLengt hForDisplayedURLs; 41 this._maxLength = maxLengthForDisplayedURLs || UI.MaxLengthForDisplayedURLs;
42 /** @type {!Map<!SDK.Target, !Array<!Element>>} */ 42 /** @type {!Map<!SDK.Target, !Array<!Element>>} */
43 this._anchorsByTarget = new Map(); 43 this._anchorsByTarget = new Map();
44 /** @type {!Map<!SDK.Target, !Bindings.LiveLocationPool>} */ 44 /** @type {!Map<!SDK.Target, !Bindings.LiveLocationPool>} */
45 this._locationPoolByTarget = new Map(); 45 this._locationPoolByTarget = new Map();
46 this._useLinkDecorator = !!useLinkDecorator; 46 this._useLinkDecorator = !!useLinkDecorator;
47 Components.Linkifier._instances.add(this); 47 Components.Linkifier._instances.add(this);
48 SDK.targetManager.observeTargets(this); 48 SDK.targetManager.observeTargets(this);
49 } 49 }
50 50
51 /** 51 /**
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 * @param {!Bindings.LiveLocation} liveLocation 297 * @param {!Bindings.LiveLocation} liveLocation
298 */ 298 */
299 _updateAnchor(anchor, liveLocation) { 299 _updateAnchor(anchor, liveLocation) {
300 Components.Linkifier._unbindUILocation(anchor); 300 Components.Linkifier._unbindUILocation(anchor);
301 var uiLocation = liveLocation.uiLocation(); 301 var uiLocation = liveLocation.uiLocation();
302 if (!uiLocation) 302 if (!uiLocation)
303 return; 303 return;
304 304
305 Components.Linkifier._bindUILocation(anchor, uiLocation); 305 Components.Linkifier._bindUILocation(anchor, uiLocation);
306 var text = uiLocation.linkText(); 306 var text = uiLocation.linkText();
307 var info = Components.Linkifier._linkInfo(anchor);
308 info.originalLinkText = text;
307 text = text.replace(/([a-f0-9]{7})[a-f0-9]{13}[a-f0-9]*/g, '$1\u2026'); 309 text = text.replace(/([a-f0-9]{7})[a-f0-9]{13}[a-f0-9]*/g, '$1\u2026');
308 if (this._maxLength) 310 if (this._maxLength)
309 text = text.trimMiddle(this._maxLength); 311 text = text.trimMiddle(this._maxLength);
310 anchor.textContent = text; 312 anchor.textContent = text;
311 313
312 var titleText = uiLocation.uiSourceCode.url(); 314 var titleText = uiLocation.uiSourceCode.url();
313 if (typeof uiLocation.lineNumber === 'number') 315 if (typeof uiLocation.lineNumber === 'number')
314 titleText += ':' + (uiLocation.lineNumber + 1); 316 titleText += ':' + (uiLocation.lineNumber + 1);
315 anchor.title = titleText; 317 anchor.title = titleText;
316 anchor.classList.toggle('webkit-html-blackbox-link', liveLocation.isBlackbox ed()); 318 anchor.classList.toggle('webkit-html-blackbox-link', liveLocation.isBlackbox ed());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 if (!url || url.trim().toLowerCase().startsWith('javascript:')) { 351 if (!url || url.trim().toLowerCase().startsWith('javascript:')) {
350 var element = createElementWithClass('span', className); 352 var element = createElementWithClass('span', className);
351 element.textContent = text || url || Common.UIString('(unknown)'); 353 element.textContent = text || url || Common.UIString('(unknown)');
352 return element; 354 return element;
353 } 355 }
354 356
355 var linkText = text || Bindings.displayNameForURL(url); 357 var linkText = text || Bindings.displayNameForURL(url);
356 if (typeof lineNumber === 'number' && !text) 358 if (typeof lineNumber === 'number' && !text)
357 linkText += ':' + (lineNumber + 1); 359 linkText += ':' + (lineNumber + 1);
358 var title = linkText !== url ? url : ''; 360 var title = linkText !== url ? url : '';
359 var link = Components.Linkifier._createLink(linkText.trimMiddle(150), classN ame || '', title, url, preventClick); 361 var link = Components.Linkifier._createLink(
362 linkText, className || '', UI.MaxLengthForDisplayedURLs, title, url, pre ventClick);
360 var info = Components.Linkifier._linkInfo(link); 363 var info = Components.Linkifier._linkInfo(link);
361 if (typeof lineNumber === 'number') 364 if (typeof lineNumber === 'number')
362 info.lineNumber = lineNumber; 365 info.lineNumber = lineNumber;
363 if (typeof columnNumber === 'number') 366 if (typeof columnNumber === 'number')
364 info.columnNumber = columnNumber; 367 info.columnNumber = columnNumber;
365 return link; 368 return link;
366 } 369 }
367 370
368 /** 371 /**
369 * @param {!Object} revealable 372 * @param {!Object} revealable
370 * @param {string} text 373 * @param {string} text
371 * @param {string=} fallbackHref 374 * @param {string=} fallbackHref
372 * @return {!Element} 375 * @return {!Element}
373 */ 376 */
374 static linkifyRevealable(revealable, text, fallbackHref) { 377 static linkifyRevealable(revealable, text, fallbackHref) {
375 var link = Components.Linkifier._createLink( 378 var link = Components.Linkifier._createLink(text, '', UI.MaxLengthForDisplay edURLs, undefined, fallbackHref);
376 text.trimMiddle(Components.Linkifier.MaxLengthForDisplayedURLs), '', und efined, fallbackHref);
377 Components.Linkifier._linkInfo(link).revealable = revealable; 379 Components.Linkifier._linkInfo(link).revealable = revealable;
378 return link; 380 return link;
379 } 381 }
380 382
381 /** 383 /**
382 * @param {string} text 384 * @param {string} text
383 * @param {string} className 385 * @param {string} className
386 * @param {number=} maxLength
384 * @param {string=} title 387 * @param {string=} title
385 * @param {string=} href 388 * @param {string=} href
386 * @param {boolean=} preventClick 389 * @param {boolean=} preventClick
387 * @returns{!Element} 390 * @returns{!Element}
388 */ 391 */
389 static _createLink(text, className, title, href, preventClick) { 392 static _createLink(text, className, maxLength, title, href, preventClick) {
390 var link = createElementWithClass('span', className); 393 var link = createElementWithClass('span', className);
391 link.classList.add('devtools-link'); 394 link.classList.add('devtools-link');
392 if (title) 395 if (title)
393 link.title = title; 396 link.title = title;
394 if (href) 397 if (href)
395 link.href = href; 398 link.href = href;
396 link.textContent = text; 399 link.textContent = text;
400 if (maxLength)
401 link.textContent = link.textContent.trimMiddle(maxLength);
397 link[Components.Linkifier._infoSymbol] = { 402 link[Components.Linkifier._infoSymbol] = {
398 icon: null, 403 icon: null,
399 enableDecorator: false, 404 enableDecorator: false,
400 uiLocation: null, 405 uiLocation: null,
401 liveLocation: null, 406 liveLocation: null,
402 url: href || null, 407 url: href || null,
403 lineNumber: null, 408 lineNumber: null,
404 columnNumber: null, 409 columnNumber: null,
405 revealable: null, 410 revealable: null,
406 fallback: null 411 fallback: null,
412 originalLinkText: text
407 }; 413 };
408 if (!preventClick) 414 if (!preventClick)
409 link.addEventListener('click', Components.Linkifier._handleClick, false); 415 link.addEventListener('click', Components.Linkifier._handleClick, false);
410 else 416 else
411 link.classList.add('devtools-link-prevent-click'); 417 link.classList.add('devtools-link-prevent-click');
412 return link; 418 return link;
413 } 419 }
414 420
415 /** 421 /**
416 * @param {?Element} link 422 * @param {?Element} link
423 * @return {?string}
424 */
425 static originalLinkText(link) {
426 var info = this._linkInfo(link);
427 return info ? info.originalLinkText : null;
428 }
429
430 /**
431 * @param {?Element} link
417 * @return {?Components._LinkInfo} 432 * @return {?Components._LinkInfo}
418 */ 433 */
419 static _linkInfo(link) { 434 static _linkInfo(link) {
420 return /** @type {?Components._LinkInfo} */ (link ? link[Components.Linkifie r._infoSymbol] || null : null); 435 return /** @type {?Components._LinkInfo} */ (link ? link[Components.Linkifie r._infoSymbol] || null : null);
421 } 436 }
422 437
423 /** 438 /**
424 * @param {!Event} event 439 * @param {!Event} event
425 */ 440 */
426 static _handleClick(event) { 441 static _handleClick(event) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 /** 553 /**
539 * @typedef {{ 554 * @typedef {{
540 * icon: ?UI.Icon, 555 * icon: ?UI.Icon,
541 * enableDecorator: boolean, 556 * enableDecorator: boolean,
542 * uiLocation: ?Workspace.UILocation, 557 * uiLocation: ?Workspace.UILocation,
543 * liveLocation: ?Bindings.LiveLocation, 558 * liveLocation: ?Bindings.LiveLocation,
544 * url: ?string, 559 * url: ?string,
545 * lineNumber: ?number, 560 * lineNumber: ?number,
546 * columnNumber: ?number, 561 * columnNumber: ?number,
547 * revealable: ?Object, 562 * revealable: ?Object,
548 * fallback: ?Element 563 * fallback: ?Element,
564 * originalLinkText: string
549 * }} 565 * }}
550 */ 566 */
551 Components._LinkInfo; 567 Components._LinkInfo;
552 568
553 /** 569 /**
554 * The maximum number of characters to display in a URL.
555 * @const
556 * @type {number}
557 */
558 Components.Linkifier.MaxLengthForDisplayedURLs = 150;
559
560 /**
561 * The maximum length before strings are considered too long for finding URLs. 570 * The maximum length before strings are considered too long for finding URLs.
562 * @const 571 * @const
563 * @type {number} 572 * @type {number}
564 */ 573 */
565 Components.Linkifier.MaxLengthToIgnoreLinkifier = 10000; 574 Components.Linkifier.MaxLengthToIgnoreLinkifier = 10000;
566 575
567 /** 576 /**
568 * @typedef {function(!Common.ContentProvider, number)} 577 * @typedef {function(!Common.ContentProvider, number)}
569 */ 578 */
570 Components.Linkifier.LinkHandler; 579 Components.Linkifier.LinkHandler;
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 contextMenu.appendSeparator(); 780 contextMenu.appendSeparator();
772 contextMenu.appendItem(Common.UIString('Save'), save.bind(null, false)); 781 contextMenu.appendItem(Common.UIString('Save'), save.bind(null, false));
773 782
774 if (contentProvider instanceof Workspace.UISourceCode) { 783 if (contentProvider instanceof Workspace.UISourceCode) {
775 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (contentProvider ); 784 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (contentProvider );
776 if (!uiSourceCode.project().canSetFileContent()) 785 if (!uiSourceCode.project().canSetFileContent())
777 contextMenu.appendItem(Common.UIString.capitalize('Save ^as...'), save.b ind(null, true)); 786 contextMenu.appendItem(Common.UIString.capitalize('Save ^as...'), save.b ind(null, true));
778 } 787 }
779 } 788 }
780 }; 789 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698