[Webkit-unassigned] [Bug 27435] adding XMLHttpRequest send idl language gobject

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Thu Jul 23 14:02:09 PDT 2009


https://bugs.webkit.org/show_bug.cgi?id=27435





--- Comment #11 from Luke Kenneth Casson Leighton <lkcl at lkcl.net>  2009-07-23 14:02:07 PDT ---
(In reply to comment #10)
> Is it really appropriate to expose XMLHttpRequest to GObject?

 of course it is.

 there are so many reasons why it's a good idea and so many as to why it's a
bad idea to not have it, i can't even begin to list them all.

 not least of them is "xulrunner, MSHTML _and_ KHTML already provide access to
XMLHttpRequest via language bindings, why on earth would you want to make
webkit language bindings that are any different??"

>   I would assume
> better options exist for making network requests in GTK environments.

 [don't forget that GTK+ is _not_ the only port that can take advantage of the
glib / gobject bindings.  i _do_ keep emphasising this and you _do_ keep making
statements that seem to not take this into account.]

 that just means writing alien code, across multiple languages.  why do you
want to make peoples' lives more difficult?

 example:

 to port pyjamas to pyjamas-desktop, all i had to do was convert javascript
 to python, which is a process that literally took only around... two days,
 to convert the 1000 or so lines of hard-coded javascript into approx-1000
 lines of python.

 line-for-line, the python is identical (near-as-damnit) to the javascript
 from which it was ported.

 this then reduces the amount of testing overhead of the pyjamas-desktop
 implementation, because the API, apart from a few wrinkles, is absolutely
identical in python as it is to javascript across thousands of functions.

 [why do you think i've been pushing so hard to get you guys to accept gobject
bindings as a peer to the de-facto javascript-driven standard, rather than the
as-yet-not-commonly-implemented HTML5 standard? it's because it makes life
absolute hell if it isn't exactly the same as it can be made ]




 example code:

 from HTTPRequest.py module, here's the javascript version:

    def asyncPostImpl(self, user, pwd, url, postData, handler,
                            returnxml, content_type):
        pdlen = str(len(postData))
        JS("""
        var xmlHttp = this.doCreateXmlHTTPRequest();
        try {
            xmlHttp.open("POST", url, true);
            xmlHttp.setRequestHeader("Content-Type", content_type);
            xmlHttp.setRequestHeader("Content-Length", pdlen);
            xmlHttp.onreadystatechange = function() {
                if (xmlHttp.readyState == 4) {
                    delete xmlHttp.onreadystatechange;
                    var localHandler = handler;
                    var response;
                    var status = xmlHttp.status;
                    if (returnxml)
                        response = xmlHttp.responseXML;
                    else
                        response = xmlHttp.responseText;
                    handler = null;
                    xmlHttp = null;
                    if(status == 200) {
                        localHandler.onCompletion(response);
                    } else {
                        localHandler.onError(response, status);
                    }
                }
            };
            xmlHttp.send(postData);
            return true;
        }
        catch (e) {
            delete xmlHttp.onreadystatechange;
            var localHandler = handler;
            handler = null;
            xmlHttp = null;
            localHandler.onError(String(e), "");
            return false;
        }
        """)


and this is the python version (with, obviously, the onreadystatechange coming
out as a separate function, not a lambda as it is in the javascript, above):


    def onReadyStateChange(self, xmlHttp, event, ignorearg):
        try:
            xmlHttp = get_main_frame().gobject_wrap(xmlHttp) # HACK!
        except:
            pass # hula / XUL
        if xmlHttp.readyState != 4:
            return
        # TODO - delete xmlHttp.onreadystatechange
        localHandler = handlers.get(xmlHttp)
        del handlers[xmlHttp]
        responseText = xmlHttp.responseText
        status = xmlHttp.status
        handler = None
        xmlHttp = None
        # XXX HACK! webkit wrapper returns 0 not 200!
        if status == 0:
            print "HACK ALERT! webkit wrapper returns 0 not 200!"
        if status == 200 or status == 0:
            localHandler.onCompletion(responseText)
        else :
            localHandler.onError(responseText, status)


    def asyncPostImpl(self, user, pwd, url, postData, handler,
                            return_xml, content_type):
        mf = get_main_frame()
        xmlHttp = self.doCreateXmlHTTPRequest()
        if url[0] != '/':
            uri = mf.getUri()
            if url[:7] != 'file://' and url[:7] != 'http://' and \
               url[:8] != 'https://':
                slash = uri.rfind('/')
                url = uri[:slash+1] + url
        # try:
        if mf.platform == 'webkit':
            xmlHttp.open("POST", url, True, '', '')
        else:
            # EEK!  xmlhttprequest.open in xpcom is a miserable bastard.
            # won't take the last 3 optional args.
            #xmlHttp.open("POST", url, True, '', '')
            xmlHttp.open("POST", url)
        xmlHttp.setRequestHeader("Content-Type", content_type)
        xmlHttp.setRequestHeader("Content-Length", str(len(postData)))

        if mf.platform == 'webkit':
            mf._addXMLHttpRequestEventListener(xmlHttp, "onreadystatechange",
                                         self.onReadyStateChange)
        else:
            mf._addXMLHttpRequestEventListener(xmlHttp, "load",
                                         self.onLoad)
        handlers[xmlHttp] = handler
        xmlHttp.send(postData)

        return True

        #except:
            #del xmlHttp.onreadystatechange
        handler = None
        xmlHttp = None
        localHandler.onError(str(e))
        return False



so you can see, it's pretty much identical.

are you _truly_ telling me that i must rip that all out, because there is
something quotes "better" quotes in some GTK library somewhere?

do those quotes "better" quotes libraries support asynchronous POST and
asynchronous GET?

are they _exactly_ the same as the API available in webkit?

are you saying that you want to force pyjamas-desktop - and anyone else who
wants to do XMLHttpRequest in vala, java, perl or anything else that wraps the
gobject bindings - to _each_ write their own version of XMLHttpRequest?

you _got_ to be kidding.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list