Tutorial :Problems with using nsIURIContentListener in Firefox Extension



Question:

I am developing a small extension that has to redirect certain URLs to another Site. It's working fine, except for one situation: if open the Link with "Context-Menu -> Open in new Tab", the current page is redirectet to my page and a second tab opens with the link that should be redirected. What am I making wrong? Is there a better way to achieve what I want?

var myListener =  {      QueryInterface: function(iid)       {           if (iid.equals(Components.interfaces.nsIURIContentListener) ||            iid.equals(Components.interfaces.nsISupportsWeakReference) ||               iid.equals(Components.interfaces.nsISupports))               return this;           throw Components.results.NS_NOINTERFACE;       },       onStartURIOpen: function(aUri)       {              if (check_url(aUri)) {                  getBrowser().mCurrentTab.linkedBrowser.loadURI(######REDIRECT IS HERE#############);                  return true;              }              return false;       },       doContent: function(aContentType, aIsContentPreferred, aRequest, aContentHandler )       {             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;       },       canHandleContent: function(aContentType, aIsContentPreferred, aDesiredContentType)      {             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;       },       isPreferred: function(aContentType, aDesiredContentType)      {           try          {               var webNavInfo =               Components.classes["@mozilla.org/webnavigation-info;1"]                           .getService(Components.interfaces.nsIWebNavigationInfo);               return webNavInfo.isTypeSupported(aContentType, null);           }         catch (e)         {               return false;           }       },         GetWeakReference : function()      {          throw Components.results.NS_ERROR_NOT_IMPLEMENTED;       }  }  

The complete extension can be found here : http://github.com/bitboxer/firefox-detinyfy


Solution:1

Okay, I did some research. The Hook was a wrong aproach. I changed the code now. Look into the git to find out more...


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »