2016-04-29 01:00:12 +00:00
|
|
|
import React, {Component, PropTypes} from 'react'
|
|
|
|
|
|
|
|
class ResponseBodyWebview extends Component {
|
|
|
|
_setBody () {
|
2016-04-30 05:01:57 +00:00
|
|
|
const {body, contentType} = this.props;
|
2016-04-29 01:00:12 +00:00
|
|
|
const {webview} = this.refs;
|
|
|
|
|
2016-04-30 05:01:57 +00:00
|
|
|
const encoded = new Buffer(body).toString('base64');
|
|
|
|
webview.loadURL(`data:${contentType};base64,${encoded}`);
|
2016-04-29 01:00:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate () {
|
|
|
|
this._setBody();
|
|
|
|
}
|
2016-05-01 19:56:30 +00:00
|
|
|
|
2016-04-29 05:58:37 +00:00
|
|
|
shouldComponentUpdate (nextProps) {
|
2016-04-30 05:01:57 +00:00
|
|
|
for (let key in nextProps) {
|
|
|
|
if (nextProps.hasOwnProperty(key)) {
|
|
|
|
if (nextProps[key] !== this.props[key]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2016-04-29 05:58:37 +00:00
|
|
|
}
|
2016-04-29 01:00:12 +00:00
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
const {webview} = this.refs;
|
2016-05-01 19:56:30 +00:00
|
|
|
|
2016-04-29 01:00:12 +00:00
|
|
|
const cb = () => {
|
|
|
|
webview.removeEventListener('dom-ready', cb);
|
|
|
|
this._setBody();
|
|
|
|
};
|
2016-05-01 19:56:30 +00:00
|
|
|
|
2016-04-29 01:00:12 +00:00
|
|
|
webview.addEventListener('dom-ready', cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
2016-05-01 19:56:30 +00:00
|
|
|
<webview ref="webview" src=""></webview>
|
2016-04-29 01:00:12 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ResponseBodyWebview.propTypes = {
|
2016-04-30 05:01:57 +00:00
|
|
|
body: PropTypes.string.isRequired,
|
|
|
|
contentType: PropTypes.string.isRequired
|
2016-04-29 01:00:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default ResponseBodyWebview;
|