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

Side by Side Diff: Source/devtools/front_end/sdk/Linkifier.js

Issue 404953004: DevTools: Refactor linkifyRawLocation to use fallback url (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Address aandrey's comments #2 Created 6 years, 4 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 } 44 }
45 45
46 /** 46 /**
47 * @constructor 47 * @constructor
48 * @implements {WebInspector.TargetManager.Observer} 48 * @implements {WebInspector.TargetManager.Observer}
49 * @param {!WebInspector.LinkifierFormatter=} formatter 49 * @param {!WebInspector.LinkifierFormatter=} formatter
50 */ 50 */
51 WebInspector.Linkifier = function(formatter) 51 WebInspector.Linkifier = function(formatter)
52 { 52 {
53 this._formatter = formatter || new WebInspector.Linkifier.DefaultFormatter(W ebInspector.Linkifier.MaxLengthForDisplayedURLs); 53 this._formatter = formatter || new WebInspector.Linkifier.DefaultFormatter(W ebInspector.Linkifier.MaxLengthForDisplayedURLs);
54 /** @type {!Map.<!WebInspector.Target, !Array.<{anchor: !Element, location: !WebInspector.LiveLocation}>>}*/
54 this._liveLocationsByTarget = new Map(); 55 this._liveLocationsByTarget = new Map();
55 WebInspector.targetManager.observeTargets(this); 56 WebInspector.targetManager.observeTargets(this);
56 } 57 }
57 58
58 /** 59 /**
59 * @param {!WebInspector.Linkifier.LinkHandler} handler 60 * @param {!WebInspector.Linkifier.LinkHandler} handler
60 */ 61 */
61 WebInspector.Linkifier.setLinkHandler = function(handler) 62 WebInspector.Linkifier.setLinkHandler = function(handler)
62 { 63 {
63 WebInspector.Linkifier._linkHandler = handler; 64 WebInspector.Linkifier._linkHandler = handler;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 anchor.title = anchor.__fallbackAnchor.title; 136 anchor.title = anchor.__fallbackAnchor.title;
136 anchor.className = anchor.__fallbackAnchor.className; 137 anchor.className = anchor.__fallbackAnchor.className;
137 anchor.textContent = anchor.__fallbackAnchor.textContent; 138 anchor.textContent = anchor.__fallbackAnchor.textContent;
138 } 139 }
139 liveLocations[i].location.dispose(); 140 liveLocations[i].location.dispose();
140 } 141 }
141 }, 142 },
142 143
143 /** 144 /**
144 * @param {?WebInspector.Target} target 145 * @param {?WebInspector.Target} target
145 * @param {string} scriptId 146 * @param {?string} scriptId
146 * @param {string} sourceURL 147 * @param {string} sourceURL
147 * @param {number} lineNumber 148 * @param {number} lineNumber
148 * @param {number=} columnNumber 149 * @param {number=} columnNumber
149 * @param {string=} classes 150 * @param {string=} classes
150 * @return {?Element} 151 * @return {!Element}
151 */ 152 */
152 linkifyLocationByScriptId: function(target, scriptId, sourceURL, lineNumber, columnNumber, classes) 153 linkifyScriptLocation: function(target, scriptId, sourceURL, lineNumber, col umnNumber, classes)
153 { 154 {
154 var rawLocation = target ? target.debuggerModel.createRawLocationByScrip tId(scriptId, sourceURL, lineNumber, columnNumber || 0) : null; 155 var rawLocation = target && !target.isDetached() ? target.debuggerModel. createRawLocationByScriptId(scriptId, sourceURL, lineNumber, columnNumber || 0) : null;
155 var fallbackAnchor = WebInspector.linkifyResourceAsNode(sourceURL, lineN umber, classes); 156 var fallbackAnchor = WebInspector.linkifyResourceAsNode(sourceURL, lineN umber, classes);
156 if (!rawLocation) 157 if (!rawLocation)
157 return fallbackAnchor; 158 return fallbackAnchor;
158 159
159 var anchor = this.linkifyRawLocation(rawLocation, classes); 160 var anchor = this._createAnchor(classes);
161 var liveLocation = rawLocation.createLiveLocation(this._updateAnchor.bin d(this, anchor));
162 this._liveLocationsByTarget.get(rawLocation.target()).push({anchor: anch or, location: liveLocation});
160 anchor.__fallbackAnchor = fallbackAnchor; 163 anchor.__fallbackAnchor = fallbackAnchor;
161 return anchor; 164 return anchor;
162
163 },
164
165 /**
166 * @param {!WebInspector.Target} target
167 * @param {string} sourceURL
168 * @param {number} lineNumber
169 * @param {number=} columnNumber
170 * @param {string=} classes
171 * @return {?Element}
172 */
173 linkifyLocation: function(target, sourceURL, lineNumber, columnNumber, class es)
174 {
175 var rawLocation = target.debuggerModel.createRawLocationByURL(sourceURL, lineNumber, columnNumber || 0);
176 if (!rawLocation)
177 return WebInspector.linkifyResourceAsNode(sourceURL, lineNumber, cla sses);
178 return this.linkifyRawLocation(rawLocation, classes);
179 }, 165 },
180 166
181 /** 167 /**
182 * @param {!WebInspector.DebuggerModel.Location} rawLocation 168 * @param {!WebInspector.DebuggerModel.Location} rawLocation
169 * @param {string} fallbackUrl
183 * @param {string=} classes 170 * @param {string=} classes
184 * @return {?Element} 171 * @return {!Element}
185 */ 172 */
186 linkifyRawLocation: function(rawLocation, classes) 173 linkifyRawLocation: function(rawLocation, fallbackUrl, classes)
187 { 174 {
188 // FIXME: this check should not be here. 175 return this.linkifyScriptLocation(rawLocation.target(), rawLocation.scri ptId, fallbackUrl, rawLocation.lineNumber, rawLocation.columnNumber, classes);
189 var script = rawLocation.target().debuggerModel.scriptForId(rawLocation. scriptId);
190 if (!script)
191 return null;
192 var anchor = this._createAnchor(classes);
193 var liveLocation = WebInspector.debuggerWorkspaceBinding.createLiveLocat ion(rawLocation, this._updateAnchor.bind(this, anchor));
194 this._liveLocationsByTarget.get(rawLocation.target()).push({anchor: anch or, location: liveLocation});
195 return anchor;
196 }, 176 },
197 177
198 /** 178 /**
179 * @param {?WebInspector.Target} target
180 * @param {!ConsoleAgent.CallFrame} callFrame
181 * @param {string=} classes
182 * @return {!Element}
183 */
184 linkifyConsoleCallFrame: function(target, callFrame, classes)
185 {
186 // FIXME(62725): console stack trace line/column numbers are one-based.
187 var lineNumber = callFrame.lineNumber ? callFrame.lineNumber - 1 : 0;
188 var columnNumber = callFrame.columnNumber ? callFrame.columnNumber - 1 : 0;
189 return this.linkifyScriptLocation(target, callFrame.scriptId, callFrame. url, lineNumber, columnNumber, classes);
190 },
191
192 /**
199 * @param {!WebInspector.CSSLocation} rawLocation 193 * @param {!WebInspector.CSSLocation} rawLocation
200 * @param {string=} classes 194 * @param {string=} classes
201 * @return {?Element} 195 * @return {?Element}
202 */ 196 */
203 linkifyCSSLocation: function(rawLocation, classes) 197 linkifyCSSLocation: function(rawLocation, classes)
204 { 198 {
205 var anchor = this._createAnchor(classes); 199 var anchor = this._createAnchor(classes);
206 var liveLocation = WebInspector.cssWorkspaceBinding.createLiveLocation(r awLocation, this._updateAnchor.bind(this, anchor)); 200 var liveLocation = WebInspector.cssWorkspaceBinding.createLiveLocation(r awLocation, this._updateAnchor.bind(this, anchor));
207 if (!liveLocation) 201 if (!liveLocation)
208 return null; 202 return null;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 */ 352 */
359 WebInspector.Linkifier.liveLocationText = function(target, scriptId, lineNumber, columnNumber) 353 WebInspector.Linkifier.liveLocationText = function(target, scriptId, lineNumber, columnNumber)
360 { 354 {
361 var script = target.debuggerModel.scriptForId(scriptId); 355 var script = target.debuggerModel.scriptForId(scriptId);
362 if (!script) 356 if (!script)
363 return ""; 357 return "";
364 var location = /** @type {!WebInspector.DebuggerModel.Location} */ (target.d ebuggerModel.createRawLocation(script, lineNumber, columnNumber || 0)); 358 var location = /** @type {!WebInspector.DebuggerModel.Location} */ (target.d ebuggerModel.createRawLocation(script, lineNumber, columnNumber || 0));
365 var uiLocation = /** @type {!WebInspector.UILocation} */ (WebInspector.debug gerWorkspaceBinding.rawLocationToUILocation(location)); 359 var uiLocation = /** @type {!WebInspector.UILocation} */ (WebInspector.debug gerWorkspaceBinding.rawLocationToUILocation(location));
366 return uiLocation.linkText(); 360 return uiLocation.linkText();
367 } 361 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/sdk/InspectorBackend.js ('k') | Source/devtools/front_end/sdk/Target.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698