'use strict' ; import { Api } from '../api/shared/api.js' ; import { Attachment } from '../core/attachment.js' ; import { Catch } from '../platform/catch.js' ; import { Dict , Url , UrlParam } from '../core/common.js' ; import { GlobalStore } from '../platform/store/global-store.js' ; import { Xss } from '../platform/xss.js' ; export class Browser { public static objUrlCreate = ( content ) => { return window . URL . createObjectURL ( new Blob ( [ content ] , { type : 'application/octet-stream' } ) ) ; } ; public static objUrlConsume = async ( url ) => { const buf = await Api . download ( url ) ; window . URL . revokeObjectURL ( url ) ; return buf ; } ; public static saveToDownloads = ( attachment ) => { const blob = new Blob ( [ attachment . getData ( ) ] , { type : attachment . type } ) ; const a = window . document . createElement ( 'a' ) ; a . href = window . URL . createObjectURL ( blob ) ; a . download = Xss . escape ( attachment . name ) ; if ( typeof a . click === 'function' ) { a . click ( ) ; } else { const ev = document . createEvent ( 'MouseEvents' ) ; ev . initMouseEvent ( 'click' , true , true , window ) ; a . dispatchEvent ( ev ) ; } if ( Catch . browser ( ) . name === 'firefox' ) { try { a . remove ( ) ; } catch ( err ) { if ( ! ( err instanceof Error && err . message === 'Node was not found' ) ) { throw err ; } } } Catch . setHandledTimeout ( ( ) => window . URL . revokeObjectURL ( a . href ) , 0 ) ; } ; public static arrFromDomNodeList = ( obj ) : Node [ ] => { const array = [ ] ; for ( let i = obj . length >>> 0 ; i -- ; ) { array [ i ] = obj [ i ] ; } return array ; } ; public static openSettingsPage = async ( path = 'index.htm' , acctEmail ? , page = '' , rawPageUrlParams ? , addNewAcct = false ) => { const basePath = chrome . runtime . getURL ( `chrome/settings/${ path }` ) ; const pageUrlParams = rawPageUrlParams ? JSON . stringify ( rawPageUrlParams ) : undefined ; if ( acctEmail || path === 'fatal.htm' ) { Browser . openExtensionTab ( Url . create ( basePath , { acctEmail , page , pageUrlParams } ) ) ; } else if ( addNewAcct ) { Browser . openExtensionTab ( Url . create ( basePath , { addNewAcct } ) ) ; } else { const acctEmails = await GlobalStore . acctEmailsGet ( ) ; Browser . openExtensionTab ( Url . create ( basePath , { acctEmail : acctEmails [ 0 ] , page , pageUrlParams } ) ) ; } } ; public static openExtensionTab = ( url ) => { const tab = window . open ( url , 'flowcrypt' ) ; if ( tab ) { tab . focus ( ) ; } } ; }