1 /* See license.txt for terms of usage */
  2 
  3 define([
  4     "firebug/lib/object",
  5     "firebug/lib/xpcom",
  6     "firebug/lib/locale",
  7     "firebug/chrome/window",
  8 ],
  9 function(Obj, Xpcom, Locale, Win) {
 10 
 11 // ********************************************************************************************* //
 12 // Constants
 13 
 14 var Cc = Components.classes;
 15 var Ci = Components.interfaces;
 16 
 17 Components.utils.import("resource://gre/modules/AddonManager.jsm");
 18 
 19 var prompts = Xpcom.CCSV("@mozilla.org/embedcomp/prompt-service;1", "nsIPromptService");
 20 var app = Xpcom.CCSV("@mozilla.org/toolkit/app-startup;1", "nsIAppStartup");
 21 
 22 // ********************************************************************************************* //
 23 // Module
 24 
 25 var CookieLegacy = Obj.extend(Firebug.Module,
 26 {
 27     initialize: function(prefDomain, prefNames)
 28     {
 29         Firebug.Module.initialize.apply(this, arguments);
 30 
 31         setTimeout(Obj.bind(this.onAlert, this), 1000);
 32     },
 33 
 34     onAlert: function()
 35     {
 36         // Detect whether Firecookie is installed. This extension has been integrated
 37         // with Firebug and so, should not be installed together with Firebug 1.10+
 38         if (!Firebug.FireCookieModel)
 39             return;
 40 
 41         // See https://developer.mozilla.org/en/nsIPromptService#confirmEx%28%29
 42         // for configuration details.
 43         var check = {value: false};
 44         var flags = prompts.BUTTON_POS_0 * prompts.BUTTON_TITLE_IS_STRING +
 45             prompts.BUTTON_POS_1 * prompts.BUTTON_TITLE_CANCEL +
 46             prompts.BUTTON_POS_2 * prompts.BUTTON_TITLE_IS_STRING +
 47             prompts.BUTTON_POS_0_DEFAULT;
 48 
 49         var index = prompts.confirmEx(null, Locale.$STR("Firebug"),
 50             Locale.$STR("cookies.legacy.firecookie_detected"), flags,
 51             Locale.$STR("cookies.legacy.uninstall_and_restart"),
 52             "",
 53             Locale.$STR("cookies.legacy.uninstall"), null, check);
 54 
 55         // Bail out if the user presses Cancel.
 56         if (index == 2)
 57             return;
 58 
 59         // Let's uninstall, restart will follow if button #0 has been clicked.
 60         this.uninstallAddon(index == 0);
 61     },
 62 
 63     uninstallAddon: function(restart)
 64     {
 65         AddonManager.getAddonByID("firecookie@janodvarko.cz", function(addon)
 66         {
 67             // Uninstall is synchronous.
 68             addon.uninstall();
 69 
 70             if (restart)
 71                 app.quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit);
 72         });
 73     }
 74 });
 75 
 76 // ********************************************************************************************* //
 77 // Registration
 78 
 79 Firebug.registerModule(CookieLegacy);
 80 
 81 return CookieLegacy;
 82 
 83 // ********************************************************************************************* //
 84 });
 85 
 86