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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/bindings/NetworkProject.js

Issue 2756103002: DevTools: remove SDK.ResourceTreeFrame.fromXXX methods (Closed)
Patch Set: remove unused code Created 3 years, 9 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 this._eventListeners.push( 99 this._eventListeners.push(
100 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, this._s tyleSheetAdded, this), 100 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, this._s tyleSheetAdded, this),
101 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetRemoved, this. _styleSheetRemoved, this)); 101 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetRemoved, this. _styleSheetRemoved, this));
102 } 102 }
103 this._eventListeners.push(target.targetManager().addEventListener( 103 this._eventListeners.push(target.targetManager().addEventListener(
104 SDK.TargetManager.Events.SuspendStateChanged, this._suspendStateChanged, this)); 104 SDK.TargetManager.Events.SuspendStateChanged, this._suspendStateChanged, this));
105 } 105 }
106 106
107 /** 107 /**
108 * @param {!SDK.Target} target 108 * @param {!SDK.Target} target
109 * @param {?SDK.ResourceTreeFrame} frame 109 * @param {string} frameId
110 * @param {boolean} isContentScripts 110 * @param {boolean} isContentScripts
111 * @return {string} 111 * @return {string}
112 */ 112 */
113 static projectId(target, frame, isContentScripts) { 113 static projectId(target, frameId, isContentScripts) {
114 return target.id() + ':' + (frame ? frame.id : '') + ':' + (isContentScripts ? 'contentscripts' : ''); 114 return target.id() + ':' + frameId + ':' + (isContentScripts ? 'contentscrip ts' : '');
115 } 115 }
116 116
117 /** 117 /**
118 * @param {!SDK.Target} target 118 * @param {!SDK.Target} target
119 * @return {!Bindings.NetworkProject} 119 * @return {!Bindings.NetworkProject}
120 */ 120 */
121 static forTarget(target) { 121 static forTarget(target) {
122 return target[Bindings.NetworkProject._networkProjectSymbol]; 122 return target[Bindings.NetworkProject._networkProjectSymbol];
123 } 123 }
124 124
(...skipping 30 matching lines...) Expand all
155 return uiSourceCode.contentType().canonicalMimeType(); 155 return uiSourceCode.contentType().canonicalMimeType();
156 156
157 var resource = uiSourceCode[Bindings.NetworkProject._resourceSymbol]; 157 var resource = uiSourceCode[Bindings.NetworkProject._resourceSymbol];
158 if (resource) 158 if (resource)
159 return resource.mimeType; 159 return resource.mimeType;
160 var mimeType = Common.ResourceType.mimeFromURL(uiSourceCode.url()); 160 var mimeType = Common.ResourceType.mimeFromURL(uiSourceCode.url());
161 return mimeType || uiSourceCode.contentType().canonicalMimeType(); 161 return mimeType || uiSourceCode.contentType().canonicalMimeType();
162 } 162 }
163 163
164 /** 164 /**
165 * @param {?SDK.ResourceTreeFrame} frame 165 * @param {string} frameId
166 * @param {boolean} isContentScripts 166 * @param {boolean} isContentScripts
167 * @return {!Bindings.ContentProviderBasedProject} 167 * @return {!Bindings.ContentProviderBasedProject}
168 */ 168 */
169 _workspaceProject(frame, isContentScripts) { 169 _workspaceProject(frameId, isContentScripts) {
170 var projectId = Bindings.NetworkProject.projectId(this.target(), frame, isCo ntentScripts); 170 var projectId = Bindings.NetworkProject.projectId(this.target(), frameId, is ContentScripts);
171 var projectType = isContentScripts ? Workspace.projectTypes.ContentScripts : Workspace.projectTypes.Network; 171 var projectType = isContentScripts ? Workspace.projectTypes.ContentScripts : Workspace.projectTypes.Network;
172 172
173 var project = this._workspaceProjects.get(projectId); 173 var project = this._workspaceProjects.get(projectId);
174 if (project) 174 if (project)
175 return project; 175 return project;
176 176
177 project = new Bindings.ContentProviderBasedProject( 177 project = new Bindings.ContentProviderBasedProject(
178 this._workspace, projectId, projectType, '', false /* isServiceProject * /); 178 this._workspace, projectId, projectType, '', false /* isServiceProject * /);
179 project[Bindings.NetworkProject._targetSymbol] = this.target(); 179 project[Bindings.NetworkProject._targetSymbol] = this.target();
180 project[Bindings.NetworkProject._frameSymbol] = frame; 180 project[Bindings.NetworkProject._frameSymbol] =
181 frameId && this._resourceTreeModel ? this._resourceTreeModel.frameForId( frameId) : null;
181 this._workspaceProjects.set(projectId, project); 182 this._workspaceProjects.set(projectId, project);
182 return project; 183 return project;
183 } 184 }
184 185
185 /** 186 /**
186 * @param {!Common.ContentProvider} contentProvider 187 * @param {!Common.ContentProvider} contentProvider
187 * @param {?SDK.ResourceTreeFrame} frame 188 * @param {string} frameId
188 * @param {boolean} isContentScript 189 * @param {boolean} isContentScript
189 * @param {?number} contentSize 190 * @param {?number} contentSize
190 * @return {!Workspace.UISourceCode} 191 * @return {!Workspace.UISourceCode}
191 */ 192 */
192 addSourceMapFile(contentProvider, frame, isContentScript, contentSize) { 193 addSourceMapFile(contentProvider, frameId, isContentScript, contentSize) {
193 var uiSourceCode = this._createFile(contentProvider, frame, isContentScript || false); 194 var uiSourceCode = this._createFile(contentProvider, frameId, isContentScrip t || false);
194 var metadata = typeof contentSize === 'number' ? new Workspace.UISourceCodeM etadata(null, contentSize) : null; 195 var metadata = typeof contentSize === 'number' ? new Workspace.UISourceCodeM etadata(null, contentSize) : null;
195 this._addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata); 196 this._addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata);
196 return uiSourceCode; 197 return uiSourceCode;
197 } 198 }
198 199
199 /** 200 /**
200 * @param {?SDK.ResourceTreeFrame} frame 201 * @param {string} frameId
201 * @param {string} url 202 * @param {string} url
202 */ 203 */
203 _removeFileForURL(frame, url) { 204 _removeFileForURL(frameId, url) {
204 var project = this._workspaceProjects.get(Bindings.NetworkProject.projectId( this.target(), frame, false)); 205 var project = this._workspaceProjects.get(Bindings.NetworkProject.projectId( this.target(), frameId, false));
205 if (!project) 206 if (!project)
206 return; 207 return;
207 project.removeFile(url); 208 project.removeFile(url);
208 } 209 }
209 210
210 _populate() { 211 _populate() {
211 /** 212 /**
212 * @param {!SDK.ResourceTreeFrame} frame 213 * @param {!SDK.ResourceTreeFrame} frame
213 * @this {Bindings.NetworkProject} 214 * @this {Bindings.NetworkProject}
214 */ 215 */
(...skipping 29 matching lines...) Expand all
244 var script = /** @type {!SDK.Script} */ (event.data); 245 var script = /** @type {!SDK.Script} */ (event.data);
245 if (!script.sourceURL || script.isLiveEdit() || (script.isInlineScript() && !script.hasSourceURL)) 246 if (!script.sourceURL || script.isLiveEdit() || (script.isInlineScript() && !script.hasSourceURL))
246 return; 247 return;
247 // Filter out embedder injected content scripts. 248 // Filter out embedder injected content scripts.
248 if (script.isContentScript() && !script.hasSourceURL) { 249 if (script.isContentScript() && !script.hasSourceURL) {
249 var parsedURL = new Common.ParsedURL(script.sourceURL); 250 var parsedURL = new Common.ParsedURL(script.sourceURL);
250 if (!parsedURL.isValid) 251 if (!parsedURL.isValid)
251 return; 252 return;
252 } 253 }
253 var originalContentProvider = script.originalContentProvider(); 254 var originalContentProvider = script.originalContentProvider();
254 var uiSourceCode = 255 var executionContext = script.executionContext();
255 this._createFile(originalContentProvider, SDK.ResourceTreeFrame.fromScri pt(script), script.isContentScript()); 256 var frameId = executionContext ? executionContext.frameId || '' : '';
257 var uiSourceCode = this._createFile(originalContentProvider, frameId, script .isContentScript());
256 uiSourceCode[Bindings.NetworkProject._scriptSymbol] = script; 258 uiSourceCode[Bindings.NetworkProject._scriptSymbol] = script;
257 var resource = SDK.ResourceTreeModel.resourceForURL(uiSourceCode.url()); 259 var resource = SDK.ResourceTreeModel.resourceForURL(uiSourceCode.url());
258 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, thi s._resourceMetadata(resource)); 260 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, thi s._resourceMetadata(resource));
259 } 261 }
260 262
261 /** 263 /**
262 * @param {!Common.Event} event 264 * @param {!Common.Event} event
263 */ 265 */
264 _styleSheetAdded(event) { 266 _styleSheetAdded(event) {
265 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); 267 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data);
266 if (header.isInline && !header.hasSourceURL && header.origin !== 'inspector' ) 268 if (header.isInline && !header.hasSourceURL && header.origin !== 'inspector' )
267 return; 269 return;
268 if (!header.resourceURL()) 270 if (!header.resourceURL())
269 return; 271 return;
270 272
271 var originalContentProvider = header.originalContentProvider(); 273 var originalContentProvider = header.originalContentProvider();
272 var uiSourceCode = this._createFile(originalContentProvider, SDK.ResourceTre eFrame.fromStyleSheet(header), false); 274 var uiSourceCode = this._createFile(originalContentProvider, header.frameId, false);
273 uiSourceCode[Bindings.NetworkProject._styleSheetSymbol] = header; 275 uiSourceCode[Bindings.NetworkProject._styleSheetSymbol] = header;
274 var resource = SDK.ResourceTreeModel.resourceForURL(uiSourceCode.url()); 276 var resource = SDK.ResourceTreeModel.resourceForURL(uiSourceCode.url());
275 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, thi s._resourceMetadata(resource)); 277 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, thi s._resourceMetadata(resource));
276 } 278 }
277 279
278 /** 280 /**
279 * @param {!Common.Event} event 281 * @param {!Common.Event} event
280 */ 282 */
281 _styleSheetRemoved(event) { 283 _styleSheetRemoved(event) {
282 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); 284 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data);
283 if (header.isInline && !header.hasSourceURL && header.origin !== 'inspector' ) 285 if (header.isInline && !header.hasSourceURL && header.origin !== 'inspector' )
284 return; 286 return;
285 287
286 this._removeFileForURL(SDK.ResourceTreeFrame.fromStyleSheet(header), header. resourceURL()); 288 this._removeFileForURL(header.frameId, header.resourceURL());
287 } 289 }
288 290
289 /** 291 /**
290 * @param {!Common.Event} event 292 * @param {!Common.Event} event
291 */ 293 */
292 _resourceAdded(event) { 294 _resourceAdded(event) {
293 var resource = /** @type {!SDK.Resource} */ (event.data); 295 var resource = /** @type {!SDK.Resource} */ (event.data);
294 this._addResource(resource); 296 this._addResource(resource);
295 } 297 }
296 298
(...skipping 10 matching lines...) Expand all
307 309
308 // Ignore non-images and non-fonts. 310 // Ignore non-images and non-fonts.
309 if (resourceType === Common.resourceTypes.Image && resource.mimeType && !res ource.mimeType.startsWith('image')) 311 if (resourceType === Common.resourceTypes.Image && resource.mimeType && !res ource.mimeType.startsWith('image'))
310 return; 312 return;
311 if (resourceType === Common.resourceTypes.Font && resource.mimeType && !reso urce.mimeType.includes('font')) 313 if (resourceType === Common.resourceTypes.Font && resource.mimeType && !reso urce.mimeType.includes('font'))
312 return; 314 return;
313 if ((resourceType === Common.resourceTypes.Image || resourceType === Common. resourceTypes.Font) && 315 if ((resourceType === Common.resourceTypes.Image || resourceType === Common. resourceTypes.Font) &&
314 resource.contentURL().startsWith('data:')) 316 resource.contentURL().startsWith('data:'))
315 return; 317 return;
316 318
317 var frame = SDK.ResourceTreeFrame.fromResource(resource);
318 // Never load document twice. 319 // Never load document twice.
319 var projectId = Bindings.NetworkProject.projectId(this.target(), frame, fals e); 320 var projectId = Bindings.NetworkProject.projectId(this.target(), resource.fr ameId, false);
320 var project = this._workspaceProjects.get(projectId); 321 var project = this._workspaceProjects.get(projectId);
321 if (project && project.uiSourceCodeForURL(resource.url)) 322 if (project && project.uiSourceCodeForURL(resource.url))
322 return; 323 return;
323 324
324 var uiSourceCode = this._createFile(resource, frame, false); 325 var uiSourceCode = this._createFile(resource, resource.frameId, false);
325 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource; 326 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource;
326 this._addUISourceCodeWithProvider(uiSourceCode, resource, this._resourceMeta data(resource)); 327 this._addUISourceCodeWithProvider(uiSourceCode, resource, this._resourceMeta data(resource));
327 } 328 }
328 329
329 /** 330 /**
330 * @param {!SDK.ResourceTreeFrame} frame 331 * @param {!SDK.ResourceTreeFrame} frame
331 */ 332 */
332 _removeFrameResources(frame) { 333 _removeFrameResources(frame) {
333 var project = this._workspaceProject(frame, false); 334 var project = this._workspaceProject(frame.id, false);
334 for (var resource of frame.resources()) 335 for (var resource of frame.resources())
335 project.removeUISourceCode(resource.url); 336 project.removeUISourceCode(resource.url);
336 project = this._workspaceProject(frame, true); 337 project = this._workspaceProject(frame.id, true);
337 for (var resource of frame.resources()) 338 for (var resource of frame.resources())
338 project.removeUISourceCode(resource.url); 339 project.removeUISourceCode(resource.url);
339 } 340 }
340 341
341 /** 342 /**
342 * @param {!Common.Event} event 343 * @param {!Common.Event} event
343 */ 344 */
344 _frameWillNavigate(event) { 345 _frameWillNavigate(event) {
345 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data); 346 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data);
346 this._removeFrameResources(frame); 347 this._removeFrameResources(frame);
(...skipping 16 matching lines...) Expand all
363 364
364 _suspendStateChanged() { 365 _suspendStateChanged() {
365 if (this.target().targetManager().allTargetsSuspended()) 366 if (this.target().targetManager().allTargetsSuspended())
366 this._reset(); 367 this._reset();
367 else 368 else
368 this._populate(); 369 this._populate();
369 } 370 }
370 371
371 /** 372 /**
372 * @param {!Common.ContentProvider} contentProvider 373 * @param {!Common.ContentProvider} contentProvider
373 * @param {?SDK.ResourceTreeFrame} frame 374 * @param {string} frameId
374 * @param {boolean} isContentScript 375 * @param {boolean} isContentScript
375 * @return {!Workspace.UISourceCode} 376 * @return {!Workspace.UISourceCode}
376 */ 377 */
377 _createFile(contentProvider, frame, isContentScript) { 378 _createFile(contentProvider, frameId, isContentScript) {
378 var url = contentProvider.contentURL(); 379 var url = contentProvider.contentURL();
379 var project = this._workspaceProject(frame, isContentScript); 380 var project = this._workspaceProject(frameId, isContentScript);
380 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe()); 381 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe());
381 uiSourceCode[Bindings.NetworkProject._targetSymbol] = this.target(); 382 uiSourceCode[Bindings.NetworkProject._targetSymbol] = this.target();
382 return uiSourceCode; 383 return uiSourceCode;
383 } 384 }
384 385
385 /** 386 /**
386 * @param {?SDK.Resource} resource 387 * @param {?SDK.Resource} resource
387 * @return {?Workspace.UISourceCodeMetadata} 388 * @return {?Workspace.UISourceCodeMetadata}
388 */ 389 */
389 _resourceMetadata(resource) { 390 _resourceMetadata(resource) {
(...skipping 15 matching lines...) Expand all
405 } 406 }
406 407
407 /** 408 /**
408 * @param {!Workspace.Workspace} workspace 409 * @param {!Workspace.Workspace} workspace
409 * @param {string} url 410 * @param {string} url
410 * @param {!SDK.Script} script 411 * @param {!SDK.Script} script
411 * @return {?Workspace.UISourceCode} 412 * @return {?Workspace.UISourceCode}
412 */ 413 */
413 static uiSourceCodeForScriptURL(workspace, url, script) { 414 static uiSourceCodeForScriptURL(workspace, url, script) {
414 var target = script.debuggerModel.target(); 415 var target = script.debuggerModel.target();
415 var frame = SDK.ResourceTreeFrame.fromScript(script); 416 var executionContext = script.executionContext();
416 return workspace.uiSourceCode(Bindings.NetworkProject.projectId(target, fram e, false), url) || 417 var frameId = executionContext ? executionContext.frameId || '' : '';
417 workspace.uiSourceCode(Bindings.NetworkProject.projectId(target, frame, true), url); 418 return workspace.uiSourceCode(Bindings.NetworkProject.projectId(target, fram eId, false), url) ||
419 workspace.uiSourceCode(Bindings.NetworkProject.projectId(target, frameId , true), url);
418 } 420 }
419 421
420 /** 422 /**
421 * @param {!Workspace.Workspace} workspace 423 * @param {!Workspace.Workspace} workspace
422 * @param {string} url 424 * @param {string} url
423 * @param {!SDK.CSSStyleSheetHeader} header 425 * @param {!SDK.CSSStyleSheetHeader} header
424 * @return {?Workspace.UISourceCode} 426 * @return {?Workspace.UISourceCode}
425 */ 427 */
426 static uiSourceCodeForStyleURL(workspace, url, header) { 428 static uiSourceCodeForStyleURL(workspace, url, header) {
427 var frame = SDK.ResourceTreeFrame.fromStyleSheet(header); 429 return workspace.uiSourceCode(Bindings.NetworkProject.projectId(header.targe t(), header.frameId, false), url);
428 return workspace.uiSourceCode(Bindings.NetworkProject.projectId(header.targe t(), frame, false), url);
429 } 430 }
430 }; 431 };
431 432
432 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); 433 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject');
433 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); 434 Bindings.NetworkProject._resourceSymbol = Symbol('resource');
434 Bindings.NetworkProject._scriptSymbol = Symbol('script'); 435 Bindings.NetworkProject._scriptSymbol = Symbol('script');
435 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); 436 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet');
436 Bindings.NetworkProject._targetSymbol = Symbol('target'); 437 Bindings.NetworkProject._targetSymbol = Symbol('target');
437 Bindings.NetworkProject._frameSymbol = Symbol('frame'); 438 Bindings.NetworkProject._frameSymbol = Symbol('frame');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698