GeckoViewIdentityCredential.sys.mjs (2464B)
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 file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 import { GeckoViewUtils } from "resource://gre/modules/GeckoViewUtils.sys.mjs"; 6 7 const lazy = {}; 8 9 ChromeUtils.defineESModuleGetters(lazy, { 10 GeckoViewPrompter: "resource://gre/modules/GeckoViewPrompter.sys.mjs", 11 }); 12 13 export const GeckoViewIdentityCredential = { 14 async onShowProviderPrompt(aBrowser, providers, resolve, reject) { 15 const prompt = new lazy.GeckoViewPrompter(aBrowser.ownerGlobal); 16 debug`onShowProviderPrompt`; 17 18 prompt.asyncShowPrompt( 19 { 20 type: "IdentityCredential:Select:Provider", 21 providers, 22 }, 23 result => { 24 if (result && result.providerIndex != null) { 25 debug`onShowProviderPrompt resolve with ${result.providerIndex}`; 26 resolve(result.providerIndex); 27 } else { 28 debug`onShowProviderPrompt rejected`; 29 reject(); 30 } 31 } 32 ); 33 }, 34 async onShowAccountsPrompt(aBrowser, accounts, resolve, reject) { 35 const prompt = new lazy.GeckoViewPrompter(aBrowser.ownerGlobal); 36 debug`onShowAccountsPrompt`; 37 38 prompt.asyncShowPrompt( 39 { 40 type: "IdentityCredential:Select:Account", 41 accounts, 42 }, 43 result => { 44 if (result && result.accountIndex != null) { 45 debug`onShowAccountsPrompt resolve with ${result.accountIndex}`; 46 resolve(result.accountIndex); 47 } else { 48 debug`onShowAccountsPrompt rejected`; 49 reject(); 50 } 51 } 52 ); 53 }, 54 async onShowPolicyPrompt( 55 aBrowser, 56 privacyPolicyUrl, 57 termsOfServiceUrl, 58 providerDomain, 59 host, 60 icon, 61 resolve, 62 reject 63 ) { 64 const prompt = new lazy.GeckoViewPrompter(aBrowser.ownerGlobal); 65 debug`onShowPolicyPrompt`; 66 67 prompt.asyncShowPrompt( 68 { 69 type: "IdentityCredential:Show:Policy", 70 privacyPolicyUrl, 71 termsOfServiceUrl, 72 providerDomain, 73 host, 74 icon, 75 }, 76 result => { 77 if (result && result.accept != null) { 78 debug`onShowPolicyPrompt resolve with ${result.accept}`; 79 resolve(result.accept); 80 } else { 81 debug`onShowPolicyPrompt rejected`; 82 reject(); 83 } 84 } 85 ); 86 }, 87 }; 88 89 const { debug } = GeckoViewUtils.initLogging("GeckoViewIdentityCredential");