Skip to content

Commit 2c03ae3

Browse files
szuendDevtools-frontend LUCI CQ
authored andcommitted
[sources] Check media type for images and fonts
If users navigate a chrome tab to an image/font it has ResourceType 'Document' and currently we'll show an error (or raw bytes). Instead we can be a bit more permissive and attempt to render an image/font if the media type indicates as such. [email protected] Fixed: 373728013 Change-Id: Ia931cbacfe0b0f41ba1789214c683e9857dd1b5b Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5952209 Reviewed-by: Benedikt Meurer <[email protected]> Commit-Queue: Simon Zünd <[email protected]>
1 parent 42181c6 commit 2c03ae3

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

front_end/panels/sources/SourcesView.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ describeWithEnvironment('SourcesView', () => {
9393
{} as Persistence.FileSystemWorkspaceBinding.FileSystem,
9494
'file:///path/to/overrides/www.example.com/.headers' as Platform.DevToolsPath.UrlString,
9595
Common.ResourceType.resourceTypes.Document);
96+
sinon.stub(uiSourceCode, 'mimeType').returns('text/plain');
9697
sourcesView.viewForFile(uiSourceCode);
9798
assert.isTrue(sourcesView.getSourceView(uiSourceCode) instanceof SourcesComponents.HeadersView.HeadersView);
9899
});

front_end/panels/sources/SourcesView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,9 @@ export class SourcesView extends Common.ObjectWrapper.eventMixin<EventTypes, typ
367367
let sourceView;
368368
const contentType = uiSourceCode.contentType();
369369

370-
if (contentType === Common.ResourceType.resourceTypes.Image) {
370+
if (contentType === Common.ResourceType.resourceTypes.Image || uiSourceCode.mimeType().startsWith('image/')) {
371371
sourceView = new SourceFrame.ImageView.ImageView(uiSourceCode.mimeType(), uiSourceCode);
372-
} else if (contentType === Common.ResourceType.resourceTypes.Font) {
372+
} else if (contentType === Common.ResourceType.resourceTypes.Font || uiSourceCode.mimeType().includes('font')) {
373373
sourceView = new SourceFrame.FontView.FontView(uiSourceCode.mimeType(), uiSourceCode);
374374
} else if (uiSourceCode.name() === HEADER_OVERRIDES_FILENAME) {
375375
sourceView = new Components.HeadersView.HeadersView(uiSourceCode);

0 commit comments

Comments
 (0)