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

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

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots 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 11 matching lines...) Expand all
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
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 * @implements {WebInspector.TargetManager.Observer} 32 * @implements {SDK.TargetManager.Observer}
33 * @unrestricted 33 * @unrestricted
34 */ 34 */
35 WebInspector.Linkifier = class { 35 Components.Linkifier = class {
36 /** 36 /**
37 * @param {number=} maxLengthForDisplayedURLs 37 * @param {number=} maxLengthForDisplayedURLs
38 * @param {boolean=} useLinkDecorator 38 * @param {boolean=} useLinkDecorator
39 */ 39 */
40 constructor(maxLengthForDisplayedURLs, useLinkDecorator) { 40 constructor(maxLengthForDisplayedURLs, useLinkDecorator) {
41 this._maxLength = maxLengthForDisplayedURLs || WebInspector.Linkifier.MaxLen gthForDisplayedURLs; 41 this._maxLength = maxLengthForDisplayedURLs || Components.Linkifier.MaxLengt hForDisplayedURLs;
42 /** @type {!Map<!WebInspector.Target, !Array<!Element>>} */ 42 /** @type {!Map<!SDK.Target, !Array<!Element>>} */
43 this._anchorsByTarget = new Map(); 43 this._anchorsByTarget = new Map();
44 /** @type {!Map<!WebInspector.Target, !WebInspector.LiveLocationPool>} */ 44 /** @type {!Map<!SDK.Target, !Bindings.LiveLocationPool>} */
45 this._locationPoolByTarget = new Map(); 45 this._locationPoolByTarget = new Map();
46 this._useLinkDecorator = !!useLinkDecorator; 46 this._useLinkDecorator = !!useLinkDecorator;
47 WebInspector.Linkifier._instances.add(this); 47 Components.Linkifier._instances.add(this);
48 WebInspector.targetManager.observeTargets(this); 48 SDK.targetManager.observeTargets(this);
49 } 49 }
50 50
51 /** 51 /**
52 * @param {!WebInspector.LinkDecorator} decorator 52 * @param {!Components.LinkDecorator} decorator
53 */ 53 */
54 static setLinkDecorator(decorator) { 54 static setLinkDecorator(decorator) {
55 console.assert(!WebInspector.Linkifier._decorator, 'Cannot re-register link decorator.'); 55 console.assert(!Components.Linkifier._decorator, 'Cannot re-register link de corator.');
56 WebInspector.Linkifier._decorator = decorator; 56 Components.Linkifier._decorator = decorator;
57 decorator.addEventListener(WebInspector.LinkDecorator.Events.LinkIconChanged , onLinkIconChanged); 57 decorator.addEventListener(Components.LinkDecorator.Events.LinkIconChanged, onLinkIconChanged);
58 for (var linkifier of WebInspector.Linkifier._instances) 58 for (var linkifier of Components.Linkifier._instances)
59 linkifier._updateAllAnchorDecorations(); 59 linkifier._updateAllAnchorDecorations();
60 60
61 /** 61 /**
62 * @param {!WebInspector.Event} event 62 * @param {!Common.Event} event
63 */ 63 */
64 function onLinkIconChanged(event) { 64 function onLinkIconChanged(event) {
65 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */(event.data); 65 var uiSourceCode = /** @type {!Workspace.UISourceCode} */(event.data);
66 var links = uiSourceCode[WebInspector.Linkifier._sourceCodeAnchors] || []; 66 var links = uiSourceCode[Components.Linkifier._sourceCodeAnchors] || [];
67 for (var link of links) 67 for (var link of links)
68 WebInspector.Linkifier._updateLinkDecorations(link); 68 Components.Linkifier._updateLinkDecorations(link);
69 } 69 }
70 } 70 }
71 71
72 _updateAllAnchorDecorations() { 72 _updateAllAnchorDecorations() {
73 for (var anchors of this._anchorsByTarget.values()) { 73 for (var anchors of this._anchorsByTarget.values()) {
74 for (var anchor of anchors) 74 for (var anchor of anchors)
75 WebInspector.Linkifier._updateLinkDecorations(anchor); 75 Components.Linkifier._updateLinkDecorations(anchor);
76 } 76 }
77 } 77 }
78 78
79 /** 79 /**
80 * @param {?WebInspector.Linkifier.LinkHandler} handler 80 * @param {?Components.Linkifier.LinkHandler} handler
81 */ 81 */
82 static setLinkHandler(handler) { 82 static setLinkHandler(handler) {
83 WebInspector.Linkifier._linkHandler = handler; 83 Components.Linkifier._linkHandler = handler;
84 } 84 }
85 85
86 /** 86 /**
87 * @param {string} url 87 * @param {string} url
88 * @param {number=} lineNumber 88 * @param {number=} lineNumber
89 * @return {boolean} 89 * @return {boolean}
90 */ 90 */
91 static handleLink(url, lineNumber) { 91 static handleLink(url, lineNumber) {
92 if (!WebInspector.Linkifier._linkHandler) 92 if (!Components.Linkifier._linkHandler)
93 return false; 93 return false;
94 return WebInspector.Linkifier._linkHandler.handleLink(url, lineNumber); 94 return Components.Linkifier._linkHandler.handleLink(url, lineNumber);
95 } 95 }
96 96
97 /** 97 /**
98 * @param {!Object} revealable 98 * @param {!Object} revealable
99 * @param {string} text 99 * @param {string} text
100 * @param {string=} fallbackHref 100 * @param {string=} fallbackHref
101 * @param {number=} fallbackLineNumber 101 * @param {number=} fallbackLineNumber
102 * @param {string=} title 102 * @param {string=} title
103 * @param {string=} classes 103 * @param {string=} classes
104 * @return {!Element} 104 * @return {!Element}
105 */ 105 */
106 static linkifyUsingRevealer(revealable, text, fallbackHref, fallbackLineNumber , title, classes) { 106 static linkifyUsingRevealer(revealable, text, fallbackHref, fallbackLineNumber , title, classes) {
107 var a = createElement('a'); 107 var a = createElement('a');
108 a.className = (classes || '') + ' webkit-html-resource-link'; 108 a.className = (classes || '') + ' webkit-html-resource-link';
109 a.textContent = text.trimMiddle(WebInspector.Linkifier.MaxLengthForDisplayed URLs); 109 a.textContent = text.trimMiddle(Components.Linkifier.MaxLengthForDisplayedUR Ls);
110 a.title = title || text; 110 a.title = title || text;
111 if (fallbackHref) { 111 if (fallbackHref) {
112 a.href = fallbackHref; 112 a.href = fallbackHref;
113 a.lineNumber = fallbackLineNumber; 113 a.lineNumber = fallbackLineNumber;
114 } 114 }
115 115
116 /** 116 /**
117 * @param {!Event} event 117 * @param {!Event} event
118 * @this {Object} 118 * @this {Object}
119 */ 119 */
120 function clickHandler(event) { 120 function clickHandler(event) {
121 event.stopImmediatePropagation(); 121 event.stopImmediatePropagation();
122 event.preventDefault(); 122 event.preventDefault();
123 if (fallbackHref && WebInspector.Linkifier.handleLink(fallbackHref, fallba ckLineNumber)) 123 if (fallbackHref && Components.Linkifier.handleLink(fallbackHref, fallback LineNumber))
124 return; 124 return;
125 125
126 WebInspector.Revealer.reveal(this); 126 Common.Revealer.reveal(this);
127 } 127 }
128 a.addEventListener('click', clickHandler.bind(revealable), false); 128 a.addEventListener('click', clickHandler.bind(revealable), false);
129 return a; 129 return a;
130 } 130 }
131 131
132 /** 132 /**
133 * @param {!Element} anchor 133 * @param {!Element} anchor
134 * @return {?WebInspector.UILocation} uiLocation 134 * @return {?Workspace.UILocation} uiLocation
135 */ 135 */
136 static uiLocationByAnchor(anchor) { 136 static uiLocationByAnchor(anchor) {
137 return anchor[WebInspector.Linkifier._uiLocationSymbol]; 137 return anchor[Components.Linkifier._uiLocationSymbol];
138 } 138 }
139 139
140 /** 140 /**
141 * @param {!Element} anchor 141 * @param {!Element} anchor
142 * @param {!WebInspector.UILocation} uiLocation 142 * @param {!Workspace.UILocation} uiLocation
143 */ 143 */
144 static _bindUILocation(anchor, uiLocation) { 144 static _bindUILocation(anchor, uiLocation) {
145 anchor[WebInspector.Linkifier._uiLocationSymbol] = uiLocation; 145 anchor[Components.Linkifier._uiLocationSymbol] = uiLocation;
146 if (!uiLocation) 146 if (!uiLocation)
147 return; 147 return;
148 var uiSourceCode = uiLocation.uiSourceCode; 148 var uiSourceCode = uiLocation.uiSourceCode;
149 var sourceCodeAnchors = uiSourceCode[WebInspector.Linkifier._sourceCodeAncho rs]; 149 var sourceCodeAnchors = uiSourceCode[Components.Linkifier._sourceCodeAnchors ];
150 if (!sourceCodeAnchors) { 150 if (!sourceCodeAnchors) {
151 sourceCodeAnchors = new Set(); 151 sourceCodeAnchors = new Set();
152 uiSourceCode[WebInspector.Linkifier._sourceCodeAnchors] = sourceCodeAnchor s; 152 uiSourceCode[Components.Linkifier._sourceCodeAnchors] = sourceCodeAnchors;
153 } 153 }
154 sourceCodeAnchors.add(anchor); 154 sourceCodeAnchors.add(anchor);
155 } 155 }
156 156
157 /** 157 /**
158 * @param {!Element} anchor 158 * @param {!Element} anchor
159 */ 159 */
160 static _unbindUILocation(anchor) { 160 static _unbindUILocation(anchor) {
161 if (!anchor[WebInspector.Linkifier._uiLocationSymbol]) 161 if (!anchor[Components.Linkifier._uiLocationSymbol])
162 return; 162 return;
163 163
164 var uiSourceCode = anchor[WebInspector.Linkifier._uiLocationSymbol].uiSource Code; 164 var uiSourceCode = anchor[Components.Linkifier._uiLocationSymbol].uiSourceCo de;
165 anchor[WebInspector.Linkifier._uiLocationSymbol] = null; 165 anchor[Components.Linkifier._uiLocationSymbol] = null;
166 var sourceCodeAnchors = uiSourceCode[WebInspector.Linkifier._sourceCodeAncho rs]; 166 var sourceCodeAnchors = uiSourceCode[Components.Linkifier._sourceCodeAnchors ];
167 if (sourceCodeAnchors) 167 if (sourceCodeAnchors)
168 sourceCodeAnchors.delete(anchor); 168 sourceCodeAnchors.delete(anchor);
169 } 169 }
170 170
171 /** 171 /**
172 * @param {!WebInspector.Target} target 172 * @param {!SDK.Target} target
173 * @param {string} scriptId 173 * @param {string} scriptId
174 * @param {number} lineNumber 174 * @param {number} lineNumber
175 * @param {number=} columnNumber 175 * @param {number=} columnNumber
176 * @return {string} 176 * @return {string}
177 */ 177 */
178 static liveLocationText(target, scriptId, lineNumber, columnNumber) { 178 static liveLocationText(target, scriptId, lineNumber, columnNumber) {
179 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target); 179 var debuggerModel = SDK.DebuggerModel.fromTarget(target);
180 if (!debuggerModel) 180 if (!debuggerModel)
181 return ''; 181 return '';
182 var script = debuggerModel.scriptForId(scriptId); 182 var script = debuggerModel.scriptForId(scriptId);
183 if (!script) 183 if (!script)
184 return ''; 184 return '';
185 var location = /** @type {!WebInspector.DebuggerModel.Location} */ ( 185 var location = /** @type {!SDK.DebuggerModel.Location} */ (
186 debuggerModel.createRawLocation(script, lineNumber, columnNumber || 0)); 186 debuggerModel.createRawLocation(script, lineNumber, columnNumber || 0));
187 var uiLocation = /** @type {!WebInspector.UILocation} */ ( 187 var uiLocation = /** @type {!Workspace.UILocation} */ (
188 WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(location)) ; 188 Bindings.debuggerWorkspaceBinding.rawLocationToUILocation(location));
189 return uiLocation.linkText(); 189 return uiLocation.linkText();
190 } 190 }
191 191
192 /** 192 /**
193 * @override 193 * @override
194 * @param {!WebInspector.Target} target 194 * @param {!SDK.Target} target
195 */ 195 */
196 targetAdded(target) { 196 targetAdded(target) {
197 this._anchorsByTarget.set(target, []); 197 this._anchorsByTarget.set(target, []);
198 this._locationPoolByTarget.set(target, new WebInspector.LiveLocationPool()); 198 this._locationPoolByTarget.set(target, new Bindings.LiveLocationPool());
199 } 199 }
200 200
201 /** 201 /**
202 * @override 202 * @override
203 * @param {!WebInspector.Target} target 203 * @param {!SDK.Target} target
204 */ 204 */
205 targetRemoved(target) { 205 targetRemoved(target) {
206 var locationPool = /** @type {!WebInspector.LiveLocationPool} */ (this._loca tionPoolByTarget.remove(target)); 206 var locationPool = /** @type {!Bindings.LiveLocationPool} */ (this._location PoolByTarget.remove(target));
207 locationPool.disposeAll(); 207 locationPool.disposeAll();
208 var anchors = this._anchorsByTarget.remove(target); 208 var anchors = this._anchorsByTarget.remove(target);
209 for (var anchor of anchors) { 209 for (var anchor of anchors) {
210 delete anchor[WebInspector.Linkifier._liveLocationSymbol]; 210 delete anchor[Components.Linkifier._liveLocationSymbol];
211 WebInspector.Linkifier._unbindUILocation(anchor); 211 Components.Linkifier._unbindUILocation(anchor);
212 var fallbackAnchor = anchor[WebInspector.Linkifier._fallbackAnchorSymbol]; 212 var fallbackAnchor = anchor[Components.Linkifier._fallbackAnchorSymbol];
213 if (fallbackAnchor) { 213 if (fallbackAnchor) {
214 anchor.href = fallbackAnchor.href; 214 anchor.href = fallbackAnchor.href;
215 anchor.lineNumber = fallbackAnchor.lineNumber; 215 anchor.lineNumber = fallbackAnchor.lineNumber;
216 anchor.title = fallbackAnchor.title; 216 anchor.title = fallbackAnchor.title;
217 anchor.className = fallbackAnchor.className; 217 anchor.className = fallbackAnchor.className;
218 anchor.textContent = fallbackAnchor.textContent; 218 anchor.textContent = fallbackAnchor.textContent;
219 delete anchor[WebInspector.Linkifier._fallbackAnchorSymbol]; 219 delete anchor[Components.Linkifier._fallbackAnchorSymbol];
220 } 220 }
221 } 221 }
222 } 222 }
223 223
224 /** 224 /**
225 * @param {?WebInspector.Target} target 225 * @param {?SDK.Target} target
226 * @param {?string} scriptId 226 * @param {?string} scriptId
227 * @param {string} sourceURL 227 * @param {string} sourceURL
228 * @param {number} lineNumber 228 * @param {number} lineNumber
229 * @param {number=} columnNumber 229 * @param {number=} columnNumber
230 * @param {string=} classes 230 * @param {string=} classes
231 * @return {?Element} 231 * @return {?Element}
232 */ 232 */
233 maybeLinkifyScriptLocation(target, scriptId, sourceURL, lineNumber, columnNumb er, classes) { 233 maybeLinkifyScriptLocation(target, scriptId, sourceURL, lineNumber, columnNumb er, classes) {
234 var fallbackAnchor = 234 var fallbackAnchor =
235 sourceURL ? WebInspector.linkifyResourceAsNode(sourceURL, lineNumber, co lumnNumber, classes) : null; 235 sourceURL ? Components.linkifyResourceAsNode(sourceURL, lineNumber, colu mnNumber, classes) : null;
236 if (!target || target.isDisposed()) 236 if (!target || target.isDisposed())
237 return fallbackAnchor; 237 return fallbackAnchor;
238 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target); 238 var debuggerModel = SDK.DebuggerModel.fromTarget(target);
239 if (!debuggerModel) 239 if (!debuggerModel)
240 return fallbackAnchor; 240 return fallbackAnchor;
241 241
242 var rawLocation = 242 var rawLocation =
243 (scriptId ? debuggerModel.createRawLocationByScriptId(scriptId, lineNumb er, columnNumber || 0) : null) || 243 (scriptId ? debuggerModel.createRawLocationByScriptId(scriptId, lineNumb er, columnNumber || 0) : null) ||
244 debuggerModel.createRawLocationByURL(sourceURL, lineNumber, columnNumber || 0); 244 debuggerModel.createRawLocationByURL(sourceURL, lineNumber, columnNumber || 0);
245 if (!rawLocation) 245 if (!rawLocation)
246 return fallbackAnchor; 246 return fallbackAnchor;
247 247
248 var anchor = this._createAnchor(classes); 248 var anchor = this._createAnchor(classes);
249 var liveLocation = WebInspector.debuggerWorkspaceBinding.createLiveLocation( 249 var liveLocation = Bindings.debuggerWorkspaceBinding.createLiveLocation(
250 rawLocation, this._updateAnchor.bind(this, anchor), 250 rawLocation, this._updateAnchor.bind(this, anchor),
251 /** @type {!WebInspector.LiveLocationPool} */ (this._locationPoolByTarge t.get(rawLocation.target()))); 251 /** @type {!Bindings.LiveLocationPool} */ (this._locationPoolByTarget.ge t(rawLocation.target())));
252 var anchors = /** @type {!Array<!Element>} */ (this._anchorsByTarget.get(raw Location.target())); 252 var anchors = /** @type {!Array<!Element>} */ (this._anchorsByTarget.get(raw Location.target()));
253 anchors.push(anchor); 253 anchors.push(anchor);
254 anchor[WebInspector.Linkifier._liveLocationSymbol] = liveLocation; 254 anchor[Components.Linkifier._liveLocationSymbol] = liveLocation;
255 anchor[WebInspector.Linkifier._fallbackAnchorSymbol] = fallbackAnchor; 255 anchor[Components.Linkifier._fallbackAnchorSymbol] = fallbackAnchor;
256 return anchor; 256 return anchor;
257 } 257 }
258 258
259 /** 259 /**
260 * @param {?WebInspector.Target} target 260 * @param {?SDK.Target} target
261 * @param {?string} scriptId 261 * @param {?string} scriptId
262 * @param {string} sourceURL 262 * @param {string} sourceURL
263 * @param {number} lineNumber 263 * @param {number} lineNumber
264 * @param {number=} columnNumber 264 * @param {number=} columnNumber
265 * @param {string=} classes 265 * @param {string=} classes
266 * @return {!Element} 266 * @return {!Element}
267 */ 267 */
268 linkifyScriptLocation(target, scriptId, sourceURL, lineNumber, columnNumber, c lasses) { 268 linkifyScriptLocation(target, scriptId, sourceURL, lineNumber, columnNumber, c lasses) {
269 return this.maybeLinkifyScriptLocation(target, scriptId, sourceURL, lineNumb er, columnNumber, classes) || 269 return this.maybeLinkifyScriptLocation(target, scriptId, sourceURL, lineNumb er, columnNumber, classes) ||
270 WebInspector.linkifyResourceAsNode(sourceURL, lineNumber, columnNumber, classes); 270 Components.linkifyResourceAsNode(sourceURL, lineNumber, columnNumber, cl asses);
271 } 271 }
272 272
273 /** 273 /**
274 * @param {!WebInspector.DebuggerModel.Location} rawLocation 274 * @param {!SDK.DebuggerModel.Location} rawLocation
275 * @param {string} fallbackUrl 275 * @param {string} fallbackUrl
276 * @param {string=} classes 276 * @param {string=} classes
277 * @return {!Element} 277 * @return {!Element}
278 */ 278 */
279 linkifyRawLocation(rawLocation, fallbackUrl, classes) { 279 linkifyRawLocation(rawLocation, fallbackUrl, classes) {
280 return this.linkifyScriptLocation( 280 return this.linkifyScriptLocation(
281 rawLocation.target(), rawLocation.scriptId, fallbackUrl, rawLocation.lin eNumber, rawLocation.columnNumber, 281 rawLocation.target(), rawLocation.scriptId, fallbackUrl, rawLocation.lin eNumber, rawLocation.columnNumber,
282 classes); 282 classes);
283 } 283 }
284 284
285 /** 285 /**
286 * @param {?WebInspector.Target} target 286 * @param {?SDK.Target} target
287 * @param {!Protocol.Runtime.CallFrame} callFrame 287 * @param {!Protocol.Runtime.CallFrame} callFrame
288 * @param {string=} classes 288 * @param {string=} classes
289 * @return {?Element} 289 * @return {?Element}
290 */ 290 */
291 maybeLinkifyConsoleCallFrame(target, callFrame, classes) { 291 maybeLinkifyConsoleCallFrame(target, callFrame, classes) {
292 return this.maybeLinkifyScriptLocation( 292 return this.maybeLinkifyScriptLocation(
293 target, callFrame.scriptId, callFrame.url, callFrame.lineNumber, callFra me.columnNumber, classes); 293 target, callFrame.scriptId, callFrame.url, callFrame.lineNumber, callFra me.columnNumber, classes);
294 } 294 }
295 295
296 /** 296 /**
297 * @param {!WebInspector.Target} target 297 * @param {!SDK.Target} target
298 * @param {!Protocol.Runtime.StackTrace} stackTrace 298 * @param {!Protocol.Runtime.StackTrace} stackTrace
299 * @param {string=} classes 299 * @param {string=} classes
300 * @return {!Element} 300 * @return {!Element}
301 */ 301 */
302 linkifyStackTraceTopFrame(target, stackTrace, classes) { 302 linkifyStackTraceTopFrame(target, stackTrace, classes) {
303 console.assert(stackTrace.callFrames && stackTrace.callFrames.length); 303 console.assert(stackTrace.callFrames && stackTrace.callFrames.length);
304 304
305 var topFrame = stackTrace.callFrames[0]; 305 var topFrame = stackTrace.callFrames[0];
306 var fallbackAnchor = 306 var fallbackAnchor =
307 WebInspector.linkifyResourceAsNode(topFrame.url, topFrame.lineNumber, to pFrame.columnNumber, classes); 307 Components.linkifyResourceAsNode(topFrame.url, topFrame.lineNumber, topF rame.columnNumber, classes);
308 if (target.isDisposed()) 308 if (target.isDisposed())
309 return fallbackAnchor; 309 return fallbackAnchor;
310 310
311 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target); 311 var debuggerModel = SDK.DebuggerModel.fromTarget(target);
312 var rawLocations = debuggerModel.createRawLocationsByStackTrace(stackTrace); 312 var rawLocations = debuggerModel.createRawLocationsByStackTrace(stackTrace);
313 if (rawLocations.length === 0) 313 if (rawLocations.length === 0)
314 return fallbackAnchor; 314 return fallbackAnchor;
315 315
316 var anchor = this._createAnchor(classes); 316 var anchor = this._createAnchor(classes);
317 var liveLocation = WebInspector.debuggerWorkspaceBinding.createStackTraceTop FrameLiveLocation( 317 var liveLocation = Bindings.debuggerWorkspaceBinding.createStackTraceTopFram eLiveLocation(
318 rawLocations, this._updateAnchor.bind(this, anchor), 318 rawLocations, this._updateAnchor.bind(this, anchor),
319 /** @type {!WebInspector.LiveLocationPool} */ (this._locationPoolByTarge t.get(target))); 319 /** @type {!Bindings.LiveLocationPool} */ (this._locationPoolByTarget.ge t(target)));
320 var anchors = /** @type {!Array<!Element>} */ (this._anchorsByTarget.get(tar get)); 320 var anchors = /** @type {!Array<!Element>} */ (this._anchorsByTarget.get(tar get));
321 anchors.push(anchor); 321 anchors.push(anchor);
322 anchor[WebInspector.Linkifier._liveLocationSymbol] = liveLocation; 322 anchor[Components.Linkifier._liveLocationSymbol] = liveLocation;
323 anchor[WebInspector.Linkifier._fallbackAnchorSymbol] = fallbackAnchor; 323 anchor[Components.Linkifier._fallbackAnchorSymbol] = fallbackAnchor;
324 return anchor; 324 return anchor;
325 } 325 }
326 326
327 /** 327 /**
328 * @param {!WebInspector.CSSLocation} rawLocation 328 * @param {!SDK.CSSLocation} rawLocation
329 * @param {string=} classes 329 * @param {string=} classes
330 * @return {!Element} 330 * @return {!Element}
331 */ 331 */
332 linkifyCSSLocation(rawLocation, classes) { 332 linkifyCSSLocation(rawLocation, classes) {
333 var anchor = this._createAnchor(classes); 333 var anchor = this._createAnchor(classes);
334 var liveLocation = WebInspector.cssWorkspaceBinding.createLiveLocation( 334 var liveLocation = Bindings.cssWorkspaceBinding.createLiveLocation(
335 rawLocation, this._updateAnchor.bind(this, anchor), 335 rawLocation, this._updateAnchor.bind(this, anchor),
336 /** @type {!WebInspector.LiveLocationPool} */ (this._locationPoolByTarge t.get(rawLocation.target()))); 336 /** @type {!Bindings.LiveLocationPool} */ (this._locationPoolByTarget.ge t(rawLocation.target())));
337 var anchors = /** @type {!Array<!Element>} */ (this._anchorsByTarget.get(raw Location.target())); 337 var anchors = /** @type {!Array<!Element>} */ (this._anchorsByTarget.get(raw Location.target()));
338 anchors.push(anchor); 338 anchors.push(anchor);
339 anchor[WebInspector.Linkifier._liveLocationSymbol] = liveLocation; 339 anchor[Components.Linkifier._liveLocationSymbol] = liveLocation;
340 return anchor; 340 return anchor;
341 } 341 }
342 342
343 /** 343 /**
344 * @param {!WebInspector.Target} target 344 * @param {!SDK.Target} target
345 * @param {!Element} anchor 345 * @param {!Element} anchor
346 */ 346 */
347 disposeAnchor(target, anchor) { 347 disposeAnchor(target, anchor) {
348 WebInspector.Linkifier._unbindUILocation(anchor); 348 Components.Linkifier._unbindUILocation(anchor);
349 delete anchor[WebInspector.Linkifier._fallbackAnchorSymbol]; 349 delete anchor[Components.Linkifier._fallbackAnchorSymbol];
350 var liveLocation = anchor[WebInspector.Linkifier._liveLocationSymbol]; 350 var liveLocation = anchor[Components.Linkifier._liveLocationSymbol];
351 if (liveLocation) 351 if (liveLocation)
352 liveLocation.dispose(); 352 liveLocation.dispose();
353 delete anchor[WebInspector.Linkifier._liveLocationSymbol]; 353 delete anchor[Components.Linkifier._liveLocationSymbol];
354 } 354 }
355 355
356 /** 356 /**
357 * @param {string=} classes 357 * @param {string=} classes
358 * @return {!Element} 358 * @return {!Element}
359 */ 359 */
360 _createAnchor(classes) { 360 _createAnchor(classes) {
361 var anchor = createElement('a'); 361 var anchor = createElement('a');
362 if (this._useLinkDecorator) 362 if (this._useLinkDecorator)
363 anchor[WebInspector.Linkifier._enableDecoratorSymbol] = true; 363 anchor[Components.Linkifier._enableDecoratorSymbol] = true;
364 anchor.className = (classes || '') + ' webkit-html-resource-link'; 364 anchor.className = (classes || '') + ' webkit-html-resource-link';
365 365
366 /** 366 /**
367 * @param {!Event} event 367 * @param {!Event} event
368 */ 368 */
369 function clickHandler(event) { 369 function clickHandler(event) {
370 var uiLocation = anchor[WebInspector.Linkifier._uiLocationSymbol]; 370 var uiLocation = anchor[Components.Linkifier._uiLocationSymbol];
371 if (!uiLocation) 371 if (!uiLocation)
372 return; 372 return;
373 373
374 event.consume(true); 374 event.consume(true);
375 if (WebInspector.Linkifier.handleLink(uiLocation.uiSourceCode.url(), uiLoc ation.lineNumber)) 375 if (Components.Linkifier.handleLink(uiLocation.uiSourceCode.url(), uiLocat ion.lineNumber))
376 return; 376 return;
377 WebInspector.Revealer.reveal(uiLocation); 377 Common.Revealer.reveal(uiLocation);
378 } 378 }
379 anchor.addEventListener('click', clickHandler, false); 379 anchor.addEventListener('click', clickHandler, false);
380 return anchor; 380 return anchor;
381 } 381 }
382 382
383 reset() { 383 reset() {
384 for (var target of this._anchorsByTarget.keysArray()) { 384 for (var target of this._anchorsByTarget.keysArray()) {
385 this.targetRemoved(target); 385 this.targetRemoved(target);
386 this.targetAdded(target); 386 this.targetAdded(target);
387 } 387 }
388 } 388 }
389 389
390 dispose() { 390 dispose() {
391 for (var target of this._anchorsByTarget.keysArray()) 391 for (var target of this._anchorsByTarget.keysArray())
392 this.targetRemoved(target); 392 this.targetRemoved(target);
393 WebInspector.targetManager.unobserveTargets(this); 393 SDK.targetManager.unobserveTargets(this);
394 WebInspector.Linkifier._instances.delete(this); 394 Components.Linkifier._instances.delete(this);
395 } 395 }
396 396
397 /** 397 /**
398 * @param {!Element} anchor 398 * @param {!Element} anchor
399 * @param {!WebInspector.LiveLocation} liveLocation 399 * @param {!Bindings.LiveLocation} liveLocation
400 */ 400 */
401 _updateAnchor(anchor, liveLocation) { 401 _updateAnchor(anchor, liveLocation) {
402 WebInspector.Linkifier._unbindUILocation(anchor); 402 Components.Linkifier._unbindUILocation(anchor);
403 var uiLocation = liveLocation.uiLocation(); 403 var uiLocation = liveLocation.uiLocation();
404 if (!uiLocation) 404 if (!uiLocation)
405 return; 405 return;
406 406
407 WebInspector.Linkifier._bindUILocation(anchor, uiLocation); 407 Components.Linkifier._bindUILocation(anchor, uiLocation);
408 var text = uiLocation.linkText(); 408 var text = uiLocation.linkText();
409 text = text.replace(/([a-f0-9]{7})[a-f0-9]{13}[a-f0-9]*/g, '$1\u2026'); 409 text = text.replace(/([a-f0-9]{7})[a-f0-9]{13}[a-f0-9]*/g, '$1\u2026');
410 if (this._maxLength) 410 if (this._maxLength)
411 text = text.trimMiddle(this._maxLength); 411 text = text.trimMiddle(this._maxLength);
412 anchor.textContent = text; 412 anchor.textContent = text;
413 413
414 var titleText = uiLocation.uiSourceCode.url(); 414 var titleText = uiLocation.uiSourceCode.url();
415 if (typeof uiLocation.lineNumber === 'number') 415 if (typeof uiLocation.lineNumber === 'number')
416 titleText += ':' + (uiLocation.lineNumber + 1); 416 titleText += ':' + (uiLocation.lineNumber + 1);
417 anchor.title = titleText; 417 anchor.title = titleText;
418 anchor.classList.toggle('webkit-html-blackbox-link', liveLocation.isBlackbox ed()); 418 anchor.classList.toggle('webkit-html-blackbox-link', liveLocation.isBlackbox ed());
419 WebInspector.Linkifier._updateLinkDecorations(anchor); 419 Components.Linkifier._updateLinkDecorations(anchor);
420 } 420 }
421 421
422 /** 422 /**
423 * @param {!Element} anchor 423 * @param {!Element} anchor
424 */ 424 */
425 static _updateLinkDecorations(anchor) { 425 static _updateLinkDecorations(anchor) {
426 if (!anchor[WebInspector.Linkifier._enableDecoratorSymbol]) 426 if (!anchor[Components.Linkifier._enableDecoratorSymbol])
427 return; 427 return;
428 var uiLocation = anchor[WebInspector.Linkifier._uiLocationSymbol]; 428 var uiLocation = anchor[Components.Linkifier._uiLocationSymbol];
429 if (!WebInspector.Linkifier._decorator || !uiLocation) 429 if (!Components.Linkifier._decorator || !uiLocation)
430 return; 430 return;
431 var icon = anchor[WebInspector.Linkifier._iconSymbol]; 431 var icon = anchor[Components.Linkifier._iconSymbol];
432 if (icon) 432 if (icon)
433 icon.remove(); 433 icon.remove();
434 icon = WebInspector.Linkifier._decorator.linkIcon(uiLocation.uiSourceCode); 434 icon = Components.Linkifier._decorator.linkIcon(uiLocation.uiSourceCode);
435 if (icon) { 435 if (icon) {
436 icon.style.setProperty('margin-right', '2px'); 436 icon.style.setProperty('margin-right', '2px');
437 anchor.insertBefore(icon, anchor.firstChild); 437 anchor.insertBefore(icon, anchor.firstChild);
438 } 438 }
439 anchor[WebInspector.Linkifier._iconSymbol] = icon; 439 anchor[Components.Linkifier._iconSymbol] = icon;
440 } 440 }
441 }; 441 };
442 442
443 /** @type {!Set<!WebInspector.Linkifier>} */ 443 /** @type {!Set<!Components.Linkifier>} */
444 WebInspector.Linkifier._instances = new Set(); 444 Components.Linkifier._instances = new Set();
445 /** @type {?WebInspector.LinkDecorator} */ 445 /** @type {?Components.LinkDecorator} */
446 WebInspector.Linkifier._decorator = null; 446 Components.Linkifier._decorator = null;
447 447
448 WebInspector.Linkifier._iconSymbol = Symbol('Linkifier.iconSymbol'); 448 Components.Linkifier._iconSymbol = Symbol('Linkifier.iconSymbol');
449 WebInspector.Linkifier._enableDecoratorSymbol = Symbol('Linkifier.enableIconsSym bol'); 449 Components.Linkifier._enableDecoratorSymbol = Symbol('Linkifier.enableIconsSymbo l');
450 WebInspector.Linkifier._sourceCodeAnchors = Symbol('Linkifier.anchors'); 450 Components.Linkifier._sourceCodeAnchors = Symbol('Linkifier.anchors');
451 WebInspector.Linkifier._uiLocationSymbol = Symbol('uiLocation'); 451 Components.Linkifier._uiLocationSymbol = Symbol('uiLocation');
452 WebInspector.Linkifier._fallbackAnchorSymbol = Symbol('fallbackAnchor'); 452 Components.Linkifier._fallbackAnchorSymbol = Symbol('fallbackAnchor');
453 WebInspector.Linkifier._liveLocationSymbol = Symbol('liveLocation'); 453 Components.Linkifier._liveLocationSymbol = Symbol('liveLocation');
454 454
455 /** 455 /**
456 * The maximum number of characters to display in a URL. 456 * The maximum number of characters to display in a URL.
457 * @const 457 * @const
458 * @type {number} 458 * @type {number}
459 */ 459 */
460 WebInspector.Linkifier.MaxLengthForDisplayedURLs = 150; 460 Components.Linkifier.MaxLengthForDisplayedURLs = 150;
461 461
462 /** 462 /**
463 * The maximum length before strings are considered too long for finding URLs. 463 * The maximum length before strings are considered too long for finding URLs.
464 * @const 464 * @const
465 * @type {number} 465 * @type {number}
466 */ 466 */
467 WebInspector.Linkifier.MaxLengthToIgnoreLinkifier = 10000; 467 Components.Linkifier.MaxLengthToIgnoreLinkifier = 10000;
468 468
469 /** 469 /**
470 * @interface 470 * @interface
471 */ 471 */
472 WebInspector.Linkifier.LinkHandler = function() {}; 472 Components.Linkifier.LinkHandler = function() {};
473 473
474 WebInspector.Linkifier.LinkHandler.prototype = { 474 Components.Linkifier.LinkHandler.prototype = {
475 /** 475 /**
476 * @param {string} url 476 * @param {string} url
477 * @param {number=} lineNumber 477 * @param {number=} lineNumber
478 * @return {boolean} 478 * @return {boolean}
479 */ 479 */
480 handleLink: function(url, lineNumber) {} 480 handleLink: function(url, lineNumber) {}
481 }; 481 };
482 482
483 /** 483 /**
484 * @extends {WebInspector.EventTarget} 484 * @extends {Common.EventTarget}
485 * @interface 485 * @interface
486 */ 486 */
487 WebInspector.LinkDecorator = function() {}; 487 Components.LinkDecorator = function() {};
488 488
489 WebInspector.LinkDecorator.prototype = { 489 Components.LinkDecorator.prototype = {
490 /** 490 /**
491 * @param {!WebInspector.UISourceCode} uiSourceCode 491 * @param {!Workspace.UISourceCode} uiSourceCode
492 * @return {?WebInspector.Icon} 492 * @return {?UI.Icon}
493 */ 493 */
494 linkIcon: function(uiSourceCode) {} 494 linkIcon: function(uiSourceCode) {}
495 }; 495 };
496 496
497 WebInspector.LinkDecorator.Events = { 497 Components.LinkDecorator.Events = {
498 LinkIconChanged: Symbol('LinkIconChanged') 498 LinkIconChanged: Symbol('LinkIconChanged')
499 }; 499 };
500 500
501 /** 501 /**
502 * @param {string} string 502 * @param {string} string
503 * @param {function(string,string,number=,number=):!Node} linkifier 503 * @param {function(string,string,number=,number=):!Node} linkifier
504 * @return {!DocumentFragment} 504 * @return {!DocumentFragment}
505 */ 505 */
506 WebInspector.linkifyStringAsFragmentWithCustomLinkifier = function(string, linki fier) { 506 Components.linkifyStringAsFragmentWithCustomLinkifier = function(string, linkifi er) {
507 var container = createDocumentFragment(); 507 var container = createDocumentFragment();
508 var linkStringRegEx = 508 var linkStringRegEx =
509 /(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\/\/|data:|www\.)[\w$\-_+*'=\|\/\\(){}[\]^% @&#~,:;.!?]{2,}[\w$\-_+*=\|\/\\({^%@&#~]/; 509 /(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\/\/|data:|www\.)[\w$\-_+*'=\|\/\\(){}[\]^% @&#~,:;.!?]{2,}[\w$\-_+*=\|\/\\({^%@&#~]/;
510 var pathLineRegex = /(?:\/[\w\.-]*)+\:[\d]+/; 510 var pathLineRegex = /(?:\/[\w\.-]*)+\:[\d]+/;
511 511
512 while (string && string.length < WebInspector.Linkifier.MaxLengthToIgnoreLinki fier) { 512 while (string && string.length < Components.Linkifier.MaxLengthToIgnoreLinkifi er) {
513 var linkString = linkStringRegEx.exec(string) || pathLineRegex.exec(string); 513 var linkString = linkStringRegEx.exec(string) || pathLineRegex.exec(string);
514 if (!linkString) 514 if (!linkString)
515 break; 515 break;
516 516
517 linkString = linkString[0]; 517 linkString = linkString[0];
518 var linkIndex = string.indexOf(linkString); 518 var linkIndex = string.indexOf(linkString);
519 var nonLink = string.substring(0, linkIndex); 519 var nonLink = string.substring(0, linkIndex);
520 container.appendChild(createTextNode(nonLink)); 520 container.appendChild(createTextNode(nonLink));
521 521
522 var title = linkString; 522 var title = linkString;
523 var realURL = (linkString.startsWith('www.') ? 'http://' + linkString : link String); 523 var realURL = (linkString.startsWith('www.') ? 'http://' + linkString : link String);
524 var splitResult = WebInspector.ParsedURL.splitLineAndColumn(realURL); 524 var splitResult = Common.ParsedURL.splitLineAndColumn(realURL);
525 var linkNode; 525 var linkNode;
526 if (splitResult) 526 if (splitResult)
527 linkNode = linkifier(title, splitResult.url, splitResult.lineNumber, split Result.columnNumber); 527 linkNode = linkifier(title, splitResult.url, splitResult.lineNumber, split Result.columnNumber);
528 else 528 else
529 linkNode = linkifier(title, realURL); 529 linkNode = linkifier(title, realURL);
530 530
531 container.appendChild(linkNode); 531 container.appendChild(linkNode);
532 string = string.substring(linkIndex + linkString.length, string.length); 532 string = string.substring(linkIndex + linkString.length, string.length);
533 } 533 }
534 534
535 if (string) 535 if (string)
536 container.appendChild(createTextNode(string)); 536 container.appendChild(createTextNode(string));
537 537
538 return container; 538 return container;
539 }; 539 };
540 540
541 /** 541 /**
542 * @param {string} string 542 * @param {string} string
543 * @return {!DocumentFragment} 543 * @return {!DocumentFragment}
544 */ 544 */
545 WebInspector.linkifyStringAsFragment = function(string) { 545 Components.linkifyStringAsFragment = function(string) {
546 /** 546 /**
547 * @param {string} title 547 * @param {string} title
548 * @param {string} url 548 * @param {string} url
549 * @param {number=} lineNumber 549 * @param {number=} lineNumber
550 * @param {number=} columnNumber 550 * @param {number=} columnNumber
551 * @return {!Node} 551 * @return {!Node}
552 */ 552 */
553 function linkifier(title, url, lineNumber, columnNumber) { 553 function linkifier(title, url, lineNumber, columnNumber) {
554 var isExternal = 554 var isExternal =
555 !WebInspector.resourceForURL(url) && !WebInspector.networkMapping.uiSour ceCodeForURLForAnyTarget(url); 555 !Bindings.resourceForURL(url) && !Bindings.networkMapping.uiSourceCodeFo rURLForAnyTarget(url);
556 var urlNode = WebInspector.linkifyURLAsNode(url, title, undefined, isExterna l); 556 var urlNode = UI.linkifyURLAsNode(url, title, undefined, isExternal);
557 if (typeof lineNumber !== 'undefined') { 557 if (typeof lineNumber !== 'undefined') {
558 urlNode.lineNumber = lineNumber; 558 urlNode.lineNumber = lineNumber;
559 if (typeof columnNumber !== 'undefined') 559 if (typeof columnNumber !== 'undefined')
560 urlNode.columnNumber = columnNumber; 560 urlNode.columnNumber = columnNumber;
561 } 561 }
562 562
563 return urlNode; 563 return urlNode;
564 } 564 }
565 565
566 return WebInspector.linkifyStringAsFragmentWithCustomLinkifier(string, linkifi er); 566 return Components.linkifyStringAsFragmentWithCustomLinkifier(string, linkifier );
567 }; 567 };
568 568
569 /** 569 /**
570 * @param {string} url 570 * @param {string} url
571 * @param {number=} lineNumber 571 * @param {number=} lineNumber
572 * @param {number=} columnNumber 572 * @param {number=} columnNumber
573 * @param {string=} classes 573 * @param {string=} classes
574 * @param {string=} tooltipText 574 * @param {string=} tooltipText
575 * @param {string=} urlDisplayName 575 * @param {string=} urlDisplayName
576 * @return {!Element} 576 * @return {!Element}
577 */ 577 */
578 WebInspector.linkifyResourceAsNode = function(url, lineNumber, columnNumber, cla sses, tooltipText, urlDisplayName) { 578 Components.linkifyResourceAsNode = function(url, lineNumber, columnNumber, class es, tooltipText, urlDisplayName) {
579 if (!url) { 579 if (!url) {
580 var element = createElementWithClass('span', classes); 580 var element = createElementWithClass('span', classes);
581 element.textContent = urlDisplayName || WebInspector.UIString('(unknown)'); 581 element.textContent = urlDisplayName || Common.UIString('(unknown)');
582 return element; 582 return element;
583 } 583 }
584 var linkText = urlDisplayName || WebInspector.displayNameForURL(url); 584 var linkText = urlDisplayName || Bindings.displayNameForURL(url);
585 if (typeof lineNumber === 'number') 585 if (typeof lineNumber === 'number')
586 linkText += ':' + (lineNumber + 1); 586 linkText += ':' + (lineNumber + 1);
587 var anchor = WebInspector.linkifyURLAsNode(url, linkText, classes, false, tool tipText); 587 var anchor = UI.linkifyURLAsNode(url, linkText, classes, false, tooltipText);
588 anchor.lineNumber = lineNumber; 588 anchor.lineNumber = lineNumber;
589 anchor.columnNumber = columnNumber; 589 anchor.columnNumber = columnNumber;
590 return anchor; 590 return anchor;
591 }; 591 };
592 592
593 /** 593 /**
594 * @param {!WebInspector.NetworkRequest} request 594 * @param {!SDK.NetworkRequest} request
595 * @return {!Element} 595 * @return {!Element}
596 */ 596 */
597 WebInspector.linkifyRequestAsNode = function(request) { 597 Components.linkifyRequestAsNode = function(request) {
598 var anchor = WebInspector.linkifyURLAsNode(request.url); 598 var anchor = UI.linkifyURLAsNode(request.url);
599 anchor.requestId = request.requestId; 599 anchor.requestId = request.requestId;
600 return anchor; 600 return anchor;
601 }; 601 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698