2017-07-26 13:28:43 +03:00
import React from 'react' ;
import PropTypes from 'prop-types' ;
2017-07-26 18:47:58 +03:00
import url from 'url' ;
2017-07-28 18:39:18 +03:00
import { _t } from '../../../languageHandler' ;
2018-06-26 13:59:16 +03:00
import WidgetUtils from "../../../utils/WidgetUtils" ;
2017-07-26 13:28:43 +03:00
export default class AppPermission extends React . Component {
constructor ( props ) {
super ( props ) ;
2017-07-28 12:18:06 +03:00
const curlBase = this . getCurlBase ( ) ;
2017-07-28 18:36:06 +03:00
this . state = { curlBase : curlBase } ;
2017-07-26 13:28:43 +03:00
}
2017-07-28 12:18:06 +03:00
// Return string representation of content URL without query parameters
getCurlBase ( ) {
2017-07-26 18:47:58 +03:00
const wurl = url . parse ( this . props . url ) ;
let curl ;
2017-07-28 12:01:58 +03:00
let curlString ;
2017-07-26 18:47:58 +03:00
const searchParams = new URLSearchParams ( wurl . search ) ;
2017-07-28 12:01:58 +03:00
2018-05-27 20:12:55 +03:00
if ( WidgetUtils . isScalarUrl ( wurl ) && searchParams && searchParams . get ( 'url' ) ) {
2017-07-28 12:01:58 +03:00
curl = url . parse ( searchParams . get ( 'url' ) ) ;
2017-11-16 16:19:36 +03:00
if ( curl ) {
2017-07-28 12:01:58 +03:00
curl . search = curl . query = "" ;
curlString = curl . format ( ) ;
}
2017-07-26 13:28:43 +03:00
}
2017-07-27 18:42:29 +03:00
if ( ! curl && wurl ) {
wurl . search = wurl . query = "" ;
2017-07-28 12:01:58 +03:00
curlString = wurl . format ( ) ;
2017-07-27 18:42:29 +03:00
}
2017-07-28 12:01:58 +03:00
return curlString ;
2017-07-26 13:28:43 +03:00
}
render ( ) {
2017-08-18 18:44:33 +03:00
let e2eWarningText ;
if ( this . props . isRoomEncrypted ) {
e2eWarningText =
2017-09-28 13:21:06 +03:00
< span className = 'mx_AppPermissionWarningTextLabel' > { _t ( 'NOTE: Apps are not end-to-end encrypted' ) } < / s p a n > ;
2017-08-18 18:44:33 +03:00
}
2018-05-23 12:46:32 +03:00
const cookieWarning =
< span className = 'mx_AppPermissionWarningTextLabel' >
{ _t ( 'Warning: This widget might use cookies.' ) }
< / s p a n > ;
2017-07-26 13:28:43 +03:00
return (
2017-07-26 18:47:58 +03:00
< div className = 'mx_AppPermissionWarning' >
< div className = 'mx_AppPermissionWarningImage' >
2019-01-11 04:37:28 +03:00
< img src = { require ( "../../../../res/img/warning.svg" ) } alt = { _t ( 'Warning!' ) } / >
2017-07-26 18:47:58 +03:00
< / d i v >
< div className = 'mx_AppPermissionWarningText' >
2017-09-28 13:21:06 +03:00
< span className = 'mx_AppPermissionWarningTextLabel' > { _t ( 'Do you want to load widget from URL:' ) } < / s p a n > < s p a n c l a s s N a m e = ' m x _ A p p P e r m i s s i o n W a r n i n g T e x t U R L ' > { t h i s . s t a t e . c u r l B a s e } < / s p a n >
{ e2eWarningText }
2018-05-23 12:46:32 +03:00
{ cookieWarning }
2017-07-26 18:47:58 +03:00
< / d i v >
2017-07-26 13:28:43 +03:00
< input
2017-07-26 18:47:58 +03:00
className = 'mx_AppPermissionButton'
2017-07-26 13:28:43 +03:00
type = 'button'
2017-07-28 18:42:07 +03:00
value = { _t ( 'Allow' ) }
2017-07-26 13:28:43 +03:00
onClick = { this . props . onPermissionGranted }
/ >
< / d i v >
) ;
}
}
AppPermission . propTypes = {
2017-08-18 18:44:33 +03:00
isRoomEncrypted : PropTypes . bool ,
2017-07-26 13:28:43 +03:00
url : PropTypes . string . isRequired ,
onPermissionGranted : PropTypes . func . isRequired ,
} ;
2017-07-28 18:23:38 +03:00
AppPermission . defaultProps = {
2017-08-18 18:44:33 +03:00
isRoomEncrypted : false ,
2017-07-26 13:28:43 +03:00
onPermissionGranted : function ( ) { } ,
} ;