//public void ObserveActivity(nsISupports aHttpChannel, uint aActivityType, uint aActivitySubtype, uint aTimestamp, ulong aExtraSizeData, nsACString aExtraStringData)
        public void ObserveActivity(nsISupports aHttpChannel,
                                                 UInt32 aActivityType,
                                                 UInt32 aActivitySubtype,
                                                 Int64 aTimestamp,
                                                 UInt64 aExtraSizeData,
                     nsACStringBase aExtraStringData)
        {
            nsIHttpChannel httpChannel = Xpcom.QueryInterface<nsIHttpChannel>(aHttpChannel);

            if (httpChannel != null)
            {
                switch (aActivityType)
                {
                    case nsIHttpActivityObserverConstants.ACTIVITY_TYPE_SOCKET_TRANSPORT:
                        switch (aActivitySubtype)
                        {
                            case nsISocketTransportConstants.STATUS_RESOLVING:
                                break;
                            case nsISocketTransportConstants.STATUS_RESOLVED:
                                break;
                            case nsISocketTransportConstants.STATUS_CONNECTING_TO:
                                break;
                            case nsISocketTransportConstants.STATUS_CONNECTED_TO:
                                break;
                            case nsISocketTransportConstants.STATUS_SENDING_TO:
                                break;
                            case nsISocketTransportConstants.STATUS_WAITING_FOR:
                                break;
                            case nsISocketTransportConstants.STATUS_RECEIVING_FROM:
                                break;
                        }
                        break;
                    case nsIHttpActivityObserverConstants.ACTIVITY_TYPE_HTTP_TRANSACTION:
                        switch (aActivitySubtype)
                        {
                            case nsIHttpActivityObserverConstants.ACTIVITY_SUBTYPE_REQUEST_HEADER:
                                {
                                    activeNetworkChannels++;

                                    var callbacks = httpChannel.GetNotificationCallbacksAttribute();
                                    var httpChannelXHR = Xpcom.QueryInterface<nsIXMLHttpRequest>(callbacks);

                                    if (httpChannelXHR != null)
                                    {
                                        nsIDOMEventListener origEventListener = httpChannelXHR.GetOnreadystatechangeAttribute();
                                        var newEventListener = new GeckoJavaScriptHttpChannelWrapper(this, httpChannel, origEventListener);
                                        origJavaScriptHttpChannels.Add(httpChannel, newEventListener);
                                        httpChannelXHR.SetOnreadystatechangeAttribute(newEventListener);
                                    }
                                }
                                break;
                            case nsIHttpActivityObserverConstants.ACTIVITY_SUBTYPE_REQUEST_BODY_SENT:
                                break;
                            case nsIHttpActivityObserverConstants.ACTIVITY_SUBTYPE_RESPONSE_START:
                                break;
                            case nsIHttpActivityObserverConstants.ACTIVITY_SUBTYPE_RESPONSE_COMPLETE:
                                break;
                            case nsIHttpActivityObserverConstants.ACTIVITY_SUBTYPE_TRANSACTION_CLOSE:
                                activeNetworkChannels--;
                                break;
                        }
                        break;
                }
            }
        }
		//public void ObserveActivity(nsISupports aHttpChannel, uint aActivityType, uint aActivitySubtype, uint aTimestamp, ulong aExtraSizeData, nsACString aExtraStringData)
		public void ObserveActivity(nsISupports aHttpChannel,
												 UInt32 aActivityType,
												 UInt32 aActivitySubtype,
												 Int64 aTimestamp,
												 UInt64 aExtraSizeData,
					 nsACStringBase aExtraStringData) {
			nsIHttpChannel httpChannel = Xpcom.QueryInterface<nsIHttpChannel>(aHttpChannel);

			if (httpChannel != null) {
				switch (aActivityType) {
					case nsIHttpActivityObserverConstants.ACTIVITY_TYPE_SOCKET_TRANSPORT:
						switch (aActivitySubtype) {
							case nsISocketTransportConstants.STATUS_RESOLVING:
								break;
							case nsISocketTransportConstants.STATUS_RESOLVED:
								break;
							case nsISocketTransportConstants.STATUS_CONNECTING_TO:
								break;
							case nsISocketTransportConstants.STATUS_CONNECTED_TO:
								break;
							case nsISocketTransportConstants.STATUS_SENDING_TO:
								break;
							case nsISocketTransportConstants.STATUS_WAITING_FOR:
								break;
							case nsISocketTransportConstants.STATUS_RECEIVING_FROM:
								break;
						}
						break;
					case nsIHttpActivityObserverConstants.ACTIVITY_TYPE_HTTP_TRANSACTION:
						switch (aActivitySubtype) {
							case nsIHttpActivityObserverConstants.ACTIVITY_SUBTYPE_REQUEST_HEADER: {
									activeNetworkChannels++;
									ActiveNetworkChannelUrls.Add(nsString.Get(httpChannel.GetURIAttribute().GetSpecAttribute));

									var callbacks = httpChannel.GetNotificationCallbacksAttribute();

                                    if (callbacks != null)
                                    {
                                        var httpChannelXHR = Xpcom.QueryInterface<nsIXMLHttpRequest>(callbacks);

                                        if (httpChannelXHR != null)
                                        {
                                            nsIXMLHttpRequestEventTarget mXMLRequestEvent = Xpcom.QueryInterface<nsIXMLHttpRequestEventTarget>(httpChannelXHR);

                                            if (mXMLRequestEvent != null)
                                            {
                                                GeckoJavaScriptHttpChannelWrapper mEventListener = new GeckoJavaScriptHttpChannelWrapper(this, httpChannel);
                                                origJavaScriptHttpChannels.Add(httpChannel, mEventListener);
                       
                                                using (nsAString mLoads = new nsAString("load"))
                                                {
                                                    mXMLRequestEvent.AddEventListener(mLoads, mEventListener, true, false, 0);
                                                }

                                                using (nsAString mLoads = new nsAString("abort"))
                                                {
                                                    mXMLRequestEvent.AddEventListener(mLoads, mEventListener, true, false, 0);
                                                }

                                                using (nsAString mLoads = new nsAString("error"))
                                                {
                                                    mXMLRequestEvent.AddEventListener(mLoads, mEventListener, true, false, 0);
                                                }

                                                Marshal.ReleaseComObject(mXMLRequestEvent);
                                            }

                                            Marshal.ReleaseComObject(httpChannelXHR);
                                        }

                                        Marshal.ReleaseComObject(callbacks);
                                    }

								}
								break;
							case nsIHttpActivityObserverConstants.ACTIVITY_SUBTYPE_REQUEST_BODY_SENT:
								break;
							case nsIHttpActivityObserverConstants.ACTIVITY_SUBTYPE_RESPONSE_START:
								break;
							case nsIHttpActivityObserverConstants.ACTIVITY_SUBTYPE_RESPONSE_COMPLETE:
								break;
							case nsIHttpActivityObserverConstants.ACTIVITY_SUBTYPE_TRANSACTION_CLOSE:
								activeNetworkChannels--;
								ActiveNetworkChannelUrls.Remove(nsString.Get(httpChannel.GetURIAttribute().GetSpecAttribute));
								break;
						}
						break;
				}
			}
		}