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

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

Issue 2902273002: DevTools: convert linkifyURL params into options object (Closed)
Patch Set: rebase and ac Created 3 years, 6 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 /** 142 /**
143 * @param {?SDK.Target} target 143 * @param {?SDK.Target} target
144 * @param {?string} scriptId 144 * @param {?string} scriptId
145 * @param {string} sourceURL 145 * @param {string} sourceURL
146 * @param {number} lineNumber 146 * @param {number} lineNumber
147 * @param {number=} columnNumber 147 * @param {number=} columnNumber
148 * @param {string=} classes 148 * @param {string=} classes
149 * @return {?Element} 149 * @return {?Element}
150 */ 150 */
151 maybeLinkifyScriptLocation(target, scriptId, sourceURL, lineNumber, columnNumb er, classes) { 151 maybeLinkifyScriptLocation(target, scriptId, sourceURL, lineNumber, columnNumb er, classes) {
152 var fallbackAnchor = sourceURL ? 152 var fallbackAnchor = null;
153 Components.Linkifier.linkifyURL( 153 if (sourceURL) {
154 sourceURL, undefined, classes, lineNumber, columnNumber, undefined, this._maxLength) : 154 fallbackAnchor = Components.Linkifier.linkifyURL(
155 null; 155 sourceURL,
156 {className: classes, lineNumber: lineNumber, columnNumber: columnNumbe r, maxLength: this._maxLength});
157 }
156 if (!target || target.isDisposed()) 158 if (!target || target.isDisposed())
157 return fallbackAnchor; 159 return fallbackAnchor;
158 var debuggerModel = target.model(SDK.DebuggerModel); 160 var debuggerModel = target.model(SDK.DebuggerModel);
159 if (!debuggerModel) 161 if (!debuggerModel)
160 return fallbackAnchor; 162 return fallbackAnchor;
161 163
162 var rawLocation = 164 var rawLocation =
163 (scriptId ? debuggerModel.createRawLocationByScriptId(scriptId, lineNumb er, columnNumber || 0) : null) || 165 (scriptId ? debuggerModel.createRawLocationByScriptId(scriptId, lineNumb er, columnNumber || 0) : null) ||
164 debuggerModel.createRawLocationByURL(sourceURL, lineNumber, columnNumber || 0); 166 debuggerModel.createRawLocationByURL(sourceURL, lineNumber, columnNumber || 0);
165 if (!rawLocation) 167 if (!rawLocation)
(...skipping 15 matching lines...) Expand all
181 /** 183 /**
182 * @param {?SDK.Target} target 184 * @param {?SDK.Target} target
183 * @param {?string} scriptId 185 * @param {?string} scriptId
184 * @param {string} sourceURL 186 * @param {string} sourceURL
185 * @param {number} lineNumber 187 * @param {number} lineNumber
186 * @param {number=} columnNumber 188 * @param {number=} columnNumber
187 * @param {string=} classes 189 * @param {string=} classes
188 * @return {!Element} 190 * @return {!Element}
189 */ 191 */
190 linkifyScriptLocation(target, scriptId, sourceURL, lineNumber, columnNumber, c lasses) { 192 linkifyScriptLocation(target, scriptId, sourceURL, lineNumber, columnNumber, c lasses) {
191 return this.maybeLinkifyScriptLocation(target, scriptId, sourceURL, lineNumb er, columnNumber, classes) || 193 var scriptLink = this.maybeLinkifyScriptLocation(target, scriptId, sourceURL , lineNumber, columnNumber, classes);
194 return scriptLink ||
192 Components.Linkifier.linkifyURL( 195 Components.Linkifier.linkifyURL(
193 sourceURL, undefined, classes, lineNumber, columnNumber, undefined, this._maxLength); 196 sourceURL,
197 {className: classes, lineNumber: lineNumber, columnNumber: columnNum ber, maxLength: this._maxLength});
194 } 198 }
195 199
196 /** 200 /**
197 * @param {!SDK.DebuggerModel.Location} rawLocation 201 * @param {!SDK.DebuggerModel.Location} rawLocation
198 * @param {string} fallbackUrl 202 * @param {string} fallbackUrl
199 * @param {string=} classes 203 * @param {string=} classes
200 * @return {!Element} 204 * @return {!Element}
201 */ 205 */
202 linkifyRawLocation(rawLocation, fallbackUrl, classes) { 206 linkifyRawLocation(rawLocation, fallbackUrl, classes) {
203 return this.linkifyScriptLocation( 207 return this.linkifyScriptLocation(
(...skipping 15 matching lines...) Expand all
219 /** 223 /**
220 * @param {!SDK.Target} target 224 * @param {!SDK.Target} target
221 * @param {!Protocol.Runtime.StackTrace} stackTrace 225 * @param {!Protocol.Runtime.StackTrace} stackTrace
222 * @param {string=} classes 226 * @param {string=} classes
223 * @return {!Element} 227 * @return {!Element}
224 */ 228 */
225 linkifyStackTraceTopFrame(target, stackTrace, classes) { 229 linkifyStackTraceTopFrame(target, stackTrace, classes) {
226 console.assert(stackTrace.callFrames && stackTrace.callFrames.length); 230 console.assert(stackTrace.callFrames && stackTrace.callFrames.length);
227 231
228 var topFrame = stackTrace.callFrames[0]; 232 var topFrame = stackTrace.callFrames[0];
229 var fallbackAnchor = Components.Linkifier.linkifyURL( 233 var fallbackAnchor = Components.Linkifier.linkifyURL(topFrame.url, {
230 topFrame.url, undefined, classes, topFrame.lineNumber, topFrame.columnNu mber, undefined, this._maxLength); 234 className: classes,
235 lineNumber: topFrame.lineNumber,
236 columnNumber: topFrame.columnNumber,
237 maxLength: this._maxLength
238 });
231 if (target.isDisposed()) 239 if (target.isDisposed())
232 return fallbackAnchor; 240 return fallbackAnchor;
233 241
234 var debuggerModel = target.model(SDK.DebuggerModel); 242 var debuggerModel = target.model(SDK.DebuggerModel);
235 var rawLocations = debuggerModel.createRawLocationsByStackTrace(stackTrace); 243 var rawLocations = debuggerModel.createRawLocationsByStackTrace(stackTrace);
236 if (rawLocations.length === 0) 244 if (rawLocations.length === 0)
237 return fallbackAnchor; 245 return fallbackAnchor;
238 246
239 var anchor = Components.Linkifier._createLink('', classes || ''); 247 var anchor = Components.Linkifier._createLink('', classes || '');
240 var info = Components.Linkifier._linkInfo(anchor); 248 var info = Components.Linkifier._linkInfo(anchor);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 var icon = Components.Linkifier._decorator.linkIcon(info.uiLocation.uiSource Code); 325 var icon = Components.Linkifier._decorator.linkIcon(info.uiLocation.uiSource Code);
318 if (icon) { 326 if (icon) {
319 icon.style.setProperty('margin-right', '2px'); 327 icon.style.setProperty('margin-right', '2px');
320 anchor.insertBefore(icon, anchor.firstChild); 328 anchor.insertBefore(icon, anchor.firstChild);
321 } 329 }
322 info.icon = icon; 330 info.icon = icon;
323 } 331 }
324 332
325 /** 333 /**
326 * @param {string} url 334 * @param {string} url
327 * @param {string=} text 335 * @param {!Components.LinkifyURLOptions=} options
328 * @param {string=} className
329 * @param {number=} lineNumber
330 * @param {number=} columnNumber
331 * @param {boolean=} preventClick
332 * @param {number=} maxLength
333 * @return {!Element} 336 * @return {!Element}
334 */ 337 */
335 static linkifyURL(url, text, className, lineNumber, columnNumber, preventClick , maxLength) { 338 static linkifyURL(url, options) {
339 options = options || {};
340 var text = options.text;
341 var className = options.className || '';
342 var lineNumber = options.lineNumber;
343 var columnNumber = options.columnNumber;
344 var preventClick = options.preventClick;
345 var maxLength = options.maxLength || UI.MaxLengthForDisplayedURLs;
336 if (!url || url.trim().toLowerCase().startsWith('javascript:')) { 346 if (!url || url.trim().toLowerCase().startsWith('javascript:')) {
337 var element = createElementWithClass('span', className); 347 var element = createElementWithClass('span', className);
338 element.textContent = text || url || Common.UIString('(unknown)'); 348 element.textContent = text || url || Common.UIString('(unknown)');
339 return element; 349 return element;
340 } 350 }
341 351
342 var linkText = text || Bindings.displayNameForURL(url); 352 var linkText = text || Bindings.displayNameForURL(url);
343 if (typeof lineNumber === 'number' && !text) 353 if (typeof lineNumber === 'number' && !text)
344 linkText += ':' + (lineNumber + 1); 354 linkText += ':' + (lineNumber + 1);
345 var title = linkText !== url ? url : ''; 355 var title = linkText !== url ? url : '';
346 var link = Components.Linkifier._createLink( 356 var link = Components.Linkifier._createLink(linkText, className, maxLength, title, url, preventClick);
347 linkText, className || '', maxLength || UI.MaxLengthForDisplayedURLs, ti tle, url, preventClick);
348 var info = Components.Linkifier._linkInfo(link); 357 var info = Components.Linkifier._linkInfo(link);
349 if (typeof lineNumber === 'number') 358 if (typeof lineNumber === 'number')
350 info.lineNumber = lineNumber; 359 info.lineNumber = lineNumber;
351 if (typeof columnNumber === 'number') 360 if (typeof columnNumber === 'number')
352 info.columnNumber = columnNumber; 361 info.columnNumber = columnNumber;
353 return link; 362 return link;
354 } 363 }
355 364
356 /** 365 /**
357 * @param {!Object} revealable 366 * @param {!Object} revealable
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 * url: ?string, 609 * url: ?string,
601 * lineNumber: ?number, 610 * lineNumber: ?number,
602 * columnNumber: ?number, 611 * columnNumber: ?number,
603 * revealable: ?Object, 612 * revealable: ?Object,
604 * fallback: ?Element 613 * fallback: ?Element
605 * }} 614 * }}
606 */ 615 */
607 Components._LinkInfo; 616 Components._LinkInfo;
608 617
609 /** 618 /**
619 * @typedef {{
620 * text: (string|undefined),
621 * className: (string|undefined),
622 * lineNumber: (number|undefined),
623 * columnNumber: (number|undefined),
624 * preventClick: (boolean|undefined),
625 * maxLength: (number|undefined)
626 * }}
627 */
628 Components.LinkifyURLOptions;
629
630 /**
610 * The maximum length before strings are considered too long for finding URLs. 631 * The maximum length before strings are considered too long for finding URLs.
611 * @const 632 * @const
612 * @type {number} 633 * @type {number}
613 */ 634 */
614 Components.Linkifier.MaxLengthToIgnoreLinkifier = 10000; 635 Components.Linkifier.MaxLengthToIgnoreLinkifier = 10000;
615 636
616 /** 637 /**
617 * @typedef {function(!Common.ContentProvider, number)} 638 * @typedef {function(!Common.ContentProvider, number)}
618 */ 639 */
619 Components.Linkifier.LinkHandler; 640 Components.Linkifier.LinkHandler;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 */ 706 */
686 Components.linkifyStringAsFragment = function(string) { 707 Components.linkifyStringAsFragment = function(string) {
687 /** 708 /**
688 * @param {string} title 709 * @param {string} title
689 * @param {string} url 710 * @param {string} url
690 * @param {number=} lineNumber 711 * @param {number=} lineNumber
691 * @param {number=} columnNumber 712 * @param {number=} columnNumber
692 * @return {!Node} 713 * @return {!Node}
693 */ 714 */
694 function linkifier(title, url, lineNumber, columnNumber) { 715 function linkifier(title, url, lineNumber, columnNumber) {
695 return Components.Linkifier.linkifyURL(url, title, undefined, lineNumber, co lumnNumber); 716 return Components.Linkifier.linkifyURL(url, {text: title, lineNumber: lineNu mber, columnNumber: columnNumber});
696 } 717 }
697 718
698 return Components.linkifyStringAsFragmentWithCustomLinkifier(string, linkifier ); 719 return Components.linkifyStringAsFragmentWithCustomLinkifier(string, linkifier );
699 }; 720 };
700 721
701 /** 722 /**
702 * @implements {UI.ContextMenu.Provider} 723 * @implements {UI.ContextMenu.Provider}
703 * @unrestricted 724 * @unrestricted
704 */ 725 */
705 Components.Linkifier.LinkContextMenuProvider = class { 726 Components.Linkifier.LinkContextMenuProvider = class {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 contextMenu.appendSeparator(); 841 contextMenu.appendSeparator();
821 contextMenu.appendItem(Common.UIString('Save'), save.bind(null, false)); 842 contextMenu.appendItem(Common.UIString('Save'), save.bind(null, false));
822 843
823 if (contentProvider instanceof Workspace.UISourceCode) { 844 if (contentProvider instanceof Workspace.UISourceCode) {
824 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (contentProvider ); 845 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (contentProvider );
825 if (!uiSourceCode.project().canSetFileContent()) 846 if (!uiSourceCode.project().canSetFileContent())
826 contextMenu.appendItem(Common.UIString.capitalize('Save ^as...'), save.b ind(null, true)); 847 contextMenu.appendItem(Common.UIString.capitalize('Save ^as...'), save.b ind(null, true));
827 } 848 }
828 } 849 }
829 }; 850 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698