OnionLocationChild.sys.mjs (1259B)
1 // Copyright (c) 2020, The Tor Project, Inc. 2 3 /** 4 * This class contains the child part of Onion Location. 5 */ 6 export class OnionLocationChild extends JSWindowActorChild { 7 handleEvent(event) { 8 this.onPageShow(event); 9 } 10 11 onPageShow(event) { 12 if (event.target != this.document) { 13 return; 14 } 15 const onionLocationURI = this.document.onionLocationURI; 16 if (onionLocationURI) { 17 this.sendAsyncMessage("OnionLocation:Set"); 18 } 19 } 20 21 receiveMessage(aMessage) { 22 if (aMessage.name == "OnionLocation:Refresh") { 23 const doc = this.document; 24 const docShell = this.docShell; 25 let onionLocationURI = doc.onionLocationURI; 26 const refreshURI = docShell.QueryInterface(Ci.nsIRefreshURI); 27 if (onionLocationURI && refreshURI) { 28 const docUrl = URL.parse(doc.URL); 29 let onionUrl = URL.parse(onionLocationURI.asciiSpec); 30 // Keep consistent with Location 31 if (!onionUrl?.hash && docUrl?.hash) { 32 onionUrl.hash = docUrl.hash; 33 onionLocationURI = Services.io.newURI(onionUrl?.toString() || ""); 34 } 35 refreshURI.refreshURI( 36 onionLocationURI, 37 doc.nodePrincipal, 38 0, 39 false, 40 true 41 ); 42 } 43 } 44 } 45 }