2009-02-27 33 views
1

我正在開發一個小擴展,它必須將某些URL重定向到另一個站點。它工作正常,除了一種情況:如果用「上下文菜單 - >在新選項卡中打開」打開鏈接,則當前頁面會重定向到我的頁面,並打開第二個選項卡,並顯示應該重定向的鏈接。我在做什麼錯了?有沒有更好的方法來實現我想要的?在Firefox擴展中使用nsIURIContentListener的問題

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; 
    } 
} 

完整的分機號可以在這裏找到:http://github.com/bitboxer/firefox-detinyfy

回答

-1

好吧,我做了一些研究。胡克是一個錯誤的方法。我現在更改了代碼。看看git瞭解更多...

+0

上面的github鏈接已損壞,並且無論如何,如果您可以包含所做修復的快速摘要,這將非常有幫助,不得不挖掘你的代碼來找到它。 – MatrixFrog 2010-09-07 23:38:24