X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fthird_party%2FWebKit%2FSource%2Fcore%2Fxml%2FXSLTProcessorLibxslt.cpp;h=a2ee29434a3cd926d346d49621db6652f699a372;hb=3545e9f2671f595d2a2f3ee75ca0393b01e35ef6;hp=197b223a0c6d47aba9939dad4c1172f0a2681b4b;hpb=42dcc1327bbd3f24706b73963db769f667a58196;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/third_party/WebKit/Source/core/xml/XSLTProcessorLibxslt.cpp b/src/third_party/WebKit/Source/core/xml/XSLTProcessorLibxslt.cpp index 197b223..a2ee294 100644 --- a/src/third_party/WebKit/Source/core/xml/XSLTProcessorLibxslt.cpp +++ b/src/third_party/WebKit/Source/core/xml/XSLTProcessorLibxslt.cpp @@ -23,19 +23,16 @@ #include "config.h" #include "core/xml/XSLTProcessor.h" -#include -#include -#include -#include -#include "FetchInitiatorTypeNames.h" +#include "core/FetchInitiatorTypeNames.h" #include "core/dom/Document.h" #include "core/dom/TransformSource.h" #include "core/editing/markup.h" #include "core/fetch/Resource.h" #include "core/fetch/ResourceFetcher.h" +#include "core/frame/FrameConsole.h" #include "core/frame/FrameHost.h" #include "core/frame/LocalFrame.h" -#include "core/frame/PageConsole.h" +#include "core/inspector/ConsoleMessage.h" #include "core/xml/XSLStyleSheet.h" #include "core/xml/XSLTExtensions.h" #include "core/xml/XSLTUnicodeSort.h" @@ -46,12 +43,15 @@ #include "platform/network/ResourceResponse.h" #include "platform/weborigin/SecurityOrigin.h" #include "wtf/Assertions.h" -#include "wtf/Vector.h" #include "wtf/text/CString.h" #include "wtf/text/StringBuffer.h" #include "wtf/unicode/UTF8.h" +#include +#include +#include +#include -namespace WebCore { +namespace blink { void XSLTProcessor::genericErrorFunc(void*, const char*, ...) { @@ -60,7 +60,7 @@ void XSLTProcessor::genericErrorFunc(void*, const char*, ...) void XSLTProcessor::parseErrorFunc(void* userData, xmlError* error) { - PageConsole* console = static_cast(userData); + FrameConsole* console = static_cast(userData); if (!console) return; @@ -79,17 +79,15 @@ void XSLTProcessor::parseErrorFunc(void* userData, xmlError* error) break; } - console->addMessage(XMLMessageSource, level, error->message, error->file, error->line); + console->addMessage(ConsoleMessage::create(XMLMessageSource, level, error->message, error->file, error->line)); } // FIXME: There seems to be no way to control the ctxt pointer for loading here, thus we have globals. static XSLTProcessor* globalProcessor = 0; static ResourceFetcher* globalResourceFetcher = 0; -static xmlDocPtr docLoaderFunc(const xmlChar* uri, - xmlDictPtr, - int options, - void* ctxt, - xsltLoadType type) + +static xmlDocPtr docLoaderFunc( + const xmlChar* uri, xmlDictPtr, int options, void* ctxt, xsltLoadType type) { if (!globalProcessor) return 0; @@ -108,10 +106,10 @@ static xmlDocPtr docLoaderFunc(const xmlChar* uri, if (!resource || !globalProcessor) return 0; - PageConsole* console = 0; + FrameConsole* console = 0; LocalFrame* frame = globalProcessor->xslStylesheet()->ownerDocument()->frame(); - if (frame && frame->host()) - console = &frame->host()->console(); + if (frame) + console = &frame->console(); xmlSetStructuredErrorFunc(console, XSLTProcessor::parseErrorFunc); xmlSetGenericErrorFunc(console, XSLTProcessor::genericErrorFunc); @@ -179,7 +177,8 @@ static bool saveResultToString(xmlDocPtr resultDoc, xsltStylesheetPtr sheet, Str if (retval < 0) return false; - // Workaround for : libxslt appends an extra line feed to the result. + // Workaround for : + // libxslt appends an extra line feed to the result. if (resultBuilder.length() > 0 && resultBuilder[resultBuilder.length() - 1] == '\n') resultBuilder.resize(resultBuilder.length() - 1); @@ -193,7 +192,7 @@ static const char** xsltParamArrayFromParameterMap(XSLTProcessor::ParameterMap& if (parameters.isEmpty()) return 0; - const char** parameterArray = (const char**)fastMalloc(((parameters.size() * 2) + 1) * sizeof(char*)); + const char** parameterArray = static_cast(fastMalloc(((parameters.size() * 2) + 1) * sizeof(char*))); XSLTProcessor::ParameterMap::iterator end = parameters.end(); unsigned index = 0; @@ -213,21 +212,25 @@ static void freeXsltParamArray(const char** params) return; while (*temp) { - fastFree((void*)*(temp++)); - fastFree((void*)*(temp++)); + fastFree(const_cast(*(temp++))); + fastFree(const_cast(*(temp++))); } fastFree(params); } -static xsltStylesheetPtr xsltStylesheetPointer(RefPtrWillBeMember& cachedStylesheet, Node* stylesheetRootNode) +static xsltStylesheetPtr xsltStylesheetPointer(Document* document, RefPtrWillBeMember& cachedStylesheet, Node* stylesheetRootNode) { if (!cachedStylesheet && stylesheetRootNode) { - cachedStylesheet = XSLStyleSheet::createForXSLTProcessor(stylesheetRootNode->parentNode() ? stylesheetRootNode->parentNode() : stylesheetRootNode, + // When using importStylesheet, we will use the given document as the imported stylesheet's owner. + cachedStylesheet = XSLStyleSheet::createForXSLTProcessor( + stylesheetRootNode->parentNode() ? &stylesheetRootNode->parentNode()->document() : document, + stylesheetRootNode, stylesheetRootNode->document().url().string(), stylesheetRootNode->document().url()); // FIXME: Should we use baseURL here? - // According to Mozilla documentation, the node must be a Document node, an xsl:stylesheet or xsl:transform element. - // But we just use text content regardless of node type. + // According to Mozilla documentation, the node must be a Document node, + // an xsl:stylesheet or xsl:transform element. But we just use text + // content regardless of node type. cachedStylesheet->parseString(createMarkup(stylesheetRootNode)); } @@ -239,7 +242,7 @@ static xsltStylesheetPtr xsltStylesheetPointer(RefPtrWillBeMember static inline xmlDocPtr xmlDocPtrFromNode(Node* sourceNode, bool& shouldDelete) { - RefPtr ownerDocument(sourceNode->document()); + RefPtrWillBeRawPtr ownerDocument(sourceNode->document()); bool sourceIsDocument = (sourceNode == ownerDocument.get()); xmlDocPtr sourceDoc = 0; @@ -274,10 +277,10 @@ static inline String resultMIMEType(xmlDocPtr resultDoc, xsltStylesheetPtr sheet bool XSLTProcessor::transformToString(Node* sourceNode, String& mimeType, String& resultString, String& resultEncoding) { - RefPtr ownerDocument(sourceNode->document()); + RefPtrWillBeRawPtr ownerDocument(sourceNode->document()); setXSLTLoadCallBack(docLoaderFunc, this, ownerDocument->fetcher()); - xsltStylesheetPtr sheet = xsltStylesheetPointer(m_stylesheet, m_stylesheetRootNode.get()); + xsltStylesheetPtr sheet = xsltStylesheetPointer(m_document.get(), m_stylesheet, m_stylesheetRootNode.get()); if (!sheet) { setXSLTLoadCallBack(0, 0, 0); m_stylesheet = nullptr; @@ -292,8 +295,9 @@ bool XSLTProcessor::transformToString(Node* sourceNode, String& mimeType, String bool success = false; bool shouldFreeSourceDoc = false; if (xmlDocPtr sourceDoc = xmlDocPtrFromNode(sourceNode, shouldFreeSourceDoc)) { - // The XML declaration would prevent parsing the result as a fragment, and it's not needed even for documents, - // as the result of this function is always immediately parsed. + // The XML declaration would prevent parsing the result as a fragment, + // and it's not needed even for documents, as the result of this + // function is always immediately parsed. sheet->omitXmlDeclaration = true; xsltTransformContextPtr transformContext = xsltNewTransformContext(sheet, sourceDoc); @@ -310,13 +314,15 @@ bool XSLTProcessor::transformToString(Node* sourceNode, String& mimeType, String if (0 != xsltSetCtxtSecurityPrefs(securityPrefs, transformContext)) CRASH(); - // : XSLT processor algorithm only compares by code point. + // : XSLT processor + // algorithm only compares by code point. xsltSetCtxtSortFunc(transformContext, xsltUnicodeSortFunction); // This is a workaround for a bug in libxslt. - // The bug has been fixed in version 1.1.13, so once we ship that this can be removed. + // The bug has been fixed in version 1.1.13, so once we ship that this + // can be removed. if (!transformContext->globalVars) - transformContext->globalVars = xmlHashCreate(20); + transformContext->globalVars = xmlHashCreate(20); const char** params = xsltParamArrayFromParameterMap(m_parameters); xsltQuoteUserParams(transformContext, params); @@ -329,7 +335,8 @@ bool XSLTProcessor::transformToString(Node* sourceNode, String& mimeType, String if (shouldFreeSourceDoc) xmlFreeDoc(sourceDoc); - if ((success = saveResultToString(resultDoc, sheet, resultString))) { + success = saveResultToString(resultDoc, sheet, resultString); + if (success) { mimeType = resultMIMEType(resultDoc, sheet); resultEncoding = (char*)resultDoc->encoding; } @@ -344,4 +351,4 @@ bool XSLTProcessor::transformToString(Node* sourceNode, String& mimeType, String return success; } -} // namespace WebCore +} // namespace blink