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

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: 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/console/ConsoleView.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(linkText, className || '', title , url, preventClick);
360 var info = Components.Linkifier._linkInfo(link); 362 var info = Components.Linkifier._linkInfo(link);
361 if (typeof lineNumber === 'number') 363 if (typeof lineNumber === 'number')
362 info.lineNumber = lineNumber; 364 info.lineNumber = lineNumber;
363 if (typeof columnNumber === 'number') 365 if (typeof columnNumber === 'number')
364 info.columnNumber = columnNumber; 366 info.columnNumber = columnNumber;
365 return link; 367 return link;
366 } 368 }
367 369
368 /** 370 /**
369 * @param {!Object} revealable 371 * @param {!Object} revealable
370 * @param {string} text 372 * @param {string} text
371 * @param {string=} fallbackHref 373 * @param {string=} fallbackHref
372 * @return {!Element} 374 * @return {!Element}
373 */ 375 */
374 static linkifyRevealable(revealable, text, fallbackHref) { 376 static linkifyRevealable(revealable, text, fallbackHref) {
375 var link = Components.Linkifier._createLink( 377 var link = Components.Linkifier._createLink(text, '', undefined, fallbackHre f);
376 text.trimMiddle(Components.Linkifier.MaxLengthForDisplayedURLs), '', und efined, fallbackHref);
377 Components.Linkifier._linkInfo(link).revealable = revealable; 378 Components.Linkifier._linkInfo(link).revealable = revealable;
378 return link; 379 return link;
379 } 380 }
380 381
381 /** 382 /**
382 * @param {string} text 383 * @param {string} text
383 * @param {string} className 384 * @param {string} className
384 * @param {string=} title 385 * @param {string=} title
385 * @param {string=} href 386 * @param {string=} href
386 * @param {boolean=} preventClick 387 * @param {boolean=} preventClick
387 * @returns{!Element} 388 * @returns{!Element}
388 */ 389 */
389 static _createLink(text, className, title, href, preventClick) { 390 static _createLink(text, className, title, href, preventClick) {
390 var link = createElementWithClass('span', className); 391 var link = createElementWithClass('span', className);
391 link.classList.add('devtools-link'); 392 link.classList.add('devtools-link');
392 if (title) 393 if (title)
393 link.title = title; 394 link.title = title;
394 if (href) 395 if (href)
395 link.href = href; 396 link.href = href;
396 link.textContent = text; 397 link.textContent = text.trimMiddle(Components.Linkifier.MaxLengthForDisplaye dURLs);
dgozman 2016/12/14 17:25:07 Why do we trim to the same length? Previously we d
luoe 2016/12/17 01:18:19 Right, I did not intend to change this. Let me ha
397 link[Components.Linkifier._infoSymbol] = { 398 link[Components.Linkifier._infoSymbol] = {
398 icon: null, 399 icon: null,
399 enableDecorator: false, 400 enableDecorator: false,
400 uiLocation: null, 401 uiLocation: null,
401 liveLocation: null, 402 liveLocation: null,
402 url: href || null, 403 url: href || null,
403 lineNumber: null, 404 lineNumber: null,
404 columnNumber: null, 405 columnNumber: null,
405 revealable: null, 406 revealable: null,
406 fallback: null 407 fallback: null,
408 originalLinkText: text
407 }; 409 };
408 if (!preventClick) 410 if (!preventClick)
409 link.addEventListener('click', Components.Linkifier._handleClick, false); 411 link.addEventListener('click', Components.Linkifier._handleClick, false);
410 else 412 else
411 link.classList.add('devtools-link-prevent-click'); 413 link.classList.add('devtools-link-prevent-click');
412 return link; 414 return link;
413 } 415 }
414 416
415 /** 417 /**
416 * @param {?Element} link 418 * @param {?Element} link
419 * @return {?string}
420 */
421 static originalLinkText(link) {
422 var info = this._linkInfo(link);
423 return info ? info.originalLinkText : null;
424 }
425
426 /**
427 * @param {?Element} link
417 * @return {?Components._LinkInfo} 428 * @return {?Components._LinkInfo}
418 */ 429 */
419 static _linkInfo(link) { 430 static _linkInfo(link) {
420 return /** @type {?Components._LinkInfo} */ (link ? link[Components.Linkifie r._infoSymbol] || null : null); 431 return /** @type {?Components._LinkInfo} */ (link ? link[Components.Linkifie r._infoSymbol] || null : null);
421 } 432 }
422 433
423 /** 434 /**
424 * @param {!Event} event 435 * @param {!Event} event
425 */ 436 */
426 static _handleClick(event) { 437 static _handleClick(event) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 /** 549 /**
539 * @typedef {{ 550 * @typedef {{
540 * icon: ?UI.Icon, 551 * icon: ?UI.Icon,
541 * enableDecorator: boolean, 552 * enableDecorator: boolean,
542 * uiLocation: ?Workspace.UILocation, 553 * uiLocation: ?Workspace.UILocation,
543 * liveLocation: ?Bindings.LiveLocation, 554 * liveLocation: ?Bindings.LiveLocation,
544 * url: ?string, 555 * url: ?string,
545 * lineNumber: ?number, 556 * lineNumber: ?number,
546 * columnNumber: ?number, 557 * columnNumber: ?number,
547 * revealable: ?Object, 558 * revealable: ?Object,
548 * fallback: ?Element 559 * fallback: ?Element,
560 * originalLinkText: string
549 * }} 561 * }}
550 */ 562 */
551 Components._LinkInfo; 563 Components._LinkInfo;
552 564
553 /** 565 /**
554 * The maximum number of characters to display in a URL. 566 * The maximum number of characters to display in a URL.
555 * @const 567 * @const
556 * @type {number} 568 * @type {number}
557 */ 569 */
558 Components.Linkifier.MaxLengthForDisplayedURLs = 150; 570 Components.Linkifier.MaxLengthForDisplayedURLs = 150;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 contextMenu.appendSeparator(); 783 contextMenu.appendSeparator();
772 contextMenu.appendItem(Common.UIString('Save'), save.bind(null, false)); 784 contextMenu.appendItem(Common.UIString('Save'), save.bind(null, false));
773 785
774 if (contentProvider instanceof Workspace.UISourceCode) { 786 if (contentProvider instanceof Workspace.UISourceCode) {
775 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (contentProvider ); 787 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (contentProvider );
776 if (!uiSourceCode.project().canSetFileContent()) 788 if (!uiSourceCode.project().canSetFileContent())
777 contextMenu.appendItem(Common.UIString.capitalize('Save ^as...'), save.b ind(null, true)); 789 contextMenu.appendItem(Common.UIString.capitalize('Save ^as...'), save.b ind(null, true));
778 } 790 }
779 } 791 }
780 }; 792 };
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/console/ConsoleView.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698