Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 * @param {!SDK.Target} target | 54 * @param {!SDK.Target} target |
| 55 */ | 55 */ |
| 56 targetRemoved(target) { | 56 targetRemoved(target) { |
| 57 Bindings.NetworkProject.forTarget(target)._dispose(); | 57 Bindings.NetworkProject.forTarget(target)._dispose(); |
| 58 } | 58 } |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 /** | 61 /** |
| 62 * @unrestricted | 62 * @unrestricted |
| 63 */ | 63 */ |
| 64 Bindings.NetworkProject = class extends SDK.SDKObject { | 64 Bindings.NetworkProject = class { |
| 65 /** | 65 /** |
| 66 * @param {!SDK.Target} target | 66 * @param {!SDK.Target} target |
| 67 * @param {!Workspace.Workspace} workspace | 67 * @param {!Workspace.Workspace} workspace |
| 68 * @param {?SDK.ResourceTreeModel} resourceTreeModel | 68 * @param {?SDK.ResourceTreeModel} resourceTreeModel |
| 69 */ | 69 */ |
| 70 constructor(target, workspace, resourceTreeModel) { | 70 constructor(target, workspace, resourceTreeModel) { |
| 71 super(target); | 71 this._target = target; |
|
pfeldman
2017/04/07 18:36:03
I don't think it makes sense removing SDKObject wi
| |
| 72 this._workspace = workspace; | 72 this._workspace = workspace; |
| 73 /** @type {!Map<string, !Bindings.ContentProviderBasedProject>} */ | 73 /** @type {!Map<string, !Bindings.ContentProviderBasedProject>} */ |
| 74 this._workspaceProjects = new Map(); | 74 this._workspaceProjects = new Map(); |
| 75 this._resourceTreeModel = resourceTreeModel; | 75 this._resourceTreeModel = resourceTreeModel; |
| 76 target[Bindings.NetworkProject._networkProjectSymbol] = this; | 76 target[Bindings.NetworkProject._networkProjectSymbol] = this; |
| 77 | 77 |
| 78 this._eventListeners = []; | 78 this._eventListeners = []; |
| 79 | 79 |
| 80 if (resourceTreeModel) { | 80 if (resourceTreeModel) { |
| 81 this._eventListeners.push( | 81 this._eventListeners.push( |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 {string} frameId | 165 * @param {string} frameId |
| 166 * @param {boolean} isContentScripts | 166 * @param {boolean} isContentScripts |
| 167 * @return {!Bindings.ContentProviderBasedProject} | 167 * @return {!Bindings.ContentProviderBasedProject} |
| 168 */ | 168 */ |
| 169 _workspaceProject(frameId, isContentScripts) { | 169 _workspaceProject(frameId, isContentScripts) { |
| 170 var projectId = Bindings.NetworkProject.projectId(this.target(), frameId, is ContentScripts); | 170 var projectId = Bindings.NetworkProject.projectId(this._target, frameId, isC ontentScripts); |
| 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] = | 180 project[Bindings.NetworkProject._frameSymbol] = |
| 181 frameId && this._resourceTreeModel ? this._resourceTreeModel.frameForId( frameId) : null; | 181 frameId && this._resourceTreeModel ? this._resourceTreeModel.frameForId( frameId) : null; |
| 182 this._workspaceProjects.set(projectId, project); | 182 this._workspaceProjects.set(projectId, project); |
| 183 return project; | 183 return project; |
| 184 } | 184 } |
| 185 | 185 |
| 186 /** | 186 /** |
| 187 * @param {!Common.ContentProvider} contentProvider | 187 * @param {!Common.ContentProvider} contentProvider |
| 188 * @param {string} frameId | 188 * @param {string} frameId |
| 189 * @param {boolean} isContentScript | 189 * @param {boolean} isContentScript |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 206 this._removeFileForURL(url, frameId, isContentScript); | 206 this._removeFileForURL(url, frameId, isContentScript); |
| 207 } | 207 } |
| 208 | 208 |
| 209 /** | 209 /** |
| 210 * @param {string} frameId | 210 * @param {string} frameId |
| 211 * @param {string} url | 211 * @param {string} url |
| 212 * @param {boolean} isContentScript | 212 * @param {boolean} isContentScript |
| 213 */ | 213 */ |
| 214 _removeFileForURL(url, frameId, isContentScript) { | 214 _removeFileForURL(url, frameId, isContentScript) { |
| 215 var project = | 215 var project = |
| 216 this._workspaceProjects.get(Bindings.NetworkProject.projectId(this.targe t(), frameId, isContentScript)); | 216 this._workspaceProjects.get(Bindings.NetworkProject.projectId(this._targ et, frameId, isContentScript)); |
| 217 if (!project) | 217 if (!project) |
| 218 return; | 218 return; |
| 219 project.removeFile(url); | 219 project.removeFile(url); |
| 220 } | 220 } |
| 221 | 221 |
| 222 _populate() { | 222 _populate() { |
| 223 /** | 223 /** |
| 224 * @param {!SDK.ResourceTreeFrame} frame | 224 * @param {!SDK.ResourceTreeFrame} frame |
| 225 * @this {Bindings.NetworkProject} | 225 * @this {Bindings.NetworkProject} |
| 226 */ | 226 */ |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 // Ignore non-images and non-fonts. | 321 // Ignore non-images and non-fonts. |
| 322 if (resourceType === Common.resourceTypes.Image && resource.mimeType && !res ource.mimeType.startsWith('image')) | 322 if (resourceType === Common.resourceTypes.Image && resource.mimeType && !res ource.mimeType.startsWith('image')) |
| 323 return; | 323 return; |
| 324 if (resourceType === Common.resourceTypes.Font && resource.mimeType && !reso urce.mimeType.includes('font')) | 324 if (resourceType === Common.resourceTypes.Font && resource.mimeType && !reso urce.mimeType.includes('font')) |
| 325 return; | 325 return; |
| 326 if ((resourceType === Common.resourceTypes.Image || resourceType === Common. resourceTypes.Font) && | 326 if ((resourceType === Common.resourceTypes.Image || resourceType === Common. resourceTypes.Font) && |
| 327 resource.contentURL().startsWith('data:')) | 327 resource.contentURL().startsWith('data:')) |
| 328 return; | 328 return; |
| 329 | 329 |
| 330 // Never load document twice. | 330 // Never load document twice. |
| 331 var projectId = Bindings.NetworkProject.projectId(this.target(), resource.fr ameId, false); | 331 var projectId = Bindings.NetworkProject.projectId(this._target, resource.fra meId, false); |
| 332 var project = this._workspaceProjects.get(projectId); | 332 var project = this._workspaceProjects.get(projectId); |
| 333 if (project && project.uiSourceCodeForURL(resource.url)) | 333 if (project && project.uiSourceCodeForURL(resource.url)) |
| 334 return; | 334 return; |
| 335 | 335 |
| 336 var uiSourceCode = this._createFile(resource, resource.frameId, false); | 336 var uiSourceCode = this._createFile(resource, resource.frameId, false); |
| 337 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource; | 337 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource; |
| 338 this._addUISourceCodeWithProvider(uiSourceCode, resource, this._resourceMeta data(resource)); | 338 this._addUISourceCodeWithProvider(uiSourceCode, resource, this._resourceMeta data(resource)); |
| 339 } | 339 } |
| 340 | 340 |
| 341 /** | 341 /** |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 367 } | 367 } |
| 368 | 368 |
| 369 /** | 369 /** |
| 370 * @param {!Common.Event} event | 370 * @param {!Common.Event} event |
| 371 */ | 371 */ |
| 372 _mainFrameNavigated(event) { | 372 _mainFrameNavigated(event) { |
| 373 this._reset(); | 373 this._reset(); |
| 374 } | 374 } |
| 375 | 375 |
| 376 _suspendStateChanged() { | 376 _suspendStateChanged() { |
| 377 if (this.target().targetManager().allTargetsSuspended()) | 377 if (this._target.targetManager().allTargetsSuspended()) |
| 378 this._reset(); | 378 this._reset(); |
| 379 else | 379 else |
| 380 this._populate(); | 380 this._populate(); |
| 381 } | 381 } |
| 382 | 382 |
| 383 /** | 383 /** |
| 384 * @param {!Common.ContentProvider} contentProvider | 384 * @param {!Common.ContentProvider} contentProvider |
| 385 * @param {string} frameId | 385 * @param {string} frameId |
| 386 * @param {boolean} isContentScript | 386 * @param {boolean} isContentScript |
| 387 * @return {!Workspace.UISourceCode} | 387 * @return {!Workspace.UISourceCode} |
| 388 */ | 388 */ |
| 389 _createFile(contentProvider, frameId, isContentScript) { | 389 _createFile(contentProvider, frameId, isContentScript) { |
| 390 var url = contentProvider.contentURL(); | 390 var url = contentProvider.contentURL(); |
| 391 var project = this._workspaceProject(frameId, isContentScript); | 391 var project = this._workspaceProject(frameId, isContentScript); |
| 392 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe()); | 392 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe()); |
| 393 uiSourceCode[Bindings.NetworkProject._targetSymbol] = this.target(); | 393 uiSourceCode[Bindings.NetworkProject._targetSymbol] = this._target; |
| 394 return uiSourceCode; | 394 return uiSourceCode; |
| 395 } | 395 } |
| 396 | 396 |
| 397 /** | 397 /** |
| 398 * @param {?SDK.Resource} resource | 398 * @param {?SDK.Resource} resource |
| 399 * @return {?Workspace.UISourceCodeMetadata} | 399 * @return {?Workspace.UISourceCodeMetadata} |
| 400 */ | 400 */ |
| 401 _resourceMetadata(resource) { | 401 _resourceMetadata(resource) { |
| 402 if (!resource || (typeof resource.contentSize() !== 'number' && !resource.la stModified())) | 402 if (!resource || (typeof resource.contentSize() !== 'number' && !resource.la stModified())) |
| 403 return null; | 403 return null; |
| 404 return new Workspace.UISourceCodeMetadata(resource.lastModified(), resource. contentSize()); | 404 return new Workspace.UISourceCodeMetadata(resource.lastModified(), resource. contentSize()); |
| 405 } | 405 } |
| 406 | 406 |
| 407 _dispose() { | 407 _dispose() { |
| 408 this._reset(); | 408 this._reset(); |
| 409 Common.EventTarget.removeEventListeners(this._eventListeners); | 409 Common.EventTarget.removeEventListeners(this._eventListeners); |
| 410 delete this.target()[Bindings.NetworkProject._networkProjectSymbol]; | 410 delete this._target[Bindings.NetworkProject._networkProjectSymbol]; |
| 411 } | 411 } |
| 412 | 412 |
| 413 _reset() { | 413 _reset() { |
| 414 for (var project of this._workspaceProjects.values()) | 414 for (var project of this._workspaceProjects.values()) |
| 415 project.removeProject(); | 415 project.removeProject(); |
| 416 this._workspaceProjects.clear(); | 416 this._workspaceProjects.clear(); |
| 417 } | 417 } |
| 418 | 418 |
| 419 /** | 419 /** |
| 420 * @param {!Workspace.Workspace} workspace | 420 * @param {!Workspace.Workspace} workspace |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 441 Bindings.NetworkProject.projectId(header.cssModel().target(), header.fra meId, false), url); | 441 Bindings.NetworkProject.projectId(header.cssModel().target(), header.fra meId, false), url); |
| 442 } | 442 } |
| 443 }; | 443 }; |
| 444 | 444 |
| 445 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); | 445 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); |
| 446 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); | 446 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); |
| 447 Bindings.NetworkProject._scriptSymbol = Symbol('script'); | 447 Bindings.NetworkProject._scriptSymbol = Symbol('script'); |
| 448 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); | 448 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); |
| 449 Bindings.NetworkProject._targetSymbol = Symbol('target'); | 449 Bindings.NetworkProject._targetSymbol = Symbol('target'); |
| 450 Bindings.NetworkProject._frameSymbol = Symbol('frame'); | 450 Bindings.NetworkProject._frameSymbol = Symbol('frame'); |
| OLD | NEW |