Exception on accessing nsIChannel.notificationCallbacks for XMLHttpRequests

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Exception on accessing nsIChannel.notificationCallbacks for XMLHttpRequests

Ajit Dhumale
I am trying to monitor AJAX requests (requests send using XMLHttpRequest
object). I am trying to use observer service
(Components.interfaces.nsIObserverService) for the same and observing events
"http-on-examine-response" and "http-on-modify-request". I get hold of
nsIChannel (actually nsIHttpChannel) on which the requests are being sent.
From the channel I am trying to get hold of XMLHttpRequest object which sent
the request. Code in nsXMLHttpRequest.cpp
(http://lxr.mozilla.org/mozilla/source/extensions/xmlextras/base/src/nsXMLHttpRequest.cpp)
suggests that XMLHttpRequest object itself is set as 'notificationCallbacks'
property for the channel. I am getting the following exception when I try to
access 'notificationCallbacks' property of the channel (I have given code
snippet at the end).

[Exception... "Component does not have requested interface arg 0
[nsIHttpChannel.notificationCallbacks]"  nsresult: "0x80004002
(NS_NOINTERFACE)"  location: "JS frame ::
file:///C:/rnd/mozilla/observertest.js :: handler_observe :: line 137"
data: no]



I tried printing the list of properties of 'channel' and it does list
'notificationCallbacks', also
channel.hasOwnProperty("notificationCallbacks") returns true. I am wondering
why mozilla throws the exception on accessing the property. Also is there
any other alternative to get hold of XMLHttpRequest from with in
"http-on-modify-request" callback? I would like to get hold of the
XMLHttpRequest object (which implements nsIDOMEventTarget) and use
addEventListener to add listeners to monitor activities on the request.





Code snippet:



handler.prototype.observe =

  function handler_observe (channel, topic, data)

{

  switch (topic)

  {

    case "http-on-examine-response":

      if (channel instanceof Components.interfaces.nsIHttpChannel)

      {

        try

        {

           var ir = channel.notificationCallbacks;

        }

        catch (ex)

        {

          log(ex);

        }

      }

      else

      {

         log("Subject is not instance of nsIHttpChannel");

      }

      break;



    case "http-on-modify-request":

      if (channel instanceof Components.interfaces.nsIHttpChannel)

      {

        try

        {

           var ir = channel.notificationCallbacks;

        }

        catch (ex)

        {

          log(ex);

       }

      }

      else

      {

        log("Subject is not instance of nsIHttpChannel");

      }

      break;

  }

}



-- Ajit Dhumale


_______________________________________________
Mozilla-netlib mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-netlib
Reply | Threaded
Open this post in threaded view
|

Re: Exception on accessing nsIChannel.notificationCallbacks for XMLHttpRequests

Christian Biesinger
Ajit Dhumale wrote:
> [Exception... "Component does not have requested interface arg 0
> [nsIHttpChannel.notificationCallbacks]"  nsresult: "0x80004002
> (NS_NOINTERFACE)"  location: "JS frame ::
> file:///C:/rnd/mozilla/observertest.js :: handler_observe :: line 137"
> data: no]

Sounds to me like you are seeing this bug:
https://bugzilla.mozilla.org/show_bug.cgi?id=317448
_______________________________________________
Mozilla-netlib mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-netlib