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

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: up + test Created 4 years 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 286 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 || '', Components.Linkifier.MaxLengthForDisplayedURL s, title, url, preventClick);
dgozman 2016/12/19 18:38:01 150
luoe 2016/12/19 19:44:39 This was 150 before, but since MaxLengthForDisplay
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(
376 text.trimMiddle(Components.Linkifier.MaxLengthForDisplayedURLs), '', und efined, fallbackHref); 379 text, '', Components.Linkifier.MaxLengthForDisplayedURLs, undefined, fal lbackHref);
377 Components.Linkifier._linkInfo(link).revealable = revealable; 380 Components.Linkifier._linkInfo(link).revealable = revealable;
378 return link; 381 return link;
379 } 382 }
380 383
381 /** 384 /**
382 * @param {string} text 385 * @param {string} text
383 * @param {string} className 386 * @param {string} className
387 * @param {number=} maxLength
384 * @param {string=} title 388 * @param {string=} title
385 * @param {string=} href 389 * @param {string=} href
386 * @param {boolean=} preventClick 390 * @param {boolean=} preventClick
387 * @returns{!Element} 391 * @returns{!Element}
388 */ 392 */
389 static _createLink(text, className, title, href, preventClick) { 393 static _createLink(text, className, maxLength, title, href, preventClick) {
390 var link = createElementWithClass('span', className); 394 var link = createElementWithClass('span', className);
391 link.classList.add('devtools-link'); 395 link.classList.add('devtools-link');
392 if (title) 396 if (title)
393 link.title = title; 397 link.title = title;
394 if (href) 398 if (href)
395 link.href = href; 399 link.href = href;
396 link.textContent = text; 400 link.textContent = text;
401 if (maxLength)
402 link.textContent = link.textContent.trimMiddle(maxLength);
397 link[Components.Linkifier._infoSymbol] = { 403 link[Components.Linkifier._infoSymbol] = {
398 icon: null, 404 icon: null,
399 enableDecorator: false, 405 enableDecorator: false,
400 uiLocation: null, 406 uiLocation: null,
401 liveLocation: null, 407 liveLocation: null,
402 url: href || null, 408 url: href || null,
403 lineNumber: null, 409 lineNumber: null,
404 columnNumber: null, 410 columnNumber: null,
405 revealable: null, 411 revealable: null,
406 fallback: null 412 fallback: null,
413 originalLinkText: text
407 }; 414 };
408 if (!preventClick) 415 if (!preventClick)
409 link.addEventListener('click', Components.Linkifier._handleClick, false); 416 link.addEventListener('click', Components.Linkifier._handleClick, false);
410 else 417 else
411 link.classList.add('devtools-link-prevent-click'); 418 link.classList.add('devtools-link-prevent-click');
412 return link; 419 return link;
413 } 420 }
414 421
415 /** 422 /**
416 * @param {?Element} link 423 * @param {?Element} link
424 * @return {?string}
425 */
426 static originalLinkText(link) {
427 var info = this._linkInfo(link);
428 return info ? info.originalLinkText : null;
429 }
430
431 /**
432 * @param {?Element} link
417 * @return {?Components._LinkInfo} 433 * @return {?Components._LinkInfo}
418 */ 434 */
419 static _linkInfo(link) { 435 static _linkInfo(link) {
420 return /** @type {?Components._LinkInfo} */ (link ? link[Components.Linkifie r._infoSymbol] || null : null); 436 return /** @type {?Components._LinkInfo} */ (link ? link[Components.Linkifie r._infoSymbol] || null : null);
421 } 437 }
422 438
423 /** 439 /**
424 * @param {!Event} event 440 * @param {!Event} event
425 */ 441 */
426 static _handleClick(event) { 442 static _handleClick(event) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 /** 554 /**
539 * @typedef {{ 555 * @typedef {{
540 * icon: ?UI.Icon, 556 * icon: ?UI.Icon,
541 * enableDecorator: boolean, 557 * enableDecorator: boolean,
542 * uiLocation: ?Workspace.UILocation, 558 * uiLocation: ?Workspace.UILocation,
543 * liveLocation: ?Bindings.LiveLocation, 559 * liveLocation: ?Bindings.LiveLocation,
544 * url: ?string, 560 * url: ?string,
545 * lineNumber: ?number, 561 * lineNumber: ?number,
546 * columnNumber: ?number, 562 * columnNumber: ?number,
547 * revealable: ?Object, 563 * revealable: ?Object,
548 * fallback: ?Element 564 * fallback: ?Element,
565 * originalLinkText: string
549 * }} 566 * }}
550 */ 567 */
551 Components._LinkInfo; 568 Components._LinkInfo;
552 569
553 /** 570 /**
554 * The maximum number of characters to display in a URL. 571 * The maximum number of characters to display in a URL.
555 * @const 572 * @const
556 * @type {number} 573 * @type {number}
557 */ 574 */
558 Components.Linkifier.MaxLengthForDisplayedURLs = 150; 575 Components.Linkifier.MaxLengthForDisplayedURLs = 150;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 contextMenu.appendSeparator(); 788 contextMenu.appendSeparator();
772 contextMenu.appendItem(Common.UIString('Save'), save.bind(null, false)); 789 contextMenu.appendItem(Common.UIString('Save'), save.bind(null, false));
773 790
774 if (contentProvider instanceof Workspace.UISourceCode) { 791 if (contentProvider instanceof Workspace.UISourceCode) {
775 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (contentProvider ); 792 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (contentProvider );
776 if (!uiSourceCode.project().canSetFileContent()) 793 if (!uiSourceCode.project().canSetFileContent())
777 contextMenu.appendItem(Common.UIString.capitalize('Save ^as...'), save.b ind(null, true)); 794 contextMenu.appendItem(Common.UIString.capitalize('Save ^as...'), save.b ind(null, true));
778 } 795 }
779 } 796 }
780 }; 797 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698