Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Attributes
nsXBLStreamListener Class Reference
Inheritance diagram for nsXBLStreamListener:
Inheritance graph
[legend]
Collaboration diagram for nsXBLStreamListener:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIREQUESTOBSERVER
NS_IMETHOD 
Load (nsIDOMEvent *aEvent)
 Processes a page or image load event.
NS_IMETHOD BeforeUnload (nsIDOMEvent *aEvent)
 Processes a page beforeUnload event.
NS_IMETHOD Unload (nsIDOMEvent *aEvent)
 Processes a page unload event.
NS_IMETHOD Abort (nsIDOMEvent *aEvent)
 Processes a load abort event.
NS_IMETHOD Error (nsIDOMEvent *aEvent)
 Processes an load error event.
NS_IMETHOD HandleEvent (nsIDOMEvent *aEvent)
 nsXBLStreamListener (nsXBLService *aXBLService, nsIStreamListener *aInner, nsIDocument *aDocument, nsIDocument *aBindingDocument)
virtual ~nsXBLStreamListener ()
void AddRequest (nsXBLBindingRequest *aRequest)
PRBool HasRequest (nsIURI *aURI, nsIContent *aBoundElement)
void onDataAvailable (in nsIRequest aRequest, in nsISupports aContext, in nsIInputStream aInputStream, in unsigned long aOffset, in unsigned long aCount)
 Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.
void onStartRequest (in nsIRequest aRequest, in nsISupports aContext)
 Called to signify the beginning of an asynchronous request.
void onStopRequest (in nsIRequest aRequest, in nsISupports aContext, in nsresult aStatusCode)
 Called to signify the end of an asynchronous request.
void handleEvent (in nsIDOMEvent event)
 This method is called whenever an event occurs of the type for which the EventListener interface was registered.

Private Attributes

nsXBLServicemXBLService
nsCOMPtr< nsIStreamListenermInner
nsAutoVoidArray mBindingRequests
nsCOMPtr< nsIWeakReferencemDocument
nsCOMPtr< nsIDocumentmBindingDocument

Detailed Description

Definition at line 221 of file nsXBLService.cpp.


Constructor & Destructor Documentation

nsXBLStreamListener::nsXBLStreamListener ( nsXBLService aXBLService,
nsIStreamListener aInner,
nsIDocument aDocument,
nsIDocument aBindingDocument 
)

Definition at line 264 of file nsXBLService.cpp.

{
  /* member initializers and constructor code */
  mXBLService = aXBLService;
  mInner = aInner;
  mDocument = do_GetWeakReference(aDocument);
  mBindingDocument = aBindingDocument;
#ifdef MOZ_XUL
  gRefCnt++;
  if (gRefCnt == 1) {
    nsresult rv = CallGetService("@mozilla.org/xul/xul-prototype-cache;1",
                                 &gXULCache);
    if (NS_FAILED(rv)) return;
  }
#endif
}

Here is the call graph for this function:

Definition at line 283 of file nsXBLService.cpp.

{
#ifdef MOZ_XUL
  /* destructor code */
  gRefCnt--;
  if (gRefCnt == 0) {
    NS_IF_RELEASE(gXULCache);
  }
#endif
}

Member Function Documentation

NS_IMETHOD nsXBLStreamListener::Abort ( nsIDOMEvent aEvent) [inline, virtual]

Processes a load abort event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMLoadListener.

Definition at line 231 of file nsXBLService.cpp.

{ return NS_OK; }

Definition at line 243 of file nsXBLService.cpp.

{ mBindingRequests.AppendElement(aRequest); };

Here is the caller graph for this function:

NS_IMETHOD nsXBLStreamListener::BeforeUnload ( nsIDOMEvent aEvent) [inline, virtual]

Processes a page beforeUnload event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMLoadListener.

Definition at line 229 of file nsXBLService.cpp.

{ return NS_OK; }
NS_IMETHOD nsXBLStreamListener::Error ( nsIDOMEvent aEvent) [inline, virtual]

Processes an load error event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMLoadListener.

Definition at line 232 of file nsXBLService.cpp.

{ return NS_OK; }

This method is called whenever an event occurs of the type for which the EventListener interface was registered.

Parameters:
evtThe Event contains contextual information about the event. It also contains the stopPropagation and preventDefault methods which are used in determining the event's flow and default action.

Definition at line 233 of file nsXBLService.cpp.

{ return NS_OK; }
PRBool nsXBLStreamListener::HasRequest ( nsIURI aURI,
nsIContent aBoundElement 
)

Definition at line 347 of file nsXBLService.cpp.

{
  // XXX Could be more efficient.
  PRUint32 count = mBindingRequests.Count();
  for (PRUint32 i = 0; i < count; i++) {
    nsXBLBindingRequest* req = (nsXBLBindingRequest*)mBindingRequests.ElementAt(i);
    PRBool eq;
    if (req->mBoundElement == aElt &&
        NS_SUCCEEDED(req->mBindingURL->Equals(aURI, &eq)) && eq)
      return PR_TRUE;
  }

  return PR_FALSE;
}

Here is the caller graph for this function:

Processes a page or image load event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMLoadListener.

Definition at line 363 of file nsXBLService.cpp.

{
  nsresult rv = NS_OK;
  PRUint32 i;
  PRUint32 count = mBindingRequests.Count();
  
  // See if we're still alive.
  nsCOMPtr<nsIDocument> doc(do_QueryReferent(mDocument));
  if (!doc) {
    NS_WARNING("XBL load did not complete until after document went away! Modal dialog bug?\n");
  }
  else {
    // Clear script handling object on asynchronously loaded XBL documents.
    NS_STATIC_CAST(nsDocument*, NS_STATIC_CAST(nsIDocument*, doc.get()))->
      ClearScriptHandlingObject();

    // We have to do a flush prior to notification of the document load.
    // This has to happen since the HTML content sink can be holding on
    // to notifications related to our children (e.g., if you bind to the
    // <body> tag) that result in duplication of content.  
    // We need to get the sink's notifications flushed and then make the binding
    // ready.
    if (count > 0) {
      nsXBLBindingRequest* req = (nsXBLBindingRequest*)mBindingRequests.ElementAt(0);
      nsIDocument* document = req->mBoundElement->GetCurrentDoc();
      if (document)
        document->FlushPendingNotifications(Flush_ContentAndNotify);
    }

    // Remove ourselves from the set of pending docs.
    nsIBindingManager *bindingManager = doc->BindingManager();
    nsIURI* documentURI = mBindingDocument->GetDocumentURI();
    bindingManager->RemoveLoadingDocListener(documentURI);

    if (!mBindingDocument->GetRootContent()) {
      NS_ERROR("*** XBL doc with no root element! Something went horribly wrong! ***");
      return NS_ERROR_FAILURE;
    }

    // Put our doc info in the doc table.
    nsCOMPtr<nsIXBLDocumentInfo> info;
    nsIBindingManager *xblDocBindingManager = mBindingDocument->BindingManager();
    xblDocBindingManager->GetXBLDocumentInfo(documentURI, getter_AddRefs(info));
    xblDocBindingManager->RemoveXBLDocumentInfo(info); // Break the self-imposed cycle.
    if (!info) {
      NS_ERROR("An XBL file is malformed.  Did you forget the XBL namespace on the bindings tag?");
      return NS_ERROR_FAILURE;
    }

    // If the doc is a chrome URI, then we put it into the XUL cache.
#ifdef MOZ_XUL
    if (IsChromeOrResourceURI(documentURI)) {
      PRBool useXULCache;
      gXULCache->GetEnabled(&useXULCache);
      if (useXULCache)
        gXULCache->PutXBLDocumentInfo(info);
    }
#endif
  
    bindingManager->PutXBLDocumentInfo(info);

    // Notify all pending requests that their bindings are
    // ready and can be installed.
    for (i = 0; i < count; i++) {
      nsXBLBindingRequest* req = (nsXBLBindingRequest*)mBindingRequests.ElementAt(i);
      req->DocumentLoaded(mBindingDocument);
    }
  }
  
  for (i = 0; i < count; i++) {
    nsXBLBindingRequest* req = (nsXBLBindingRequest*)mBindingRequests.ElementAt(i);
    nsXBLBindingRequest::Destroy(mXBLService->mPool, req);
  }

  nsCOMPtr<nsIDOMEventReceiver> rec(do_QueryInterface(mBindingDocument));
  rec->RemoveEventListener(NS_LITERAL_STRING("load"), (nsIDOMLoadListener*)this, PR_FALSE);

  mBindingRequests.Clear();
  mDocument = nsnull;
  mBindingDocument = nsnull;

  return rv;
}

Here is the call graph for this function:

void nsIStreamListener::onDataAvailable ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsIInputStream  aInputStream,
in unsigned long  aOffset,
in unsigned long  aCount 
) [inherited]

Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.

The onDataAvailable impl must read exactly |aCount| bytes of data before returning.

Parameters:
aRequestrequest corresponding to the source of the data
aContextuser defined context
aInputStreaminput stream containing the data chunk
aOffsetNumber of bytes that were sent in previous onDataAvailable calls for this request. In other words, the sum of all previous count parameters. If that number is greater than or equal to 2^32, this parameter will be PR_UINT32_MAX (2^32 - 1).
aCountnumber of bytes available in the stream

NOTE: The aInputStream parameter must implement readSegments.

An exception thrown from onDataAvailable has the side-effect of causing the request to be canceled.

void nsIRequestObserver::onStartRequest ( in nsIRequest  aRequest,
in nsISupports  aContext 
) [inherited]

Called to signify the beginning of an asynchronous request.

Parameters:
aRequestrequest being observed
aContextuser defined context

An exception thrown from onStartRequest has the side-effect of causing the request to be canceled.

Here is the caller graph for this function:

void nsIRequestObserver::onStopRequest ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsresult  aStatusCode 
) [inherited]

Called to signify the end of an asynchronous request.

This call is always preceded by a call to onStartRequest.

Parameters:
aRequestrequest being observed
aContextuser defined context
aStatusCodereason for stopping (NS_OK if completed successfully)

An exception thrown from onStopRequest is generally ignored.

Here is the caller graph for this function:

NS_IMETHOD nsXBLStreamListener::Unload ( nsIDOMEvent aEvent) [inline, virtual]

Processes a page unload event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMLoadListener.

Definition at line 230 of file nsXBLService.cpp.

{ return NS_OK; }

Member Data Documentation

Definition at line 253 of file nsXBLService.cpp.

nsAutoVoidArray nsXBLStreamListener::mBindingRequests [private]

Definition at line 250 of file nsXBLService.cpp.

Definition at line 252 of file nsXBLService.cpp.

Definition at line 249 of file nsXBLService.cpp.

Definition at line 247 of file nsXBLService.cpp.


The documentation for this class was generated from the following file: