B2G/gecko/toolkit/mozapps/extensions/XPIProvider.jsm
/**
   * Loads a bootstrapped add-on's bootstrap.js into a sandbox and the reason
   * values as constants in the scope. This will also add information about the
   * add-on to the bootstrappedAddons dictionary and notify the crash reporter
   * that new add-ons have been loaded.
   *
   * @param  aId
   *         The add-on's ID
   * @param  aFile
   *         The nsIFile for the add-on
   * @param  aVersion
   *         The add-on's version
   * @return a JavaScript scope
   */
Loads a bootstrapped add-on's bootstrap.js into a sandbox and the reason
values as constants in the scope. This will also add information about the
add-on to the bootstrappedAddons dictionary and notify the crash reporter
that new add-ons have been loaded.

@param  aId
The add-on's ID
@param  aFile
The nsIFile for the add-on
@param  aVersion
The add-on's version
@return a JavaScript scope
Loads a bootstrapped add - on ' s bootstrap . js into a sandbox and the reason values as constants in the scope . This will also add information about the add - on to the bootstrappedAddons dictionary and notify the crash reporter that new add - ons have been loaded . @param aId The add - on ' s ID @param aFile The nsIFile for the add - on @param aVersion The add - on ' s version @return a JavaScript scope
function XPI_loadBootstrapScope(aId, aFile, aVersion, aType) {
    LOG("Loading bootstrap scope from " + aFile.path);
    this.bootstrappedAddons[aId] = {
      version: aVersion,
      type: aType,
      descriptor: aFile.persistentDescriptor
    };
    this.addAddonsToCrashReporter();
    let principal = Cc["@mozilla.org/systemprincipal;1"].
                    createInstance(Ci.nsIPrincipal);
    if (!aFile.exists()) {
      this.bootstrapScopes[aId] = new Components.utils.Sandbox(principal,
                                                               {sandboxName: aFile.path});
      ERROR("Attempted to load bootstrap scope from missing directory " + aFile.path);
      return;
    }
    let uri = getURIForResourceInFile(aFile, "bootstrap.js").spec;
    this.bootstrapScopes[aId] = new Components.utils.Sandbox(principal,
                                                             {sandboxName: uri});
    let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
                 createInstance(Ci.mozIJSSubScriptLoader);
    try {
      for (let name in BOOTSTRAP_REASONS)
        this.bootstrapScopes[aId][name] = BOOTSTRAP_REASONS[name];
      const features = [ "Worker", "ChromeWorker" ];
      for (let feature of features)
        this.bootstrapScopes[aId][feature] = gGlobalScope[feature];
      if (aType == "dictionary") {
        this.bootstrapScopes[aId].__SCRIPT_URI_SPEC__ =
            "resource://gre/modules/SpellCheckDictionaryBootstrap.js"
      } else {
        this.bootstrapScopes[aId].__SCRIPT_URI_SPEC__ = uri;
      }
      Components.utils.evalInSandbox(
        "Components.classes['@mozilla.org/moz/jssubscript-loader;1'] \
                   .createInstance(Components.interfaces.mozIJSSubScriptLoader) \
                   .loadSubScript(__SCRIPT_URI_SPEC__);", this.bootstrapScopes[aId], "ECMAv5");
    }
    catch (e) {
      WARN("Error loading bootstrap.js for " + aId, e);
    }
  }
function XPI_loadBootstrapScope ( aId , aFile , aVersion , aType ) { LOG ( "Loading bootstrap scope from " + aFile . path ) ; this . bootstrappedAddons [ aId ] = { version : aVersion , type : aType , descriptor : aFile . persistentDescriptor } ; this . addAddonsToCrashReporter ( ) ; let principal = Cc [ "@mozilla.org/systemprincipal;1" ] . createInstance ( Ci . nsIPrincipal ) ; if ( ! aFile . exists ( ) ) { this . bootstrapScopes [ aId ] = new Components . utils . Sandbox ( principal , { sandboxName : aFile . path } ) ; ERROR ( "Attempted to load bootstrap scope from missing directory " + aFile . path ) ; return ; } let uri = getURIForResourceInFile ( aFile , "bootstrap.js" ) . spec ; this . bootstrapScopes [ aId ] = new Components . utils . Sandbox ( principal , { sandboxName : uri } ) ; let loader = Cc [ "@mozilla.org/moz/jssubscript-loader;1" ] . createInstance ( Ci . mozIJSSubScriptLoader ) ; try { for ( let name in BOOTSTRAP_REASONS ) this . bootstrapScopes [ aId ] [ name ] = BOOTSTRAP_REASONS [ name ] ; const features = [ "Worker" , "ChromeWorker" ] ; for ( let feature of features ) this . bootstrapScopes [ aId ] [ feature ] = gGlobalScope [ feature ] ; if ( aType == "dictionary" ) { this . bootstrapScopes [ aId ] . __SCRIPT_URI_SPEC__ = "resource://gre/modules/SpellCheckDictionaryBootstrap.js" } else { this . bootstrapScopes [ aId ] . __SCRIPT_URI_SPEC__ = uri ; } Components . utils . evalInSandbox ( "Components.classes['@mozilla.org/moz/jssubscript-loader;1'] \
                   .createInstance(Components.interfaces.mozIJSSubScriptLoader) \
                   .loadSubScript(__SCRIPT_URI_SPEC__);" , this . bootstrapScopes [ aId ] , "ECMAv5" ) ; } catch ( e ) { WARN ( "Error loading bootstrap.js for " + aId , e ) ; } }
Loads a bootstrapped add-on's bootstrap.js into a sandbox and the reason
 values as constants in the scope.
Loads a bootstrapped add - on ' s bootstrap . js into a sandbox and the reason values as constants in the scope .
// Mark the add-on as active for the crash reporter before loading // Copy the reason values from the global object into the bootstrap scope. // Add other stuff that extensions want. // As we don't want our caller to control the JS version used for the // bootstrap file, we run loadSubScript within the context of the // sandbox with the latest JS version set explicitly.