home *** CD-ROM | disk | FTP | other *** search
/ Chip 2006 June / CHIP 2006-06.2.iso / program / freeware / Democracy-0.8.2.exe / components / dispatchhandler.py next >
Encoding:
Python Source  |  2006-04-10  |  3.9 KB  |  111 lines

  1. from xpcom import components, nsError, ServerException
  2. import traceback
  3. import sys
  4. import time
  5. import re
  6.  
  7. class DispatchHandler:
  8.     _com_interfaces_ = [components.interfaces.nsIProtocolHandler]
  9.     _reg_clsid_ = "{E48AA35F-7E2D-4a2b-8971-FD2EE0E5A231}"
  10.     _reg_contractid_ = "@mozilla.org/network/protocol;1?name=dispatch"
  11.     _reg_desc_ = "Handles DTV 'dispatch:' URLs"
  12.  
  13.     def __init__(self):
  14.      print "******** DispatchHandler init"
  15.      self.scheme = "dispatch"
  16.      self.defaultPort = -1
  17.      iph = components.interfaces.nsIProtocolHandler
  18.      self.protocolFlags = iph.URI_NORELATIVE | iph.URI_NOAUTH
  19.      print "DispatchHandler init done"
  20.  
  21.     def allowPort(self, port, scheme):
  22.      print "allowPort"
  23.      return False
  24.  
  25.     def newURI(self, spec, charset, baseURI):
  26.      # I doubt that ignoring 'charset' is completely correct
  27.      ret = components.classes["@mozilla.org/network/simple-uri;1"] \
  28.          .createInstance(components.interfaces.nsIURI)
  29.      ret.spec = spec
  30.      return ret
  31.  
  32.     def newChannel(self, inputURI):
  33.     match = re.compile(r"dispatch:([^?]+)\?(.*)").match(inputURI.spec)
  34.     if match:
  35.         cookie = match.group(1)
  36.         url = match.group(2)
  37.         import frontend
  38.         frontend.HTMLDisplay.dispatchEventByCookie(cookie, url)
  39.     else:
  40.         print "Warning: badly formed dispatch url '%s'" % inputURI.spec
  41.         raise ValueError
  42.     
  43.     # Return a channel that returns the empty string
  44.     ioS = components.classes["@mozilla.org/network/io-service;1"] \
  45.         .getService(components.interfaces.nsIIOService)
  46.  
  47.     # NEEDS: return a channel returning valid XML, to avoid noise
  48.     # in JS logs. While we're at it, it'd be clever to load
  49.     # template-generated HTML from a channel, rather than a file:
  50.     # URL, and use that as the basis for the permission grant.
  51.     out = ioS.newChannel("about:blank", None, None)
  52.     return out
  53.  
  54. class ActionHandler:
  55.     _com_interfaces_ = [components.interfaces.nsIProtocolHandler]
  56.     _reg_clsid_ = "{C6C5665E-ECD6-4770-9B3B-1C78C71AEEC0}"
  57.     _reg_contractid_ = "@mozilla.org/network/protocol;1?name=action"
  58.     _reg_desc_ = "Handles DTV 'action:' URLs"
  59.  
  60.     def __init__(self):
  61.      self.scheme = "action"
  62.      self.defaultPort = -1
  63.      iph = components.interfaces.nsIProtocolHandler
  64.      self.protocolFlags = iph.URI_NORELATIVE | iph.URI_NOAUTH
  65.  
  66.     def allowPort(self, port, scheme):
  67.      return False
  68.  
  69.     def newURI(self, spec, charset, baseURI):
  70.      # I doubt that ignoring 'charset' is completely correct
  71.      ret = components.classes["@mozilla.org/network/simple-uri;1"] \
  72.          .createInstance(components.interfaces.nsIURI)
  73.      ret.spec = spec
  74.      return ret
  75.  
  76.     def newChannel(self, inputURI):
  77.     print "NEEDS: global dispatch of URI: %s" % inputURI.spec
  78.     ioS = components.classes["@mozilla.org/network/io-service;1"] \
  79.         .getService(components.interfaces.nsIIOService)
  80.     out = ioS.newChannel("about:blank", None, None)
  81.     return out
  82.  
  83. class TemplateHandler:
  84.     _com_interfaces_ = [components.interfaces.nsIProtocolHandler]
  85.     _reg_clsid_ = "{8D189EBA-6BEF-4119-9047-9B3CCADAD0A8}"
  86.     _reg_contractid_ = "@mozilla.org/network/protocol;1?name=template"
  87.     _reg_desc_ = "Handles DTV 'template:' URLs"
  88.  
  89.     def __init__(self):
  90.      self.scheme = "template"
  91.      self.defaultPort = -1
  92.      iph = components.interfaces.nsIProtocolHandler
  93.      self.protocolFlags = iph.URI_NORELATIVE | iph.URI_NOAUTH
  94.  
  95.     def allowPort(self, port, scheme):
  96.      return False
  97.  
  98.     def newURI(self, spec, charset, baseURI):
  99.      # I doubt that ignoring 'charset' is completely correct
  100.      ret = components.classes["@mozilla.org/network/simple-uri;1"] \
  101.          .createInstance(components.interfaces.nsIURI)
  102.      ret.spec = spec
  103.      return ret
  104.  
  105.     def newChannel(self, inputURI):
  106.     print "NEEDS: global dispatch of URI: %s" % inputURI.spec
  107.     ioS = components.classes["@mozilla.org/network/io-service;1"] \
  108.         .getService(components.interfaces.nsIIOService)
  109.     out = ioS.newChannel("about:blank", None, None)
  110.     return out
  111.