@@ -172,7 +172,7 @@ export { Management };
172172
173173const { getUniqueId, promiseTimeout } = ExtensionUtils ;
174174
175- const { EventEmitter, updateAllowedOrigins } = ExtensionCommon ;
175+ const { EventEmitter, redefineGetter , updateAllowedOrigins } = ExtensionCommon ;
176176
177177ChromeUtils . defineLazyGetter (
178178 lazy ,
@@ -869,6 +869,19 @@ const manifestTypes = new Map([
869869 * `loadManifest` has been called, and completed.
870870 */
871871export class ExtensionData {
872+ /**
873+ * Note: These fields are only available and meant to be used on Extension
874+ * instances, declared here because methods from this class reference them.
875+ */
876+ /** @type {object } TODO: move to the Extension class, bug 1871094. */
877+ addonData ;
878+ /** @type {nsIURI } */
879+ baseURI ;
880+ /** @type {nsIPrincipal } */
881+ principal ;
882+ /** @type {boolean } */
883+ temporarilyInstalled ;
884+
872885 constructor ( rootURI , isPrivileged = false ) {
873886 this . rootURI = rootURI ;
874887 this . resourceURL = rootURI . spec ;
@@ -2676,7 +2689,7 @@ class BootstrapScope {
26762689 // APP_STARTED. In some situations, such as background and
26772690 // persisted listeners, we also need to know that the addon
26782691 // was updated.
2679- this . updateReason = this . BOOTSTRAP_REASON_TO_STRING_MAP [ reason ] ;
2692+ this . updateReason = BootstrapScope . BOOTSTRAP_REASON_MAP [ reason ] ;
26802693 // Retain any previously granted permissions that may have migrated
26812694 // into the optional list.
26822695 if ( data . oldPermissions ) {
@@ -2703,39 +2716,35 @@ class BootstrapScope {
27032716 // eslint-disable-next-line no-use-before-define
27042717 this . extension = new Extension (
27052718 data ,
2706- this . BOOTSTRAP_REASON_TO_STRING_MAP [ reason ] ,
2719+ BootstrapScope . BOOTSTRAP_REASON_MAP [ reason ] ,
27072720 this . updateReason
27082721 ) ;
27092722 return this . extension . startup ( ) ;
27102723 }
27112724
27122725 async shutdown ( data , reason ) {
27132726 let result = await this . extension . shutdown (
2714- this . BOOTSTRAP_REASON_TO_STRING_MAP [ reason ]
2727+ BootstrapScope . BOOTSTRAP_REASON_MAP [ reason ]
27152728 ) ;
27162729 this . extension = null ;
27172730 return result ;
27182731 }
2719- }
27202732
2721- ChromeUtils . defineLazyGetter (
2722- BootstrapScope . prototype ,
2723- "BOOTSTRAP_REASON_TO_STRING_MAP" ,
2724- ( ) => {
2725- const { BOOTSTRAP_REASONS } = lazy . AddonManagerPrivate ;
2726-
2727- return Object . freeze ( {
2728- [ BOOTSTRAP_REASONS . APP_STARTUP ] : "APP_STARTUP" ,
2729- [ BOOTSTRAP_REASONS . APP_SHUTDOWN ] : "APP_SHUTDOWN" ,
2730- [ BOOTSTRAP_REASONS . ADDON_ENABLE ] : "ADDON_ENABLE" ,
2731- [ BOOTSTRAP_REASONS . ADDON_DISABLE ] : "ADDON_DISABLE" ,
2732- [ BOOTSTRAP_REASONS . ADDON_INSTALL ] : "ADDON_INSTALL" ,
2733- [ BOOTSTRAP_REASONS . ADDON_UNINSTALL ] : "ADDON_UNINSTALL" ,
2734- [ BOOTSTRAP_REASONS . ADDON_UPGRADE ] : "ADDON_UPGRADE" ,
2735- [ BOOTSTRAP_REASONS . ADDON_DOWNGRADE ] : "ADDON_DOWNGRADE" ,
2733+ static get BOOTSTRAP_REASON_MAP ( ) {
2734+ const BR = lazy . AddonManagerPrivate . BOOTSTRAP_REASONS ;
2735+ const value = Object . freeze ( {
2736+ [ BR . APP_STARTUP ] : "APP_STARTUP" ,
2737+ [ BR . APP_SHUTDOWN ] : "APP_SHUTDOWN" ,
2738+ [ BR . ADDON_ENABLE ] : "ADDON_ENABLE" ,
2739+ [ BR . ADDON_DISABLE ] : "ADDON_DISABLE" ,
2740+ [ BR . ADDON_INSTALL ] : "ADDON_INSTALL" ,
2741+ [ BR . ADDON_UNINSTALL ] : "ADDON_UNINSTALL" ,
2742+ [ BR . ADDON_UPGRADE ] : "ADDON_UPGRADE" ,
2743+ [ BR . ADDON_DOWNGRADE ] : "ADDON_DOWNGRADE" ,
27362744 } ) ;
2745+ return redefineGetter ( this , "BOOTSTRAP_REASON_TO_STRING_MAP" , value ) ;
27372746 }
2738- ) ;
2747+ }
27392748
27402749class DictionaryBootstrapScope extends BootstrapScope {
27412750 install ( data , reason ) { }
@@ -2744,28 +2753,28 @@ class DictionaryBootstrapScope extends BootstrapScope {
27442753 startup ( data , reason ) {
27452754 // eslint-disable-next-line no-use-before-define
27462755 this . dictionary = new Dictionary ( data ) ;
2747- return this . dictionary . startup ( this . BOOTSTRAP_REASON_TO_STRING_MAP [ reason ] ) ;
2756+ return this . dictionary . startup ( BootstrapScope . BOOTSTRAP_REASON_MAP [ reason ] ) ;
27482757 }
27492758
2750- shutdown ( data , reason ) {
2751- this . dictionary . shutdown ( this . BOOTSTRAP_REASON_TO_STRING_MAP [ reason ] ) ;
2759+ async shutdown ( data , reason ) {
2760+ this . dictionary . shutdown ( BootstrapScope . BOOTSTRAP_REASON_MAP [ reason ] ) ;
27522761 this . dictionary = null ;
27532762 }
27542763}
27552764
27562765class LangpackBootstrapScope extends BootstrapScope {
27572766 install ( data , reason ) { }
27582767 uninstall ( data , reason ) { }
2759- update ( data , reason ) { }
2768+ async update ( data , reason ) { }
27602769
27612770 startup ( data , reason ) {
27622771 // eslint-disable-next-line no-use-before-define
27632772 this . langpack = new Langpack ( data ) ;
2764- return this . langpack . startup ( this . BOOTSTRAP_REASON_TO_STRING_MAP [ reason ] ) ;
2773+ return this . langpack . startup ( BootstrapScope . BOOTSTRAP_REASON_MAP [ reason ] ) ;
27652774 }
27662775
2767- shutdown ( data , reason ) {
2768- this . langpack . shutdown ( this . BOOTSTRAP_REASON_TO_STRING_MAP [ reason ] ) ;
2776+ async shutdown ( data , reason ) {
2777+ this . langpack . shutdown ( BootstrapScope . BOOTSTRAP_REASON_MAP [ reason ] ) ;
27692778 this . langpack = null ;
27702779 }
27712780}
@@ -2779,12 +2788,12 @@ class SitePermissionBootstrapScope extends BootstrapScope {
27792788 // eslint-disable-next-line no-use-before-define
27802789 this . sitepermission = new SitePermission ( data ) ;
27812790 return this . sitepermission . startup (
2782- this . BOOTSTRAP_REASON_TO_STRING_MAP [ reason ]
2791+ BootstrapScope . BOOTSTRAP_REASON_MAP [ reason ]
27832792 ) ;
27842793 }
27852794
2786- shutdown ( data , reason ) {
2787- this . sitepermission . shutdown ( this . BOOTSTRAP_REASON_TO_STRING_MAP [ reason ] ) ;
2795+ async shutdown ( data , reason ) {
2796+ this . sitepermission . shutdown ( BootstrapScope . BOOTSTRAP_REASON_MAP [ reason ] ) ;
27882797 this . sitepermission = null ;
27892798 }
27902799}
@@ -2800,6 +2809,9 @@ let pendingExtensions = new Map();
28002809 * @augments ExtensionData
28012810 */
28022811export class Extension extends ExtensionData {
2812+ /** @type {Map<string, Map<string, any>> } */
2813+ persistentListeners ;
2814+
28032815 constructor ( addonData , startupReason , updateReason ) {
28042816 super ( addonData . resourceURI , addonData . isPrivileged ) ;
28052817
@@ -2832,6 +2844,7 @@ export class Extension extends ExtensionData {
28322844 this . startupData = addonData . startupData || { } ;
28332845 this . startupReason = startupReason ;
28342846 this . updateReason = updateReason ;
2847+ this . temporarilyInstalled = ! ! addonData . temporarilyInstalled ;
28352848
28362849 if (
28372850 updateReason ||
@@ -3077,10 +3090,6 @@ export class Extension extends ExtensionData {
30773090 return [ this . id , this . version , Services . locale . appLocaleAsBCP47 ] ;
30783091 }
30793092
3080- get temporarilyInstalled ( ) {
3081- return ! ! this . addonData . temporarilyInstalled ;
3082- }
3083-
30843093 saveStartupData ( ) {
30853094 if ( this . dontSaveStartupData ) {
30863095 return ;
0 commit comments