From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../src/components/previews/ImagePreview.js | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 devtools/client/netmonitor/src/components/previews/ImagePreview.js (limited to 'devtools/client/netmonitor/src/components/previews/ImagePreview.js') diff --git a/devtools/client/netmonitor/src/components/previews/ImagePreview.js b/devtools/client/netmonitor/src/components/previews/ImagePreview.js new file mode 100644 index 0000000000..003a7ec38e --- /dev/null +++ b/devtools/client/netmonitor/src/components/previews/ImagePreview.js @@ -0,0 +1,91 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { + Component, +} = require("resource://devtools/client/shared/vendor/react.js"); +const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.js"); +const { + L10N, +} = require("resource://devtools/client/netmonitor/src/utils/l10n.js"); + +const { + div, + img, +} = require("resource://devtools/client/shared/vendor/react-dom-factories.js"); + +const { + formDataURI, + getUrlBaseName, +} = require("resource://devtools/client/netmonitor/src/utils/request-utils.js"); + +const RESPONSE_IMG_NAME = L10N.getStr("netmonitor.response.name"); +const RESPONSE_IMG_DIMENSIONS = L10N.getStr("netmonitor.response.dimensions"); +const RESPONSE_IMG_MIMETYPE = L10N.getStr("netmonitor.response.mime"); + +class ImagePreview extends Component { + static get propTypes() { + return { + mimeType: PropTypes.string, + encoding: PropTypes.string, + text: PropTypes.string, + url: PropTypes.string, + }; + } + + constructor(props) { + super(props); + + this.state = { + dimensions: { + width: 0, + height: 0, + }, + }; + + this.updateDimensions = this.updateDimensions.bind(this); + } + + updateDimensions({ target }) { + this.setState({ + dimensions: { + width: target.naturalWidth, + height: target.naturalHeight, + }, + }); + } + + render() { + const { mimeType, encoding, text, url } = this.props; + const { width, height } = this.state.dimensions; + + return div( + { className: "panel-container response-image-box devtools-monospace" }, + img({ + className: "response-image", + src: formDataURI(mimeType, encoding, text), + onLoad: this.updateDimensions, + }), + div( + { className: "response-summary" }, + div({ className: "tabpanel-summary-label" }, RESPONSE_IMG_NAME), + div({ className: "tabpanel-summary-value" }, getUrlBaseName(url)) + ), + div( + { className: "response-summary" }, + div({ className: "tabpanel-summary-label" }, RESPONSE_IMG_DIMENSIONS), + div({ className: "tabpanel-summary-value" }, `${width} × ${height}`) + ), + div( + { className: "response-summary" }, + div({ className: "tabpanel-summary-label" }, RESPONSE_IMG_MIMETYPE), + div({ className: "tabpanel-summary-value" }, mimeType) + ) + ); + } +} + +module.exports = ImagePreview; -- cgit v1.2.3