Skip to content

Commit

Permalink
get XMLHttpRequest event handling working in MSHTML
Browse files Browse the repository at this point in the history
git-svn-id: https://pyjamas.svn.sourceforge.net/svnroot/pyjamas/trunk@1108 7a2bd370-bda8-463c-979e-2900ccfb811e
  • Loading branch information
lkcl committed Aug 6, 2009
1 parent d6fe619 commit 789a975
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
17 changes: 17 additions & 0 deletions INSTALL.txt
Expand Up @@ -13,6 +13,23 @@ are critical to pyjamas. It goes without saying that if you overwrite
the standard python modules with the pyjamas equivalents, you will run into
massive problems. Don't do it.

Dependencies
============

For pyjamas javascript compilation, you need python 2 - that's it.

For Pyjamas Desktop, you will need:

* Win32 comtypes, or python-hulahop and python-xpcom, or a patched
version of pywebkitgtk and webkit-gobject: see
http://github.com/lkcl/webkit/16401.master

These are for the MSHTML, XULrunner and Webkit ports of Pyjamas
Desktop, respectively.

* python-jsonrpc which can be downloaded from http://json-rpc.org
if you wish to use JSONRPC.

Developer Sandbox Setup
=======================

Expand Down
Empty file modified examples/jsonrpc/JSONRPCExample.py 100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions library/pyjamas/HTTPRequest.py
Expand Up @@ -86,7 +86,7 @@ def asyncPostImpl(self, user, pwd, url, postData, handler,
url = uri[:slash+1] + url
print "xmlHttp", user, pwd, url, postData, handler, dir(xmlHttp)
#try :
if mf.platform == 'webkit':
if mf.platform == 'webkit' or mf.platform == 'mshtml':
xmlHttp.open("POST", url, True, '', '')
else:
# EEK! xmlhttprequest.open in xpcom is a miserable bastard.
Expand All @@ -99,7 +99,7 @@ def asyncPostImpl(self, user, pwd, url, postData, handler,
# xmlHttp.setRequestHeader("Set-Cookie", c)
# print "setting cookie", c

if mf.platform == 'webkit':
if mf.platform == 'webkit' or mf.platform == 'mshtml':
mf._addXMLHttpRequestEventListener(xmlHttp, "onreadystatechange",
self.onReadyStateChange)
else:
Expand Down
29 changes: 20 additions & 9 deletions pyjd/mshtml.py
Expand Up @@ -26,6 +26,7 @@
if not hasattr(sys, 'frozen'):
GetModule('atl.dll')
GetModule('shdocvw.dll')
GetModule('msxml2.dll')

kernel32 = windll.kernel32
user32 = windll.user32
Expand All @@ -38,6 +39,7 @@
#from comtypes.client import GetEvents, ShowEvents
import mshtmlevents
from comtypes.gen import SHDocVw
from comtypes.gen import MSXML2
from comtypes.gen import MSHTML

kernel32 = windll.kernel32
Expand Down Expand Up @@ -325,12 +327,20 @@ def getDomWindow(self):

def _addXMLHttpRequestEventListener(self, node, event_name, event_fn):

return None
listener = xpcom.server.WrapObject(ContentInvoker(node, event_fn),
interfaces.nsIDOMEventListener)
print event_name, listener
node.addEventListener(event_name, listener, False)
return listener
print "_addXMLHttpRequestEventListener", event_name

rcvr = mshtmlevents._DispEventReceiver()
rcvr.dispmap = {0: event_fn}

print rcvr
rcvr.sender = node
print rcvr.sender
ifc = rcvr.QueryInterface(IDispatch)
print ifc
v = VARIANT(ifc)
print v
setattr(node, event_name, v)
return ifc

def addEventListener(self, node, event_name, event_fn):

Expand Down Expand Up @@ -368,9 +378,10 @@ def _addWindowEventListener(self, event_name, event_fn):
return event_name # hmmm...

def getXmlHttpRequest(self):
xml_svc_cls = components.classes[ \
"@mozilla.org/xmlextras/xmlhttprequest;1"]
return xml_svc_cls.createInstance(interfaces.nsIXMLHttpRequest)
print "getXMLHttpRequest"
o = comtypes.client.CreateObject('MSXML2.XMLHTTP.3.0')
print "getXMLHttpRequest", o
return Dispatch(o)

def getUri(self):
return self.application
Expand Down
11 changes: 7 additions & 4 deletions pyjd/mshtmlevents.py
Expand Up @@ -226,17 +226,20 @@ class _DispEventReceiver(comtypes.COMObject):
# as last parameter?
def IDispatch_Invoke(self, this, memid, riid, lcid, wFlags, pDispParams,
pVarResult, pExcepInfo, puArgErr):
#print "IDispatch_Invoke", memid, this, riid, lcid, pDispParams
print "IDispatch_Invoke", memid, this, riid, lcid, pDispParams
mth = self.dispmap.get(memid, None)
if mth is None:
return S_OK
dp = pDispParams[0]
#print "num args", dp.cArgs
print "num args", dp.cArgs
# DISPPARAMS contains the arguments in reverse order
args = [dp.rgvarg[i].value for i in range(dp.cArgs)]
#print "Event", self, memid, mth, args
print "Event", self, memid, mth, args
event = None
if len(args) > 0:
event = wrap(args[0])
try:
result = mth(self.sender, wrap(args[0]), None)
result = mth(self.sender, event, None)
except:
sys.stderr.write( traceback.print_exc() )
sys.stderr.flush()
Expand Down

0 comments on commit 789a975

Please sign in to comment.