| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 120 |
| 121 /** | 121 /** |
| 122 * @param {!SDK.Target} target | 122 * @param {!SDK.Target} target |
| 123 * @return {!Bindings.NetworkProject} | 123 * @return {!Bindings.NetworkProject} |
| 124 */ | 124 */ |
| 125 static forTarget(target) { | 125 static forTarget(target) { |
| 126 return target[Bindings.NetworkProject._networkProjectSymbol]; | 126 return target[Bindings.NetworkProject._networkProjectSymbol]; |
| 127 } | 127 } |
| 128 | 128 |
| 129 /** | 129 /** |
| 130 * @param {!Workspace.Project} project | 130 * @param {!Workspace.UISourceCode} uiSourceCode |
| 131 * @return {?SDK.Target} target | 131 * @return {?Set<string>} |
| 132 */ | 132 */ |
| 133 static targetForProject(project) { | 133 static frameAttribution(uiSourceCode) { |
| 134 return project[Bindings.NetworkProject._targetSymbol] || null; | 134 var frameId = uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol]; |
| 135 } | 135 return frameId ? new Set([frameId]) : null; |
| 136 | |
| 137 /** | |
| 138 * @param {!Workspace.Project} project | |
| 139 * @return {?SDK.ResourceTreeFrame} | |
| 140 */ | |
| 141 static frameForProject(project) { | |
| 142 return project[Bindings.NetworkProject._frameSymbol] || null; | |
| 143 } | 136 } |
| 144 | 137 |
| 145 /** | 138 /** |
| 146 * @param {!Workspace.UISourceCode} uiSourceCode | 139 * @param {!Workspace.UISourceCode} uiSourceCode |
| 147 * @return {?SDK.Target} target | 140 * @return {?SDK.Target} target |
| 148 */ | 141 */ |
| 149 static targetForUISourceCode(uiSourceCode) { | 142 static targetForUISourceCode(uiSourceCode) { |
| 150 return uiSourceCode[Bindings.NetworkProject._targetSymbol] || null; | 143 return uiSourceCode.project()[Bindings.NetworkProject._targetSymbol] || null
; |
| 151 } | 144 } |
| 152 | 145 |
| 153 /** | 146 /** |
| 147 * @param {!Workspace.UISourceCode} uiSourceCode |
| 148 * @return {!Array<!SDK.ResourceTreeFrame>} |
| 149 */ |
| 150 static framesForUISourceCode(uiSourceCode) { |
| 151 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode); |
| 152 var resourceTreeModel = target && target.model(SDK.ResourceTreeModel); |
| 153 var frameIds = Bindings.NetworkProject.frameAttribution(uiSourceCode); |
| 154 if (!resourceTreeModel || !frameIds) |
| 155 return []; |
| 156 var frames = Array.from(frameIds).map(frameId => resourceTreeModel.frameForI
d(frameId)); |
| 157 return frames.filter(frame => !!frame); |
| 158 } |
| 159 |
| 160 /** |
| 154 * @param {!Workspace.UISourceCode} uiSourceCode | 161 * @param {!Workspace.UISourceCode} uiSourceCode |
| 155 * @return {string} | 162 * @return {string} |
| 156 */ | 163 */ |
| 157 static uiSourceCodeMimeType(uiSourceCode) { | 164 static uiSourceCodeMimeType(uiSourceCode) { |
| 158 if (uiSourceCode[Bindings.NetworkProject._scriptSymbol] || uiSourceCode[Bind
ings.NetworkProject._styleSheetSymbol]) | 165 if (uiSourceCode[Bindings.NetworkProject._scriptSymbol] || uiSourceCode[Bind
ings.NetworkProject._styleSheetSymbol]) |
| 159 return uiSourceCode.contentType().canonicalMimeType(); | 166 return uiSourceCode.contentType().canonicalMimeType(); |
| 160 | 167 |
| 161 var resource = uiSourceCode[Bindings.NetworkProject._resourceSymbol]; | 168 var resource = uiSourceCode[Bindings.NetworkProject._resourceSymbol]; |
| 162 if (resource) | 169 if (resource) |
| 163 return resource.mimeType; | 170 return resource.mimeType; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 174 var projectId = Bindings.NetworkProject.projectId(this._target, frameId, isC
ontentScripts); | 181 var projectId = Bindings.NetworkProject.projectId(this._target, frameId, isC
ontentScripts); |
| 175 var projectType = isContentScripts ? Workspace.projectTypes.ContentScripts :
Workspace.projectTypes.Network; | 182 var projectType = isContentScripts ? Workspace.projectTypes.ContentScripts :
Workspace.projectTypes.Network; |
| 176 | 183 |
| 177 var project = this._workspaceProjects.get(projectId); | 184 var project = this._workspaceProjects.get(projectId); |
| 178 if (project) | 185 if (project) |
| 179 return project; | 186 return project; |
| 180 | 187 |
| 181 project = new Bindings.ContentProviderBasedProject( | 188 project = new Bindings.ContentProviderBasedProject( |
| 182 this._workspace, projectId, projectType, '', false /* isServiceProject *
/); | 189 this._workspace, projectId, projectType, '', false /* isServiceProject *
/); |
| 183 project[Bindings.NetworkProject._targetSymbol] = this._target; | 190 project[Bindings.NetworkProject._targetSymbol] = this._target; |
| 184 project[Bindings.NetworkProject._frameSymbol] = | |
| 185 frameId && this._resourceTreeModel ? this._resourceTreeModel.frameForId(
frameId) : null; | |
| 186 this._workspaceProjects.set(projectId, project); | 191 this._workspaceProjects.set(projectId, project); |
| 187 return project; | 192 return project; |
| 188 } | 193 } |
| 189 | 194 |
| 190 /** | 195 /** |
| 191 * @param {!Common.ContentProvider} contentProvider | 196 * @param {!Common.ContentProvider} contentProvider |
| 192 * @param {string} frameId | 197 * @param {string} frameId |
| 193 * @param {boolean} isContentScript | 198 * @param {boolean} isContentScript |
| 194 * @param {?number} contentSize | 199 * @param {?number} contentSize |
| 195 * @return {!Workspace.UISourceCode} | 200 * @return {!Workspace.UISourceCode} |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 } | 275 } |
| 271 | 276 |
| 272 /** | 277 /** |
| 273 * @param {!Common.Event} event | 278 * @param {!Common.Event} event |
| 274 */ | 279 */ |
| 275 _parsedScriptSource(event) { | 280 _parsedScriptSource(event) { |
| 276 var script = /** @type {!SDK.Script} */ (event.data); | 281 var script = /** @type {!SDK.Script} */ (event.data); |
| 277 if (!this._acceptsScript(script)) | 282 if (!this._acceptsScript(script)) |
| 278 return; | 283 return; |
| 279 var originalContentProvider = script.originalContentProvider(); | 284 var originalContentProvider = script.originalContentProvider(); |
| 280 var executionContext = script.executionContext(); | 285 var frameId = Bindings.frameIdForScript(script); |
| 281 var frameId = executionContext ? executionContext.frameId || '' : ''; | |
| 282 script[Bindings.NetworkProject._frameIdSymbol] = frameId; | 286 script[Bindings.NetworkProject._frameIdSymbol] = frameId; |
| 283 var uiSourceCode = this._createFile(originalContentProvider, frameId, script
.isContentScript()); | 287 var uiSourceCode = this._createFile(originalContentProvider, frameId, script
.isContentScript()); |
| 284 uiSourceCode[Bindings.NetworkProject._scriptSymbol] = script; | 288 uiSourceCode[Bindings.NetworkProject._scriptSymbol] = script; |
| 285 var resource = SDK.ResourceTreeModel.resourceForURL(uiSourceCode.url()); | 289 var metadata = this._fetchMetadata(frameId, uiSourceCode.url()); |
| 286 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, thi
s._resourceMetadata(resource)); | 290 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, met
adata); |
| 287 } | 291 } |
| 288 | 292 |
| 289 /** | 293 /** |
| 290 * @param {!Common.Event} event | 294 * @param {!Common.Event} event |
| 291 */ | 295 */ |
| 292 _executionContextDestroyed(event) { | 296 _executionContextDestroyed(event) { |
| 293 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); | 297 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); |
| 294 var scripts = this._debuggerModel.scriptsForExecutionContext(executionContex
t); | 298 var scripts = this._debuggerModel.scriptsForExecutionContext(executionContex
t); |
| 295 for (var script of scripts) { | 299 for (var script of scripts) { |
| 296 if (!this._acceptsScript(script)) | 300 if (!this._acceptsScript(script)) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 315 * @param {!Common.Event} event | 319 * @param {!Common.Event} event |
| 316 */ | 320 */ |
| 317 _styleSheetAdded(event) { | 321 _styleSheetAdded(event) { |
| 318 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); | 322 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); |
| 319 if (!this._acceptsHeader(header)) | 323 if (!this._acceptsHeader(header)) |
| 320 return; | 324 return; |
| 321 | 325 |
| 322 var originalContentProvider = header.originalContentProvider(); | 326 var originalContentProvider = header.originalContentProvider(); |
| 323 var uiSourceCode = this._createFile(originalContentProvider, header.frameId,
false); | 327 var uiSourceCode = this._createFile(originalContentProvider, header.frameId,
false); |
| 324 uiSourceCode[Bindings.NetworkProject._styleSheetSymbol] = header; | 328 uiSourceCode[Bindings.NetworkProject._styleSheetSymbol] = header; |
| 325 var resource = SDK.ResourceTreeModel.resourceForURL(uiSourceCode.url()); | 329 var metadata = this._fetchMetadata(header.frameId, uiSourceCode.url()); |
| 326 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, thi
s._resourceMetadata(resource)); | 330 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, met
adata); |
| 327 } | 331 } |
| 328 | 332 |
| 329 /** | 333 /** |
| 330 * @param {!Common.Event} event | 334 * @param {!Common.Event} event |
| 331 */ | 335 */ |
| 332 _styleSheetRemoved(event) { | 336 _styleSheetRemoved(event) { |
| 333 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); | 337 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); |
| 334 if (!this._acceptsHeader(header)) | 338 if (!this._acceptsHeader(header)) |
| 335 return; | 339 return; |
| 336 this._removeFileForURL(header.resourceURL(), header.frameId, false); | 340 this._removeFileForURL(header.resourceURL(), header.frameId, false); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 364 return; | 368 return; |
| 365 | 369 |
| 366 // Never load document twice. | 370 // Never load document twice. |
| 367 var projectId = Bindings.NetworkProject.projectId(this._target, resource.fra
meId, false); | 371 var projectId = Bindings.NetworkProject.projectId(this._target, resource.fra
meId, false); |
| 368 var project = this._workspaceProjects.get(projectId); | 372 var project = this._workspaceProjects.get(projectId); |
| 369 if (project && project.uiSourceCodeForURL(resource.url)) | 373 if (project && project.uiSourceCodeForURL(resource.url)) |
| 370 return; | 374 return; |
| 371 | 375 |
| 372 var uiSourceCode = this._createFile(resource, resource.frameId, false); | 376 var uiSourceCode = this._createFile(resource, resource.frameId, false); |
| 373 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource; | 377 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource; |
| 374 this._addUISourceCodeWithProvider(uiSourceCode, resource, this._resourceMeta
data(resource)); | 378 this._addUISourceCodeWithProvider(uiSourceCode, resource, Bindings.resourceM
etadata(resource)); |
| 375 } | 379 } |
| 376 | 380 |
| 377 /** | 381 /** |
| 378 * @param {!SDK.ResourceTreeFrame} frame | 382 * @param {!SDK.ResourceTreeFrame} frame |
| 379 */ | 383 */ |
| 380 _removeFrameResources(frame) { | 384 _removeFrameResources(frame) { |
| 381 var project = this._workspaceProject(frame.id, false); | 385 var project = this._workspaceProject(frame.id, false); |
| 382 for (var resource of frame.resources()) | 386 for (var resource of frame.resources()) |
| 383 project.removeUISourceCode(resource.url); | 387 project.removeUISourceCode(resource.url); |
| 384 project = this._workspaceProject(frame.id, true); | 388 project = this._workspaceProject(frame.id, true); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 /** | 423 /** |
| 420 * @param {!Common.ContentProvider} contentProvider | 424 * @param {!Common.ContentProvider} contentProvider |
| 421 * @param {string} frameId | 425 * @param {string} frameId |
| 422 * @param {boolean} isContentScript | 426 * @param {boolean} isContentScript |
| 423 * @return {!Workspace.UISourceCode} | 427 * @return {!Workspace.UISourceCode} |
| 424 */ | 428 */ |
| 425 _createFile(contentProvider, frameId, isContentScript) { | 429 _createFile(contentProvider, frameId, isContentScript) { |
| 426 var url = contentProvider.contentURL(); | 430 var url = contentProvider.contentURL(); |
| 427 var project = this._workspaceProject(frameId, isContentScript); | 431 var project = this._workspaceProject(frameId, isContentScript); |
| 428 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy
pe()); | 432 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy
pe()); |
| 429 uiSourceCode[Bindings.NetworkProject._targetSymbol] = this._target; | 433 uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol] = frameId; |
| 430 return uiSourceCode; | 434 return uiSourceCode; |
| 431 } | 435 } |
| 432 | 436 |
| 433 /** | 437 /** |
| 434 * @param {?SDK.Resource} resource | 438 * @param {string} frameId |
| 439 * @param {string} url |
| 435 * @return {?Workspace.UISourceCodeMetadata} | 440 * @return {?Workspace.UISourceCodeMetadata} |
| 436 */ | 441 */ |
| 437 _resourceMetadata(resource) { | 442 _fetchMetadata(frameId, url) { |
| 438 if (!resource || (typeof resource.contentSize() !== 'number' && !resource.la
stModified())) | 443 if (!this._resourceTreeModel) |
| 439 return null; | 444 return null; |
| 440 return new Workspace.UISourceCodeMetadata(resource.lastModified(), resource.
contentSize()); | 445 var frame = this._resourceTreeModel.frameForId(frameId); |
| 446 if (!frame) |
| 447 return null; |
| 448 return Bindings.resourceMetadata(frame.resourceForURL(url)); |
| 441 } | 449 } |
| 442 | 450 |
| 443 _dispose() { | 451 _dispose() { |
| 444 this._reset(); | 452 this._reset(); |
| 445 Common.EventTarget.removeEventListeners(this._eventListeners); | 453 Common.EventTarget.removeEventListeners(this._eventListeners); |
| 446 delete this._target[Bindings.NetworkProject._networkProjectSymbol]; | 454 delete this._target[Bindings.NetworkProject._networkProjectSymbol]; |
| 447 } | 455 } |
| 448 | 456 |
| 449 _reset() { | 457 _reset() { |
| 450 for (var project of this._workspaceProjects.values()) | 458 for (var project of this._workspaceProjects.values()) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 static styleHeaderForUISourceCode(uiSourceCode) { | 492 static styleHeaderForUISourceCode(uiSourceCode) { |
| 485 return uiSourceCode[Bindings.NetworkProject._styleSheetSymbol]; | 493 return uiSourceCode[Bindings.NetworkProject._styleSheetSymbol]; |
| 486 } | 494 } |
| 487 }; | 495 }; |
| 488 | 496 |
| 489 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); | 497 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); |
| 490 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); | 498 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); |
| 491 Bindings.NetworkProject._scriptSymbol = Symbol('script'); | 499 Bindings.NetworkProject._scriptSymbol = Symbol('script'); |
| 492 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); | 500 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); |
| 493 Bindings.NetworkProject._targetSymbol = Symbol('target'); | 501 Bindings.NetworkProject._targetSymbol = Symbol('target'); |
| 494 Bindings.NetworkProject._frameSymbol = Symbol('frame'); | 502 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid'); |
| 495 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid'); | 503 |
| 504 Bindings.NetworkProject._frameAttributionSymbol = Symbol('Bindings.NetworkProjec
t._frameAttributionSymbol'); |
| OLD | NEW |