| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 if (resourceTreeModel) { | 80 if (resourceTreeModel) { |
| 81 this._eventListeners.push( | 81 this._eventListeners.push( |
| 82 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Resour
ceAdded, this._resourceAdded, this), | 82 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Resour
ceAdded, this._resourceAdded, this), |
| 83 resourceTreeModel.addEventListener( | 83 resourceTreeModel.addEventListener( |
| 84 SDK.ResourceTreeModel.Events.FrameWillNavigate, this._frameWillNav
igate, this), | 84 SDK.ResourceTreeModel.Events.FrameWillNavigate, this._frameWillNav
igate, this), |
| 85 resourceTreeModel.addEventListener( | 85 resourceTreeModel.addEventListener( |
| 86 SDK.ResourceTreeModel.Events.MainFrameNavigated, this._mainFrameNa
vigated, this), | 86 SDK.ResourceTreeModel.Events.MainFrameNavigated, this._mainFrameNa
vigated, this), |
| 87 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.FrameD
etached, this._frameDetached, this)); | 87 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.FrameD
etached, this._frameDetached, this)); |
| 88 } | 88 } |
| 89 | 89 |
| 90 var debuggerModel = SDK.DebuggerModel.fromTarget(target); | 90 var runtimeModel = target.runtimeModel; |
| 91 if (debuggerModel) { | 91 this._debuggerModel = SDK.DebuggerModel.fromTarget(target); |
| 92 if (this._debuggerModel && runtimeModel) { |
| 92 this._eventListeners.push( | 93 this._eventListeners.push( |
| 93 debuggerModel.addEventListener(SDK.DebuggerModel.Events.ParsedScriptSo
urce, this._parsedScriptSource, this), | 94 runtimeModel.addEventListener( |
| 94 debuggerModel.addEventListener( | 95 SDK.RuntimeModel.Events.ExecutionContextDestroyed, this._execution
ContextDestroyed, this), |
| 96 this._debuggerModel.addEventListener( |
| 97 SDK.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSou
rce, this), |
| 98 this._debuggerModel.addEventListener( |
| 95 SDK.DebuggerModel.Events.FailedToParseScriptSource, this._parsedSc
riptSource, this)); | 99 SDK.DebuggerModel.Events.FailedToParseScriptSource, this._parsedSc
riptSource, this)); |
| 96 } | 100 } |
| 97 var cssModel = target.model(SDK.CSSModel); | 101 var cssModel = target.model(SDK.CSSModel); |
| 98 if (cssModel) { | 102 if (cssModel) { |
| 99 this._eventListeners.push( | 103 this._eventListeners.push( |
| 100 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, this._s
tyleSheetAdded, this), | 104 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, this._s
tyleSheetAdded, this), |
| 101 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetRemoved, this.
_styleSheetRemoved, this)); | 105 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetRemoved, this.
_styleSheetRemoved, this)); |
| 102 } | 106 } |
| 103 this._eventListeners.push(target.targetManager().addEventListener( | 107 this._eventListeners.push(target.targetManager().addEventListener( |
| 104 SDK.TargetManager.Events.SuspendStateChanged, this._suspendStateChanged,
this)); | 108 SDK.TargetManager.Events.SuspendStateChanged, this._suspendStateChanged,
this)); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 * @param {!Workspace.UISourceCode} uiSourceCode | 241 * @param {!Workspace.UISourceCode} uiSourceCode |
| 238 * @param {!Common.ContentProvider} contentProvider | 242 * @param {!Common.ContentProvider} contentProvider |
| 239 * @param {?Workspace.UISourceCodeMetadata} metadata | 243 * @param {?Workspace.UISourceCodeMetadata} metadata |
| 240 */ | 244 */ |
| 241 _addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata) { | 245 _addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata) { |
| 242 /** @type {!Bindings.ContentProviderBasedProject} */ (uiSourceCode.project()
) | 246 /** @type {!Bindings.ContentProviderBasedProject} */ (uiSourceCode.project()
) |
| 243 .addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata); | 247 .addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata); |
| 244 } | 248 } |
| 245 | 249 |
| 246 /** | 250 /** |
| 251 * @param {!SDK.Script} script |
| 252 * @return {boolean} |
| 253 */ |
| 254 _acceptsScript(script) { |
| 255 if (!script.sourceURL || script.isLiveEdit() || (script.isInlineScript() &&
!script.hasSourceURL)) |
| 256 return false; |
| 257 // Filter out embedder injected content scripts. |
| 258 if (script.isContentScript() && !script.hasSourceURL) { |
| 259 var parsedURL = new Common.ParsedURL(script.sourceURL); |
| 260 if (!parsedURL.isValid) |
| 261 return false; |
| 262 } |
| 263 return true; |
| 264 } |
| 265 |
| 266 /** |
| 247 * @param {!Common.Event} event | 267 * @param {!Common.Event} event |
| 248 */ | 268 */ |
| 249 _parsedScriptSource(event) { | 269 _parsedScriptSource(event) { |
| 250 var script = /** @type {!SDK.Script} */ (event.data); | 270 var script = /** @type {!SDK.Script} */ (event.data); |
| 251 if (!script.sourceURL || script.isLiveEdit() || (script.isInlineScript() &&
!script.hasSourceURL)) | 271 if (!this._acceptsScript(script)) |
| 252 return; | 272 return; |
| 253 // Filter out embedder injected content scripts. | 273 var frame = SDK.ResourceTreeFrame.fromScript(script); |
| 254 if (script.isContentScript() && !script.hasSourceURL) { | |
| 255 var parsedURL = new Common.ParsedURL(script.sourceURL); | |
| 256 if (!parsedURL.isValid) | |
| 257 return; | |
| 258 } | |
| 259 var originalContentProvider = script.originalContentProvider(); | 274 var originalContentProvider = script.originalContentProvider(); |
| 260 var bucketType = script.isContentScript() ? Bindings.ProjectBuckets.ContentS
criptsBucket : | 275 var bucketType = script.isContentScript() ? Bindings.ProjectBuckets.ContentS
criptsBucket : |
| 261 Bindings.ProjectBuckets.RegularS
criptsBucket; | 276 Bindings.ProjectBuckets.RegularS
criptsBucket; |
| 262 var uiSourceCode = this._createFile(originalContentProvider, SDK.ResourceTre
eFrame.fromScript(script), bucketType); | 277 var uiSourceCode = this._createFile(originalContentProvider, frame, bucketTy
pe); |
| 263 uiSourceCode[Bindings.NetworkProject._scriptSymbol] = script; | 278 uiSourceCode[Bindings.NetworkProject._scriptSymbol] = script; |
| 279 script[Bindings.NetworkProject._frameSymbol] = frame; |
| 264 var resource = SDK.ResourceTreeModel.resourceForURL(uiSourceCode.url()); | 280 var resource = SDK.ResourceTreeModel.resourceForURL(uiSourceCode.url()); |
| 265 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, thi
s._resourceMetadata(resource)); | 281 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, thi
s._resourceMetadata(resource)); |
| 266 } | 282 } |
| 267 | 283 |
| 268 /** | 284 /** |
| 269 * @param {!Common.Event} event | 285 * @param {!Common.Event} event |
| 270 */ | 286 */ |
| 287 _executionContextDestroyed(event) { |
| 288 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); |
| 289 var scripts = this._debuggerModel.scriptsForExecutionContext(executionContex
t); |
| 290 for (var script of scripts) { |
| 291 if (!this._acceptsScript(script)) |
| 292 continue; |
| 293 var frame = script[Bindings.NetworkProject._frameSymbol]; |
| 294 var bucketType = script.isContentScript() ? Bindings.ProjectBuckets.Conten
tScriptsBucket : |
| 295 Bindings.ProjectBuckets.Regula
rScriptsBucket; |
| 296 this._removeFileForURL(frame, script.contentURL(), bucketType); |
| 297 } |
| 298 } |
| 299 |
| 300 /** |
| 301 * @param {!Common.Event} event |
| 302 */ |
| 271 _styleSheetAdded(event) { | 303 _styleSheetAdded(event) { |
| 272 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); | 304 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); |
| 273 if (header.isInline && !header.hasSourceURL && header.origin !== 'inspector'
) | 305 if (header.isInline && !header.hasSourceURL && header.origin !== 'inspector'
) |
| 274 return; | 306 return; |
| 275 if (!header.resourceURL()) | 307 if (!header.resourceURL()) |
| 276 return; | 308 return; |
| 277 | 309 |
| 278 var originalContentProvider = header.originalContentProvider(); | 310 var originalContentProvider = header.originalContentProvider(); |
| 279 var uiSourceCode = this._createFile( | 311 var uiSourceCode = this._createFile( |
| 280 originalContentProvider, SDK.ResourceTreeFrame.fromStyleSheet(header), | 312 originalContentProvider, SDK.ResourceTreeFrame.fromStyleSheet(header), |
| (...skipping 26 matching lines...) Expand all Loading... |
| 307 /** | 339 /** |
| 308 * @param {!SDK.Resource} resource | 340 * @param {!SDK.Resource} resource |
| 309 */ | 341 */ |
| 310 _addResource(resource) { | 342 _addResource(resource) { |
| 311 var resourceType = resource.resourceType(); | 343 var resourceType = resource.resourceType(); |
| 312 // Only load selected resource types from resources. | 344 // Only load selected resource types from resources. |
| 313 if (resourceType !== Common.resourceTypes.Image && resourceType !== Common.r
esourceTypes.Font && | 345 if (resourceType !== Common.resourceTypes.Image && resourceType !== Common.r
esourceTypes.Font && |
| 314 resourceType !== Common.resourceTypes.Document && resourceType !== Commo
n.resourceTypes.Manifest) | 346 resourceType !== Common.resourceTypes.Document && resourceType !== Commo
n.resourceTypes.Manifest) |
| 315 return; | 347 return; |
| 316 | 348 |
| 317 | |
| 318 // Ignore non-images and non-fonts. | 349 // Ignore non-images and non-fonts. |
| 319 if (resourceType === Common.resourceTypes.Image && resource.mimeType && !res
ource.mimeType.startsWith('image')) | 350 if (resourceType === Common.resourceTypes.Image && resource.mimeType && !res
ource.mimeType.startsWith('image')) |
| 320 return; | 351 return; |
| 321 if (resourceType === Common.resourceTypes.Font && resource.mimeType && !reso
urce.mimeType.includes('font')) | 352 if (resourceType === Common.resourceTypes.Font && resource.mimeType && !reso
urce.mimeType.includes('font')) |
| 322 return; | 353 return; |
| 323 if ((resourceType === Common.resourceTypes.Image || resourceType === Common.
resourceTypes.Font) && | 354 if ((resourceType === Common.resourceTypes.Image || resourceType === Common.
resourceTypes.Font) && |
| 324 resource.contentURL().startsWith('data:')) | 355 resource.contentURL().startsWith('data:')) |
| 325 return; | 356 return; |
| 326 | 357 |
| 327 var frame = SDK.ResourceTreeFrame.fromResource(resource); | 358 var frame = SDK.ResourceTreeFrame.fromResource(resource); |
| 328 // Never load document twice. | 359 // Never load document twice. |
| 329 var projectId = Bindings.NetworkProject.projectId(this.target(), frame, Bind
ings.ProjectBuckets.ResourcesBucket); | 360 var projectId = Bindings.NetworkProject.projectId(this.target(), frame, Bind
ings.ProjectBuckets.ResourcesBucket); |
| 330 var project = this._workspaceProjects.get(projectId); | 361 var project = this._workspaceProjects.get(projectId); |
| 331 if (project && project.uiSourceCodeForURL(resource.url)) | 362 if (project && project.uiSourceCodeForURL(resource.url)) |
| 332 return; | 363 return; |
| 333 | 364 |
| 334 var uiSourceCode = this._createFile(resource, frame, Bindings.ProjectBuckets
.ResourcesBucket); | 365 var uiSourceCode = this._createFile(resource, frame, Bindings.ProjectBuckets
.ResourcesBucket); |
| 335 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource; | 366 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource; |
| 336 this._addUISourceCodeWithProvider(uiSourceCode, resource, this._resourceMeta
data(resource)); | 367 this._addUISourceCodeWithProvider(uiSourceCode, resource, this._resourceMeta
data(resource)); |
| 337 } | 368 } |
| 338 | 369 |
| 339 /** | 370 /** |
| 340 * @param {!SDK.ResourceTreeFrame} frame | 371 * @param {!SDK.ResourceTreeFrame} frame |
| 341 */ | 372 */ |
| 342 _removeFrameResources(frame) { | 373 _removeFrameResources(frame) { |
| 343 // TODO(lushnikov): this method should clean up only ResourcesBucket. | 374 // TODO(lushnikov): this method should clean up only ResourcesBucket. |
| 344 var projects = [ | 375 var projects = [ |
| 345 this._workspaceProject(frame, Bindings.ProjectBuckets.ResourcesBucket), | 376 this._workspaceProject(frame, Bindings.ProjectBuckets.ResourcesBucket), |
| 346 this._workspaceProject(frame, Bindings.ProjectBuckets.ContentScriptsBucket
), | |
| 347 this._workspaceProject(frame, Bindings.ProjectBuckets.RegularScriptsBucket
), | |
| 348 this._workspaceProject(frame, Bindings.ProjectBuckets.StyleSheetsBucket), | 377 this._workspaceProject(frame, Bindings.ProjectBuckets.StyleSheetsBucket), |
| 349 ]; | 378 ]; |
| 350 for (var resource of frame.resources()) { | 379 for (var resource of frame.resources()) { |
| 351 for (var project of projects) | 380 for (var project of projects) |
| 352 project.removeUISourceCode(resource.url); | 381 project.removeUISourceCode(resource.url); |
| 353 } | 382 } |
| 354 } | 383 } |
| 355 | 384 |
| 356 /** | 385 /** |
| 357 * @param {!Common.Event} event | 386 * @param {!Common.Event} event |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 Common.EventTarget.removeEventListeners(this._eventListeners); | 442 Common.EventTarget.removeEventListeners(this._eventListeners); |
| 414 delete this.target()[Bindings.NetworkProject._networkProjectSymbol]; | 443 delete this.target()[Bindings.NetworkProject._networkProjectSymbol]; |
| 415 } | 444 } |
| 416 | 445 |
| 417 _resetResources() { | 446 _resetResources() { |
| 418 // TODO(lushnikov): this method should clean up only ResourcesBucket. | 447 // TODO(lushnikov): this method should clean up only ResourcesBucket. |
| 419 for (var projectId of this._workspaceProjects.keys()) { | 448 for (var projectId of this._workspaceProjects.keys()) { |
| 420 var project = this._workspaceProjects.get(projectId); | 449 var project = this._workspaceProjects.get(projectId); |
| 421 switch (project[Bindings.NetworkProject._bucketSymbol]) { | 450 switch (project[Bindings.NetworkProject._bucketSymbol]) { |
| 422 case Bindings.ProjectBuckets.ResourcesBucket: | 451 case Bindings.ProjectBuckets.ResourcesBucket: |
| 423 case Bindings.ProjectBuckets.ContentScriptsBucket: | |
| 424 case Bindings.ProjectBuckets.RegularScriptsBucket: | |
| 425 case Bindings.ProjectBuckets.StyleSheetsBucket: | 452 case Bindings.ProjectBuckets.StyleSheetsBucket: |
| 426 case Bindings.ProjectBuckets.SourceMapBucket: | 453 case Bindings.ProjectBuckets.SourceMapBucket: |
| 427 case Bindings.ProjectBuckets.SourceMapContentScriptsBucket: | 454 case Bindings.ProjectBuckets.SourceMapContentScriptsBucket: |
| 428 project.removeProject(); | 455 project.removeProject(); |
| 429 this._workspaceProjects.delete(projectId); | 456 this._workspaceProjects.delete(projectId); |
| 430 break; | 457 break; |
| 431 } | 458 } |
| 432 } | 459 } |
| 433 } | 460 } |
| 434 | 461 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 SourceMapContentScriptsBucket: 'SourceMapContentScriptsBucket', | 519 SourceMapContentScriptsBucket: 'SourceMapContentScriptsBucket', |
| 493 }; | 520 }; |
| 494 | 521 |
| 495 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); | 522 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); |
| 496 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); | 523 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); |
| 497 Bindings.NetworkProject._scriptSymbol = Symbol('script'); | 524 Bindings.NetworkProject._scriptSymbol = Symbol('script'); |
| 498 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); | 525 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); |
| 499 Bindings.NetworkProject._targetSymbol = Symbol('target'); | 526 Bindings.NetworkProject._targetSymbol = Symbol('target'); |
| 500 Bindings.NetworkProject._frameSymbol = Symbol('frame'); | 527 Bindings.NetworkProject._frameSymbol = Symbol('frame'); |
| 501 Bindings.NetworkProject._bucketSymbol = Symbol('bucket'); | 528 Bindings.NetworkProject._bucketSymbol = Symbol('bucket'); |
| OLD | NEW |