[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.15.1-1414-gc69ee75

hausmann at webkit.org hausmann at webkit.org
Thu Oct 29 20:34:59 UTC 2009


The following commit has been merged in the webkit-1.1 branch:
commit 34a3f963fabd0f37e604afcb8648f33e322964aa
Author: hausmann at webkit.org <hausmann at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Sep 28 14:36:24 2009 +0000

    Move the libxslt specific part of XSLTProcessor to a separate file.
    https://bugs.webkit.org/show_bug.cgi?id=28303
    
    Patch by Jakub Wieczorek <faw217 at gmail.com> on 2009-09-28
    Reviewed by Simon Hausmann.
    
    In preparation for adding XSLT support with QtXmlPatterns to the Qt
    port, move the libxslt part of the XSLTProcessor implementation into
    another file and leave the part that can be reused and shared.
    
    Additionally, fix some coding style issues.
    
    * GNUmakefile.am:
    * WebCore.gypi:
    * WebCore.vcproj/WebCore.vcproj:
    * WebCore.xcodeproj/project.pbxproj:
    * WebCoreSources.bkl:
    * xml/XSLTProcessor.cpp:
    (WebCore::XSLTProcessor::createDocumentFromSource): Remove trailing whitespaces.
    (WebCore::createFragmentFromSource): Remove trailing whitespaces.
    (WebCore::XSLTProcessor::transformToFragment): Remove trailing whitespaces.
    (WebCore::XSLTProcessor::reset): Moved out of the class definition.
    * xml/XSLTProcessorLibxslt.cpp: Added.
    (WebCore::XSLTProcessor::genericErrorFunc): Moved.
    (WebCore::XSLTProcessor::parseErrorFunc): Moved.
    (WebCore::docLoaderFunc): Moved.
    (WebCore::setXSLTLoadCallBack): Moved.
    (WebCore::writeToVector): Moved.
    (WebCore::saveResultToString): Moved.
    (WebCore::xsltParamArrayFromParameterMap): Moved.
    (WebCore::freeXsltParamArray): Moved.
    (WebCore::xsltStylesheetPointer): Moved.
    (WebCore::xmlDocPtrFromNode): Moved.
    (WebCore::resultMIMEType): Moved.
    (WebCore::XSLTProcessor::transformToString): Moved.
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@48812 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index c71bd4d..5a34608 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,40 @@
+2009-09-28  Jakub Wieczorek  <faw217 at gmail.com>
+
+        Reviewed by Simon Hausmann.
+
+        Move the libxslt specific part of XSLTProcessor to a separate file.
+        https://bugs.webkit.org/show_bug.cgi?id=28303
+
+        In preparation for adding XSLT support with QtXmlPatterns to the Qt
+        port, move the libxslt part of the XSLTProcessor implementation into
+        another file and leave the part that can be reused and shared.
+
+        Additionally, fix some coding style issues.
+
+        * GNUmakefile.am:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * WebCoreSources.bkl:
+        * xml/XSLTProcessor.cpp:
+        (WebCore::XSLTProcessor::createDocumentFromSource): Remove trailing whitespaces.
+        (WebCore::createFragmentFromSource): Remove trailing whitespaces.
+        (WebCore::XSLTProcessor::transformToFragment): Remove trailing whitespaces.
+        (WebCore::XSLTProcessor::reset): Moved out of the class definition.
+        * xml/XSLTProcessorLibxslt.cpp: Added.
+        (WebCore::XSLTProcessor::genericErrorFunc): Moved.
+        (WebCore::XSLTProcessor::parseErrorFunc): Moved.
+        (WebCore::docLoaderFunc): Moved.
+        (WebCore::setXSLTLoadCallBack): Moved.
+        (WebCore::writeToVector): Moved.
+        (WebCore::saveResultToString): Moved.
+        (WebCore::xsltParamArrayFromParameterMap): Moved.
+        (WebCore::freeXsltParamArray): Moved.
+        (WebCore::xsltStylesheetPointer): Moved.
+        (WebCore::xmlDocPtrFromNode): Moved.
+        (WebCore::resultMIMEType): Moved.
+        (WebCore::XSLTProcessor::transformToString): Moved.
+
 2009-09-28  Charles Wei  <charles.wei at torchmobile.com.cn>
 
         Reviewed by Nikolas Zimmermann.
diff --git a/WebCore/GNUmakefile.am b/WebCore/GNUmakefile.am
index 715e23c..b1b4339 100644
--- a/WebCore/GNUmakefile.am
+++ b/WebCore/GNUmakefile.am
@@ -2417,6 +2417,7 @@ webcore_sources += \
 	WebCore/xml/XSLTExtensions.cpp \
 	WebCore/xml/XSLTExtensions.h \
 	WebCore/xml/XSLTProcessor.cpp \
+	WebCore/xml/XSLTProcessorLibxslt.cpp \
 	WebCore/xml/XSLTProcessor.h \
 	WebCore/xml/XSLTUnicodeSort.cpp \
 	WebCore/xml/XSLTUnicodeSort.h
diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
index 18cfb0c..3e180ee 100644
--- a/WebCore/WebCore.gypi
+++ b/WebCore/WebCore.gypi
@@ -3519,6 +3519,7 @@
             'xml/XSLTExtensions.cpp',
             'xml/XSLTExtensions.h',
             'xml/XSLTProcessor.cpp',
+            'xml/XSLTProcessorLibxslt.cpp',
             'xml/XSLTProcessor.h',
             'xml/XSLTUnicodeSort.cpp',
             'xml/XSLTUnicodeSort.h',
diff --git a/WebCore/WebCore.vcproj/WebCore.vcproj b/WebCore/WebCore.vcproj/WebCore.vcproj
index 4c6c43d..b02d525 100644
--- a/WebCore/WebCore.vcproj/WebCore.vcproj
+++ b/WebCore/WebCore.vcproj/WebCore.vcproj
@@ -23828,6 +23828,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\xml\XSLTProcessorLibxslt.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\xml\XSLTProcessor.h"
 				>
 			</File>
diff --git a/WebCore/WebCore.xcodeproj/project.pbxproj b/WebCore/WebCore.xcodeproj/project.pbxproj
index 5113f68..40078c8 100644
--- a/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -2322,6 +2322,7 @@
 		93F19AFF08245E59001E9ABC /* ClipboardMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D90660C0665D937006B6F1A /* ClipboardMac.mm */; };
 		93F19B0308245E59001E9ABC /* XSLStyleSheet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC06F24906D18A7E004A6FA3 /* XSLStyleSheet.cpp */; };
 		93F19B0408245E59001E9ABC /* XSLTProcessor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC06F24B06D18A7E004A6FA3 /* XSLTProcessor.cpp */; };
+		93F19B0508245E59001E9ABC /* XSLTProcessorLibxslt.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC06F24D06D18A7E004A6FA3 /* XSLTProcessorLibxslt.cpp */; };
 		93F19B0708245E59001E9ABC /* WebCoreView.m in Sources */ = {isa = PBXBuildFile; fileRef = BE8560510701F91100239769 /* WebCoreView.m */; };
 		93F19B0808245E59001E9ABC /* WebDashboardRegion.m in Sources */ = {isa = PBXBuildFile; fileRef = 5150C2A50702629800AF642C /* WebDashboardRegion.m */; settings = {COMPILER_FLAGS = "-Wno-cast-qual"; }; };
 		93F19B1308245E59001E9ABC /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F5C2869302846DCD018635CA /* ApplicationServices.framework */; };
@@ -9075,6 +9076,7 @@
 		BC06F24A06D18A7E004A6FA3 /* XSLStyleSheet.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = XSLStyleSheet.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
 		BC06F24B06D18A7E004A6FA3 /* XSLTProcessor.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XSLTProcessor.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
 		BC06F24C06D18A7E004A6FA3 /* XSLTProcessor.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = XSLTProcessor.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
+		BC06F24D06D18A7E004A6FA3 /* XSLTProcessorLibxslt.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XSLTProcessorLibxslt.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
 		BC073BA90C399B1F000F5979 /* FloatConversion.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FloatConversion.h; sourceTree = "<group>"; };
 		BC0B36A10CD3C67C00AC7EB5 /* Console.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Console.cpp; sourceTree = "<group>"; };
 		BC0B36A20CD3C67C00AC7EB5 /* Console.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Console.h; sourceTree = "<group>"; };
@@ -14844,6 +14846,7 @@
 				E1F1E82E0C3C2BB9006DB391 /* XSLTExtensions.h */,
 				BC06F24B06D18A7E004A6FA3 /* XSLTProcessor.cpp */,
 				BC06F24C06D18A7E004A6FA3 /* XSLTProcessor.h */,
+				BC06F24D06D18A7E004A6FA3 /* XSLTProcessorLibxslt.cpp */,
 				BCEFE1DC0DCA5CFD00739219 /* XSLTProcessor.idl */,
 				E1BE512B0CF6C512002EA959 /* XSLTUnicodeSort.cpp */,
 				E1BE512C0CF6C512002EA959 /* XSLTUnicodeSort.h */,
@@ -19912,6 +19915,7 @@
 				93F19B0308245E59001E9ABC /* XSLStyleSheet.cpp in Sources */,
 				E1F1E82F0C3C2BB9006DB391 /* XSLTExtensions.cpp in Sources */,
 				93F19B0408245E59001E9ABC /* XSLTProcessor.cpp in Sources */,
+				93F19B0508245E59001E9ABC /* XSLTProcessorLibxslt.cpp in Sources */,
 				E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */,
 				97DD4D860FDF4D6E00ECF9A4 /* XSSAuditor.cpp in Sources */,
 				0FF5025C102BA9010066F39A /* DOMMedia.mm in Sources */,
diff --git a/WebCore/WebCoreSources.bkl b/WebCore/WebCoreSources.bkl
index 8e5384c..3716af3 100644
--- a/WebCore/WebCoreSources.bkl
+++ b/WebCore/WebCoreSources.bkl
@@ -1,5 +1,5 @@
 <?xml version="1.0" ?>
-<!-- 
+<!--
 
 Copyright (C) 2007 Kevin Ollivier.  All rights reserved.
 
@@ -8,13 +8,13 @@ modification, are permitted provided that the following conditions
 are met:
 
 1.  Redistributions of source code must retain the above copyright
-    notice, this list of conditions and the following disclaimer. 
+    notice, this list of conditions and the following disclaimer.
 2.  Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in the
-    documentation and/or other materials provided with the distribution. 
+    documentation and/or other materials provided with the distribution.
 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
     its contributors may be used to endorse or promote products derived
-    from this software without specific prior written permission. 
+    from this software without specific prior written permission.
 
 THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@@ -51,7 +51,7 @@ This file contains the list of files needed to build WebCore.
         accessibility/AccessibilityTableRow.cpp
         accessibility/AXObjectCache.cpp
     </set>
-    
+
     <set append="1" var="WEBCORE_SOURCES_JS">
         bindings/js/GCController.cpp
         bindings/js/JSAttrCustom.cpp
@@ -499,7 +499,7 @@ This file contains the list of files needed to build WebCore.
         dom/RegisteredEventListener.cpp
         dom/ScriptElement.cpp
         dom/ScriptExecutionContext.cpp
-        dom/SelectElement.cpp 
+        dom/SelectElement.cpp
         dom/SelectorNodeList.cpp
         dom/StaticNodeList.cpp
         dom/StyleElement.cpp
@@ -568,7 +568,7 @@ This file contains the list of files needed to build WebCore.
         editing/markup.cpp
         editing/visible_units.cpp
     </set>
-    
+
     <set append="1" var="WEBCORE_SOURCES_HISTORY">
         history/BackForwardList.cpp
         history/CachedFrame.cpp
@@ -576,7 +576,7 @@ This file contains the list of files needed to build WebCore.
         history/PageCache.cpp
         history/HistoryItem.cpp
     </set>
-    
+
     <set append="1" var="WEBCORE_SOURCES_HTML">
         html/canvas/CanvasGradient.cpp
         html/canvas/CanvasPattern.cpp
@@ -736,7 +736,7 @@ This file contains the list of files needed to build WebCore.
         loader/WorkerThreadableLoader.cpp
         loader/loader.cpp
     </set>
-    
+
     <set append="1" var="WEBCORE_SOURCES_ICON">
         loader/icon/IconDatabase.cpp
         loader/icon/IconLoader.cpp
@@ -1087,6 +1087,7 @@ This file contains the list of files needed to build WebCore.
         xml/XSLTExtensions.cpp
         xml/XSLTUnicodeSort.cpp
         xml/XSLTProcessor.cpp
+        xml/XSLTProcessorLibxslt.cpp
     </set>
 
 </makefile>
diff --git a/WebCore/xml/XSLTProcessor.cpp b/WebCore/xml/XSLTProcessor.cpp
index 8eaef67..b182243 100644
--- a/WebCore/xml/XSLTProcessor.cpp
+++ b/WebCore/xml/XSLTProcessor.cpp
@@ -26,10 +26,7 @@
 
 #include "XSLTProcessor.h"
 
-#include "CString.h"
-#include "Console.h"
 #include "DOMImplementation.h"
-#include "DOMWindow.h"
 #include "DocLoader.h"
 #include "DocumentFragment.h"
 #include "Frame.h"
@@ -38,166 +35,17 @@
 #include "HTMLDocument.h"
 #include "HTMLTokenizer.h" // for parseHTMLDocumentFragment
 #include "Page.h"
-#include "ResourceError.h"
-#include "ResourceHandle.h"
-#include "ResourceRequest.h"
-#include "ResourceResponse.h"
 #include "Text.h"
 #include "TextResourceDecoder.h"
 #include "XMLTokenizer.h"
-#include "XSLTExtensions.h"
-#include "XSLTUnicodeSort.h"
 #include "loader.h"
 #include "markup.h"
-#include <libxslt/imports.h>
-#include <libxslt/variables.h>
-#include <libxslt/xsltutils.h>
 #include <wtf/Assertions.h>
 #include <wtf/Platform.h>
 #include <wtf/Vector.h>
 
-#if PLATFORM(MAC)
-#include "SoftLinking.h"
-
-SOFT_LINK_LIBRARY(libxslt);
-SOFT_LINK(libxslt, xsltFreeStylesheet, void, (xsltStylesheetPtr sheet), (sheet))
-SOFT_LINK(libxslt, xsltFreeTransformContext, void, (xsltTransformContextPtr ctxt), (ctxt))
-SOFT_LINK(libxslt, xsltNewTransformContext, xsltTransformContextPtr, (xsltStylesheetPtr style, xmlDocPtr doc), (style, doc))
-SOFT_LINK(libxslt, xsltApplyStylesheetUser, xmlDocPtr, (xsltStylesheetPtr style, xmlDocPtr doc, const char** params, const char* output, FILE* profile, xsltTransformContextPtr userCtxt), (style, doc, params, output, profile, userCtxt))
-SOFT_LINK(libxslt, xsltQuoteUserParams, int, (xsltTransformContextPtr ctxt, const char** params), (ctxt, params))
-SOFT_LINK(libxslt, xsltSetCtxtSortFunc, void, (xsltTransformContextPtr ctxt, xsltSortFunc handler), (ctxt, handler))
-SOFT_LINK(libxslt, xsltSetLoaderFunc, void, (xsltDocLoaderFunc f), (f))
-SOFT_LINK(libxslt, xsltSaveResultTo, int, (xmlOutputBufferPtr buf, xmlDocPtr result, xsltStylesheetPtr style), (buf, result, style))
-SOFT_LINK(libxslt, xsltNextImport, xsltStylesheetPtr, (xsltStylesheetPtr style), (style))
-#endif
-
 namespace WebCore {
 
-void XSLTProcessor::genericErrorFunc(void*, const char*, ...)
-{
-    // It would be nice to do something with this error message.
-}
-    
-void XSLTProcessor::parseErrorFunc(void* userData, xmlError* error)
-{
-    Console* console = static_cast<Console*>(userData);
-    if (!console)
-        return;
-
-    MessageLevel level;
-    switch (error->level) {
-        case XML_ERR_NONE:
-            level = TipMessageLevel;
-            break;
-        case XML_ERR_WARNING:
-            level = WarningMessageLevel;
-            break;
-        case XML_ERR_ERROR:
-        case XML_ERR_FATAL:
-        default:
-            level = ErrorMessageLevel;
-            break;
-    }
-
-    console->addMessage(XMLMessageSource, LogMessageType, level, error->message, error->line, error->file);
-}
-
-// FIXME: There seems to be no way to control the ctxt pointer for loading here, thus we have globals.
-static XSLTProcessor* globalProcessor = 0;
-static DocLoader* globalDocLoader = 0;
-static xmlDocPtr docLoaderFunc(const xmlChar* uri,
-                                    xmlDictPtr,
-                                    int options,
-                                    void* ctxt,
-                                    xsltLoadType type)
-{
-    if (!globalProcessor)
-        return 0;
-    
-    switch (type) {
-        case XSLT_LOAD_DOCUMENT: {
-            xsltTransformContextPtr context = (xsltTransformContextPtr)ctxt;
-            xmlChar* base = xmlNodeGetBase(context->document->doc, context->node);
-            KURL url(KURL(ParsedURLString, reinterpret_cast<const char*>(base)), reinterpret_cast<const char*>(uri));
-            xmlFree(base);
-            ResourceError error;
-            ResourceResponse response;
-
-            Vector<char> data;
-
-            bool requestAllowed = globalDocLoader->frame() && globalDocLoader->doc()->securityOrigin()->canRequest(url);
-            if (requestAllowed) {
-                globalDocLoader->frame()->loader()->loadResourceSynchronously(url, AllowStoredCredentials, error, response, data);
-                requestAllowed = globalDocLoader->doc()->securityOrigin()->canRequest(response.url());
-            }
-            if (!requestAllowed) {
-                data.clear();
-                globalDocLoader->printAccessDeniedMessage(url);
-            }
-
-            Console* console = 0;
-            if (Frame* frame = globalProcessor->xslStylesheet()->ownerDocument()->frame())
-                console = frame->domWindow()->console();
-            xmlSetStructuredErrorFunc(console, XSLTProcessor::parseErrorFunc);
-            xmlSetGenericErrorFunc(console, XSLTProcessor::genericErrorFunc);
-            
-            // We don't specify an encoding here. Neither Gecko nor WinIE respects
-            // the encoding specified in the HTTP headers.
-            xmlDocPtr doc = xmlReadMemory(data.data(), data.size(), (const char*)uri, 0, options);
-
-            xmlSetStructuredErrorFunc(0, 0);
-            xmlSetGenericErrorFunc(0, 0);
-
-            return doc;
-        }
-        case XSLT_LOAD_STYLESHEET:
-            return globalProcessor->xslStylesheet()->locateStylesheetSubResource(((xsltStylesheetPtr)ctxt)->doc, uri);
-        default:
-            break;
-    }
-    
-    return 0;
-}
-
-static inline void setXSLTLoadCallBack(xsltDocLoaderFunc func, XSLTProcessor* processor, DocLoader* loader)
-{
-    xsltSetLoaderFunc(func);
-    globalProcessor = processor;
-    globalDocLoader = loader;
-}
-
-static int writeToVector(void* context, const char* buffer, int len)
-{
-    Vector<UChar>& resultOutput = *static_cast<Vector<UChar>*>(context);
-    String decodedChunk = String::fromUTF8(buffer, len);
-    resultOutput.append(decodedChunk.characters(), decodedChunk.length());
-    return len;
-}
-
-static bool saveResultToString(xmlDocPtr resultDoc, xsltStylesheetPtr sheet, String& resultString)
-{
-    xmlOutputBufferPtr outputBuf = xmlAllocOutputBuffer(0);
-    if (!outputBuf)
-        return false;
-
-    Vector<UChar> resultVector;
-    outputBuf->context = &resultVector;
-    outputBuf->writecallback = writeToVector;
-    
-    int retval = xsltSaveResultTo(outputBuf, resultDoc, sheet);
-    xmlOutputBufferClose(outputBuf);
-    if (retval < 0)
-        return false;
-
-    // Workaround for <http://bugzilla.gnome.org/show_bug.cgi?id=495668>: libxslt appends an extra line feed to the result.
-    if (resultVector.size() > 0 && resultVector[resultVector.size() - 1] == '\n')
-        resultVector.removeLast();
-
-    resultString = String::adopt(resultVector);
-
-    return true;
-}
-
 static inline void transformTextStringToXHTMLDocumentString(String& text)
 {
     // Modify the output so that it is a well-formed XHTML document with a <pre> tag enclosing the text.
@@ -213,38 +61,6 @@ static inline void transformTextStringToXHTMLDocumentString(String& text)
         "</html>\n";
 }
 
-static const char** xsltParamArrayFromParameterMap(XSLTProcessor::ParameterMap& parameters)
-{
-    if (parameters.isEmpty())
-        return 0;
-
-    const char** parameterArray = (const char**)fastMalloc(((parameters.size() * 2) + 1) * sizeof(char*));
-
-    XSLTProcessor::ParameterMap::iterator end = parameters.end();
-    unsigned index = 0;
-    for (XSLTProcessor::ParameterMap::iterator it = parameters.begin(); it != end; ++it) {
-        parameterArray[index++] = strdup(it->first.utf8().data());
-        parameterArray[index++] = strdup(it->second.utf8().data());
-    }
-    parameterArray[index] = 0;
-
-    return parameterArray;
-}
-
-static void freeXsltParamArray(const char** params)
-{
-    const char** temp = params;
-    if (!params)
-        return;
-    
-    while (*temp) {
-        free((void*)*(temp++)); // strdup returns malloc'd blocks, so we have to use free() here
-        free((void*)*(temp++));
-    }
-    fastFree(params);
-}
-
-
 PassRefPtr<Document> XSLTProcessor::createDocumentFromSource(const String& sourceString,
     const String& sourceEncoding, const String& sourceMIMEType, Node* sourceNode, Frame* frame)
 {
@@ -258,7 +74,7 @@ PassRefPtr<Document> XSLTProcessor::createDocumentFromSource(const String& sourc
         transformTextStringToXHTMLDocumentString(documentSource);
     } else
         result = ownerDocument->implementation()->createDocument(sourceMIMEType, frame, false);
-    
+
     // Before parsing, we need to save & detach the old document and get the new document
     // in place. We have to do this only if we're rendering the result document.
     if (frame) {
@@ -267,15 +83,15 @@ PassRefPtr<Document> XSLTProcessor::createDocumentFromSource(const String& sourc
         result->setTransformSourceDocument(frame->document());
         frame->setDocument(result);
     }
-    
+
     if (sourceIsDocument)
         result->setURL(ownerDocument->url());
     result->open();
-    
+
     RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create(sourceMIMEType);
     decoder->setEncoding(sourceEncoding.isEmpty() ? UTF8Encoding() : TextEncoding(sourceEncoding), TextResourceDecoder::EncodingFromXMLHeader);
     result->setDecoder(decoder.release());
-    
+
     result->write(documentSource);
     result->finishParsing();
     result->close();
@@ -286,7 +102,7 @@ PassRefPtr<Document> XSLTProcessor::createDocumentFromSource(const String& sourc
 static inline RefPtr<DocumentFragment> createFragmentFromSource(const String& sourceString, const String& sourceMIMEType, Document* outputDoc)
 {
     RefPtr<DocumentFragment> fragment = DocumentFragment::create(outputDoc);
-    
+
     if (sourceMIMEType == "text/html")
         parseHTMLDocumentFragment(sourceString, fragment.get());
     else if (sourceMIMEType == "text/plain")
@@ -296,118 +112,10 @@ static inline RefPtr<DocumentFragment> createFragmentFromSource(const String& so
         if (!successfulParse)
             return 0;
     }
-    
-    // FIXME: Do we need to mess with URLs here?
-        
-    return fragment;
-}
-
-static xsltStylesheetPtr xsltStylesheetPointer(RefPtr<XSLStyleSheet>& cachedStylesheet, Node* stylesheetRootNode)
-{
-    if (!cachedStylesheet && stylesheetRootNode) {
-        cachedStylesheet = XSLStyleSheet::create(stylesheetRootNode->parent() ? stylesheetRootNode->parent() : stylesheetRootNode,
-            stylesheetRootNode->document()->url().string());
-        cachedStylesheet->parseString(createMarkup(stylesheetRootNode));
-    }
-    
-    if (!cachedStylesheet || !cachedStylesheet->document())
-        return 0;
-    
-    return cachedStylesheet->compileStyleSheet();
-}
 
-static inline xmlDocPtr xmlDocPtrFromNode(Node* sourceNode, bool& shouldDelete)
-{
-    RefPtr<Document> ownerDocument = sourceNode->document();
-    bool sourceIsDocument = (sourceNode == ownerDocument.get());
-    
-    xmlDocPtr sourceDoc = 0;
-    if (sourceIsDocument)
-        sourceDoc = (xmlDocPtr)ownerDocument->transformSource();
-    if (!sourceDoc) {
-        sourceDoc = (xmlDocPtr)xmlDocPtrForString(ownerDocument->docLoader(), createMarkup(sourceNode),
-            sourceIsDocument ? ownerDocument->url().string() : String());
-        shouldDelete = (sourceDoc != 0);
-    }
-    return sourceDoc;
-}
-
-static inline String resultMIMEType(xmlDocPtr resultDoc, xsltStylesheetPtr sheet)
-{
-    // There are three types of output we need to be able to deal with:
-    // HTML (create an HTML document), XML (create an XML document),
-    // and text (wrap in a <pre> and create an XML document).
-
-    const xmlChar* resultType = 0;
-    XSLT_GET_IMPORT_PTR(resultType, sheet, method);
-    if (resultType == 0 && resultDoc->type == XML_HTML_DOCUMENT_NODE)
-        resultType = (const xmlChar*)"html";
-    
-    if (xmlStrEqual(resultType, (const xmlChar*)"html"))
-        return "text/html";
-    else if (xmlStrEqual(resultType, (const xmlChar*)"text"))
-        return "text/plain";
-        
-    return "application/xml";
-}
-
-bool XSLTProcessor::transformToString(Node* sourceNode, String& mimeType, String& resultString, String& resultEncoding)
-{
-    RefPtr<Document> ownerDocument = sourceNode->document();
-    
-    setXSLTLoadCallBack(docLoaderFunc, this, ownerDocument->docLoader());
-    xsltStylesheetPtr sheet = xsltStylesheetPointer(m_stylesheet, m_stylesheetRootNode.get());
-    if (!sheet) {
-        setXSLTLoadCallBack(0, 0, 0);
-        return false;
-    }
-    m_stylesheet->clearDocuments();
-
-    xmlChar* origMethod = sheet->method;
-    if (!origMethod && mimeType == "text/html")
-        sheet->method = (xmlChar*)"html";
-
-    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.
-        sheet->omitXmlDeclaration = true;
-
-        xsltTransformContextPtr transformContext = xsltNewTransformContext(sheet, sourceDoc);
-        registerXSLTExtensions(transformContext);
-
-        // <http://bugs.webkit.org/show_bug.cgi?id=16077>: XSLT processor <xsl:sort> 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.
-        if (transformContext->globalVars == NULL)
-           transformContext->globalVars = xmlHashCreate(20);
-
-        const char** params = xsltParamArrayFromParameterMap(m_parameters);
-        xsltQuoteUserParams(transformContext, params);
-        xmlDocPtr resultDoc = xsltApplyStylesheetUser(sheet, sourceDoc, 0, 0, 0, transformContext);
-        
-        xsltFreeTransformContext(transformContext);        
-        freeXsltParamArray(params);
-        
-        if (shouldFreeSourceDoc)
-            xmlFreeDoc(sourceDoc);
-        
-        if (success = saveResultToString(resultDoc, sheet, resultString)) {
-            mimeType = resultMIMEType(resultDoc, sheet);
-            resultEncoding = (char*)resultDoc->encoding;
-        }
-        xmlFreeDoc(resultDoc);
-    }
-    
-    sheet->method = origMethod;
-    setXSLTLoadCallBack(0, 0, 0);
-    xsltFreeStylesheet(sheet);
-    m_stylesheet = 0;
+    // FIXME: Do we need to mess with URLs here?
 
-    return success;
+    return fragment;
 }
 
 PassRefPtr<Document> XSLTProcessor::transformToDocument(Node* sourceNode)
@@ -429,7 +137,7 @@ PassRefPtr<DocumentFragment> XSLTProcessor::transformToFragment(Node* sourceNode
     // If the output document is HTML, default to HTML method.
     if (outputDoc->isHTMLDocument())
         resultMIMEType = "text/html";
-    
+
     if (!transformToString(sourceNode, resultMIMEType, resultString, resultEncoding))
         return 0;
     return createFragmentFromSource(resultString, resultMIMEType, outputDoc);
@@ -455,6 +163,13 @@ void XSLTProcessor::removeParameter(const String& /*namespaceURI*/, const String
     m_parameters.remove(localName);
 }
 
+void XSLTProcessor::reset()
+{
+    m_stylesheet.clear();
+    m_stylesheetRootNode.clear();
+    m_parameters.clear();
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(XSLT)
diff --git a/WebCore/xml/XSLTProcessorLibxslt.cpp b/WebCore/xml/XSLTProcessorLibxslt.cpp
new file mode 100644
index 0000000..6b2a0fd
--- /dev/null
+++ b/WebCore/xml/XSLTProcessorLibxslt.cpp
@@ -0,0 +1,334 @@
+/*
+ * This file is part of the XSL implementation.
+ *
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple, Inc. All rights reserved.
+ * Copyright (C) 2005, 2006 Alexey Proskuryakov <ap at webkit.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#if ENABLE(XSLT)
+
+#include "XSLTProcessor.h"
+
+#include "Console.h"
+#include "CString.h"
+#include "DOMWindow.h"
+#include "DocLoader.h"
+#include "Frame.h"
+#include "ResourceError.h"
+#include "ResourceHandle.h"
+#include "ResourceRequest.h"
+#include "ResourceResponse.h"
+#include "XMLTokenizer.h"
+#include "XSLStyleSheet.h"
+#include "XSLTExtensions.h"
+#include "XSLTUnicodeSort.h"
+#include "loader.h"
+#include "markup.h"
+#include <libxslt/imports.h>
+#include <libxslt/variables.h>
+#include <libxslt/xsltutils.h>
+#include <wtf/Assertions.h>
+#include <wtf/Platform.h>
+#include <wtf/Vector.h>
+
+#if PLATFORM(MAC)
+#include "SoftLinking.h"
+
+SOFT_LINK_LIBRARY(libxslt);
+SOFT_LINK(libxslt, xsltFreeStylesheet, void, (xsltStylesheetPtr sheet), (sheet))
+SOFT_LINK(libxslt, xsltFreeTransformContext, void, (xsltTransformContextPtr ctxt), (ctxt))
+SOFT_LINK(libxslt, xsltNewTransformContext, xsltTransformContextPtr, (xsltStylesheetPtr style, xmlDocPtr doc), (style, doc))
+SOFT_LINK(libxslt, xsltApplyStylesheetUser, xmlDocPtr, (xsltStylesheetPtr style, xmlDocPtr doc, const char** params, const char* output, FILE* profile, xsltTransformContextPtr userCtxt), (style, doc, params, output, profile, userCtxt))
+SOFT_LINK(libxslt, xsltQuoteUserParams, int, (xsltTransformContextPtr ctxt, const char** params), (ctxt, params))
+SOFT_LINK(libxslt, xsltSetCtxtSortFunc, void, (xsltTransformContextPtr ctxt, xsltSortFunc handler), (ctxt, handler))
+SOFT_LINK(libxslt, xsltSetLoaderFunc, void, (xsltDocLoaderFunc f), (f))
+SOFT_LINK(libxslt, xsltSaveResultTo, int, (xmlOutputBufferPtr buf, xmlDocPtr result, xsltStylesheetPtr style), (buf, result, style))
+SOFT_LINK(libxslt, xsltNextImport, xsltStylesheetPtr, (xsltStylesheetPtr style), (style))
+#endif
+
+namespace WebCore {
+
+void XSLTProcessor::genericErrorFunc(void*, const char*, ...)
+{
+    // It would be nice to do something with this error message.
+}
+
+void XSLTProcessor::parseErrorFunc(void* userData, xmlError* error)
+{
+    Console* console = static_cast<Console*>(userData);
+    if (!console)
+        return;
+
+    MessageLevel level;
+    switch (error->level) {
+    case XML_ERR_NONE:
+        level = TipMessageLevel;
+        break;
+    case XML_ERR_WARNING:
+        level = WarningMessageLevel;
+        break;
+    case XML_ERR_ERROR:
+    case XML_ERR_FATAL:
+    default:
+        level = ErrorMessageLevel;
+        break;
+    }
+
+    console->addMessage(XMLMessageSource, LogMessageType, level, error->message, error->line, error->file);
+}
+
+// FIXME: There seems to be no way to control the ctxt pointer for loading here, thus we have globals.
+static XSLTProcessor* globalProcessor = 0;
+static DocLoader* globalDocLoader = 0;
+static xmlDocPtr docLoaderFunc(const xmlChar* uri,
+                                    xmlDictPtr,
+                                    int options,
+                                    void* ctxt,
+                                    xsltLoadType type)
+{
+    if (!globalProcessor)
+        return 0;
+
+    switch (type) {
+    case XSLT_LOAD_DOCUMENT: {
+        xsltTransformContextPtr context = (xsltTransformContextPtr)ctxt;
+        xmlChar* base = xmlNodeGetBase(context->document->doc, context->node);
+        KURL url(KURL(ParsedURLString, reinterpret_cast<const char*>(base)), reinterpret_cast<const char*>(uri));
+        xmlFree(base);
+        ResourceError error;
+        ResourceResponse response;
+
+        Vector<char> data;
+
+        bool requestAllowed = globalDocLoader->frame() && globalDocLoader->doc()->securityOrigin()->canRequest(url);
+        if (requestAllowed) {
+            globalDocLoader->frame()->loader()->loadResourceSynchronously(url, AllowStoredCredentials, error, response, data);
+            requestAllowed = globalDocLoader->doc()->securityOrigin()->canRequest(response.url());
+        }
+        if (!requestAllowed) {
+            data.clear();
+            globalDocLoader->printAccessDeniedMessage(url);
+        }
+
+        Console* console = 0;
+        if (Frame* frame = globalProcessor->xslStylesheet()->ownerDocument()->frame())
+            console = frame->domWindow()->console();
+        xmlSetStructuredErrorFunc(console, XSLTProcessor::parseErrorFunc);
+        xmlSetGenericErrorFunc(console, XSLTProcessor::genericErrorFunc);
+
+        // We don't specify an encoding here. Neither Gecko nor WinIE respects
+        // the encoding specified in the HTTP headers.
+        xmlDocPtr doc = xmlReadMemory(data.data(), data.size(), (const char*)uri, 0, options);
+
+        xmlSetStructuredErrorFunc(0, 0);
+        xmlSetGenericErrorFunc(0, 0);
+
+        return doc;
+    }
+    case XSLT_LOAD_STYLESHEET:
+        return globalProcessor->xslStylesheet()->locateStylesheetSubResource(((xsltStylesheetPtr)ctxt)->doc, uri);
+    default:
+        break;
+    }
+
+    return 0;
+}
+
+static inline void setXSLTLoadCallBack(xsltDocLoaderFunc func, XSLTProcessor* processor, DocLoader* loader)
+{
+    xsltSetLoaderFunc(func);
+    globalProcessor = processor;
+    globalDocLoader = loader;
+}
+
+static int writeToVector(void* context, const char* buffer, int len)
+{
+    Vector<UChar>& resultOutput = *static_cast<Vector<UChar>*>(context);
+    String decodedChunk = String::fromUTF8(buffer, len);
+    resultOutput.append(decodedChunk.characters(), decodedChunk.length());
+    return len;
+}
+
+static bool saveResultToString(xmlDocPtr resultDoc, xsltStylesheetPtr sheet, String& resultString)
+{
+    xmlOutputBufferPtr outputBuf = xmlAllocOutputBuffer(0);
+    if (!outputBuf)
+        return false;
+
+    Vector<UChar> resultVector;
+    outputBuf->context = &resultVector;
+    outputBuf->writecallback = writeToVector;
+
+    int retval = xsltSaveResultTo(outputBuf, resultDoc, sheet);
+    xmlOutputBufferClose(outputBuf);
+    if (retval < 0)
+        return false;
+
+    // Workaround for <http://bugzilla.gnome.org/show_bug.cgi?id=495668>: libxslt appends an extra line feed to the result.
+    if (resultVector.size() > 0 && resultVector[resultVector.size() - 1] == '\n')
+        resultVector.removeLast();
+
+    resultString = String::adopt(resultVector);
+
+    return true;
+}
+
+static const char** xsltParamArrayFromParameterMap(XSLTProcessor::ParameterMap& parameters)
+{
+    if (parameters.isEmpty())
+        return 0;
+
+    const char** parameterArray = (const char**)fastMalloc(((parameters.size() * 2) + 1) * sizeof(char*));
+
+    XSLTProcessor::ParameterMap::iterator end = parameters.end();
+    unsigned index = 0;
+    for (XSLTProcessor::ParameterMap::iterator it = parameters.begin(); it != end; ++it) {
+        parameterArray[index++] = strdup(it->first.utf8().data());
+        parameterArray[index++] = strdup(it->second.utf8().data());
+    }
+    parameterArray[index] = 0;
+
+    return parameterArray;
+}
+
+static void freeXsltParamArray(const char** params)
+{
+    const char** temp = params;
+    if (!params)
+        return;
+
+    while (*temp) {
+        free((void*)*(temp++)); // strdup returns malloc'd blocks, so we have to use free() here
+        free((void*)*(temp++));
+    }
+    fastFree(params);
+}
+
+static xsltStylesheetPtr xsltStylesheetPointer(RefPtr<XSLStyleSheet>& cachedStylesheet, Node* stylesheetRootNode)
+{
+    if (!cachedStylesheet && stylesheetRootNode) {
+        cachedStylesheet = XSLStyleSheet::create(stylesheetRootNode->parent() ? stylesheetRootNode->parent() : stylesheetRootNode,
+            stylesheetRootNode->document()->url().string());
+        cachedStylesheet->parseString(createMarkup(stylesheetRootNode));
+    }
+
+    if (!cachedStylesheet || !cachedStylesheet->document())
+        return 0;
+
+    return cachedStylesheet->compileStyleSheet();
+}
+
+static inline xmlDocPtr xmlDocPtrFromNode(Node* sourceNode, bool& shouldDelete)
+{
+    RefPtr<Document> ownerDocument = sourceNode->document();
+    bool sourceIsDocument = (sourceNode == ownerDocument.get());
+
+    xmlDocPtr sourceDoc = 0;
+    if (sourceIsDocument)
+        sourceDoc = (xmlDocPtr)ownerDocument->transformSource();
+    if (!sourceDoc) {
+        sourceDoc = (xmlDocPtr)xmlDocPtrForString(ownerDocument->docLoader(), createMarkup(sourceNode),
+            sourceIsDocument ? ownerDocument->url().string() : String());
+        shouldDelete = sourceDoc;
+    }
+    return sourceDoc;
+}
+
+static inline String resultMIMEType(xmlDocPtr resultDoc, xsltStylesheetPtr sheet)
+{
+    // There are three types of output we need to be able to deal with:
+    // HTML (create an HTML document), XML (create an XML document),
+    // and text (wrap in a <pre> and create an XML document).
+
+    const xmlChar* resultType = 0;
+    XSLT_GET_IMPORT_PTR(resultType, sheet, method);
+    if (!resultType && resultDoc->type == XML_HTML_DOCUMENT_NODE)
+        resultType = (const xmlChar*)"html";
+
+    if (xmlStrEqual(resultType, (const xmlChar*)"html"))
+        return "text/html";
+    if (xmlStrEqual(resultType, (const xmlChar*)"text"))
+        return "text/plain";
+
+    return "application/xml";
+}
+
+bool XSLTProcessor::transformToString(Node* sourceNode, String& mimeType, String& resultString, String& resultEncoding)
+{
+    RefPtr<Document> ownerDocument = sourceNode->document();
+
+    setXSLTLoadCallBack(docLoaderFunc, this, ownerDocument->docLoader());
+    xsltStylesheetPtr sheet = xsltStylesheetPointer(m_stylesheet, m_stylesheetRootNode.get());
+    if (!sheet) {
+        setXSLTLoadCallBack(0, 0, 0);
+        return false;
+    }
+    m_stylesheet->clearDocuments();
+
+    xmlChar* origMethod = sheet->method;
+    if (!origMethod && mimeType == "text/html")
+        sheet->method = (xmlChar*)"html";
+
+    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.
+        sheet->omitXmlDeclaration = true;
+
+        xsltTransformContextPtr transformContext = xsltNewTransformContext(sheet, sourceDoc);
+        registerXSLTExtensions(transformContext);
+
+        // <http://bugs.webkit.org/show_bug.cgi?id=16077>: XSLT processor <xsl:sort> 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.
+        if (!transformContext->globalVars)
+           transformContext->globalVars = xmlHashCreate(20);
+
+        const char** params = xsltParamArrayFromParameterMap(m_parameters);
+        xsltQuoteUserParams(transformContext, params);
+        xmlDocPtr resultDoc = xsltApplyStylesheetUser(sheet, sourceDoc, 0, 0, 0, transformContext);
+
+        xsltFreeTransformContext(transformContext);
+        freeXsltParamArray(params);
+
+        if (shouldFreeSourceDoc)
+            xmlFreeDoc(sourceDoc);
+
+        if (success = saveResultToString(resultDoc, sheet, resultString)) {
+            mimeType = resultMIMEType(resultDoc, sheet);
+            resultEncoding = (char*)resultDoc->encoding;
+        }
+        xmlFreeDoc(resultDoc);
+    }
+
+    sheet->method = origMethod;
+    setXSLTLoadCallBack(0, 0, 0);
+    xsltFreeStylesheet(sheet);
+    m_stylesheet = 0;
+
+    return success;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(XSLT)

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list