IPProtectionHelpers.sys.mjs (3300B)
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 /** 6 * Note: If you add or modify the list of helpers, make sure to update the 7 * corresponding documentation in the `docs` folder as well. 8 */ 9 10 const lazy = {}; 11 12 ChromeUtils.defineESModuleGetters(lazy, { 13 IPPExceptionsManager: 14 "moz-src:///browser/components/ipprotection/IPPExceptionsManager.sys.mjs", 15 IPProtection: 16 "moz-src:///browser/components/ipprotection/IPProtection.sys.mjs", 17 IPProtectionService: 18 "moz-src:///browser/components/ipprotection/IPProtectionService.sys.mjs", 19 IPProtectionStates: 20 "moz-src:///browser/components/ipprotection/IPProtectionService.sys.mjs", 21 }); 22 23 import { IPPProxyManager } from "moz-src:///browser/components/ipprotection/IPPProxyManager.sys.mjs"; 24 import { IPPAutoStartHelpers } from "moz-src:///browser/components/ipprotection/IPPAutoStart.sys.mjs"; 25 import { IPPEnrollAndEntitleManager } from "moz-src:///browser/components/ipprotection/IPPEnrollAndEntitleManager.sys.mjs"; 26 import { IPPNimbusHelper } from "moz-src:///browser/components/ipprotection/IPPNimbusHelper.sys.mjs"; 27 import { IPPOnboardingMessage } from "moz-src:///browser/components/ipprotection/IPPOnboardingMessageHelper.sys.mjs"; 28 import { IPProtectionServerlist } from "moz-src:///browser/components/ipprotection/IPProtectionServerlist.sys.mjs"; 29 import { IPPSignInWatcher } from "moz-src:///browser/components/ipprotection/IPPSignInWatcher.sys.mjs"; 30 import { IPPStartupCache } from "moz-src:///browser/components/ipprotection/IPPStartupCache.sys.mjs"; 31 import { IPPOptOutHelper } from "moz-src:///browser/components/ipprotection/IPPOptOutHelper.sys.mjs"; 32 import { IPPVPNAddonHelper } from "moz-src:///browser/components/ipprotection/IPPVPNAddonHelper.sys.mjs"; 33 34 /** 35 * This simple class controls the UI activation/deactivation. 36 */ 37 class UIHelper { 38 constructor() { 39 this.handleEvent = this.#handleEvent.bind(this); 40 } 41 42 init() { 43 lazy.IPProtectionService.addEventListener( 44 "IPProtectionService:StateChanged", 45 this.handleEvent 46 ); 47 } 48 49 initOnStartupCompleted() {} 50 51 uninit() { 52 lazy.IPProtectionService.removeEventListener( 53 "IPProtectionService:StateChanged", 54 this.handleEvent 55 ); 56 lazy.IPProtection.uninit(); 57 lazy.IPPExceptionsManager.uninit(); 58 } 59 60 #handleEvent(_event) { 61 const state = lazy.IPProtectionService.state; 62 63 if ( 64 !lazy.IPProtection.isInitialized && 65 state !== lazy.IPProtectionStates.UNINITIALIZED && 66 state !== lazy.IPProtectionStates.UNAVAILABLE 67 ) { 68 lazy.IPProtection.init(); 69 lazy.IPPExceptionsManager.init(); 70 } 71 72 if ( 73 lazy.IPProtection.isInitialized && 74 (state === lazy.IPProtectionStates.UNINITIALIZED || 75 state === lazy.IPProtectionStates.UNAVAILABLE) 76 ) { 77 lazy.IPProtection.uninit(); 78 lazy.IPPExceptionsManager.uninit(); 79 } 80 } 81 } 82 83 const IPPHelpers = [ 84 IPPStartupCache, 85 IPPSignInWatcher, 86 IPProtectionServerlist, 87 IPPEnrollAndEntitleManager, 88 IPPOnboardingMessage, 89 IPPProxyManager, 90 new UIHelper(), 91 IPPVPNAddonHelper, 92 ...IPPAutoStartHelpers, 93 IPPOptOutHelper, 94 IPPNimbusHelper, 95 ]; 96 97 export { IPPHelpers };