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

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

Issue 2440953003: DevTools: use semicolons after each statement. (Closed)
Patch Set: rebaseline 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 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @interface 32 * @interface
33 */ 33 */
34 WebInspector.LinkifierFormatter = function() 34 WebInspector.LinkifierFormatter = function()
35 { 35 {
36 } 36 };
37 37
38 WebInspector.LinkifierFormatter.prototype = { 38 WebInspector.LinkifierFormatter.prototype = {
39 /** 39 /**
40 * @param {!Element} anchor 40 * @param {!Element} anchor
41 * @param {!WebInspector.UILocation} uiLocation 41 * @param {!WebInspector.UILocation} uiLocation
42 * @param {boolean} isBlackboxed 42 * @param {boolean} isBlackboxed
43 */ 43 */
44 formatLiveAnchor: function(anchor, uiLocation, isBlackboxed) { } 44 formatLiveAnchor: function(anchor, uiLocation, isBlackboxed) { }
45 } 45 };
46 46
47 /** 47 /**
48 * @constructor 48 * @constructor
49 * @implements {WebInspector.TargetManager.Observer} 49 * @implements {WebInspector.TargetManager.Observer}
50 * @param {!WebInspector.LinkifierFormatter=} formatter 50 * @param {!WebInspector.LinkifierFormatter=} formatter
51 */ 51 */
52 WebInspector.Linkifier = function(formatter) 52 WebInspector.Linkifier = function(formatter)
53 { 53 {
54 this._formatter = formatter || new WebInspector.Linkifier.DefaultFormatter(W ebInspector.Linkifier.MaxLengthForDisplayedURLs); 54 this._formatter = formatter || new WebInspector.Linkifier.DefaultFormatter(W ebInspector.Linkifier.MaxLengthForDisplayedURLs);
55 /** @type {!Map<!WebInspector.Target, !Array<!Element>>} */ 55 /** @type {!Map<!WebInspector.Target, !Array<!Element>>} */
56 this._anchorsByTarget = new Map(); 56 this._anchorsByTarget = new Map();
57 /** @type {!Map<!WebInspector.Target, !WebInspector.LiveLocationPool>} */ 57 /** @type {!Map<!WebInspector.Target, !WebInspector.LiveLocationPool>} */
58 this._locationPoolByTarget = new Map(); 58 this._locationPoolByTarget = new Map();
59 WebInspector.targetManager.observeTargets(this); 59 WebInspector.targetManager.observeTargets(this);
60 } 60 };
61 61
62 /** 62 /**
63 * @param {?WebInspector.Linkifier.LinkHandler} handler 63 * @param {?WebInspector.Linkifier.LinkHandler} handler
64 */ 64 */
65 WebInspector.Linkifier.setLinkHandler = function(handler) 65 WebInspector.Linkifier.setLinkHandler = function(handler)
66 { 66 {
67 WebInspector.Linkifier._linkHandler = handler; 67 WebInspector.Linkifier._linkHandler = handler;
68 } 68 };
69 69
70 /** 70 /**
71 * @param {string} url 71 * @param {string} url
72 * @param {number=} lineNumber 72 * @param {number=} lineNumber
73 * @return {boolean} 73 * @return {boolean}
74 */ 74 */
75 WebInspector.Linkifier.handleLink = function(url, lineNumber) 75 WebInspector.Linkifier.handleLink = function(url, lineNumber)
76 { 76 {
77 if (!WebInspector.Linkifier._linkHandler) 77 if (!WebInspector.Linkifier._linkHandler)
78 return false; 78 return false;
79 return WebInspector.Linkifier._linkHandler.handleLink(url, lineNumber); 79 return WebInspector.Linkifier._linkHandler.handleLink(url, lineNumber);
80 } 80 };
81 81
82 /** 82 /**
83 * @param {!Object} revealable 83 * @param {!Object} revealable
84 * @param {string} text 84 * @param {string} text
85 * @param {string=} fallbackHref 85 * @param {string=} fallbackHref
86 * @param {number=} fallbackLineNumber 86 * @param {number=} fallbackLineNumber
87 * @param {string=} title 87 * @param {string=} title
88 * @param {string=} classes 88 * @param {string=} classes
89 * @return {!Element} 89 * @return {!Element}
90 */ 90 */
(...skipping 15 matching lines...) Expand all
106 { 106 {
107 event.stopImmediatePropagation(); 107 event.stopImmediatePropagation();
108 event.preventDefault(); 108 event.preventDefault();
109 if (fallbackHref && WebInspector.Linkifier.handleLink(fallbackHref, fall backLineNumber)) 109 if (fallbackHref && WebInspector.Linkifier.handleLink(fallbackHref, fall backLineNumber))
110 return; 110 return;
111 111
112 WebInspector.Revealer.reveal(this); 112 WebInspector.Revealer.reveal(this);
113 } 113 }
114 a.addEventListener("click", clickHandler.bind(revealable), false); 114 a.addEventListener("click", clickHandler.bind(revealable), false);
115 return a; 115 return a;
116 } 116 };
117 117
118 WebInspector.Linkifier._uiLocationSymbol = Symbol("uiLocation"); 118 WebInspector.Linkifier._uiLocationSymbol = Symbol("uiLocation");
119 WebInspector.Linkifier._fallbackAnchorSymbol = Symbol("fallbackAnchor"); 119 WebInspector.Linkifier._fallbackAnchorSymbol = Symbol("fallbackAnchor");
120 WebInspector.Linkifier._liveLocationSymbol = Symbol("liveLocation"); 120 WebInspector.Linkifier._liveLocationSymbol = Symbol("liveLocation");
121 121
122 WebInspector.Linkifier.prototype = { 122 WebInspector.Linkifier.prototype = {
123 /** 123 /**
124 * @override 124 * @override
125 * @param {!WebInspector.Target} target 125 * @param {!WebInspector.Target} target
126 */ 126 */
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 * @param {!WebInspector.LiveLocation} liveLocation 328 * @param {!WebInspector.LiveLocation} liveLocation
329 */ 329 */
330 _updateAnchor: function(anchor, liveLocation) 330 _updateAnchor: function(anchor, liveLocation)
331 { 331 {
332 var uiLocation = liveLocation.uiLocation(); 332 var uiLocation = liveLocation.uiLocation();
333 if (!uiLocation) 333 if (!uiLocation)
334 return; 334 return;
335 anchor[WebInspector.Linkifier._uiLocationSymbol] = uiLocation; 335 anchor[WebInspector.Linkifier._uiLocationSymbol] = uiLocation;
336 this._formatter.formatLiveAnchor(anchor, uiLocation, liveLocation.isBlac kboxed()); 336 this._formatter.formatLiveAnchor(anchor, uiLocation, liveLocation.isBlac kboxed());
337 } 337 }
338 } 338 };
339 339
340 /** 340 /**
341 * @param {!Element} anchor 341 * @param {!Element} anchor
342 * @return {?WebInspector.UILocation} uiLocation 342 * @return {?WebInspector.UILocation} uiLocation
343 */ 343 */
344 WebInspector.Linkifier.uiLocationByAnchor = function(anchor) 344 WebInspector.Linkifier.uiLocationByAnchor = function(anchor)
345 { 345 {
346 return anchor[WebInspector.Linkifier._uiLocationSymbol]; 346 return anchor[WebInspector.Linkifier._uiLocationSymbol];
347 } 347 };
348 348
349 /** 349 /**
350 * @constructor 350 * @constructor
351 * @implements {WebInspector.LinkifierFormatter} 351 * @implements {WebInspector.LinkifierFormatter}
352 * @param {number=} maxLength 352 * @param {number=} maxLength
353 */ 353 */
354 WebInspector.Linkifier.DefaultFormatter = function(maxLength) 354 WebInspector.Linkifier.DefaultFormatter = function(maxLength)
355 { 355 {
356 this._maxLength = maxLength; 356 this._maxLength = maxLength;
357 } 357 };
358 358
359 WebInspector.Linkifier.DefaultFormatter.prototype = { 359 WebInspector.Linkifier.DefaultFormatter.prototype = {
360 /** 360 /**
361 * @override 361 * @override
362 * @param {!Element} anchor 362 * @param {!Element} anchor
363 * @param {!WebInspector.UILocation} uiLocation 363 * @param {!WebInspector.UILocation} uiLocation
364 * @param {boolean} isBlackboxed 364 * @param {boolean} isBlackboxed
365 */ 365 */
366 formatLiveAnchor: function(anchor, uiLocation, isBlackboxed) 366 formatLiveAnchor: function(anchor, uiLocation, isBlackboxed)
367 { 367 {
368 var text = uiLocation.linkText(); 368 var text = uiLocation.linkText();
369 text = text.replace(/([a-f0-9]{7})[a-f0-9]{13}[a-f0-9]*/g, "$1\u2026"); 369 text = text.replace(/([a-f0-9]{7})[a-f0-9]{13}[a-f0-9]*/g, "$1\u2026");
370 if (this._maxLength) 370 if (this._maxLength)
371 text = text.trimMiddle(this._maxLength); 371 text = text.trimMiddle(this._maxLength);
372 anchor.textContent = text; 372 anchor.textContent = text;
373 373
374 var titleText = uiLocation.uiSourceCode.url(); 374 var titleText = uiLocation.uiSourceCode.url();
375 if (typeof uiLocation.lineNumber === "number") 375 if (typeof uiLocation.lineNumber === "number")
376 titleText += ":" + (uiLocation.lineNumber + 1); 376 titleText += ":" + (uiLocation.lineNumber + 1);
377 anchor.title = titleText; 377 anchor.title = titleText;
378 378
379 anchor.classList.toggle("webkit-html-blackbox-link", isBlackboxed); 379 anchor.classList.toggle("webkit-html-blackbox-link", isBlackboxed);
380 } 380 }
381 } 381 };
382 382
383 /** 383 /**
384 * @constructor 384 * @constructor
385 * @extends {WebInspector.Linkifier.DefaultFormatter} 385 * @extends {WebInspector.Linkifier.DefaultFormatter}
386 */ 386 */
387 WebInspector.Linkifier.DefaultCSSFormatter = function() 387 WebInspector.Linkifier.DefaultCSSFormatter = function()
388 { 388 {
389 WebInspector.Linkifier.DefaultFormatter.call(this, WebInspector.Linkifier.De faultCSSFormatter.MaxLengthForDisplayedURLs); 389 WebInspector.Linkifier.DefaultFormatter.call(this, WebInspector.Linkifier.De faultCSSFormatter.MaxLengthForDisplayedURLs);
390 } 390 };
391 391
392 WebInspector.Linkifier.DefaultCSSFormatter.MaxLengthForDisplayedURLs = 30; 392 WebInspector.Linkifier.DefaultCSSFormatter.MaxLengthForDisplayedURLs = 30;
393 393
394 WebInspector.Linkifier.DefaultCSSFormatter.prototype = { 394 WebInspector.Linkifier.DefaultCSSFormatter.prototype = {
395 /** 395 /**
396 * @override 396 * @override
397 * @param {!Element} anchor 397 * @param {!Element} anchor
398 * @param {!WebInspector.UILocation} uiLocation 398 * @param {!WebInspector.UILocation} uiLocation
399 * @param {boolean} isBlackboxed 399 * @param {boolean} isBlackboxed
400 */ 400 */
401 formatLiveAnchor: function(anchor, uiLocation, isBlackboxed) 401 formatLiveAnchor: function(anchor, uiLocation, isBlackboxed)
402 { 402 {
403 WebInspector.Linkifier.DefaultFormatter.prototype.formatLiveAnchor.call( this, anchor, uiLocation, isBlackboxed); 403 WebInspector.Linkifier.DefaultFormatter.prototype.formatLiveAnchor.call( this, anchor, uiLocation, isBlackboxed);
404 anchor.classList.add("webkit-html-resource-link"); 404 anchor.classList.add("webkit-html-resource-link");
405 anchor.setAttribute("data-uncopyable", anchor.textContent); 405 anchor.setAttribute("data-uncopyable", anchor.textContent);
406 anchor.textContent = ""; 406 anchor.textContent = "";
407 }, 407 },
408 __proto__: WebInspector.Linkifier.DefaultFormatter.prototype 408 __proto__: WebInspector.Linkifier.DefaultFormatter.prototype
409 } 409 };
410 410
411 /** 411 /**
412 * The maximum number of characters to display in a URL. 412 * The maximum number of characters to display in a URL.
413 * @const 413 * @const
414 * @type {number} 414 * @type {number}
415 */ 415 */
416 WebInspector.Linkifier.MaxLengthForDisplayedURLs = 150; 416 WebInspector.Linkifier.MaxLengthForDisplayedURLs = 150;
417 417
418 /** 418 /**
419 * The maximum length before strings are considered too long for finding URLs. 419 * The maximum length before strings are considered too long for finding URLs.
420 * @const 420 * @const
421 * @type {number} 421 * @type {number}
422 */ 422 */
423 WebInspector.Linkifier.MaxLengthToIgnoreLinkifier = 10000; 423 WebInspector.Linkifier.MaxLengthToIgnoreLinkifier = 10000;
424 424
425 /** 425 /**
426 * @interface 426 * @interface
427 */ 427 */
428 WebInspector.Linkifier.LinkHandler = function() 428 WebInspector.Linkifier.LinkHandler = function()
429 { 429 {
430 } 430 };
431 431
432 WebInspector.Linkifier.LinkHandler.prototype = { 432 WebInspector.Linkifier.LinkHandler.prototype = {
433 /** 433 /**
434 * @param {string} url 434 * @param {string} url
435 * @param {number=} lineNumber 435 * @param {number=} lineNumber
436 * @return {boolean} 436 * @return {boolean}
437 */ 437 */
438 handleLink: function(url, lineNumber) {} 438 handleLink: function(url, lineNumber) {}
439 } 439 };
440 440
441 /** 441 /**
442 * @param {!WebInspector.Target} target 442 * @param {!WebInspector.Target} target
443 * @param {string} scriptId 443 * @param {string} scriptId
444 * @param {number} lineNumber 444 * @param {number} lineNumber
445 * @param {number=} columnNumber 445 * @param {number=} columnNumber
446 * @return {string} 446 * @return {string}
447 */ 447 */
448 WebInspector.Linkifier.liveLocationText = function(target, scriptId, lineNumber, columnNumber) 448 WebInspector.Linkifier.liveLocationText = function(target, scriptId, lineNumber, columnNumber)
449 { 449 {
450 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target); 450 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target);
451 if (!debuggerModel) 451 if (!debuggerModel)
452 return ""; 452 return "";
453 var script = debuggerModel.scriptForId(scriptId); 453 var script = debuggerModel.scriptForId(scriptId);
454 if (!script) 454 if (!script)
455 return ""; 455 return "";
456 var location = /** @type {!WebInspector.DebuggerModel.Location} */ (debugger Model.createRawLocation(script, lineNumber, columnNumber || 0)); 456 var location = /** @type {!WebInspector.DebuggerModel.Location} */ (debugger Model.createRawLocation(script, lineNumber, columnNumber || 0));
457 var uiLocation = /** @type {!WebInspector.UILocation} */ (WebInspector.debug gerWorkspaceBinding.rawLocationToUILocation(location)); 457 var uiLocation = /** @type {!WebInspector.UILocation} */ (WebInspector.debug gerWorkspaceBinding.rawLocationToUILocation(location));
458 return uiLocation.linkText(); 458 return uiLocation.linkText();
459 } 459 };
460 460
461 /** 461 /**
462 * @param {string} string 462 * @param {string} string
463 * @param {function(string,string,number=,number=):!Node} linkifier 463 * @param {function(string,string,number=,number=):!Node} linkifier
464 * @return {!DocumentFragment} 464 * @return {!DocumentFragment}
465 */ 465 */
466 WebInspector.linkifyStringAsFragmentWithCustomLinkifier = function(string, linki fier) 466 WebInspector.linkifyStringAsFragmentWithCustomLinkifier = function(string, linki fier)
467 { 467 {
468 var container = createDocumentFragment(); 468 var container = createDocumentFragment();
469 var linkStringRegEx = /(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\/\/|data:|www\.)[\w$\- _+*'=\|\/\\(){}[\]^%@&#~,:;.!?]{2,}[\w$\-_+*=\|\/\\({^%@&#~]/; 469 var linkStringRegEx = /(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\/\/|data:|www\.)[\w$\- _+*'=\|\/\\(){}[\]^%@&#~,:;.!?]{2,}[\w$\-_+*=\|\/\\({^%@&#~]/;
(...skipping 19 matching lines...) Expand all
489 linkNode = linkifier(title, realURL); 489 linkNode = linkifier(title, realURL);
490 490
491 container.appendChild(linkNode); 491 container.appendChild(linkNode);
492 string = string.substring(linkIndex + linkString.length, string.length); 492 string = string.substring(linkIndex + linkString.length, string.length);
493 } 493 }
494 494
495 if (string) 495 if (string)
496 container.appendChild(createTextNode(string)); 496 container.appendChild(createTextNode(string));
497 497
498 return container; 498 return container;
499 } 499 };
500 500
501 /** 501 /**
502 * @param {string} string 502 * @param {string} string
503 * @return {!DocumentFragment} 503 * @return {!DocumentFragment}
504 */ 504 */
505 WebInspector.linkifyStringAsFragment = function(string) 505 WebInspector.linkifyStringAsFragment = function(string)
506 { 506 {
507 /** 507 /**
508 * @param {string} title 508 * @param {string} title
509 * @param {string} url 509 * @param {string} url
510 * @param {number=} lineNumber 510 * @param {number=} lineNumber
511 * @param {number=} columnNumber 511 * @param {number=} columnNumber
512 * @return {!Node} 512 * @return {!Node}
513 */ 513 */
514 function linkifier(title, url, lineNumber, columnNumber) 514 function linkifier(title, url, lineNumber, columnNumber)
515 { 515 {
516 var isExternal = !WebInspector.resourceForURL(url) && !WebInspector.netw orkMapping.uiSourceCodeForURLForAnyTarget(url); 516 var isExternal = !WebInspector.resourceForURL(url) && !WebInspector.netw orkMapping.uiSourceCodeForURLForAnyTarget(url);
517 var urlNode = WebInspector.linkifyURLAsNode(url, title, undefined, isExt ernal); 517 var urlNode = WebInspector.linkifyURLAsNode(url, title, undefined, isExt ernal);
518 if (typeof lineNumber !== "undefined") { 518 if (typeof lineNumber !== "undefined") {
519 urlNode.lineNumber = lineNumber; 519 urlNode.lineNumber = lineNumber;
520 if (typeof columnNumber !== "undefined") 520 if (typeof columnNumber !== "undefined")
521 urlNode.columnNumber = columnNumber; 521 urlNode.columnNumber = columnNumber;
522 } 522 }
523 523
524 return urlNode; 524 return urlNode;
525 } 525 }
526 526
527 return WebInspector.linkifyStringAsFragmentWithCustomLinkifier(string, linki fier); 527 return WebInspector.linkifyStringAsFragmentWithCustomLinkifier(string, linki fier);
528 } 528 };
529 529
530 /** 530 /**
531 * @param {string} url 531 * @param {string} url
532 * @param {number=} lineNumber 532 * @param {number=} lineNumber
533 * @param {number=} columnNumber 533 * @param {number=} columnNumber
534 * @param {string=} classes 534 * @param {string=} classes
535 * @param {string=} tooltipText 535 * @param {string=} tooltipText
536 * @param {string=} urlDisplayName 536 * @param {string=} urlDisplayName
537 * @return {!Element} 537 * @return {!Element}
538 */ 538 */
539 WebInspector.linkifyResourceAsNode = function(url, lineNumber, columnNumber, cla sses, tooltipText, urlDisplayName) 539 WebInspector.linkifyResourceAsNode = function(url, lineNumber, columnNumber, cla sses, tooltipText, urlDisplayName)
540 { 540 {
541 if (!url) { 541 if (!url) {
542 var element = createElementWithClass("span", classes); 542 var element = createElementWithClass("span", classes);
543 element.textContent = urlDisplayName || WebInspector.UIString("(unknown) "); 543 element.textContent = urlDisplayName || WebInspector.UIString("(unknown) ");
544 return element; 544 return element;
545 } 545 }
546 var linkText = urlDisplayName || WebInspector.displayNameForURL(url); 546 var linkText = urlDisplayName || WebInspector.displayNameForURL(url);
547 if (typeof lineNumber === "number") 547 if (typeof lineNumber === "number")
548 linkText += ":" + (lineNumber + 1); 548 linkText += ":" + (lineNumber + 1);
549 var anchor = WebInspector.linkifyURLAsNode(url, linkText, classes, false, to oltipText); 549 var anchor = WebInspector.linkifyURLAsNode(url, linkText, classes, false, to oltipText);
550 anchor.lineNumber = lineNumber; 550 anchor.lineNumber = lineNumber;
551 anchor.columnNumber = columnNumber; 551 anchor.columnNumber = columnNumber;
552 return anchor; 552 return anchor;
553 } 553 };
554 554
555 /** 555 /**
556 * @param {!WebInspector.NetworkRequest} request 556 * @param {!WebInspector.NetworkRequest} request
557 * @return {!Element} 557 * @return {!Element}
558 */ 558 */
559 WebInspector.linkifyRequestAsNode = function(request) 559 WebInspector.linkifyRequestAsNode = function(request)
560 { 560 {
561 var anchor = WebInspector.linkifyURLAsNode(request.url); 561 var anchor = WebInspector.linkifyURLAsNode(request.url);
562 anchor.requestId = request.requestId; 562 anchor.requestId = request.requestId;
563 return anchor; 563 return anchor;
564 } 564 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698