Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
txMozillaStylesheetCompiler.cpp File Reference
#include "nsCOMArray.h"
#include "nsIAuthPrompt.h"
#include "nsICharsetAlias.h"
#include "nsIDOMNode.h"
#include "nsIDOMDocument.h"
#include "nsIDocument.h"
#include "nsIExpatSink.h"
#include "nsIChannelEventSink.h"
#include "nsIInterfaceRequestor.h"
#include "nsILoadGroup.h"
#include "nsINameSpaceManager.h"
#include "nsINodeInfo.h"
#include "nsIParser.h"
#include "nsIRequestObserver.h"
#include "nsIScriptSecurityManager.h"
#include "nsContentPolicyUtils.h"
#include "nsIStreamConverterService.h"
#include "nsISyncLoadDOMService.h"
#include "nsIURI.h"
#include "nsIPrincipal.h"
#include "nsIWindowWatcher.h"
#include "nsIXMLContentSink.h"
#include "nsMimeTypes.h"
#include "nsNetUtil.h"
#include "nsParserCIID.h"
#include "txAtoms.h"
#include "TxLog.h"
#include "txMozillaXSLTProcessor.h"
#include "txStylesheetCompiler.h"
#include "XMLUtils.h"

Go to the source code of this file.

Classes

class  txStylesheetSink
class  txCompileObserver
class  txSyncCompileObserver

Functions

static NS_DEFINE_CID (kCParserCID, NS_PARSER_CID)
static void getSpec (nsIChannel *aChannel, nsAString &aSpec)
 NS_IMPL_ISUPPORTS7 (txStylesheetSink, nsIXMLContentSink, nsIContentSink, nsIExpatSink, nsIStreamListener, nsIRequestObserver, nsIChannelEventSink, nsIInterfaceRequestor) NS_IMETHODIMP txStylesheetSink
static nsresult CheckLoadURI (nsIURI *aUri, nsIURI *aReferrerUri, nsIPrincipal *aReferrerPrincipal, nsISupports *aContext)
nsresult TX_LoadSheet (nsIURI *aUri, txMozillaXSLTProcessor *aProcessor, nsILoadGroup *aLoadGroup, nsIPrincipal *aCallerPrincipal)
static nsresult handleNode (nsIDOMNode *aNode, txStylesheetCompiler *aCompiler)
 handling DOM->txStylesheet Observer needs to do synchronous loads.
nsresult TX_CompileStylesheet (nsIDOMNode *aNode, txMozillaXSLTProcessor *aProcessor, txStylesheet **aStylesheet)

Variables

static const char kLoadAsData [] = "loadAsData"

Function Documentation

static nsresult CheckLoadURI ( nsIURI aUri,
nsIURI aReferrerUri,
nsIPrincipal aReferrerPrincipal,
nsISupports *  aContext 
) [static]

Definition at line 421 of file txMozillaStylesheetCompiler.cpp.

{
    // First do a security check.
    nsresult rv;
    nsCOMPtr<nsIScriptSecurityManager> securityManager = 
        do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    if (aReferrerPrincipal) {
        rv = securityManager->
            CheckLoadURIWithPrincipal(aReferrerPrincipal, aUri,
                                      nsIScriptSecurityManager::STANDARD);
    }
    else {
        rv = securityManager->CheckLoadURI(aReferrerUri, aUri,
                                           nsIScriptSecurityManager::STANDARD);
    }
    NS_ENSURE_SUCCESS(rv, NS_ERROR_XSLT_LOAD_BLOCKED_ERROR);

    rv = securityManager->CheckSameOriginURI(aReferrerUri, aUri);
    NS_ENSURE_SUCCESS(rv, NS_ERROR_XSLT_LOAD_BLOCKED_ERROR);

    // Then do a content policy check.
    PRInt16 decision = nsIContentPolicy::ACCEPT;
    rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_STYLESHEET,
                                   aUri, aReferrerUri, aContext,
                                   NS_LITERAL_CSTRING("application/xml"), nsnull,
                                   &decision);
    NS_ENSURE_SUCCESS(rv, rv);

    return NS_CP_REJECTED(decision) ? NS_ERROR_XSLT_LOAD_BLOCKED_ERROR : NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void getSpec ( nsIChannel aChannel,
nsAString &  aSpec 
) [static]

Definition at line 74 of file txMozillaStylesheetCompiler.cpp.

{
    if (!aChannel) {
        return;
    }

    nsCOMPtr<nsIURI> uri;
    aChannel->GetOriginalURI(getter_AddRefs(uri));
    if (!uri) {
        return;
    }

    nsCAutoString spec;
    uri->GetSpec(spec);
    AppendUTF8toUTF16(spec, aSpec);
}

Here is the call graph for this function:

static nsresult handleNode ( nsIDOMNode aNode,
txStylesheetCompiler aCompiler 
) [static]

handling DOM->txStylesheet Observer needs to do synchronous loads.

Definition at line 616 of file txMozillaStylesheetCompiler.cpp.

{
    nsresult rv = NS_OK;
    PRUint16 nodetype;
    aNode->GetNodeType(&nodetype);
    switch (nodetype) {
        case nsIDOMNode::ELEMENT_NODE:
        {
            nsCOMPtr<nsIContent> element = do_QueryInterface(aNode);

            PRUint32 attsCount = element->GetAttrCount();
            nsAutoArrayPtr<txStylesheetAttr> atts;
            if (attsCount > 0) {
                atts = new txStylesheetAttr[attsCount];
                NS_ENSURE_TRUE(atts, NS_ERROR_OUT_OF_MEMORY);

                PRUint32 counter;
                for (counter = 0; counter < attsCount; ++counter) {
                    txStylesheetAttr& att = atts[counter];
                    element->GetAttrNameAt(counter, &att.mNamespaceID,
                                           getter_AddRefs(att.mLocalName),
                                           getter_AddRefs(att.mPrefix));
                    element->GetAttr(att.mNamespaceID, att.mLocalName, att.mValue);
                }
            }

            nsINodeInfo *ni = element->GetNodeInfo();

            rv = aCompiler->startElement(ni->NamespaceID(),
                                         ni->NameAtom(),
                                         ni->GetPrefixAtom(), atts,
                                         attsCount);
            NS_ENSURE_SUCCESS(rv, rv);

            // explicitly destroy the attrs here since we no longer need it
            atts = nsnull;

            PRUint32 childCount = element->GetChildCount();
            if (childCount > 0) {
                PRUint32 counter = 0;
                nsIContent *child;
                while ((child = element->GetChildAt(counter++))) {
                    nsCOMPtr<nsIDOMNode> childNode = do_QueryInterface(child);
                    rv = handleNode(childNode, aCompiler);
                    NS_ENSURE_SUCCESS(rv, rv);
                }
            }

            rv = aCompiler->endElement();
            NS_ENSURE_SUCCESS(rv, rv);

            break;
        }
        case nsIDOMNode::CDATA_SECTION_NODE:
        case nsIDOMNode::TEXT_NODE:
        {
            nsAutoString chars;
            aNode->GetNodeValue(chars);
            rv = aCompiler->characters(chars);
            NS_ENSURE_SUCCESS(rv, rv);

            break;
        }
        case nsIDOMNode::DOCUMENT_NODE:
        {
            nsCOMPtr<nsIDocument> document = do_QueryInterface(aNode);

            PRUint32 counter = 0;
            nsIContent *child;
            while ((child = document->GetChildAt(counter++))) {
                nsCOMPtr<nsIDOMNode> childNode = do_QueryInterface(child);
                rv = handleNode(childNode, aCompiler);
                NS_ENSURE_SUCCESS(rv, rv);
            }
            break;
        }
    }
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static NS_DEFINE_CID ( kCParserCID  ,
NS_PARSER_CID   
) [static]

Definition at line 140 of file txMozillaStylesheetCompiler.cpp.

{
    NS_PRECONDITION(aAttsCount % 2 == 0, "incorrect aAttsCount");

    nsresult rv =
        mCompiler->startElement(aName, aAtts, aAttsCount / 2, aIndex);
    if (NS_FAILED(rv)) {
        mCompiler->cancel(rv);

        return rv;
    }
    
    return NS_OK;
}
nsresult TX_CompileStylesheet ( nsIDOMNode aNode,
txMozillaXSLTProcessor aProcessor,
txStylesheet **  aStylesheet 
)

Definition at line 802 of file txMozillaStylesheetCompiler.cpp.

{
    // XXX This would be simpler if GetBaseURI lived on nsINode
    nsCOMPtr<nsIURI> uri;
    nsCOMPtr<nsIDocument> doc;
    nsCOMPtr<nsIContent> cont = do_QueryInterface(aNode);
    if (cont) {
        doc = cont->GetOwnerDoc();
        NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);

        uri = cont->GetBaseURI();
    }
    else {
        doc = do_QueryInterface(aNode);
        NS_ASSERTION(doc, "aNode should be a doc or an element by now");

        uri = doc->GetBaseURI();
    }

    NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE);
    
    nsCAutoString spec;
    uri->GetSpec(spec);
    NS_ConvertUTF8toUTF16 baseURI(spec);

    uri = doc->GetDocumentURI();
    NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE);

    uri->GetSpec(spec);
    NS_ConvertUTF8toUTF16 stylesheetURI(spec);

    nsRefPtr<txSyncCompileObserver> obs =
        new txSyncCompileObserver(aProcessor);
    NS_ENSURE_TRUE(obs, NS_ERROR_OUT_OF_MEMORY);

    nsRefPtr<txStylesheetCompiler> compiler =
        new txStylesheetCompiler(stylesheetURI, obs);
    NS_ENSURE_TRUE(compiler, NS_ERROR_OUT_OF_MEMORY);

    compiler->setBaseURI(baseURI);

    nsresult rv = handleNode(aNode, compiler);
    if (NS_FAILED(rv)) {
        compiler->cancel(rv);
        return rv;
    }

    rv = compiler->doneLoading();
    NS_ENSURE_SUCCESS(rv, rv);
    
    *aStylesheet = compiler->getStylesheet();
    NS_ADDREF(*aStylesheet);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult TX_LoadSheet ( nsIURI aUri,
txMozillaXSLTProcessor aProcessor,
nsILoadGroup aLoadGroup,
nsIPrincipal aCallerPrincipal 
)

Definition at line 584 of file txMozillaStylesheetCompiler.cpp.

{
    nsCAutoString spec;
    aUri->GetSpec(spec);
    PR_LOG(txLog::xslt, PR_LOG_ALWAYS, ("TX_LoadSheet: %s\n", spec.get()));

    nsCOMPtr<nsIURI> referrerURI;
    aCallerPrincipal->GetURI(getter_AddRefs(referrerURI));
    NS_ASSERTION(referrerURI, "Caller principal must have a URI!");

    // Pass source document as the context
    nsresult rv = CheckLoadURI(aUri, referrerURI, aCallerPrincipal,
                               aProcessor->GetSourceContentModel());
    NS_ENSURE_SUCCESS(rv, rv);

    nsRefPtr<txCompileObserver> observer =
        new txCompileObserver(aProcessor, aLoadGroup);
    NS_ENSURE_TRUE(observer, NS_ERROR_OUT_OF_MEMORY);

    nsRefPtr<txStylesheetCompiler> compiler =
        new txStylesheetCompiler(NS_ConvertUTF8toUTF16(spec), observer);
    NS_ENSURE_TRUE(compiler, NS_ERROR_OUT_OF_MEMORY);

    return observer->startLoad(aUri, compiler, referrerURI);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

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

Definition at line 70 of file txMozillaStylesheetCompiler.cpp.