TLSCertificateBindingChild.sys.mjs (1449B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 export class TLSCertificateBindingChild extends JSWindowActorChild { 6 #tlsCertificateBindingPromise = undefined; 7 8 constructor() { 9 super(); 10 } 11 12 async receiveMessage(message) { 13 if (message.name == "TLSCertificateBinding::Get") { 14 this.maybeFetchTLSCertificateBinding(); 15 return this.#tlsCertificateBindingPromise; 16 } 17 return undefined; 18 } 19 20 maybeFetchTLSCertificateBinding() { 21 // `#tlsCertificateBindingPromise` will be undefined if we haven't yet 22 // attempted fetching for this document. 23 if (this.#tlsCertificateBindingPromise === undefined) { 24 this.#tlsCertificateBindingPromise = this.#fetchTLSCertificateBinding(); 25 } 26 } 27 28 async #fetchTLSCertificateBinding() { 29 if (this.document.tlsCertificateBindingURI) { 30 try { 31 let response = await this.contentWindow.fetch( 32 this.document.tlsCertificateBindingURI.spec 33 ); 34 if (response.ok) { 35 return response.text(); 36 } 37 } catch (e) { 38 console.error("Fetching TLS certificate binding failed:", e); 39 } 40 } 41 // If there is no TLS certificate binding URI, or if fetching it failed, 42 // return null to indicate that an attempt to fetch it was made. 43 return null; 44 } 45 }