home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / xul-ext / adblock-plus / bootstrap.js next >
Encoding:
JavaScript  |  2012-10-06  |  4.3 KB  |  156 lines

  1. /*
  2.  * This Source Code is subject to the terms of the Mozilla Public License
  3.  * version 2.0 (the "License"). You can obtain a copy of the License at
  4.  * http://mozilla.org/MPL/2.0/.
  5.  */
  6.  
  7. const Cc = Components.classes;
  8. const Ci = Components.interfaces;
  9. const Cr = Components.results;
  10. const Cu = Components.utils;
  11.  
  12. let {Services, atob, btoa} = Cu.import("resource://gre/modules/Services.jsm", null);
  13.  
  14. let addonData = null;
  15.  
  16. function startup(params, reason)
  17. {
  18.     addonData = params;
  19.     if (Services.vc.compare(Services.appinfo.platformVersion, "10.0") < 0)
  20.     {
  21.         Components.manager.addBootstrappedManifestLocation(params.installPath);
  22.         onShutdown.add(function() Components.manager.removeBootstrappedManifestLocation(params.installPath));
  23.     }
  24.     Services.obs.addObserver(RequireObserver, "adblockplus-require", true);
  25.     onShutdown.add(function() Services.obs.removeObserver(RequireObserver, "adblockplus-require"));
  26.  
  27.     require("main");
  28. }
  29.  
  30. function shutdown(params, reason)
  31. {
  32.     let windowNames = ["abp:subscriptionSelection", "abp:composer", "abp:filters"];
  33.     for (let i = 0; i < windowNames.length; i++)
  34.     {
  35.         let enumerator = Services.wm.getEnumerator(windowNames[i]);
  36.         while (enumerator.hasMoreElements())
  37.         {
  38.             let window = enumerator.getNext().QueryInterface(Ci.nsIDOMWindow);
  39.             window.setTimeout("window.close()", 0); // Closing immediately might not work due to modal windows
  40.             try
  41.             {
  42.                 window.close();
  43.             } catch(e) {}
  44.         }
  45.     }
  46.     onShutdown.done = true;
  47.     for (let i = shutdownHandlers.length - 1; i >= 0; i --)
  48.     {
  49.         try
  50.         {
  51.             shutdownHandlers[i]();
  52.         }
  53.         catch (e)
  54.         {
  55.             Cu.reportError(e);
  56.         }
  57.     }
  58.     shutdownHandlers = null;
  59.  
  60.     // Make sure to release our ties to the modules even if the sandbox cannot be
  61.     // released for some reason.
  62.     for (let key in require.scopes)
  63.     {
  64.         let scope = require.scopes[key];
  65.         let list = Object.keys(scope);
  66.         for (let i = 0; i < list.length; i++)
  67.             scope[list[i]] = null;
  68.     }
  69.     require.scopes = null;
  70.     addonData = null;
  71. }
  72.  
  73. function install(params, reason) {}
  74.  
  75. function uninstall(params, reason)
  76. {
  77.     const ADDON_UNINSTALL = 6;  // https://developer.mozilla.org/en/Extensions/Bootstrapped_extensions#Reason_constants
  78.     if (reason == ADDON_UNINSTALL)
  79.     {
  80.         // Users often uninstall/reinstall extension to "fix" issues. Clear current
  81.         // version number on uninstall to rerun first-run actions in this scenario.
  82.         Services.prefs.clearUserPref("extensions.adblockplus.currentVersion");
  83.     }
  84. }
  85. let shutdownHandlers = [];
  86. let onShutdown =
  87. {
  88.     done: false,
  89.     add: function(handler)
  90.     {
  91.         if (shutdownHandlers.indexOf(handler) < 0)
  92.             shutdownHandlers.push(handler);
  93.     },
  94.     remove: function(handler)
  95.     {
  96.         let index = shutdownHandlers.indexOf(handler);
  97.         if (index >= 0)
  98.             shutdownHandlers.splice(index, 1);
  99.     }
  100. };
  101.  
  102. function require(module)
  103. {
  104.     let scopes = require.scopes;
  105.     if (!(module in scopes))
  106.     {
  107.         if (module == "info")
  108.         {
  109.             let applications = {"{a23983c0-fd0e-11dc-95ff-0800200c9a66}": "fennec", "toolkit@mozilla.org": "toolkit", "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}": "firefox", "dlm@emusic.com": "emusic", "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}": "seamonkey", "{aa3c5121-dab2-40e2-81ca-7ea25febc110}": "fennec2", "{a79fe89b-6662-4ff4-8e88-09950ad4dfde}": "conkeror", "{aa5ca914-c309-495d-91cf-3141bbb04115}": "midbrowser", "songbird@songbirdnest.com": "songbird", "prism@developer.mozilla.org": "prism", "{3550f703-e582-4d05-9a08-453d09bdfdc6}": "thunderbird"};
  110.             let appID = Services.appinfo.ID;
  111.  
  112.             scopes[module] = {};
  113.             scopes[module].exports =
  114.             {
  115.                 addonID: addonData.id,
  116.                 addonVersion: addonData.version,
  117.                 addonRoot: addonData.resourceURI.spec,
  118.                 addonName: "adblockplus",
  119.                 application: (appID in applications ? applications[appID] : "other"),
  120.             };
  121.         }
  122.         else
  123.         {
  124.             let url = addonData.resourceURI.spec + "lib/" + module + ".js";
  125.             scopes[module] = {
  126.                 Cc: Cc,
  127.                 Ci: Ci,
  128.                 Cr: Cr,
  129.                 Cu: Cu,
  130.                 atob: atob,
  131.                 btoa: btoa,
  132.                 require: require,
  133.                 
  134.                 onShutdown: onShutdown,
  135.                 
  136.                 exports: {}};
  137.             Services.scriptloader.loadSubScript(url, scopes[module]);
  138.         }
  139.     }
  140.     return scopes[module].exports;
  141. }
  142. require.scopes = {__proto__: null};
  143. Cu.import("resource://gre/modules/XPCOMUtils.jsm");
  144.  
  145. let RequireObserver =
  146. {
  147.     observe: function(subject, topic, data)
  148.     {
  149.         if (topic == "adblockplus-require")
  150.         {
  151.             subject.wrappedJSObject.exports = require(data);
  152.         }
  153.     },
  154.  
  155.     QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObserver])
  156. };