Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
nsSyncLoadService.cpp File Reference
#include "nsCOMPtr.h"
#include "nsIChannel.h"
#include "nsIDOMLoadListener.h"
#include "nsIChannelEventSink.h"
#include "nsIInterfaceRequestor.h"
#include "nsIScriptContext.h"
#include "nsISyncLoadDOMService.h"
#include "nsString.h"
#include "nsWeakReference.h"
#include "jsapi.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMDOMImplementation.h"
#include "nsIDOMEventReceiver.h"
#include "nsIEventQueueService.h"
#include "nsIJSContextStack.h"
#include "nsIPrivateDOMImplementation.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptSecurityManager.h"
#include "nsContentCID.h"
#include "nsContentUtils.h"
#include "nsNetUtil.h"
#include "nsIHttpChannel.h"
#include "nsIScriptLoader.h"
#include "nsIScriptLoaderObserver.h"
#include "nsIXMLContentSink.h"
#include "nsIContent.h"
#include "nsAutoPtr.h"
#include "nsLoadListenerProxy.h"

Go to the source code of this file.

Classes

class  nsSyncLoadService
class  nsSyncLoader
 This class manages loading a single XML document. More...
class  nsForceXMLListener

Functions

static NS_DEFINE_CID (kXMLDocumentCID, NS_XMLDOCUMENT_CID)
nsresult NS_NewXBLContentSink (nsIXMLContentSink **aResult, nsIDocument *aDoc, nsIURI *aURL, nsISupports *aContainer)
 NS_IMPL_ISUPPORTS2 (nsForceXMLListener, nsIStreamListener, nsIRequestObserver) NS_IMETHODIMP nsForceXMLListener
 NS_IMPL_ISUPPORTS4 (nsSyncLoader, nsIDOMLoadListener, nsIChannelEventSink, nsIInterfaceRequestor, nsISupportsWeakReference) nsresult nsSyncLoader
 NS_IMPL_ISUPPORTS1 (nsSyncLoadService, nsISyncLoadDOMService) NS_IMETHODIMP nsSyncLoadService
nsresult NS_NewSyncLoadDOMService (nsISyncLoadDOMService **aResult)

Variables

static const char kLoadAsData [] = "loadAsData"

Function Documentation

static NS_DEFINE_CID ( kXMLDocumentCID  ,
NS_XMLDOCUMENT_CID   
) [static]

Definition at line 455 of file nsSyncLoadService.cpp.

{
    nsRefPtr<nsSyncLoader> loader = new nsSyncLoader();
    NS_ENSURE_TRUE(loader, NS_ERROR_OUT_OF_MEMORY);

    return loader->LoadDocument(aChannel, aLoaderURI, PR_FALSE, PR_FALSE,
                                aResult);
}

Definition at line 161 of file nsSyncLoadService.cpp.

{
    nsresult status;
    aRequest->GetStatus(&status);
    nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
    if (channel && NS_SUCCEEDED(status)) {
      channel->SetContentType(NS_LITERAL_CSTRING("text/xml"));
    }

    return mListener->OnStartRequest(aRequest, aContext);
}

Here is the call graph for this function:

Definition at line 196 of file nsSyncLoadService.cpp.

{
    NS_ENSURE_ARG_POINTER(aResult);
    *aResult = nsnull;
    nsresult rv = NS_OK;

    mChannel = aChannel;
    nsCOMPtr<nsIHttpChannel> http = do_QueryInterface(mChannel);
    if (http) {
        http->SetRequestHeader(NS_LITERAL_CSTRING("Accept"),     
                               NS_LITERAL_CSTRING("text/xml,application/xml,application/xhtml+xml,*/*;q=0.1"),
                               PR_FALSE);
    }

    if (aLoaderURI) {
        nsCOMPtr<nsIURI> docURI;
        rv = aChannel->GetOriginalURI(getter_AddRefs(docURI));
        NS_ENSURE_SUCCESS(rv, rv);

        nsIScriptSecurityManager *securityManager =
            nsContentUtils::GetSecurityManager();

        rv = securityManager->CheckLoadURI(aLoaderURI, docURI,
                                           nsIScriptSecurityManager::STANDARD);
        NS_ENSURE_SUCCESS(rv, rv);

        rv = securityManager->CheckSameOriginURI(aLoaderURI, docURI);
        NS_ENSURE_SUCCESS(rv, rv);
    }

    // Get the loadgroup of the channel
    nsCOMPtr<nsILoadGroup> loadGroup;
    rv = aChannel->GetLoadGroup(getter_AddRefs(loadGroup));
    NS_ENSURE_SUCCESS(rv, rv);

    // Create document
    nsCOMPtr<nsIDocument> document = do_CreateInstance(kXMLDocumentCID, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    // Start the document load. Do this before we attach the load listener
    // since we reset the document which drops all observers.
    nsCOMPtr<nsIStreamListener> listener;
    rv = document->StartDocumentLoad(kLoadAsData, mChannel, 
                                     loadGroup, nsnull, 
                                     getter_AddRefs(listener),
                                     PR_TRUE);
    NS_ENSURE_SUCCESS(rv, rv);

    if (aForceToXML) {
        nsCOMPtr<nsIStreamListener> forceListener =
            new nsForceXMLListener(listener);
        listener.swap(forceListener);
    }

    // Register as a load listener on the document
    nsCOMPtr<nsIDOMEventReceiver> target = do_QueryInterface(document);
    NS_ENSURE_TRUE(target, NS_ERROR_FAILURE);

    nsWeakPtr requestWeak = do_GetWeakReference(NS_STATIC_CAST(nsIDOMLoadListener*, this));
    nsLoadListenerProxy* proxy = new nsLoadListenerProxy(requestWeak);
    NS_ENSURE_TRUE(proxy, NS_ERROR_OUT_OF_MEMORY);

    // This will addref the proxy
    rv = target->AddEventListenerByIID(NS_STATIC_CAST(nsIDOMEventListener*, 
                                                      proxy), 
                                       NS_GET_IID(nsIDOMLoadListener));
    NS_ENSURE_SUCCESS(rv, rv);
    
    mLoadSuccess = PR_FALSE;
    if (aChannelIsSync) {
        rv = PushSyncStream(listener);
    }
    else {
        rv = PushAsyncStream(listener);
    }

    http = do_QueryInterface(mChannel);
    if (mLoadSuccess && http) {
        PRBool succeeded;
        mLoadSuccess = NS_SUCCEEDED(http->GetRequestSucceeded(&succeeded)) &&
                       succeeded;
    }
    mChannel = nsnull;

    // This will release the proxy. Don't use the errorvalue from this since
    // we're more interested in the errorvalue from the loading
    target->RemoveEventListenerByIID(NS_STATIC_CAST(nsIDOMEventListener*, 
                                                    proxy), 
                                     NS_GET_IID(nsIDOMLoadListener));

    // check that the load succeeded
    NS_ENSURE_SUCCESS(rv, rv);

    NS_ENSURE_TRUE(mLoadSuccess, NS_ERROR_FAILURE);

    NS_ENSURE_TRUE(document->GetRootContent(), NS_ERROR_FAILURE);

    return CallQueryInterface(document, aResult);
}

Here is the call graph for this function:

Definition at line 575 of file nsSyncLoadService.cpp.

{
    *aResult = new nsSyncLoadService();
    NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
    NS_ADDREF(*aResult);
    return NS_OK;
}

Here is the call graph for this function:

nsresult NS_NewXBLContentSink ( nsIXMLContentSink **  aResult,
nsIDocument aDoc,
nsIURI aURL,
nsISupports *  aContainer 
)

Definition at line 67 of file nsXBLContentSink.cpp.

Here is the caller graph for this function:


Variable Documentation

const char kLoadAsData[] = "loadAsData" [static]

Definition at line 70 of file nsSyncLoadService.cpp.