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

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

Issue 1523193002: DevTools: merge UISourceCode's parentPath, name, originURL and uri. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 95 }
96 96
97 WebInspector.NetworkProject._networkProjectSymbol = Symbol("networkProject"); 97 WebInspector.NetworkProject._networkProjectSymbol = Symbol("networkProject");
98 WebInspector.NetworkProject._resourceSymbol = Symbol("resource"); 98 WebInspector.NetworkProject._resourceSymbol = Symbol("resource");
99 WebInspector.NetworkProject._scriptSymbol = Symbol("script"); 99 WebInspector.NetworkProject._scriptSymbol = Symbol("script");
100 WebInspector.NetworkProject._styleSheetSymbol = Symbol("styleSheet"); 100 WebInspector.NetworkProject._styleSheetSymbol = Symbol("styleSheet");
101 WebInspector.NetworkProject._targetSymbol = Symbol("target"); 101 WebInspector.NetworkProject._targetSymbol = Symbol("target");
102 102
103 /** 103 /**
104 * @param {!WebInspector.Target} target 104 * @param {!WebInspector.Target} target
105 * @param {string} projectURL
106 * @param {boolean} isContentScripts 105 * @param {boolean} isContentScripts
107 * @return {string} 106 * @return {string}
108 */ 107 */
109 WebInspector.NetworkProject.projectId = function(target, projectURL, isContentSc ripts) 108 WebInspector.NetworkProject.projectId = function(target, isContentScripts)
110 { 109 {
111 return target.id() + ":" + (isContentScripts ? "contentscripts:" : "") + pro jectURL; 110 return target.id() + ":" + (isContentScripts ? "contentscripts:" : "");
112 } 111 }
113 112
114 /** 113 /**
115 * @param {!WebInspector.Target} target 114 * @param {!WebInspector.Target} target
116 * @return {!WebInspector.NetworkProject} 115 * @return {!WebInspector.NetworkProject}
117 */ 116 */
118 WebInspector.NetworkProject.forTarget = function(target) 117 WebInspector.NetworkProject.forTarget = function(target)
119 { 118 {
120 return target[WebInspector.NetworkProject._networkProjectSymbol]; 119 return target[WebInspector.NetworkProject._networkProjectSymbol];
121 } 120 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 var resource = uiSourceCode[WebInspector.NetworkProject._resourceSymbol] ; 174 var resource = uiSourceCode[WebInspector.NetworkProject._resourceSymbol] ;
176 if (resource) 175 if (resource)
177 frameId = resource.frameId; 176 frameId = resource.frameId;
178 } 177 }
179 178
180 return frameId ? target.resourceTreeModel.frameForId(frameId) : null; 179 return frameId ? target.resourceTreeModel.frameForId(frameId) : null;
181 } 180 }
182 181
183 WebInspector.NetworkProject.prototype = { 182 WebInspector.NetworkProject.prototype = {
184 /** 183 /**
185 * @param {string} projectURL
186 * @param {boolean} isContentScripts 184 * @param {boolean} isContentScripts
187 * @return {!WebInspector.ContentProviderBasedProject} 185 * @return {!WebInspector.ContentProviderBasedProject}
188 */ 186 */
189 _workspaceProject: function(projectURL, isContentScripts) 187 _workspaceProject: function(isContentScripts)
190 { 188 {
191 var projectId = WebInspector.NetworkProject.projectId(this.target(), pro jectURL, isContentScripts); 189 var projectId = WebInspector.NetworkProject.projectId(this.target(), isC ontentScripts);
192 var projectType = isContentScripts ? WebInspector.projectTypes.ContentSc ripts : WebInspector.projectTypes.Network; 190 var projectType = isContentScripts ? WebInspector.projectTypes.ContentSc ripts : WebInspector.projectTypes.Network;
193 191
194 var project = this._workspaceProjects.get(projectId); 192 var project = this._workspaceProjects.get(projectId);
195 if (project) 193 if (project)
196 return project; 194 return project;
197 195
198 project = new WebInspector.ContentProviderBasedProject(this._workspace, projectId, projectType, projectURL, this._computeDisplayName(projectURL)); 196 project = new WebInspector.ContentProviderBasedProject(this._workspace, projectId, projectType, "");
199 this._workspaceProjects.set(projectId, project); 197 this._workspaceProjects.set(projectId, project);
200 return project; 198 return project;
201 }, 199 },
202 200
203 /** 201 /**
204 * @param {string} url 202 * @param {string} url
205 * @return {string}
206 */
207 _computeDisplayName: function(url)
208 {
209 for (var context of this.target().runtimeModel.executionContexts()) {
210 if (context.name && context.origin && url.startsWith(context.origin) )
211 return context.name;
212 }
213
214 var targetSuffix = this.target().isPage() ? "" : " \u2014 " + this.targe t().name();
215 if (!url)
216 return WebInspector.UIString("(no domain)") + targetSuffix;
217 var parsedURL = new WebInspector.ParsedURL(url);
218 var prettyURL = parsedURL.isValid ? parsedURL.host + (parsedURL.port ? ( ":" + parsedURL.port) : "") : "";
219 return (prettyURL || url) + targetSuffix;
220 },
221
222 /**
223 * @param {string} url
224 * @param {!WebInspector.ContentProvider} contentProvider 203 * @param {!WebInspector.ContentProvider} contentProvider
225 * @param {boolean=} isContentScript 204 * @param {boolean=} isContentScript
226 * @return {?WebInspector.UISourceCode} 205 * @return {?WebInspector.UISourceCode}
227 */ 206 */
228 addFileForURL: function(url, contentProvider, isContentScript) 207 addFileForURL: function(url, contentProvider, isContentScript)
229 { 208 {
230 return this._createFile(url, contentProvider, isContentScript || false, true); 209 return this._createFile(url, contentProvider, isContentScript || false, true);
231 }, 210 },
232 211
233 /** 212 /**
234 * @param {string} url 213 * @param {string} url
235 */ 214 */
236 _removeFileForURL: function(url) 215 _removeFileForURL: function(url)
237 { 216 {
238 var splitURL = WebInspector.ParsedURL.splitURLIntoPathComponents(url); 217 var project = this._workspaceProjects.get(WebInspector.NetworkProject.pr ojectId(this.target(), false));
239 var projectURL = splitURL[0];
240 var path = splitURL.slice(1).join("/");
241 var project = this._workspaceProjects.get(WebInspector.NetworkProject.pr ojectId(this.target(), projectURL, false));
242 if (!project) 218 if (!project)
243 return; 219 return;
244 project.removeFile(path); 220 project.removeFile(url);
245 }, 221 },
246 222
247 _populate: function() 223 _populate: function()
248 { 224 {
249 /** 225 /**
250 * @param {!WebInspector.ResourceTreeFrame} frame 226 * @param {!WebInspector.ResourceTreeFrame} frame
251 * @this {WebInspector.NetworkProject} 227 * @this {WebInspector.NetworkProject}
252 */ 228 */
253 function populateFrame(frame) 229 function populateFrame(frame)
254 { 230 {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 if (resourceType === WebInspector.resourceTypes.Font && resource.mimeTyp e && !resource.mimeType.includes("font")) 327 if (resourceType === WebInspector.resourceTypes.Font && resource.mimeTyp e && !resource.mimeType.includes("font"))
352 return; 328 return;
353 if ((resourceType === WebInspector.resourceTypes.Image || resourceType = == WebInspector.resourceTypes.Font) && resource.contentURL().startsWith("data:") ) 329 if ((resourceType === WebInspector.resourceTypes.Image || resourceType = == WebInspector.resourceTypes.Font) && resource.contentURL().startsWith("data:") )
354 return; 330 return;
355 331
356 // Never load document twice. 332 // Never load document twice.
357 if (this._workspace.uiSourceCodeForOriginURL(resource.url)) 333 if (this._workspace.uiSourceCodeForOriginURL(resource.url))
358 return; 334 return;
359 335
360 var uiSourceCode = this._createFile(resource.url, resource, false, false ); 336 var uiSourceCode = this._createFile(resource.url, resource, false, false );
361 uiSourceCode[WebInspector.NetworkProject._resourceSymbol] = resource; 337 if (uiSourceCode) {
362 this._addUISourceCodeWithProvider(uiSourceCode, resource); 338 uiSourceCode[WebInspector.NetworkProject._resourceSymbol] = resource ;
339 this._addUISourceCodeWithProvider(uiSourceCode, resource);
340 }
363 }, 341 },
364 342
365 /** 343 /**
366 * @param {!WebInspector.Event} event 344 * @param {!WebInspector.Event} event
367 */ 345 */
368 _mainFrameNavigated: function(event) 346 _mainFrameNavigated: function(event)
369 { 347 {
370 this._reset(); 348 this._reset();
371 this._populate(); 349 this._populate();
372 }, 350 },
(...skipping 11 matching lines...) Expand all
384 * @param {!WebInspector.ContentProvider} contentProvider 362 * @param {!WebInspector.ContentProvider} contentProvider
385 * @param {boolean} isContentScript 363 * @param {boolean} isContentScript
386 * @param {boolean} addIntoProject 364 * @param {boolean} addIntoProject
387 * @return {?WebInspector.UISourceCode} 365 * @return {?WebInspector.UISourceCode}
388 */ 366 */
389 _createFile: function(url, contentProvider, isContentScript, addIntoProject) 367 _createFile: function(url, contentProvider, isContentScript, addIntoProject)
390 { 368 {
391 if (this._networkMapping.hasMappingForURL(url)) 369 if (this._networkMapping.hasMappingForURL(url))
392 return null; 370 return null;
393 371
394 var splitURL = WebInspector.ParsedURL.splitURLIntoPathComponents(url); 372 var project = this._workspaceProject(isContentScript);
395 var projectURL = splitURL[0]; 373 var uiSourceCode = project.createUISourceCode(url, contentProvider.conte ntType());
396 var parentPath = splitURL.slice(1, -1).join("/");
397 var name = splitURL.peekLast() || "";
398 var project = this._workspaceProject(projectURL, isContentScript);
399 var uiSourceCode = project.createUISourceCode(parentPath, name, url, con tentProvider.contentType());
400 uiSourceCode[WebInspector.NetworkProject._targetSymbol] = this.target(); 374 uiSourceCode[WebInspector.NetworkProject._targetSymbol] = this.target();
401 if (addIntoProject) 375 if (addIntoProject)
402 project.addUISourceCodeWithProvider(uiSourceCode, contentProvider); 376 project.addUISourceCodeWithProvider(uiSourceCode, contentProvider);
403 return uiSourceCode; 377 return uiSourceCode;
404 }, 378 },
405 379
406 _dispose: function() 380 _dispose: function()
407 { 381 {
408 this._reset(); 382 this._reset();
409 var target = this.target(); 383 var target = this.target();
(...skipping 14 matching lines...) Expand all
424 398
425 _reset: function() 399 _reset: function()
426 { 400 {
427 for (var project of this._workspaceProjects.values()) 401 for (var project of this._workspaceProjects.values())
428 project.reset(); 402 project.reset();
429 this._workspaceProjects.clear(); 403 this._workspaceProjects.clear();
430 }, 404 },
431 405
432 __proto__: WebInspector.SDKObject.prototype 406 __proto__: WebInspector.SDKObject.prototype
433 } 407 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698