summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/webextensions/test/xpcshell/data/BootstrapMonitor.jsm
blob: 7c1e4aa9d6cc70aa478c2782803b01aecab7bc8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Components.utils.import("resource://gre/modules/Services.jsm");

this.EXPORTED_SYMBOLS = [ "monitor" ];

function notify(event, originalMethod, data, reason) {
  let info = {
    event,
    data: Object.assign({}, data, {
      installPath: data.installPath.path,
      resourceURI: data.resourceURI.spec,
    }),
    reason
  };

  let subject = {wrappedJSObject: {data}};

  Services.obs.notifyObservers(subject, "bootstrapmonitor-event", JSON.stringify(info));

  // If the bootstrap scope already declares a method call it
  if (originalMethod)
    originalMethod(data, reason);
}

// Allows a simple one-line bootstrap script:
// Components.utils.import("resource://xpcshelldata/bootstrapmonitor.jsm").monitor(this);
this.monitor = function(scope) {
  for (let event of ["install", "startup", "shutdown", "uninstall"]) {
    scope[event] = notify.bind(null, event, scope[event]);
  }
}