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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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} url | 201 * @param {string} url |
| 202 * @param {string} frameId | |
| 203 * @param {boolean} isContentScript | |
| 202 */ | 204 */ |
| 203 _removeFileForURL(frame, url) { | 205 removeSourceMapFile(url, frameId, isContentScript) { |
| 204 var project = this._workspaceProjects.get(Bindings.NetworkProject.projectId( this.target(), frame, false)); | 206 this._removeFileForURL(frameId, url, isContentScript); |
| 207 } | |
| 208 | |
| 209 /** | |
| 210 * @param {string} frameId | |
| 211 * @param {string} url | |
| 212 * @param {boolean} isContentScript | |
| 213 */ | |
| 214 _removeFileForURL(frameId, url, isContentScript) { | |
| 215 var project = | |
| 216 this._workspaceProjects.get(Bindings.NetworkProject.projectId(this.targe t(), frameId, isContentScript)); | |
| 205 if (!project) | 217 if (!project) |
| 206 return; | 218 return; |
| 207 project.removeFile(url); | 219 project.removeFile(url); |
| 208 } | 220 } |
| 209 | 221 |
| 210 _populate() { | 222 _populate() { |
| 211 /** | 223 /** |
| 212 * @param {!SDK.ResourceTreeFrame} frame | 224 * @param {!SDK.ResourceTreeFrame} frame |
| 213 * @this {Bindings.NetworkProject} | 225 * @this {Bindings.NetworkProject} |
| 214 */ | 226 */ |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 244 var script = /** @type {!SDK.Script} */ (event.data); | 256 var script = /** @type {!SDK.Script} */ (event.data); |
| 245 if (!script.sourceURL || script.isLiveEdit() || (script.isInlineScript() && !script.hasSourceURL)) | 257 if (!script.sourceURL || script.isLiveEdit() || (script.isInlineScript() && !script.hasSourceURL)) |
| 246 return; | 258 return; |
| 247 // Filter out embedder injected content scripts. | 259 // Filter out embedder injected content scripts. |
| 248 if (script.isContentScript() && !script.hasSourceURL) { | 260 if (script.isContentScript() && !script.hasSourceURL) { |
| 249 var parsedURL = new Common.ParsedURL(script.sourceURL); | 261 var parsedURL = new Common.ParsedURL(script.sourceURL); |
| 250 if (!parsedURL.isValid) | 262 if (!parsedURL.isValid) |
| 251 return; | 263 return; |
| 252 } | 264 } |
| 253 var originalContentProvider = script.originalContentProvider(); | 265 var originalContentProvider = script.originalContentProvider(); |
| 254 var uiSourceCode = | 266 var executionContext = script.executionContext(); |
| 255 this._createFile(originalContentProvider, SDK.ResourceTreeFrame.fromScri pt(script), script.isContentScript()); | 267 var frameId = executionContext ? executionContext.frameId || '' : ''; |
| 268 var uiSourceCode = this._createFile(originalContentProvider, frameId, script .isContentScript()); | |
| 256 uiSourceCode[Bindings.NetworkProject._scriptSymbol] = script; | 269 uiSourceCode[Bindings.NetworkProject._scriptSymbol] = script; |
| 257 var resource = SDK.ResourceTreeModel.resourceForURL(uiSourceCode.url()); | 270 var resource = SDK.ResourceTreeModel.resourceForURL(uiSourceCode.url()); |
| 258 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, thi s._resourceMetadata(resource)); | 271 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, thi s._resourceMetadata(resource)); |
| 259 } | 272 } |
| 260 | 273 |
| 261 /** | 274 /** |
| 262 * @param {!Common.Event} event | 275 * @param {!Common.Event} event |
| 263 */ | 276 */ |
| 264 _styleSheetAdded(event) { | 277 _styleSheetAdded(event) { |
| 265 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); | 278 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); |
| 266 if (header.isInline && !header.hasSourceURL && header.origin !== 'inspector' ) | 279 if (header.isInline && !header.hasSourceURL && header.origin !== 'inspector' ) |
| 267 return; | 280 return; |
| 268 if (!header.resourceURL()) | 281 if (!header.resourceURL()) |
| 269 return; | 282 return; |
| 270 | 283 |
| 271 var originalContentProvider = header.originalContentProvider(); | 284 var originalContentProvider = header.originalContentProvider(); |
| 272 var uiSourceCode = this._createFile(originalContentProvider, SDK.ResourceTre eFrame.fromStyleSheet(header), false); | 285 var uiSourceCode = this._createFile(originalContentProvider, header.frameId, false); |
| 273 uiSourceCode[Bindings.NetworkProject._styleSheetSymbol] = header; | 286 uiSourceCode[Bindings.NetworkProject._styleSheetSymbol] = header; |
| 274 var resource = SDK.ResourceTreeModel.resourceForURL(uiSourceCode.url()); | 287 var resource = SDK.ResourceTreeModel.resourceForURL(uiSourceCode.url()); |
| 275 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, thi s._resourceMetadata(resource)); | 288 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, thi s._resourceMetadata(resource)); |
| 276 } | 289 } |
| 277 | 290 |
| 278 /** | 291 /** |
| 279 * @param {!Common.Event} event | 292 * @param {!Common.Event} event |
| 280 */ | 293 */ |
| 281 _styleSheetRemoved(event) { | 294 _styleSheetRemoved(event) { |
| 282 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); | 295 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); |
| 283 if (header.isInline && !header.hasSourceURL && header.origin !== 'inspector' ) | 296 if (header.isInline && !header.hasSourceURL && header.origin !== 'inspector' ) |
| 284 return; | 297 return; |
| 285 | 298 |
| 286 this._removeFileForURL(SDK.ResourceTreeFrame.fromStyleSheet(header), header. resourceURL()); | 299 this._removeFileForURL(header.frameId, header.resourceURL(), false); |
| 287 } | 300 } |
| 288 | 301 |
| 289 /** | 302 /** |
| 290 * @param {!Common.Event} event | 303 * @param {!Common.Event} event |
| 291 */ | 304 */ |
| 292 _resourceAdded(event) { | 305 _resourceAdded(event) { |
| 293 var resource = /** @type {!SDK.Resource} */ (event.data); | 306 var resource = /** @type {!SDK.Resource} */ (event.data); |
| 294 this._addResource(resource); | 307 this._addResource(resource); |
| 295 } | 308 } |
| 296 | 309 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 307 | 320 |
| 308 // Ignore non-images and non-fonts. | 321 // Ignore non-images and non-fonts. |
| 309 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')) |
| 310 return; | 323 return; |
| 311 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')) |
| 312 return; | 325 return; |
| 313 if ((resourceType === Common.resourceTypes.Image || resourceType === Common. resourceTypes.Font) && | 326 if ((resourceType === Common.resourceTypes.Image || resourceType === Common. resourceTypes.Font) && |
| 314 resource.contentURL().startsWith('data:')) | 327 resource.contentURL().startsWith('data:')) |
| 315 return; | 328 return; |
| 316 | 329 |
| 317 var frame = SDK.ResourceTreeFrame.fromResource(resource); | |
| 318 // Never load document twice. | 330 // Never load document twice. |
| 319 var projectId = Bindings.NetworkProject.projectId(this.target(), frame, fals e); | 331 var projectId = Bindings.NetworkProject.projectId(this.target(), resource.fr ameId, false); |
| 320 var project = this._workspaceProjects.get(projectId); | 332 var project = this._workspaceProjects.get(projectId); |
| 321 if (project && project.uiSourceCodeForURL(resource.url)) | 333 if (project && project.uiSourceCodeForURL(resource.url)) |
| 322 return; | 334 return; |
| 323 | 335 |
| 324 var uiSourceCode = this._createFile(resource, frame, false); | 336 var uiSourceCode = this._createFile(resource, resource.frameId, false); |
| 325 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource; | 337 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource; |
| 326 this._addUISourceCodeWithProvider(uiSourceCode, resource, this._resourceMeta data(resource)); | 338 this._addUISourceCodeWithProvider(uiSourceCode, resource, this._resourceMeta data(resource)); |
| 327 } | 339 } |
| 328 | 340 |
| 329 /** | 341 /** |
| 330 * @param {!SDK.ResourceTreeFrame} frame | 342 * @param {!SDK.ResourceTreeFrame} frame |
| 331 */ | 343 */ |
| 332 _removeFrameResources(frame) { | 344 _removeFrameResources(frame) { |
| 333 var project = this._workspaceProject(frame, false); | 345 var frameId = frame ? frame.id : ''; |
|
dgozman
2017/03/17 19:00:21
frame is annotated as non-null here.
lushnikov
2017/03/17 21:21:47
Done.
| |
| 346 var project = this._workspaceProject(frameId, false); | |
| 334 for (var resource of frame.resources()) | 347 for (var resource of frame.resources()) |
| 335 project.removeUISourceCode(resource.url); | 348 project.removeUISourceCode(resource.url); |
| 336 project = this._workspaceProject(frame, true); | 349 project = this._workspaceProject(frameId, true); |
| 337 for (var resource of frame.resources()) | 350 for (var resource of frame.resources()) |
| 338 project.removeUISourceCode(resource.url); | 351 project.removeUISourceCode(resource.url); |
| 339 } | 352 } |
| 340 | 353 |
| 341 /** | 354 /** |
| 342 * @param {!Common.Event} event | 355 * @param {!Common.Event} event |
| 343 */ | 356 */ |
| 344 _frameWillNavigate(event) { | 357 _frameWillNavigate(event) { |
| 345 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data); | 358 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data); |
| 346 this._removeFrameResources(frame); | 359 this._removeFrameResources(frame); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 363 | 376 |
| 364 _suspendStateChanged() { | 377 _suspendStateChanged() { |
| 365 if (this.target().targetManager().allTargetsSuspended()) | 378 if (this.target().targetManager().allTargetsSuspended()) |
| 366 this._reset(); | 379 this._reset(); |
| 367 else | 380 else |
| 368 this._populate(); | 381 this._populate(); |
| 369 } | 382 } |
| 370 | 383 |
| 371 /** | 384 /** |
| 372 * @param {!Common.ContentProvider} contentProvider | 385 * @param {!Common.ContentProvider} contentProvider |
| 373 * @param {?SDK.ResourceTreeFrame} frame | 386 * @param {string} frameId |
| 374 * @param {boolean} isContentScript | 387 * @param {boolean} isContentScript |
| 375 * @return {!Workspace.UISourceCode} | 388 * @return {!Workspace.UISourceCode} |
| 376 */ | 389 */ |
| 377 _createFile(contentProvider, frame, isContentScript) { | 390 _createFile(contentProvider, frameId, isContentScript) { |
| 378 var url = contentProvider.contentURL(); | 391 var url = contentProvider.contentURL(); |
| 379 var project = this._workspaceProject(frame, isContentScript); | 392 var project = this._workspaceProject(frameId, isContentScript); |
| 380 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe()); | 393 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe()); |
| 381 uiSourceCode[Bindings.NetworkProject._targetSymbol] = this.target(); | 394 uiSourceCode[Bindings.NetworkProject._targetSymbol] = this.target(); |
| 382 return uiSourceCode; | 395 return uiSourceCode; |
| 383 } | 396 } |
| 384 | 397 |
| 385 /** | 398 /** |
| 386 * @param {?SDK.Resource} resource | 399 * @param {?SDK.Resource} resource |
| 387 * @return {?Workspace.UISourceCodeMetadata} | 400 * @return {?Workspace.UISourceCodeMetadata} |
| 388 */ | 401 */ |
| 389 _resourceMetadata(resource) { | 402 _resourceMetadata(resource) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 405 } | 418 } |
| 406 | 419 |
| 407 /** | 420 /** |
| 408 * @param {!Workspace.Workspace} workspace | 421 * @param {!Workspace.Workspace} workspace |
| 409 * @param {string} url | 422 * @param {string} url |
| 410 * @param {!SDK.Script} script | 423 * @param {!SDK.Script} script |
| 411 * @return {?Workspace.UISourceCode} | 424 * @return {?Workspace.UISourceCode} |
| 412 */ | 425 */ |
| 413 static uiSourceCodeForScriptURL(workspace, url, script) { | 426 static uiSourceCodeForScriptURL(workspace, url, script) { |
| 414 var target = script.debuggerModel.target(); | 427 var target = script.debuggerModel.target(); |
| 415 var frame = SDK.ResourceTreeFrame.fromScript(script); | 428 var frame = SDK.ResourceTreeFrame.fromScript(script); |
|
dgozman
2017/03/17 19:00:21
Get the frameId manually similar to the _parsedScr
lushnikov
2017/03/17 21:21:47
Done.
| |
| 416 return workspace.uiSourceCode(Bindings.NetworkProject.projectId(target, fram e, false), url) || | 429 return workspace.uiSourceCode(Bindings.NetworkProject.projectId(target, fram e ? frame.id : '', false), url) || |
| 417 workspace.uiSourceCode(Bindings.NetworkProject.projectId(target, frame, true), url); | 430 workspace.uiSourceCode(Bindings.NetworkProject.projectId(target, frame ? frame.id : '', true), url); |
| 418 } | 431 } |
| 419 | 432 |
| 420 /** | 433 /** |
| 421 * @param {!Workspace.Workspace} workspace | 434 * @param {!Workspace.Workspace} workspace |
| 422 * @param {string} url | 435 * @param {string} url |
| 423 * @param {!SDK.CSSStyleSheetHeader} header | 436 * @param {!SDK.CSSStyleSheetHeader} header |
| 424 * @return {?Workspace.UISourceCode} | 437 * @return {?Workspace.UISourceCode} |
| 425 */ | 438 */ |
| 426 static uiSourceCodeForStyleURL(workspace, url, header) { | 439 static uiSourceCodeForStyleURL(workspace, url, header) { |
| 427 var frame = SDK.ResourceTreeFrame.fromStyleSheet(header); | 440 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 } | 441 } |
| 430 }; | 442 }; |
| 431 | 443 |
| 432 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); | 444 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); |
| 433 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); | 445 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); |
| 434 Bindings.NetworkProject._scriptSymbol = Symbol('script'); | 446 Bindings.NetworkProject._scriptSymbol = Symbol('script'); |
| 435 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); | 447 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); |
| 436 Bindings.NetworkProject._targetSymbol = Symbol('target'); | 448 Bindings.NetworkProject._targetSymbol = Symbol('target'); |
| 437 Bindings.NetworkProject._frameSymbol = Symbol('frame'); | 449 Bindings.NetworkProject._frameSymbol = Symbol('frame'); |
| OLD | NEW |