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

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

Issue 2662513003: DevTools: make StylesSourceMapping in charge of creating and removing UISourceCodes (Closed)
Patch Set: move projects under stylessourcemapping Created 3 years, 10 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 SDK.ResourceTreeModel.Events.MainFrameNavigated, this._mainFrameNa vigated, this)); 86 SDK.ResourceTreeModel.Events.MainFrameNavigated, this._mainFrameNa vigated, this));
87 } 87 }
88 88
89 var debuggerModel = SDK.DebuggerModel.fromTarget(target); 89 var debuggerModel = SDK.DebuggerModel.fromTarget(target);
90 if (debuggerModel) { 90 if (debuggerModel) {
91 this._eventListeners.push( 91 this._eventListeners.push(
92 debuggerModel.addEventListener(SDK.DebuggerModel.Events.ParsedScriptSo urce, this._parsedScriptSource, this), 92 debuggerModel.addEventListener(SDK.DebuggerModel.Events.ParsedScriptSo urce, this._parsedScriptSource, this),
93 debuggerModel.addEventListener( 93 debuggerModel.addEventListener(
94 SDK.DebuggerModel.Events.FailedToParseScriptSource, this._parsedSc riptSource, this)); 94 SDK.DebuggerModel.Events.FailedToParseScriptSource, this._parsedSc riptSource, this));
95 } 95 }
96 var cssModel = SDK.CSSModel.fromTarget(target);
97 if (cssModel) {
98 this._eventListeners.push(
99 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, this._s tyleSheetAdded, this),
100 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetRemoved, this. _styleSheetRemoved, this));
101 }
102 this._eventListeners.push(target.targetManager().addEventListener( 96 this._eventListeners.push(target.targetManager().addEventListener(
103 SDK.TargetManager.Events.SuspendStateChanged, this._suspendStateChanged, this)); 97 SDK.TargetManager.Events.SuspendStateChanged, this._suspendStateChanged, this));
104 } 98 }
105 99
106 /** 100 /**
107 * @param {!SDK.Target} target 101 * @param {!SDK.Target} target
108 * @param {?SDK.ResourceTreeFrame} frame 102 * @param {?SDK.ResourceTreeFrame} frame
109 * @param {boolean} isContentScripts 103 * @param {boolean} isContentScripts
110 * @return {string} 104 * @return {string}
111 */ 105 */
(...skipping 23 matching lines...) Expand all
135 */ 129 */
136 static frameForProject(project) { 130 static frameForProject(project) {
137 return project[Bindings.NetworkProject._frameSymbol] || null; 131 return project[Bindings.NetworkProject._frameSymbol] || null;
138 } 132 }
139 133
140 /** 134 /**
141 * @param {!Workspace.UISourceCode} uiSourceCode 135 * @param {!Workspace.UISourceCode} uiSourceCode
142 * @return {?SDK.Target} target 136 * @return {?SDK.Target} target
143 */ 137 */
144 static targetForUISourceCode(uiSourceCode) { 138 static targetForUISourceCode(uiSourceCode) {
145 return uiSourceCode[Bindings.NetworkProject._targetSymbol] || null; 139 return uiSourceCode.project()[Bindings.NetworkProject._targetSymbol] || null ;
146 } 140 }
147 141
148 /** 142 /**
149 * @param {!Workspace.UISourceCode} uiSourceCode 143 * @param {!Workspace.UISourceCode} uiSourceCode
150 * @return {string} 144 * @return {string}
151 */ 145 */
152 static uiSourceCodeMimeType(uiSourceCode) { 146 static uiSourceCodeMimeType(uiSourceCode) {
153 if (uiSourceCode[Bindings.NetworkProject._scriptSymbol] || uiSourceCode[Bind ings.NetworkProject._styleSheetSymbol]) 147 if (uiSourceCode[Bindings.NetworkProject._useExplicitMimeType])
154 return uiSourceCode.contentType().canonicalMimeType(); 148 return uiSourceCode.contentType().canonicalMimeType();
155 149
156 var resource = uiSourceCode[Bindings.NetworkProject._resourceSymbol]; 150 var resource = uiSourceCode[Bindings.NetworkProject._resourceSymbol];
157 if (resource) 151 if (resource)
158 return resource.mimeType; 152 return resource.mimeType;
159 var mimeType = Common.ResourceType.mimeFromURL(uiSourceCode.url()); 153 var mimeType = Common.ResourceType.mimeFromURL(uiSourceCode.url());
160 return mimeType || uiSourceCode.contentType().canonicalMimeType(); 154 return mimeType || uiSourceCode.contentType().canonicalMimeType();
161 } 155 }
162 156
163 /** 157 /**
(...skipping 11 matching lines...) Expand all
175 169
176 project = new Bindings.ContentProviderBasedProject( 170 project = new Bindings.ContentProviderBasedProject(
177 this._workspace, projectId, projectType, '', false /* isServiceProject * /); 171 this._workspace, projectId, projectType, '', false /* isServiceProject * /);
178 project[Bindings.NetworkProject._targetSymbol] = this.target(); 172 project[Bindings.NetworkProject._targetSymbol] = this.target();
179 project[Bindings.NetworkProject._frameSymbol] = frame; 173 project[Bindings.NetworkProject._frameSymbol] = frame;
180 this._workspaceProjects.set(projectId, project); 174 this._workspaceProjects.set(projectId, project);
181 return project; 175 return project;
182 } 176 }
183 177
184 /** 178 /**
179 * @param {!Workspace.Project} project
180 * @param {!SDK.Target} target
181 * @param {?SDK.ResourceTreeFrame} frame
182 */
183 static annotateProjectWithTargetAndFrame(project, target, frame) {
184 project[Bindings.NetworkProject._targetSymbol] = target;
185 project[Bindings.NetworkProject._frameSymbol] = frame;
186 }
187
188 /**
189 * @param {!Workspace.UISourceCode} uiSourceCode
190 */
191 static useExplicitMimeType(uiSourceCode) {
192 uiSourceCode[Bindings.NetworkProject._useExplicitMimeType] = true;
193 }
194
195 /**
185 * @param {!Common.ContentProvider} contentProvider 196 * @param {!Common.ContentProvider} contentProvider
186 * @param {?SDK.ResourceTreeFrame} frame 197 * @param {?SDK.ResourceTreeFrame} frame
187 * @param {boolean} isContentScript 198 * @param {boolean} isContentScript
188 * @param {?number} contentSize 199 * @param {?number} contentSize
189 * @return {!Workspace.UISourceCode} 200 * @return {!Workspace.UISourceCode}
190 */ 201 */
191 addFile(contentProvider, frame, isContentScript, contentSize) { 202 addFile(contentProvider, frame, isContentScript, contentSize) {
192 var uiSourceCode = this._createFile(contentProvider, frame, isContentScript || false); 203 var uiSourceCode = this._createFile(contentProvider, frame, isContentScript || false);
193 var metadata = typeof contentSize === 'number' ? new Workspace.UISourceCodeM etadata(null, contentSize) : null; 204 var metadata = typeof contentSize === 'number' ? new Workspace.UISourceCodeM etadata(null, contentSize) : null;
194 this._addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata); 205 this._addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata);
195 return uiSourceCode; 206 return uiSourceCode;
196 } 207 }
197 208
198 /**
199 * @param {?SDK.ResourceTreeFrame} frame
200 * @param {string} url
201 */
202 _removeFileForURL(frame, url) {
203 var project = this._workspaceProjects.get(Bindings.NetworkProject.projectId( this.target(), frame, false));
204 if (!project)
205 return;
206 project.removeFile(url);
207 }
208
209 _populate() { 209 _populate() {
210 /** 210 /**
211 * @param {!SDK.ResourceTreeFrame} frame 211 * @param {!SDK.ResourceTreeFrame} frame
212 * @this {Bindings.NetworkProject} 212 * @this {Bindings.NetworkProject}
213 */ 213 */
214 function populateFrame(frame) { 214 function populateFrame(frame) {
215 for (var i = 0; i < frame.childFrames.length; ++i) 215 for (var i = 0; i < frame.childFrames.length; ++i)
216 populateFrame.call(this, frame.childFrames[i]); 216 populateFrame.call(this, frame.childFrames[i]);
217 217
218 var resources = frame.resources(); 218 var resources = frame.resources();
(...skipping 24 matching lines...) Expand all
243 var script = /** @type {!SDK.Script} */ (event.data); 243 var script = /** @type {!SDK.Script} */ (event.data);
244 if (!script.sourceURL || script.isLiveEdit() || (script.isInlineScript() && !script.hasSourceURL)) 244 if (!script.sourceURL || script.isLiveEdit() || (script.isInlineScript() && !script.hasSourceURL))
245 return; 245 return;
246 // Filter out embedder injected content scripts. 246 // Filter out embedder injected content scripts.
247 if (script.isContentScript() && !script.hasSourceURL) { 247 if (script.isContentScript() && !script.hasSourceURL) {
248 var parsedURL = new Common.ParsedURL(script.sourceURL); 248 var parsedURL = new Common.ParsedURL(script.sourceURL);
249 if (!parsedURL.isValid) 249 if (!parsedURL.isValid)
250 return; 250 return;
251 } 251 }
252 var uiSourceCode = this._createFile(script, SDK.ResourceTreeFrame.fromScript (script), script.isContentScript()); 252 var uiSourceCode = this._createFile(script, SDK.ResourceTreeFrame.fromScript (script), script.isContentScript());
253 uiSourceCode[Bindings.NetworkProject._scriptSymbol] = script; 253 uiSourceCode[Bindings.NetworkProject._useExplicitMimeType] = true;
254 var resource = SDK.ResourceTreeModel.resourceForURL(uiSourceCode.url()); 254 var resource = SDK.ResourceTreeModel.resourceForURL(uiSourceCode.url());
255 this._addUISourceCodeWithProvider(uiSourceCode, script, this._resourceMetada ta(resource)); 255 this._addUISourceCodeWithProvider(uiSourceCode, script, Bindings.NetworkProj ect.resourceMetadata(resource));
256 } 256 }
257 257
258 /** 258 /**
259 * @param {!Common.Event} event
260 */
261 _styleSheetAdded(event) {
262 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data);
263 if (header.isInline && !header.hasSourceURL && header.origin !== 'inspector' )
264 return;
265 if (!header.resourceURL())
266 return;
267
268 var originalContentProvider = header.originalContentProvider();
269 var uiSourceCode = this._createFile(originalContentProvider, SDK.ResourceTre eFrame.fromStyleSheet(header), false);
270 uiSourceCode[Bindings.NetworkProject._styleSheetSymbol] = header;
271 var resource = SDK.ResourceTreeModel.resourceForURL(uiSourceCode.url());
272 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, thi s._resourceMetadata(resource));
273 }
274
275 /**
276 * @param {!Common.Event} event
277 */
278 _styleSheetRemoved(event) {
279 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data);
280 if (header.isInline && !header.hasSourceURL && header.origin !== 'inspector' )
281 return;
282
283 this._removeFileForURL(SDK.ResourceTreeFrame.fromStyleSheet(header), header. resourceURL());
284 }
285
286 /**
287 * @param {!Common.Event} event 259 * @param {!Common.Event} event
288 */ 260 */
289 _resourceAdded(event) { 261 _resourceAdded(event) {
290 var resource = /** @type {!SDK.Resource} */ (event.data); 262 var resource = /** @type {!SDK.Resource} */ (event.data);
291 this._addResource(resource); 263 this._addResource(resource);
292 } 264 }
293 265
294 /** 266 /**
295 * @param {!SDK.Resource} resource 267 * @param {!SDK.Resource} resource
296 */ 268 */
(...skipping 13 matching lines...) Expand all
310 if ((resourceType === Common.resourceTypes.Image || resourceType === Common. resourceTypes.Font) && 282 if ((resourceType === Common.resourceTypes.Image || resourceType === Common. resourceTypes.Font) &&
311 resource.contentURL().startsWith('data:')) 283 resource.contentURL().startsWith('data:'))
312 return; 284 return;
313 285
314 // Never load document twice. 286 // Never load document twice.
315 if (this._workspace.uiSourceCodeForURL(resource.url)) 287 if (this._workspace.uiSourceCodeForURL(resource.url))
316 return; 288 return;
317 289
318 var uiSourceCode = this._createFile(resource, SDK.ResourceTreeFrame.fromReso urce(resource), false); 290 var uiSourceCode = this._createFile(resource, SDK.ResourceTreeFrame.fromReso urce(resource), false);
319 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource; 291 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource;
320 this._addUISourceCodeWithProvider(uiSourceCode, resource, this._resourceMeta data(resource)); 292 this._addUISourceCodeWithProvider(uiSourceCode, resource, Bindings.NetworkPr oject.resourceMetadata(resource));
321 } 293 }
322 294
323 /** 295 /**
324 * @param {!Common.Event} event 296 * @param {!Common.Event} event
325 */ 297 */
326 _frameWillNavigate(event) { 298 _frameWillNavigate(event) {
327 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data); 299 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data);
328 var project = this._workspaceProject(frame, false); 300 var project = this._workspaceProject(frame, false);
329 for (var resource of frame.resources()) 301 for (var resource of frame.resources())
330 project.removeUISourceCode(resource.url); 302 project.removeUISourceCode(resource.url);
(...skipping 20 matching lines...) Expand all
351 /** 323 /**
352 * @param {!Common.ContentProvider} contentProvider 324 * @param {!Common.ContentProvider} contentProvider
353 * @param {?SDK.ResourceTreeFrame} frame 325 * @param {?SDK.ResourceTreeFrame} frame
354 * @param {boolean} isContentScript 326 * @param {boolean} isContentScript
355 * @return {!Workspace.UISourceCode} 327 * @return {!Workspace.UISourceCode}
356 */ 328 */
357 _createFile(contentProvider, frame, isContentScript) { 329 _createFile(contentProvider, frame, isContentScript) {
358 var url = contentProvider.contentURL(); 330 var url = contentProvider.contentURL();
359 var project = this._workspaceProject(frame, isContentScript); 331 var project = this._workspaceProject(frame, isContentScript);
360 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe()); 332 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe());
361 uiSourceCode[Bindings.NetworkProject._targetSymbol] = this.target();
362 return uiSourceCode; 333 return uiSourceCode;
363 } 334 }
364 335
365 /** 336 /**
366 * @param {?SDK.Resource} resource 337 * @param {?SDK.Resource} resource
367 * @return {?Workspace.UISourceCodeMetadata} 338 * @return {?Workspace.UISourceCodeMetadata}
368 */ 339 */
369 _resourceMetadata(resource) { 340 static resourceMetadata(resource) {
370 if (!resource || (typeof resource.contentSize() !== 'number' && !resource.la stModified())) 341 if (!resource || (typeof resource.contentSize() !== 'number' && !resource.la stModified()))
371 return null; 342 return null;
372 return new Workspace.UISourceCodeMetadata(resource.lastModified(), resource. contentSize()); 343 return new Workspace.UISourceCodeMetadata(resource.lastModified(), resource. contentSize());
373 } 344 }
374 345
375 _dispose() { 346 _dispose() {
376 this._reset(); 347 this._reset();
377 Common.EventTarget.removeEventListeners(this._eventListeners); 348 Common.EventTarget.removeEventListeners(this._eventListeners);
378 delete this.target()[Bindings.NetworkProject._networkProjectSymbol]; 349 delete this.target()[Bindings.NetworkProject._networkProjectSymbol];
379 } 350 }
(...skipping 24 matching lines...) Expand all
404 * @return {?Workspace.UISourceCode} 375 * @return {?Workspace.UISourceCode}
405 */ 376 */
406 static uiSourceCodeForStyleURL(workspace, url, header) { 377 static uiSourceCodeForStyleURL(workspace, url, header) {
407 var frame = SDK.ResourceTreeFrame.fromStyleSheet(header); 378 var frame = SDK.ResourceTreeFrame.fromStyleSheet(header);
408 return workspace.uiSourceCode(Bindings.NetworkProject.projectId(header.targe t(), frame, false), url); 379 return workspace.uiSourceCode(Bindings.NetworkProject.projectId(header.targe t(), frame, false), url);
409 } 380 }
410 }; 381 };
411 382
412 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); 383 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject');
413 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); 384 Bindings.NetworkProject._resourceSymbol = Symbol('resource');
414 Bindings.NetworkProject._scriptSymbol = Symbol('script'); 385 Bindings.NetworkProject._useExplicitMimeType = Symbol('useExplicitMimeType');
415 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet');
416 Bindings.NetworkProject._targetSymbol = Symbol('target'); 386 Bindings.NetworkProject._targetSymbol = Symbol('target');
417 Bindings.NetworkProject._frameSymbol = Symbol('frame'); 387 Bindings.NetworkProject._frameSymbol = Symbol('frame');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698