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

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

Issue 2889013002: DevTools: introduce uiSourceCode.mimeType() method (Closed)
Patch Set: address comments Created 3 years, 7 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode); 216 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode);
217 var resourceTreeModel = target && target.model(SDK.ResourceTreeModel); 217 var resourceTreeModel = target && target.model(SDK.ResourceTreeModel);
218 var attribution = uiSourceCode[Bindings.NetworkProject._frameAttributionSymb ol]; 218 var attribution = uiSourceCode[Bindings.NetworkProject._frameAttributionSymb ol];
219 if (!resourceTreeModel || !attribution) 219 if (!resourceTreeModel || !attribution)
220 return []; 220 return [];
221 var frames = Array.from(attribution.keys()).map(frameId => resourceTreeModel .frameForId(frameId)); 221 var frames = Array.from(attribution.keys()).map(frameId => resourceTreeModel .frameForId(frameId));
222 return frames.filter(frame => !!frame); 222 return frames.filter(frame => !!frame);
223 } 223 }
224 224
225 /** 225 /**
226 * @param {!Workspace.UISourceCode} uiSourceCode
227 * @return {string}
228 */
229 static uiSourceCodeMimeType(uiSourceCode) {
230 if (uiSourceCode[Bindings.NetworkProject._scriptSymbol] || uiSourceCode[Bind ings.NetworkProject._styleSheetSymbol])
231 return uiSourceCode.contentType().canonicalMimeType();
232
233 var resource = uiSourceCode[Bindings.NetworkProject._resourceSymbol];
234 if (resource)
235 return resource.mimeType;
236 var mimeType = Common.ResourceType.mimeFromURL(uiSourceCode.url());
237 return mimeType || uiSourceCode.contentType().canonicalMimeType();
238 }
239
240 /**
241 * @param {string} frameId 226 * @param {string} frameId
242 * @param {boolean} isContentScripts 227 * @param {boolean} isContentScripts
243 * @return {!Bindings.ContentProviderBasedProject} 228 * @return {!Bindings.ContentProviderBasedProject}
244 */ 229 */
245 _workspaceProject(frameId, isContentScripts) { 230 _workspaceProject(frameId, isContentScripts) {
246 var projectId = Bindings.NetworkProject.projectId(this._target, frameId, isC ontentScripts); 231 var projectId = Bindings.NetworkProject.projectId(this._target, frameId, isC ontentScripts);
247 var projectType = isContentScripts ? Workspace.projectTypes.ContentScripts : Workspace.projectTypes.Network; 232 var projectType = isContentScripts ? Workspace.projectTypes.ContentScripts : Workspace.projectTypes.Network;
248 233
249 var project = this._workspaceProjects.get(projectId); 234 var project = this._workspaceProjects.get(projectId);
250 if (project) 235 if (project)
(...skipping 16 matching lines...) Expand all
267 this._workspaceProjects.get(Bindings.NetworkProject.projectId(this._targ et, frameId, isContentScript)); 252 this._workspaceProjects.get(Bindings.NetworkProject.projectId(this._targ et, frameId, isContentScript));
268 if (!project) 253 if (!project)
269 return; 254 return;
270 project.removeFile(url); 255 project.removeFile(url);
271 } 256 }
272 257
273 /** 258 /**
274 * @param {!Workspace.UISourceCode} uiSourceCode 259 * @param {!Workspace.UISourceCode} uiSourceCode
275 * @param {!Common.ContentProvider} contentProvider 260 * @param {!Common.ContentProvider} contentProvider
276 * @param {?Workspace.UISourceCodeMetadata} metadata 261 * @param {?Workspace.UISourceCodeMetadata} metadata
262 * @param {string} mimeType
277 */ 263 */
278 _addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata) { 264 _addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata, mimeType ) {
279 /** @type {!Bindings.ContentProviderBasedProject} */ (uiSourceCode.project() ) 265 /** @type {!Bindings.ContentProviderBasedProject} */ (uiSourceCode.project() )
280 .addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata); 266 .addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata, mi meType);
281 } 267 }
282 268
283 /** 269 /**
284 * @param {!SDK.Script} script 270 * @param {!SDK.Script} script
285 * @return {boolean} 271 * @return {boolean}
286 */ 272 */
287 _acceptsScript(script) { 273 _acceptsScript(script) {
288 if (!script.sourceURL || script.isLiveEdit() || (script.isInlineScript() && !script.hasSourceURL)) 274 if (!script.sourceURL || script.isLiveEdit() || (script.isInlineScript() && !script.hasSourceURL))
289 return false; 275 return false;
290 // Filter out embedder injected content scripts. 276 // Filter out embedder injected content scripts.
(...skipping 10 matching lines...) Expand all
301 */ 287 */
302 _parsedScriptSource(event) { 288 _parsedScriptSource(event) {
303 var script = /** @type {!SDK.Script} */ (event.data); 289 var script = /** @type {!SDK.Script} */ (event.data);
304 if (!this._acceptsScript(script)) 290 if (!this._acceptsScript(script))
305 return; 291 return;
306 this._acceptedScripts.add(script); 292 this._acceptedScripts.add(script);
307 var originalContentProvider = script.originalContentProvider(); 293 var originalContentProvider = script.originalContentProvider();
308 var frameId = Bindings.frameIdForScript(script); 294 var frameId = Bindings.frameIdForScript(script);
309 script[Bindings.NetworkProject._frameIdSymbol] = frameId; 295 script[Bindings.NetworkProject._frameIdSymbol] = frameId;
310 var uiSourceCode = this._createFile(originalContentProvider, frameId, script .isContentScript()); 296 var uiSourceCode = this._createFile(originalContentProvider, frameId, script .isContentScript());
311 uiSourceCode[Bindings.NetworkProject._scriptSymbol] = script;
312 var metadata = this._fetchMetadata(frameId, uiSourceCode.url()); 297 var metadata = this._fetchMetadata(frameId, uiSourceCode.url());
313 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, met adata); 298 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, met adata, 'text/javascript');
314 } 299 }
315 300
316 /** 301 /**
317 * @param {!Common.Event} event 302 * @param {!Common.Event} event
318 */ 303 */
319 _executionContextDestroyed(event) { 304 _executionContextDestroyed(event) {
320 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data); 305 var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data);
321 var scripts = this._debuggerModel.scriptsForExecutionContext(executionContex t); 306 var scripts = this._debuggerModel.scriptsForExecutionContext(executionContex t);
322 this._removeScripts(scripts); 307 this._removeScripts(scripts);
323 } 308 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 */ 343 */
359 _styleSheetAdded(event) { 344 _styleSheetAdded(event) {
360 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); 345 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data);
361 if (!this._acceptsHeader(header)) 346 if (!this._acceptsHeader(header))
362 return; 347 return;
363 348
364 var originalContentProvider = header.originalContentProvider(); 349 var originalContentProvider = header.originalContentProvider();
365 var uiSourceCode = this._createFile(originalContentProvider, header.frameId, false); 350 var uiSourceCode = this._createFile(originalContentProvider, header.frameId, false);
366 uiSourceCode[Bindings.NetworkProject._styleSheetSymbol] = header; 351 uiSourceCode[Bindings.NetworkProject._styleSheetSymbol] = header;
367 var metadata = this._fetchMetadata(header.frameId, uiSourceCode.url()); 352 var metadata = this._fetchMetadata(header.frameId, uiSourceCode.url());
368 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, met adata); 353 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, met adata, 'text/css');
369 } 354 }
370 355
371 /** 356 /**
372 * @param {!Common.Event} event 357 * @param {!Common.Event} event
373 */ 358 */
374 _styleSheetRemoved(event) { 359 _styleSheetRemoved(event) {
375 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); 360 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data);
376 if (!this._acceptsHeader(header)) 361 if (!this._acceptsHeader(header))
377 return; 362 return;
378 this._removeFileForURL(header.resourceURL(), header.frameId, false); 363 this._removeFileForURL(header.resourceURL(), header.frameId, false);
(...skipping 29 matching lines...) Expand all
408 } 393 }
409 394
410 /** 395 /**
411 * @param {!SDK.Resource} resource 396 * @param {!SDK.Resource} resource
412 */ 397 */
413 _addResource(resource) { 398 _addResource(resource) {
414 if (!this._acceptsResource(resource)) 399 if (!this._acceptsResource(resource))
415 return; 400 return;
416 401
417 var uiSourceCode = this._createFile(resource, resource.frameId, false); 402 var uiSourceCode = this._createFile(resource, resource.frameId, false);
418 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource; 403 this._addUISourceCodeWithProvider(uiSourceCode, resource, Bindings.resourceM etadata(resource), resource.mimeType);
419 this._addUISourceCodeWithProvider(uiSourceCode, resource, Bindings.resourceM etadata(resource));
420 } 404 }
421 405
422 /** 406 /**
423 * @param {!SDK.ResourceTreeFrame} frame 407 * @param {!SDK.ResourceTreeFrame} frame
424 */ 408 */
425 _removeFrameResources(frame) { 409 _removeFrameResources(frame) {
426 var regularProject = this._workspaceProject(frame.id, false); 410 var regularProject = this._workspaceProject(frame.id, false);
427 var contentScriptsProject = this._workspaceProject(frame.id, true); 411 var contentScriptsProject = this._workspaceProject(frame.id, true);
428 for (var resource of frame.resources()) { 412 for (var resource of frame.resources()) {
429 if (!this._acceptsResource(resource)) 413 if (!this._acceptsResource(resource))
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 /** 502 /**
519 * @param {!Workspace.UISourceCode} uiSourceCode 503 * @param {!Workspace.UISourceCode} uiSourceCode
520 * @return {?SDK.CSSStyleSheetHeader} 504 * @return {?SDK.CSSStyleSheetHeader}
521 */ 505 */
522 static styleHeaderForUISourceCode(uiSourceCode) { 506 static styleHeaderForUISourceCode(uiSourceCode) {
523 return uiSourceCode[Bindings.NetworkProject._styleSheetSymbol]; 507 return uiSourceCode[Bindings.NetworkProject._styleSheetSymbol];
524 } 508 }
525 }; 509 };
526 510
527 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); 511 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject');
528 Bindings.NetworkProject._resourceSymbol = Symbol('resource');
529 Bindings.NetworkProject._scriptSymbol = Symbol('script');
530 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); 512 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet');
531 Bindings.NetworkProject._targetSymbol = Symbol('target'); 513 Bindings.NetworkProject._targetSymbol = Symbol('target');
532 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid'); 514 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid');
533 515
534 Bindings.NetworkProject._frameAttributionSymbol = Symbol('Bindings.NetworkProjec t._frameAttributionSymbol'); 516 Bindings.NetworkProject._frameAttributionSymbol = Symbol('Bindings.NetworkProjec t._frameAttributionSymbol');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698