1

Everyone is asking about how to implement nsIContentPolicy shouldLoad() with js. But now i'm using python to do that to block the script while loading the pages. shouldLoad() now can be called but not working as i expect. when i return -2, the script still can be loaded. Is my code wrong or missing something else? thanks

My python code:

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 
Blisskarthik
  • 1,246
  • 8
  • 20
Basil
  • 39
  • 3

0 Answers0