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

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

Issue 2826173003: DevTools: prepare Navigator and Network Project for merging uiSourceCodes (Closed)
Patch Set: nice vocabulary Created 3 years, 8 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 return frameId ? new Set([frameId]) : null;
135 } 136 }
136 137
137 /** 138 /**
138 * @param {!Workspace.Project} project
139 * @return {?SDK.ResourceTreeFrame}
140 */
141 static frameForProject(project) {
142 return project[Bindings.NetworkProject._frameSymbol] || null;
143 }
144
145 /**
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 /**
154 * @param {!Workspace.UISourceCode} uiSourceCode 147 * @param {!Workspace.UISourceCode} uiSourceCode
155 * @return {string} 148 * @return {string}
156 */ 149 */
157 static uiSourceCodeMimeType(uiSourceCode) { 150 static uiSourceCodeMimeType(uiSourceCode) {
158 if (uiSourceCode[Bindings.NetworkProject._scriptSymbol] || uiSourceCode[Bind ings.NetworkProject._styleSheetSymbol]) 151 if (uiSourceCode[Bindings.NetworkProject._scriptSymbol] || uiSourceCode[Bind ings.NetworkProject._styleSheetSymbol])
159 return uiSourceCode.contentType().canonicalMimeType(); 152 return uiSourceCode.contentType().canonicalMimeType();
160 153
(...skipping 13 matching lines...) Expand all
174 var projectId = Bindings.NetworkProject.projectId(this._target, frameId, isC ontentScripts); 167 var projectId = Bindings.NetworkProject.projectId(this._target, frameId, isC ontentScripts);
175 var projectType = isContentScripts ? Workspace.projectTypes.ContentScripts : Workspace.projectTypes.Network; 168 var projectType = isContentScripts ? Workspace.projectTypes.ContentScripts : Workspace.projectTypes.Network;
176 169
177 var project = this._workspaceProjects.get(projectId); 170 var project = this._workspaceProjects.get(projectId);
178 if (project) 171 if (project)
179 return project; 172 return project;
180 173
181 project = new Bindings.ContentProviderBasedProject( 174 project = new Bindings.ContentProviderBasedProject(
182 this._workspace, projectId, projectType, '', false /* isServiceProject * /); 175 this._workspace, projectId, projectType, '', false /* isServiceProject * /);
183 project[Bindings.NetworkProject._targetSymbol] = this._target; 176 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); 177 this._workspaceProjects.set(projectId, project);
187 return project; 178 return project;
188 } 179 }
189 180
190 /** 181 /**
191 * @param {!Common.ContentProvider} contentProvider 182 * @param {!Common.ContentProvider} contentProvider
192 * @param {string} frameId 183 * @param {string} frameId
193 * @param {boolean} isContentScript 184 * @param {boolean} isContentScript
194 * @param {?number} contentSize 185 * @param {?number} contentSize
195 * @return {!Workspace.UISourceCode} 186 * @return {!Workspace.UISourceCode}
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 _parsedScriptSource(event) { 266 _parsedScriptSource(event) {
276 var script = /** @type {!SDK.Script} */ (event.data); 267 var script = /** @type {!SDK.Script} */ (event.data);
277 if (!this._acceptsScript(script)) 268 if (!this._acceptsScript(script))
278 return; 269 return;
279 var originalContentProvider = script.originalContentProvider(); 270 var originalContentProvider = script.originalContentProvider();
280 var executionContext = script.executionContext(); 271 var executionContext = script.executionContext();
281 var frameId = executionContext ? executionContext.frameId || '' : ''; 272 var frameId = executionContext ? executionContext.frameId || '' : '';
282 script[Bindings.NetworkProject._frameIdSymbol] = frameId; 273 script[Bindings.NetworkProject._frameIdSymbol] = frameId;
283 var uiSourceCode = this._createFile(originalContentProvider, frameId, script .isContentScript()); 274 var uiSourceCode = this._createFile(originalContentProvider, frameId, script .isContentScript());
284 uiSourceCode[Bindings.NetworkProject._scriptSymbol] = script; 275 uiSourceCode[Bindings.NetworkProject._scriptSymbol] = script;
285 var resource = SDK.ResourceTreeModel.resourceForURL(uiSourceCode.url()); 276 var metadata = this._fetchMetadata(frameId, uiSourceCode.url());
286 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, thi s._resourceMetadata(resource)); 277 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, met adata);
287 } 278 }
288 279
289 /** 280 /**
290 * @param {!Common.Event} event 281 * @param {!Common.Event} event
291 */ 282 */
292 _executionContextDestroyed(event) { 283 _executionContextDestroyed(event) {
293 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); 284 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data);
294 var scripts = this._debuggerModel.scriptsForExecutionContext(executionContex t); 285 var scripts = this._debuggerModel.scriptsForExecutionContext(executionContex t);
295 for (var script of scripts) { 286 for (var script of scripts) {
296 if (!this._acceptsScript(script)) 287 if (!this._acceptsScript(script))
(...skipping 18 matching lines...) Expand all
315 * @param {!Common.Event} event 306 * @param {!Common.Event} event
316 */ 307 */
317 _styleSheetAdded(event) { 308 _styleSheetAdded(event) {
318 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); 309 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data);
319 if (!this._acceptsHeader(header)) 310 if (!this._acceptsHeader(header))
320 return; 311 return;
321 312
322 var originalContentProvider = header.originalContentProvider(); 313 var originalContentProvider = header.originalContentProvider();
323 var uiSourceCode = this._createFile(originalContentProvider, header.frameId, false); 314 var uiSourceCode = this._createFile(originalContentProvider, header.frameId, false);
324 uiSourceCode[Bindings.NetworkProject._styleSheetSymbol] = header; 315 uiSourceCode[Bindings.NetworkProject._styleSheetSymbol] = header;
325 var resource = SDK.ResourceTreeModel.resourceForURL(uiSourceCode.url()); 316 var metadata = this._fetchMetadata(header.frameId, uiSourceCode.url());
326 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, thi s._resourceMetadata(resource)); 317 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, met adata);
327 } 318 }
328 319
329 /** 320 /**
330 * @param {!Common.Event} event 321 * @param {!Common.Event} event
331 */ 322 */
332 _styleSheetRemoved(event) { 323 _styleSheetRemoved(event) {
333 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); 324 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data);
334 if (!this._acceptsHeader(header)) 325 if (!this._acceptsHeader(header))
335 return; 326 return;
336 this._removeFileForURL(header.resourceURL(), header.frameId, false); 327 this._removeFileForURL(header.resourceURL(), header.frameId, false);
(...skipping 27 matching lines...) Expand all
364 return; 355 return;
365 356
366 // Never load document twice. 357 // Never load document twice.
367 var projectId = Bindings.NetworkProject.projectId(this._target, resource.fra meId, false); 358 var projectId = Bindings.NetworkProject.projectId(this._target, resource.fra meId, false);
368 var project = this._workspaceProjects.get(projectId); 359 var project = this._workspaceProjects.get(projectId);
369 if (project && project.uiSourceCodeForURL(resource.url)) 360 if (project && project.uiSourceCodeForURL(resource.url))
370 return; 361 return;
371 362
372 var uiSourceCode = this._createFile(resource, resource.frameId, false); 363 var uiSourceCode = this._createFile(resource, resource.frameId, false);
373 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource; 364 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource;
374 this._addUISourceCodeWithProvider(uiSourceCode, resource, this._resourceMeta data(resource)); 365 this._addUISourceCodeWithProvider(uiSourceCode, resource, Bindings.resourceM etadata(resource));
375 } 366 }
376 367
377 /** 368 /**
378 * @param {!SDK.ResourceTreeFrame} frame 369 * @param {!SDK.ResourceTreeFrame} frame
379 */ 370 */
380 _removeFrameResources(frame) { 371 _removeFrameResources(frame) {
381 var project = this._workspaceProject(frame.id, false); 372 var project = this._workspaceProject(frame.id, false);
382 for (var resource of frame.resources()) 373 for (var resource of frame.resources())
383 project.removeUISourceCode(resource.url); 374 project.removeUISourceCode(resource.url);
384 project = this._workspaceProject(frame.id, true); 375 project = this._workspaceProject(frame.id, true);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 /** 410 /**
420 * @param {!Common.ContentProvider} contentProvider 411 * @param {!Common.ContentProvider} contentProvider
421 * @param {string} frameId 412 * @param {string} frameId
422 * @param {boolean} isContentScript 413 * @param {boolean} isContentScript
423 * @return {!Workspace.UISourceCode} 414 * @return {!Workspace.UISourceCode}
424 */ 415 */
425 _createFile(contentProvider, frameId, isContentScript) { 416 _createFile(contentProvider, frameId, isContentScript) {
426 var url = contentProvider.contentURL(); 417 var url = contentProvider.contentURL();
427 var project = this._workspaceProject(frameId, isContentScript); 418 var project = this._workspaceProject(frameId, isContentScript);
428 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe()); 419 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe());
429 uiSourceCode[Bindings.NetworkProject._targetSymbol] = this._target; 420 uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol] = frameId;
430 return uiSourceCode; 421 return uiSourceCode;
431 } 422 }
432 423
433 /** 424 /**
434 * @param {?SDK.Resource} resource 425 * @param {string} frameId
426 * @param {string} url
435 * @return {?Workspace.UISourceCodeMetadata} 427 * @return {?Workspace.UISourceCodeMetadata}
436 */ 428 */
437 _resourceMetadata(resource) { 429 _fetchMetadata(frameId, url) {
438 if (!resource || (typeof resource.contentSize() !== 'number' && !resource.la stModified())) 430 if (!this._resourceTreeModel)
439 return null; 431 return null;
440 return new Workspace.UISourceCodeMetadata(resource.lastModified(), resource. contentSize()); 432 var frame = this._resourceTreeModel.frameForId(frameId);
433 var resource = frame ? frame.resourceForURL(url) : this._resourceTreeModel.r esourceForURL(url);
dgozman 2017/04/20 17:12:07 Why second part here? It's either from the frame o
lushnikov 2017/04/21 01:21:51 Nailed it.
434 return Bindings.resourceMetadata(resource);
441 } 435 }
442 436
443 _dispose() { 437 _dispose() {
444 this._reset(); 438 this._reset();
445 Common.EventTarget.removeEventListeners(this._eventListeners); 439 Common.EventTarget.removeEventListeners(this._eventListeners);
446 delete this._target[Bindings.NetworkProject._networkProjectSymbol]; 440 delete this._target[Bindings.NetworkProject._networkProjectSymbol];
447 } 441 }
448 442
449 _reset() { 443 _reset() {
450 for (var project of this._workspaceProjects.values()) 444 for (var project of this._workspaceProjects.values())
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 static styleHeaderForUISourceCode(uiSourceCode) { 478 static styleHeaderForUISourceCode(uiSourceCode) {
485 return uiSourceCode[Bindings.NetworkProject._styleSheetSymbol]; 479 return uiSourceCode[Bindings.NetworkProject._styleSheetSymbol];
486 } 480 }
487 }; 481 };
488 482
489 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); 483 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject');
490 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); 484 Bindings.NetworkProject._resourceSymbol = Symbol('resource');
491 Bindings.NetworkProject._scriptSymbol = Symbol('script'); 485 Bindings.NetworkProject._scriptSymbol = Symbol('script');
492 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); 486 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet');
493 Bindings.NetworkProject._targetSymbol = Symbol('target'); 487 Bindings.NetworkProject._targetSymbol = Symbol('target');
494 Bindings.NetworkProject._frameSymbol = Symbol('frame'); 488 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid');
495 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid'); 489
490 Bindings.NetworkProject._frameAttributionSymbol = Symbol('Bindings.NetworkProjec t._frameAttributionSymbol');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698