使用Python如何实现nsIContentPolicy shouldLoad()

时间:2014-07-09 07:00:35

标签: python pyxpcom

每个人都在询问如何使用js实现nsIContentPolicy shouldLoad()。但现在我正在使用python来加载页面时阻止脚本。 shouldLoad()现在可以被调用但不能像我期望的那样工作。当我返回-2时,仍然可以加载脚本。 我的代码是错误还是缺少其他内容?感谢

我的python代码:

class ContentPolicy:
    _com_interfaces_ = components.interfaces.nsIContentPolicy
    _reg_clsid_ = "{648639fb-05a4-4695-a3a4-9cd9607951e6}"
    _reg_contractid_ = "@ucweb.com/myfun;1"

  def __init__(self):
    print 'brasil!!!!!!!!!!!!!!!!!!!!!----------------------------------****************************--------------basil'
    logging.getLogger('errinfo').debug('brasil!!!!!!!!---world cup!!!')

  def __del__(self):
    logging.getLogger('errinfo').debug('bye bye ----------testing-----rio')
    pass

def shouldLoad(self,aContentType,aContentLocation,aRequestOrigin,aContext,aMimeTypeGuess,aExtra):
    print 'world cup!!!!!!!!!!!!!!!!!!!!!!!!!---------------------------------------------------------------------*************basil'
    print 'type=' , (aContentType)
    logging.getLogger('errinfo').debug('type=%d' % (aContentType))
    if 2 == aContentType or 4 == aContentType or 3 == aContentType or 7 == aContentType:
        logging.getLogger('errinfo').debug('rejecting type=%d' % (aContentType))
        print str(aContentLocation)
        return (-2)
    return 1 

0 个答案:

没有答案