如何在卸载firefox插件时在浏览器中打开页面

时间:2011-07-13 11:53:45

标签: firefox-addon

我想在用户卸载插件时打开链接,所以为此我必须编写代码以及在哪个事件下。

如果有人知道这件事,请帮助我。

目前这是我在卸载时所做的事情。但是gBrowser.addTab(Website + 'uninstalled=true&token=' + uniqueguid);在这里没有工作。

var UninstallObserver = {
_uninstall : false,
observe : function(subject, topic, data) {

           //===Write Code here for Delete File Uninsatll Time
           //alert("Uninstall Time Delete File");
           var Filename = "webmail";
           // Delete all template file.

try{
var pref =  Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
var finished = "";
pref.setBoolPref("myextension.install.just_installed", false);  
}
catch(e) {}


            gBrowser.addTab(Website + 'uninstalled=true&token=' + uniqueguid);
            var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);

            file.initWithPath(Components.classes["@mozilla.org/file/directory_service;1"].getService( Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile).path+"\\DefaultTemplate.txt");
            if ( file.exists() == true )
            {   
                var aFile = Components.classes["@mozilla.org/file/local;1"].createInstance();
                if (aFile instanceof Components.interfaces.nsILocalFile)
                {                            
                    aFile.initWithPath(Components.classes["@mozilla.org/file/directory_service;1"].getService( Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile).path + "\\DefaultTemplate.txt");
                    aFile.remove(false);
                }
            }           
        //=======       
  if (topic == "em-action-requested") {
    subject.QueryInterface(Components.interfaces.nsIUpdateItem);

    if (subject.id == MY_EXTENSION_UUID)
     {

      if (data == "item-uninstalled")
      {
                    //==Delete File Whenever Uninstall          
                         //alert("When Uninatall");
                    //===========   
         data =  "item-cancel-action";
         this._uninstall = true;
      }

      if (data == "disabled")
      {
        //  alert("You are not allow to disable SysLocker.");
        this._uninstall = true;
      }

      else if (data == "item-cancel-action") 
      {
        this._uninstall = false;
      }
    }
  } 
  else if (topic == "quit-application-granted")
  {

  data =  "item-cancel-action";
    if (this._uninstall) 
    {     
      //Code here to delete registry       
    }
    this.unregister();
  }
},

register : function() {

 var observerService =
   Components.classes["@mozilla.org/observer-service;1"].
     getService(Components.interfaces.nsIObserverService);

 observerService.addObserver(this, "em-action-requested", false);
 observerService.addObserver(this, "quit-application-granted", false);

},

unregister : function() {

  var observerService =
    Components.classes["@mozilla.org/observer-service;1"].
      getService(Components.interfaces.nsIObserverService);

  observerService.removeObserver(this,"em-action-requested");
  observerService.removeObserver(this,"quit-application-granted");
}

}

由于

2 个答案:

答案 0 :(得分:0)

我不认为在实际卸载扩展之前,会向观察者发布em-action请求的主题,这在重启时会发生(假设它不是无重启的扩展)。您希望什么时候出现新标签?我会尝试在触发卸载主题时设置pref并在启动时检查该pref。如果它在那里,您可以显示您的选项卡并删除pref。

答案 1 :(得分:0)

0)这是什么类型的延伸?我认为这是一个需要重启的常规扩展; bootstrapped (restartless) extensions have their own uninstall notification

1)根据MDC docs,{4}}的em-action-requested通知已替换为Firefox 4+中的其他通知,您是使用Firefox 4还是3.6进行测试?

2)gBrowser.addTab究竟是什么“不在这里工作”?代码是否达到了这一点?您是否在Error Console中收到任何消息(请参阅该页面了解设置提示)?如果您将代码放在XPCOM组件中(这是正确的),您首先必须获得对浏览器窗口的引用。请参阅Working with windows in chrome code