forked from mirrors/gecko-dev
		
	This patch was generated as follows: Run: `./mach esmify --imports . --prefix=toolkit/mozapps/extensions/AddonManager` In the output there are linter/prettifier errors due to unused XPCOMUtils or separate importESModule calls. These have been fixed manually and verified with `./mach lint --outgoing`. The `esmify` script also inserts many unwanted newlines around imports that are broken on two lines due to length. Due to the number of these, I fixed them programatically. 1. Create patch from the changes so far. 2. From the patch, delete all lines that consist of "+" (i.e. added blank line). 3. Reset the working dir and apply the revised patch. 4. Verify that the diff between step 1 and 3 looks reasonable. 5. Verify that this patch as a whole looks reasonable. Commands: ``` git diff > rename.diff :%g/^+$/d git commit -va -m WIP-rename git revert HEAD git apply --recount rename.diff git diff HEAD^ # and verify that the removed lines are ok. git commit -va # one last review to verify correctness of whole patch. git rebase -i HEAD~3 # drop the WIP + reverted commit, pick only the last. ``` `git apply` has the `--recount` option to force it to ignore mismatches in line counts, which happens because we deleted added lines (^+$) without fixing up the line counts in the file headers. Differential Revision: https://phabricator.services.mozilla.com/D179874
		
			
				
	
	
		
			84 lines
		
	
	
	
		
			2.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			84 lines
		
	
	
	
		
			2.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
/* This Source Code Form is subject to the terms of the Mozilla Public
 | 
						|
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 | 
						|
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
 | 
						|
 | 
						|
"use strict";
 | 
						|
 | 
						|
const { AddonStudies } = ChromeUtils.importESModule(
 | 
						|
  "resource://normandy/lib/AddonStudies.sys.mjs"
 | 
						|
);
 | 
						|
const { ClientID } = ChromeUtils.importESModule(
 | 
						|
  "resource://gre/modules/ClientID.sys.mjs"
 | 
						|
);
 | 
						|
 | 
						|
ChromeUtils.defineESModuleGetters(this, {
 | 
						|
  AddonManager: "resource://gre/modules/AddonManager.sys.mjs",
 | 
						|
});
 | 
						|
 | 
						|
this.normandyAddonStudy = class extends ExtensionAPI {
 | 
						|
  getAPI(context) {
 | 
						|
    let { extension } = context;
 | 
						|
 | 
						|
    return {
 | 
						|
      normandyAddonStudy: {
 | 
						|
        /**
 | 
						|
         * Returns a study object for the current study.
 | 
						|
         *
 | 
						|
         * @returns {Study}
 | 
						|
         */
 | 
						|
        async getStudy() {
 | 
						|
          const studies = await AddonStudies.getAll();
 | 
						|
          return studies.find(study => study.addonId === extension.id);
 | 
						|
        },
 | 
						|
 | 
						|
        /**
 | 
						|
         * Marks the study as ended and then uninstalls the addon.
 | 
						|
         *
 | 
						|
         * @param {string} reason Why the study is ending
 | 
						|
         */
 | 
						|
        async endStudy(reason) {
 | 
						|
          const study = await this.getStudy();
 | 
						|
 | 
						|
          // Mark the study as ended
 | 
						|
          await AddonStudies.markAsEnded(study, reason);
 | 
						|
 | 
						|
          // Uninstall the addon
 | 
						|
          const addon = await AddonManager.getAddonByID(study.addonId);
 | 
						|
          if (addon) {
 | 
						|
            await addon.uninstall();
 | 
						|
          }
 | 
						|
        },
 | 
						|
 | 
						|
        /**
 | 
						|
         * Returns an object with metadata about the client which may
 | 
						|
         * be required for constructing survey URLs.
 | 
						|
         *
 | 
						|
         * @returns {object}
 | 
						|
         */
 | 
						|
        async getClientMetadata() {
 | 
						|
          return {
 | 
						|
            updateChannel: Services.appinfo.defaultUpdateChannel,
 | 
						|
            fxVersion: Services.appinfo.version,
 | 
						|
            clientID: await ClientID.getClientID(),
 | 
						|
          };
 | 
						|
        },
 | 
						|
 | 
						|
        onUnenroll: new EventManager({
 | 
						|
          context,
 | 
						|
          name: "normandyAddonStudy.onUnenroll",
 | 
						|
          register: fire => {
 | 
						|
            const listener = async reason => {
 | 
						|
              await fire.async(reason);
 | 
						|
            };
 | 
						|
 | 
						|
            AddonStudies.addUnenrollListener(extension.id, listener);
 | 
						|
 | 
						|
            return () => {
 | 
						|
              AddonStudies.removeUnenrollListener(extension.id, listener);
 | 
						|
            };
 | 
						|
          },
 | 
						|
        }).api(),
 | 
						|
      },
 | 
						|
    };
 | 
						|
  }
 | 
						|
};
 |