Skip to content

Commit 2224ba7

Browse files
szuendDevtools-frontend LUCI CQ
authored andcommitted
[network] Pass StreamingContentData to BinaryResourceView(Factory)
This is required to use BinaryResourceView(Factory) for arbitrary NetworkRequests and not just individual websocket frames. [email protected] Bug: 375546679 Change-Id: I6d19d5636ee36426f9651074261f7fd66ac3013e Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5965156 Commit-Queue: Simon Zünd <[email protected]> Reviewed-by: Philip Pfaffe <[email protected]>
1 parent 6fc5141 commit 2224ba7

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

front_end/panels/network/BinaryResourceView.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as Common from '../../core/common/common.js';
66
import * as Host from '../../core/host/host.js';
77
import * as i18n from '../../core/i18n/i18n.js';
88
import type * as Platform from '../../core/platform/platform.js';
9+
import type * as TextUtils from '../../models/text_utils/text_utils.js';
910
import * as SourceFrame from '../../ui/legacy/components/source_frame/source_frame.js';
1011
import * as UI from '../../ui/legacy/legacy.js';
1112

@@ -70,12 +71,12 @@ export class BinaryResourceView extends UI.Widget.VBox {
7071
private lastView: UI.Widget.Widget|null;
7172

7273
constructor(
73-
base64content: string, contentUrl: Platform.DevToolsPath.UrlString,
74+
content: TextUtils.StreamingContentData.StreamingContentData, contentUrl: Platform.DevToolsPath.UrlString,
7475
resourceType: Common.ResourceType.ResourceType) {
7576
super();
7677

7778
this.binaryResourceViewFactory =
78-
new SourceFrame.BinaryResourceViewFactory.BinaryResourceViewFactory(base64content, contentUrl, resourceType);
79+
new SourceFrame.BinaryResourceViewFactory.BinaryResourceViewFactory(content, contentUrl, resourceType);
7980

8081
this.toolbar = new UI.Toolbar.Toolbar('binary-view-toolbar', this.element);
8182

front_end/panels/network/ResourceWebSocketFrameView.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,9 @@ export class ResourceWebSocketFrameNode extends DataGrid.SortableDataGrid.Sortab
469469
if (!this.binaryViewInternal) {
470470
if (this.dataTextInternal.length > 0) {
471471
this.binaryViewInternal = new BinaryResourceView(
472-
this.dataTextInternal, Platform.DevToolsPath.EmptyUrlString, Common.ResourceType.resourceTypes.WebSocket);
472+
TextUtils.StreamingContentData.StreamingContentData.from(
473+
new TextUtils.ContentData.ContentData(this.dataTextInternal, true, 'applicaiton/octet-stream')),
474+
Platform.DevToolsPath.EmptyUrlString, Common.ResourceType.resourceTypes.WebSocket);
473475
}
474476
}
475477
return this.binaryViewInternal;

front_end/ui/legacy/components/source_frame/BinaryResourceViewFactory.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import * as SourceFrame from './source_frame.js';
1111

1212
describeWithEnvironment('BinaryResourceViewFactory', () => {
1313
it('interprets base64 content correctly', async () => {
14-
const base64content = 'c2VuZGluZyB0aGlzIHV0Zi04IHN0cmluZyBhcyBhIGJpbmFyeSBtZXNzYWdlLi4u';
14+
const base64content = new TextUtils.ContentData.ContentData(
15+
'c2VuZGluZyB0aGlzIHV0Zi04IHN0cmluZyBhcyBhIGJpbmFyeSBtZXNzYWdlLi4u', true, '');
1516
const factory = new SourceFrame.BinaryResourceViewFactory.BinaryResourceViewFactory(
16-
base64content, 'http://example.com' as Platform.DevToolsPath.UrlString,
17-
Common.ResourceType.resourceTypes.WebSocket);
17+
TextUtils.StreamingContentData.StreamingContentData.from(base64content),
18+
'http://example.com' as Platform.DevToolsPath.UrlString, Common.ResourceType.resourceTypes.WebSocket);
1819

1920
async function getResourceText(view: SourceFrame.ResourceSourceFrame.ResourceSourceFrame): Promise<string> {
2021
const contentData =

front_end/ui/legacy/components/source_frame/BinaryResourceViewFactory.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import * as TextUtils from '../../../../models/text_utils/text_utils.js';
99
import {ResourceSourceFrame} from './ResourceSourceFrame.js';
1010

1111
export class BinaryResourceViewFactory {
12-
private base64content: string;
12+
private streamingContent: TextUtils.StreamingContentData.StreamingContentData;
1313
private readonly contentUrl: Platform.DevToolsPath.UrlString;
1414
private readonly resourceType: Common.ResourceType.ResourceType;
1515
private arrayPromise: Promise<Uint8Array>|null;
1616
private hexPromise: Promise<string>|null;
1717
private utf8Promise: Promise<string>|null;
1818
constructor(
19-
base64content: string, contentUrl: Platform.DevToolsPath.UrlString,
19+
content: TextUtils.StreamingContentData.StreamingContentData, contentUrl: Platform.DevToolsPath.UrlString,
2020
resourceType: Common.ResourceType.ResourceType) {
21-
this.base64content = base64content;
21+
this.streamingContent = content;
2222
this.contentUrl = contentUrl;
2323
this.resourceType = resourceType;
2424
this.arrayPromise = null;
@@ -29,7 +29,7 @@ export class BinaryResourceViewFactory {
2929
private async fetchContentAsArray(): Promise<Uint8Array> {
3030
if (!this.arrayPromise) {
3131
this.arrayPromise = new Promise(async resolve => {
32-
const fetchResponse = await fetch('data:;base64,' + this.base64content);
32+
const fetchResponse = await fetch('data:;base64,' + this.streamingContent.content().base64);
3333
resolve(new Uint8Array(await fetchResponse.arrayBuffer()));
3434
});
3535
}
@@ -49,7 +49,7 @@ export class BinaryResourceViewFactory {
4949
}
5050

5151
base64(): string {
52-
return this.base64content;
52+
return this.streamingContent.content().base64;
5353
}
5454

5555
async utf8(): Promise<string> {
@@ -67,7 +67,7 @@ export class BinaryResourceViewFactory {
6767
createBase64View(): ResourceSourceFrame {
6868
return new ResourceSourceFrame(
6969
TextUtils.StaticContentProvider.StaticContentProvider.fromString(
70-
this.contentUrl, this.resourceType, this.base64content),
70+
this.contentUrl, this.resourceType, this.streamingContent.content().base64),
7171
this.resourceType.canonicalMimeType(), {lineNumbers: false, lineWrapping: true});
7272
}
7373

0 commit comments

Comments
 (0)