Mercurial > firefox-enso
comparison enso_pyxpcom.py @ 0:b1c0ab5d5f14
Origination, originally taken from the about:python source code from pyxpcom.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Thu, 08 May 2008 11:06:36 -0700 |
parents | |
children | 6e4335fa3321 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:b1c0ab5d5f14 |
---|---|
1 from xpcom import components, verbose | |
2 import sys, os | |
3 import logging | |
4 import platform | |
5 | |
6 _ensoStarted = False | |
7 | |
8 def getAbout(): | |
9 global _ensoStarted | |
10 | |
11 import enso | |
12 if not _ensoStarted: | |
13 logging.info("Launching Enso.") | |
14 _ensoStarted = True | |
15 enso.run() | |
16 return "Enso is running." | |
17 | |
18 class ShutdownObserver: | |
19 _com_interfaces_ = components.interfaces.nsIObserver | |
20 | |
21 def observe(self, subject, topic, data): | |
22 print "quit-application received; calling sys.exitfunc()." | |
23 sys.exitfunc() | |
24 | |
25 class AboutPython: | |
26 _com_interfaces_ = components.interfaces.nsIAboutModule | |
27 _reg_contractid_ = '@mozilla.org/network/protocol/about;1?what=enso' | |
28 _reg_clsid_ = '{6d5d462e-6de7-4bca-bbc6-c488d481351c}' | |
29 _reg_desc_ = "about:enso handler" | |
30 | |
31 def __init__(self): | |
32 logging.basicConfig( level=logging.INFO ) | |
33 logging.info("Setting shutdown observer.") | |
34 observerService = components.classes["@mozilla.org/observer-service;1"].getService(components.interfaces.nsIObserverService) | |
35 observerService.addObserver(ShutdownObserver(), "quit-application", False) | |
36 | |
37 def newChannel(self, aURI): | |
38 ioService = components.classes["@mozilla.org/network/io-service;1"] \ | |
39 .getService(); | |
40 | |
41 istream = components.classes["@mozilla.org/io/string-input-stream;1"] \ | |
42 .createInstance() | |
43 | |
44 about = getAbout() | |
45 istream.setData(about, len(about)) | |
46 | |
47 channel = components.classes["@mozilla.org/network/input-stream-channel;1"] \ | |
48 .createInstance(components.interfaces.nsIInputStreamChannel) | |
49 | |
50 channel.setURI(aURI) | |
51 #channel.contentType = "text/html" | |
52 channel.contentStream = istream | |
53 return channel | |
54 | |
55 def getURIFlags(self, aURI): | |
56 return 0; |