Skip to content

Commit 24b562d

Browse files
szuendDevtools-frontend LUCI CQ
authored andcommitted
[network] Use BinaryResourceView for binary response content
Screenshot: https://imgur.com/a/HguIx06 This CL changes two things: - For binary network requests we'll show the BinaryResourceView instead of the linear memory inspector. - In the BinaryResourceView we use the linear memory inspector when the "hex" option is selected instead of showing an editor with a hex dump. This allows users to see binary network request response data not just in hex view, but also in base64 and even force utf-8 decode it. [email protected] Bug: 375546679 Change-Id: Ie048d02ade1cd0bae26dd900f9ca24f78c67fa39 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5973207 Commit-Queue: Simon Zünd <[email protected]> Reviewed-by: Kim-Anh Tran <[email protected]>
1 parent 703c46c commit 24b562d

File tree

4 files changed

+9
-18
lines changed

4 files changed

+9
-18
lines changed

front_end/panels/network/RequestResponseView.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describeWithEnvironment('RequestResponseView', () => {
4242
component.detach();
4343
});
4444

45-
it('shows the StreamingContentHexView for binary content', async () => {
45+
it('shows the BinaryResourceView for binary content', async () => {
4646
const request = SDK.NetworkRequest.NetworkRequest.create(
4747
'requestId' as Protocol.Network.RequestId,
4848
'http://devtools-frontend.test/image.png' as Platform.DevToolsPath.UrlString,
@@ -60,7 +60,7 @@ describeWithEnvironment('RequestResponseView', () => {
6060
component.show(document.body);
6161
const widget = await showPreviewSpy.returnValues[0];
6262

63-
assert.instanceOf(widget, SourceFrame.StreamingContentHexView.StreamingContentHexView);
63+
assert.instanceOf(widget, Network.BinaryResourceView.BinaryResourceView);
6464

6565
await raf();
6666
component.detach();

front_end/panels/network/RequestResponseView.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import * as SourceFrame from '../../ui/legacy/components/source_frame/source_fra
3737
import * as UI from '../../ui/legacy/legacy.js';
3838
import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
3939

40+
import {BinaryResourceView} from './BinaryResourceView.js';
41+
4042
const UIStrings = {
4143
/**
4244
*@description Text in Request Response View of the Network panel
@@ -94,7 +96,7 @@ export class RequestResponseView extends UI.Widget.VBox {
9496
// Note: Even though WASM is binary data, the source view will disassemble it and show a text representation.
9597
sourceView = SourceFrame.ResourceSourceFrame.ResourceSourceFrame.createSearchableView(request, mimeType);
9698
} else {
97-
sourceView = new SourceFrame.StreamingContentHexView.StreamingContentHexView(contentData);
99+
sourceView = new BinaryResourceView(contentData, request.url(), request.resourceType());
98100
}
99101

100102
requestToSourceView.set(request, sourceView);

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ describeWithEnvironment('BinaryResourceViewFactory', () => {
2626
assert.strictEqual(
2727
await getResourceText(factory.createBase64View()),
2828
'c2VuZGluZyB0aGlzIHV0Zi04IHN0cmluZyBhcyBhIGJpbmFyeSBtZXNzYWdlLi4u');
29-
assert.strictEqual(
30-
await getResourceText(factory.createHexView()),
31-
`00000000: 7365 6e64 696e 6720 7468 6973 2075 7466 sending this utf
32-
00000001: 2d38 2073 7472 696e 6720 6173 2061 2062 -8 string as a b
33-
00000002: 696e 6172 7920 6d65 7373 6167 652e 2e2e inary message...
34-
`);
29+
assert.instanceOf(factory.createHexView(), SourceFrame.StreamingContentHexView.StreamingContentHexView);
3530
assert.strictEqual(
3631
await getResourceText(factory.createUtf8View()), 'sending this utf-8 string as a binary message...');
3732
});

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type * as Platform from '../../../../core/platform/platform.js';
77
import * as TextUtils from '../../../../models/text_utils/text_utils.js';
88

99
import {ResourceSourceFrame} from './ResourceSourceFrame.js';
10+
import {StreamingContentHexView} from './StreamingContentHexView.js';
1011

1112
export class BinaryResourceViewFactory {
1213
private streamingContent: TextUtils.StreamingContentData.StreamingContentData;
@@ -71,15 +72,8 @@ export class BinaryResourceViewFactory {
7172
this.resourceType.canonicalMimeType(), {lineNumbers: false, lineWrapping: true});
7273
}
7374

74-
createHexView(): ResourceSourceFrame {
75-
const hexViewerContentProvider =
76-
new TextUtils.StaticContentProvider.StaticContentProvider(this.contentUrl, this.resourceType, async () => {
77-
const contentAsArray = await this.fetchContentAsArray();
78-
const content = BinaryResourceViewFactory.uint8ArrayToHexViewer(contentAsArray);
79-
return new TextUtils.ContentData.ContentData(content, /* isBase64 */ false, 'text/plain');
80-
});
81-
return new ResourceSourceFrame(
82-
hexViewerContentProvider, this.resourceType.canonicalMimeType(), {lineNumbers: false, lineWrapping: false});
75+
createHexView(): StreamingContentHexView {
76+
return new StreamingContentHexView(this.streamingContent);
8377
}
8478

8579
createUtf8View(): ResourceSourceFrame {

0 commit comments

Comments
 (0)