| OLD | NEW |
| 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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 if (!url) { | 451 if (!url) { |
| 452 var element = createElementWithClass('span', className); | 452 var element = createElementWithClass('span', className); |
| 453 element.textContent = text || Common.UIString('(unknown)'); | 453 element.textContent = text || Common.UIString('(unknown)'); |
| 454 return element; | 454 return element; |
| 455 } | 455 } |
| 456 | 456 |
| 457 var linkText = text || Bindings.displayNameForURL(url); | 457 var linkText = text || Bindings.displayNameForURL(url); |
| 458 if (typeof lineNumber === 'number' && !text) | 458 if (typeof lineNumber === 'number' && !text) |
| 459 linkText += ':' + (lineNumber + 1); | 459 linkText += ':' + (lineNumber + 1); |
| 460 | 460 |
| 461 var anchor = createElementWithClass('a', className); | 461 var link = createElementWithClass('a', className); |
| 462 if (!url.trim().toLowerCase().startsWith('javascript:')) { | 462 if (!url.trim().toLowerCase().startsWith('javascript:')) { |
| 463 anchor.href = url; | 463 link.href = url; |
| 464 anchor.classList.add('webkit-html-resource-link'); | 464 link.classList.add('webkit-html-resource-link'); |
| 465 link[Components.Linkifier._linkSymbol] = true; |
| 466 link.addEventListener('click', Components.Linkifier._handleClick, false); |
| 465 } | 467 } |
| 466 anchor.title = linkText !== url ? url : ''; | 468 link.title = linkText !== url ? url : ''; |
| 467 anchor.textContent = linkText.trimMiddle(150); | 469 link.textContent = linkText.trimMiddle(150); |
| 468 anchor.lineNumber = lineNumber; | 470 link.lineNumber = lineNumber; |
| 469 anchor.columnNumber = columnNumber; | 471 link.columnNumber = columnNumber; |
| 470 return anchor; | 472 return link; |
| 473 } |
| 474 |
| 475 /** |
| 476 * @param {!Event} event |
| 477 */ |
| 478 static _handleClick(event) { |
| 479 var link = /** @type {!Element} */ (event.currentTarget); |
| 480 event.consume(true); |
| 481 if (link.preventFollow || UI.isBeingEdited(/** @type {!Node} */ (event.targe
t))) |
| 482 return; |
| 483 var url = link.href; |
| 484 if (Components.openAnchorLocationRegistry.dispatch({url: url, lineNumber: li
nk.lineNumber})) |
| 485 return; |
| 486 var actions = Components.Linkifier._linkActions(link); |
| 487 if (actions.length) { |
| 488 Common.Revealer.reveal(actions[0].revealable); |
| 489 return; |
| 490 } |
| 491 InspectorFrontendHost.openInNewTab(url); |
| 492 } |
| 493 |
| 494 /** |
| 495 * @param {!Element} link |
| 496 * @return {!Array<{revealable: !Object, title: string}>} |
| 497 */ |
| 498 static _linkActions(link) { |
| 499 var url = link.href; |
| 500 var result = []; |
| 501 var uiSourceCode = Workspace.workspace.uiSourceCodeForURL(url); |
| 502 if (uiSourceCode) { |
| 503 result.push({ |
| 504 revealable: uiSourceCode.uiLocation(link.lineNumber || 0, link.columnNum
ber || 0), |
| 505 title: Common.UIString('Open') |
| 506 }); |
| 507 } |
| 508 var resource = Bindings.resourceForURL(url); |
| 509 if (resource) |
| 510 result.push({revealable: resource, title: Common.UIString.capitalize('Open
^link in Application ^panel')}); |
| 511 var request = SDK.NetworkLog.requestForURL(url); |
| 512 if (request) |
| 513 result.push({revealable: request, title: Common.UIString.capitalize('Open
^request in Network ^panel')}); |
| 514 return result; |
| 471 } | 515 } |
| 472 }; | 516 }; |
| 473 | 517 |
| 474 /** @type {!Set<!Components.Linkifier>} */ | 518 /** @type {!Set<!Components.Linkifier>} */ |
| 475 Components.Linkifier._instances = new Set(); | 519 Components.Linkifier._instances = new Set(); |
| 476 /** @type {?Components.LinkDecorator} */ | 520 /** @type {?Components.LinkDecorator} */ |
| 477 Components.Linkifier._decorator = null; | 521 Components.Linkifier._decorator = null; |
| 478 | 522 |
| 479 Components.Linkifier._iconSymbol = Symbol('Linkifier.iconSymbol'); | 523 Components.Linkifier._iconSymbol = Symbol('Linkifier.iconSymbol'); |
| 480 Components.Linkifier._enableDecoratorSymbol = Symbol('Linkifier.enableIconsSymbo
l'); | 524 Components.Linkifier._enableDecoratorSymbol = Symbol('Linkifier.enableIconsSymbo
l'); |
| 481 Components.Linkifier._sourceCodeAnchors = Symbol('Linkifier.anchors'); | 525 Components.Linkifier._sourceCodeAnchors = Symbol('Linkifier.anchors'); |
| 482 Components.Linkifier._uiLocationSymbol = Symbol('uiLocation'); | 526 Components.Linkifier._uiLocationSymbol = Symbol('uiLocation'); |
| 483 Components.Linkifier._fallbackAnchorSymbol = Symbol('fallbackAnchor'); | 527 Components.Linkifier._fallbackAnchorSymbol = Symbol('fallbackAnchor'); |
| 484 Components.Linkifier._liveLocationSymbol = Symbol('liveLocation'); | 528 Components.Linkifier._liveLocationSymbol = Symbol('liveLocation'); |
| 529 Components.Linkifier._linkSymbol = Symbol('Linkifier.link'); |
| 485 | 530 |
| 486 /** | 531 /** |
| 487 * The maximum number of characters to display in a URL. | 532 * The maximum number of characters to display in a URL. |
| 488 * @const | 533 * @const |
| 489 * @type {number} | 534 * @type {number} |
| 490 */ | 535 */ |
| 491 Components.Linkifier.MaxLengthForDisplayedURLs = 150; | 536 Components.Linkifier.MaxLengthForDisplayedURLs = 150; |
| 492 | 537 |
| 493 /** | 538 /** |
| 494 * The maximum length before strings are considered too long for finding URLs. | 539 * The maximum length before strings are considered too long for finding URLs. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 * @param {number=} lineNumber | 625 * @param {number=} lineNumber |
| 581 * @param {number=} columnNumber | 626 * @param {number=} columnNumber |
| 582 * @return {!Node} | 627 * @return {!Node} |
| 583 */ | 628 */ |
| 584 function linkifier(title, url, lineNumber, columnNumber) { | 629 function linkifier(title, url, lineNumber, columnNumber) { |
| 585 return Components.Linkifier.linkifyURL(url, title, undefined, lineNumber, co
lumnNumber); | 630 return Components.Linkifier.linkifyURL(url, title, undefined, lineNumber, co
lumnNumber); |
| 586 } | 631 } |
| 587 | 632 |
| 588 return Components.linkifyStringAsFragmentWithCustomLinkifier(string, linkifier
); | 633 return Components.linkifyStringAsFragmentWithCustomLinkifier(string, linkifier
); |
| 589 }; | 634 }; |
| 635 |
| 636 /** |
| 637 * @implements {UI.ContextMenu.Provider} |
| 638 * @unrestricted |
| 639 */ |
| 640 Components.Linkifier.LinkContextMenuProvider = class { |
| 641 /** |
| 642 * @override |
| 643 * @param {!Event} event |
| 644 * @param {!UI.ContextMenu} contextMenu |
| 645 * @param {!Object} target |
| 646 */ |
| 647 appendApplicableItems(event, contextMenu, target) { |
| 648 var targetNode = /** @type {!Node} */ (target); |
| 649 while (targetNode && !targetNode[Components.Linkifier._linkSymbol]) |
| 650 targetNode = targetNode.parentNodeOrShadowHost(); |
| 651 if (!targetNode || !targetNode.href) |
| 652 return; |
| 653 var link = /** @type {!Element} */ (targetNode); |
| 654 var actions = Components.Linkifier._linkActions(link); |
| 655 for (var action of actions) |
| 656 contextMenu.appendItem(action.title, Common.Revealer.reveal.bind(Common.Re
vealer, action.revealable)); |
| 657 contextMenu.appendItem(UI.openLinkExternallyLabel(), () => InspectorFrontend
Host.openInNewTab(link.href)); |
| 658 contextMenu.appendItem(UI.copyLinkAddressLabel(), () => InspectorFrontendHos
t.copyText(link.href)); |
| 659 } |
| 660 }; |
| OLD | NEW |