diff options
author | Jocelyn Turcotte <jocelyn.turcotte@nokia.com> | 2009-10-01 09:45:01 (GMT) |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@nokia.com> | 2009-10-01 09:45:01 (GMT) |
commit | 34bd937aea27fabbfac964b80bc0ab50d677277e (patch) | |
tree | b82cc9d1fa598f81244482f6d48859c54031a70e /src/3rdparty/webkit/WebCore/xml | |
parent | 0ec49eca052e452a20d0ab7219c3a42589745ba5 (diff) | |
download | Qt-34bd937aea27fabbfac964b80bc0ab50d677277e.zip Qt-34bd937aea27fabbfac964b80bc0ab50d677277e.tar.gz Qt-34bd937aea27fabbfac964b80bc0ab50d677277e.tar.bz2 |
Updated WebKit from /home/joce/dev/qtwebkit/ to qtwebkit-4.6-snapshot-30092009-2 ( 284ebfc0df42d408d99838507c1ed335fba9bcf0 )
Changes in WebKit/qt since the last update:
++ b/WebKit/qt/ChangeLog
2009-09-29 Andras Becsi <becsi.andras@stud.u-szeged.hu>
Reviewed by Tor Arne Vestbø.
[Qt] Default font size reconciliation to 16px/13px to match other platform's de-facto standard.
This fixes https://bugs.webkit.org/show_bug.cgi?id=19674.
* Api/qwebsettings.cpp:
(QWebSettings::QWebSettings):
2009-09-29 Jedrzej Nowacki <jedrzej.nowacki@nokia.com>
Reviewed by Simon Hausmann.
https://bugs.webkit.org/show_bug.cgi?id=29844
QWebPage dependency autotest fix.
Fix for database() autotest. All opened databases should be removed at
end of test.
* tests/qwebpage/tst_qwebpage.cpp:
(tst_QWebPage::database):
2009-09-29 Jedrzej Nowacki <jedrzej.nowacki@nokia.com>
Reviewed by Simon Hausmann.
Some QWebHistory and QWebPage autotest crash fixes.
Some checking for m_mainFrame were added. MainFrame should be created
at some point of QWebPage live cicle.
https://bugs.webkit.org/show_bug.cgi?id=29803
* Api/qwebpage.cpp:
(QWebPage::~QWebPage):
(QWebPage::currentFrame):
(QWebPage::history):
(QWebPage::selectedText):
(QWebPage::updatePositionDependentActions):
* tests/qwebpage/tst_qwebpage.cpp:
(tst_QWebPage::crashTests_LazyInitializationOfMainFrame):
2009-09-29 Kenneth Rohde Christiansen <kenneth@webkit.org>
Reviewed by Simon Hausmann and Tor Arne Vestbø.
Implement QWebPage Extension for error pages, incl.
an example on how to use it in QtLauncher.
Correct our use of ResourceError.
* Api/qwebpage.h:
(ExtensionOption::):
(ExtensionOption::ErrorPageExtensionReturn::ErrorPageExtensionReturn):
* QtLauncher/main.cpp:
(WebPage::supportsExtension):
(MainWindow::MainWindow):
(MainWindow::selectElements):
(WebPage::extension):
* WebCoreSupport/FrameLoaderClientQt.cpp:
(WebCore::FrameLoaderClientQt::cancelledError):
(WebCore::FrameLoaderClientQt::blockedError):
(WebCore::FrameLoaderClientQt::cannotShowURLError):
(WebCore::FrameLoaderClientQt::interruptForPolicyChangeError):
(WebCore::FrameLoaderClientQt::cannotShowMIMETypeError):
(WebCore::FrameLoaderClientQt::fileDoesNotExistError):
(WebCore::FrameLoaderClientQt::callErrorPageExtension):
(WebCore::FrameLoaderClientQt::dispatchDidFailProvisionalLoad):
(WebCore::FrameLoaderClientQt::dispatchDidFailLoad):
* WebCoreSupport/FrameLoaderClientQt.h:
Diffstat (limited to 'src/3rdparty/webkit/WebCore/xml')
-rw-r--r-- | src/3rdparty/webkit/WebCore/xml/XSLStyleSheet.h | 26 | ||||
-rw-r--r-- | src/3rdparty/webkit/WebCore/xml/XSLStyleSheetLibxslt.cpp (renamed from src/3rdparty/webkit/WebCore/xml/XSLStyleSheet.cpp) | 31 | ||||
-rw-r--r-- | src/3rdparty/webkit/WebCore/xml/XSLStyleSheetQt.cpp | 103 | ||||
-rw-r--r-- | src/3rdparty/webkit/WebCore/xml/XSLTProcessor.cpp | 315 | ||||
-rw-r--r-- | src/3rdparty/webkit/WebCore/xml/XSLTProcessor.h | 10 | ||||
-rw-r--r-- | src/3rdparty/webkit/WebCore/xml/XSLTProcessorLibxslt.cpp | 335 | ||||
-rw-r--r-- | src/3rdparty/webkit/WebCore/xml/XSLTProcessorQt.cpp | 149 |
7 files changed, 646 insertions, 323 deletions
diff --git a/src/3rdparty/webkit/WebCore/xml/XSLStyleSheet.h b/src/3rdparty/webkit/WebCore/xml/XSLStyleSheet.h index fe97b54..c9729bb 100644 --- a/src/3rdparty/webkit/WebCore/xml/XSLStyleSheet.h +++ b/src/3rdparty/webkit/WebCore/xml/XSLStyleSheet.h @@ -26,8 +26,12 @@ #if ENABLE(XSLT) #include "StyleSheet.h" + +#if !USE(QXMLQUERY) #include <libxml/parser.h> #include <libxslt/transform.h> +#endif + #include <wtf/PassRefPtr.h> namespace WebCore { @@ -38,10 +42,12 @@ class XSLImportRule; class XSLStyleSheet : public StyleSheet { public: +#if !USE(QXMLQUERY) static PassRefPtr<XSLStyleSheet> create(XSLImportRule* parentImport, const String& href) { return adoptRef(new XSLStyleSheet(parentImport, href)); } +#endif static PassRefPtr<XSLStyleSheet> create(Node* parentNode, const String& href) { return adoptRef(new XSLStyleSheet(parentNode, href, false)); @@ -65,31 +71,41 @@ public: void loadChildSheets(); void loadChildSheet(const String& href); - xsltStylesheetPtr compileStyleSheet(); - DocLoader* docLoader(); Document* ownerDocument() { return m_ownerDocument; } void setParentStyleSheet(XSLStyleSheet* parent); +#if USE(QXMLQUERY) + String sheetString() const { return m_sheetString; } +#else xmlDocPtr document(); + xsltStylesheetPtr compileStyleSheet(); + xmlDocPtr locateStylesheetSubResource(xmlDocPtr parentDoc, const xmlChar* uri); +#endif void clearDocuments(); - xmlDocPtr locateStylesheetSubResource(xmlDocPtr parentDoc, const xmlChar* uri); - void markAsProcessed(); bool processed() const { return m_processed; } private: XSLStyleSheet(Node* parentNode, const String& href, bool embedded); +#if !USE(QXMLQUERY) XSLStyleSheet(XSLImportRule* parentImport, const String& href); +#endif Document* m_ownerDocument; - xmlDocPtr m_stylesheetDoc; bool m_embedded; bool m_processed; + +#if USE(QXMLQUERY) + String m_sheetString; +#else + xmlDocPtr m_stylesheetDoc; bool m_stylesheetDocTaken; +#endif + XSLStyleSheet* m_parentStyleSheet; }; diff --git a/src/3rdparty/webkit/WebCore/xml/XSLStyleSheet.cpp b/src/3rdparty/webkit/WebCore/xml/XSLStyleSheetLibxslt.cpp index b7d52f8..2ae8b82 100644 --- a/src/3rdparty/webkit/WebCore/xml/XSLStyleSheet.cpp +++ b/src/3rdparty/webkit/WebCore/xml/XSLStyleSheetLibxslt.cpp @@ -31,6 +31,7 @@ #include "Document.h" #include "Frame.h" #include "Node.h" +#include "TransformSource.h" #include "XMLTokenizer.h" #include "XMLTokenizerScope.h" #include "XSLImportRule.h" @@ -57,9 +58,9 @@ namespace WebCore { XSLStyleSheet::XSLStyleSheet(XSLImportRule* parentRule, const String& href) : StyleSheet(parentRule, href) , m_ownerDocument(0) - , m_stylesheetDoc(0) , m_embedded(false) , m_processed(false) // Child sheets get marked as processed when the libxslt engine has finally seen them. + , m_stylesheetDoc(0) , m_stylesheetDocTaken(false) , m_parentStyleSheet(0) { @@ -68,9 +69,9 @@ XSLStyleSheet::XSLStyleSheet(XSLImportRule* parentRule, const String& href) XSLStyleSheet::XSLStyleSheet(Node* parentNode, const String& href, bool embedded) : StyleSheet(parentNode, href) , m_ownerDocument(parentNode->document()) - , m_stylesheetDoc(0) , m_embedded(embedded) , m_processed(true) // The root sheet starts off processed. + , m_stylesheetDoc(0) , m_stylesheetDocTaken(false) , m_parentStyleSheet(0) { @@ -98,7 +99,7 @@ bool XSLStyleSheet::isLoading() void XSLStyleSheet::checkLoaded() { - if (isLoading()) + if (isLoading()) return; if (parent()) parent()->checkLoaded(); @@ -108,8 +109,8 @@ void XSLStyleSheet::checkLoaded() xmlDocPtr XSLStyleSheet::document() { - if (m_embedded && ownerDocument()) - return (xmlDocPtr)ownerDocument()->transformSource(); + if (m_embedded && ownerDocument() && ownerDocument()->transformSource()) + return (xmlDocPtr)ownerDocument()->transformSource()->platformSource(); return m_stylesheetDoc; } @@ -168,7 +169,7 @@ bool XSLStyleSheet::parseString(const String& string, bool) m_stylesheetDoc = xmlCtxtReadMemory(ctxt, buffer, size, href().utf8().data(), - BOMHighByte == 0xFF ? "UTF-16LE" : "UTF-16BE", + BOMHighByte == 0xFF ? "UTF-16LE" : "UTF-16BE", XML_PARSE_NOENT | XML_PARSE_DTDATTR | XML_PARSE_NOWARNING | XML_PARSE_NOCDATA); xmlFreeParserCtxt(ctxt); @@ -181,15 +182,15 @@ void XSLStyleSheet::loadChildSheets() { if (!document()) return; - + xmlNodePtr stylesheetRoot = document()->children; - + // Top level children may include other things such as DTD nodes, we ignore those. while (stylesheetRoot && stylesheetRoot->type != XML_ELEMENT_NODE) stylesheetRoot = stylesheetRoot->next; - + if (m_embedded) { - // We have to locate (by ID) the appropriate embedded stylesheet element, so that we can walk the + // We have to locate (by ID) the appropriate embedded stylesheet element, so that we can walk the // import/include list. xmlAttrPtr idNode = xmlGetID(document(), (const xmlChar*)(href().utf8().data())); if (!idNode) @@ -199,7 +200,7 @@ void XSLStyleSheet::loadChildSheets() // FIXME: Need to handle an external URI with a # in it. This is a pretty minor edge case, so we'll deal // with it later. } - + if (stylesheetRoot) { // Walk the children of the root element and look for import/include elements. // Imports must occur first. @@ -210,7 +211,7 @@ void XSLStyleSheet::loadChildSheets() continue; } if (IS_XSLT_ELEM(curr) && IS_XSLT_NAME(curr, "import")) { - xmlChar* uriRef = xsltGetNsProp(curr, (const xmlChar*)"href", XSLT_NAMESPACE); + xmlChar* uriRef = xsltGetNsProp(curr, (const xmlChar*)"href", XSLT_NAMESPACE); loadChildSheet(String::fromUTF8((const char*)uriRef)); xmlFree(uriRef); } else @@ -242,7 +243,7 @@ xsltStylesheetPtr XSLStyleSheet::compileStyleSheet() // FIXME: Hook up error reporting for the stylesheet compilation process. if (m_embedded) return xsltLoadStylesheetPI(document()); - + // xsltParseStylesheetDoc makes the document part of the stylesheet // so we have to release our pointer to it. ASSERT(!m_stylesheetDocTaken); @@ -273,7 +274,7 @@ xmlDocPtr XSLStyleSheet::locateStylesheetSubResource(xmlDocPtr parentDoc, const if (matchedParent) { if (child->processed()) continue; // libxslt has been given this sheet already. - + // Check the URI of the child stylesheet against the doc URI. // In order to ensure that libxml canonicalized both URLs, we get the original href // string from the import rule and canonicalize it using libxml before comparing it @@ -295,7 +296,7 @@ xmlDocPtr XSLStyleSheet::locateStylesheetSubResource(xmlDocPtr parentDoc, const } } } - + return 0; } diff --git a/src/3rdparty/webkit/WebCore/xml/XSLStyleSheetQt.cpp b/src/3rdparty/webkit/WebCore/xml/XSLStyleSheetQt.cpp new file mode 100644 index 0000000..9fada0e --- /dev/null +++ b/src/3rdparty/webkit/WebCore/xml/XSLStyleSheetQt.cpp @@ -0,0 +1,103 @@ +/* + * This file is part of the XSL implementation. + * + * Copyright (C) 2009 Jakub Wieczorek <faw217@gmail.com> + * + * 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" +#include "XSLStyleSheet.h" + +#if ENABLE(XSLT) + +#include "DOMWindow.h" +#include "Document.h" +#include "Node.h" +#include "NotImplemented.h" +#include "XSLTProcessor.h" +#include "loader.h" + +namespace WebCore { + +XSLStyleSheet::XSLStyleSheet(Node* parentNode, const String& href, bool embedded) + : StyleSheet(parentNode, href) + , m_ownerDocument(parentNode->document()) + , m_embedded(embedded) +{ +} + +XSLStyleSheet::~XSLStyleSheet() +{ +} + +bool XSLStyleSheet::isLoading() +{ + notImplemented(); + return false; +} + +void XSLStyleSheet::checkLoaded() +{ + if (ownerNode()) + ownerNode()->sheetLoaded(); +} + +void XSLStyleSheet::clearDocuments() +{ + notImplemented(); +} + +DocLoader* XSLStyleSheet::docLoader() +{ + if (!m_ownerDocument) + return 0; + return m_ownerDocument->docLoader(); +} + +bool XSLStyleSheet::parseString(const String& string, bool) +{ + // FIXME: Fix QXmlQuery so that it allows compiling the stylesheet before setting the document + // to be transformed. This way we could not only check if the stylesheet is correct before using it + // but also turn XSLStyleSheet::sheetString() into XSLStyleSheet::query() that returns a QXmlQuery. + + m_sheetString = string; + return !m_sheetString.isEmpty(); +} + +void XSLStyleSheet::loadChildSheets() +{ + notImplemented(); +} + +void XSLStyleSheet::loadChildSheet(const String& href) +{ + notImplemented(); +} + +void XSLStyleSheet::setParentStyleSheet(XSLStyleSheet* parent) +{ + notImplemented(); +} + +void XSLStyleSheet::markAsProcessed() +{ + notImplemented(); +} + +} // namespace WebCore + +#endif // ENABLE(XSLT) diff --git a/src/3rdparty/webkit/WebCore/xml/XSLTProcessor.cpp b/src/3rdparty/webkit/WebCore/xml/XSLTProcessor.cpp index 8eaef67..b182243 100644 --- a/src/3rdparty/webkit/WebCore/xml/XSLTProcessor.cpp +++ b/src/3rdparty/webkit/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/src/3rdparty/webkit/WebCore/xml/XSLTProcessor.h b/src/3rdparty/webkit/WebCore/xml/XSLTProcessor.h index 9ee2aad..9b91017 100644 --- a/src/3rdparty/webkit/WebCore/xml/XSLTProcessor.h +++ b/src/3rdparty/webkit/WebCore/xml/XSLTProcessor.h @@ -28,9 +28,12 @@ #include "Node.h" #include "StringHash.h" #include "XSLStyleSheet.h" +#include <wtf/HashMap.h> + +#if !USE(QXMLQUERY) #include <libxml/parserInternals.h> #include <libxslt/documents.h> -#include <wtf/HashMap.h> +#endif namespace WebCore { @@ -56,14 +59,15 @@ public: void removeParameter(const String& namespaceURI, const String& localName); void clearParameters() { m_parameters.clear(); } - void reset() { m_stylesheet.clear(); m_stylesheetRootNode.clear(); m_parameters.clear(); } + void reset(); +#if !USE(QXMLQUERY) static void parseErrorFunc(void* userData, xmlError*); static void genericErrorFunc(void* userData, const char* msg, ...); -public: // Only for libXSLT callbacks XSLStyleSheet* xslStylesheet() const { return m_stylesheet.get(); } +#endif typedef HashMap<String, String> ParameterMap; diff --git a/src/3rdparty/webkit/WebCore/xml/XSLTProcessorLibxslt.cpp b/src/3rdparty/webkit/WebCore/xml/XSLTProcessorLibxslt.cpp new file mode 100644 index 0000000..200c56b --- /dev/null +++ b/src/3rdparty/webkit/WebCore/xml/XSLTProcessorLibxslt.cpp @@ -0,0 +1,335 @@ +/* + * 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@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 "TransformSource.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 && ownerDocument->transformSource()) + sourceDoc = (xmlDocPtr)ownerDocument->transformSource()->platformSource(); + 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) diff --git a/src/3rdparty/webkit/WebCore/xml/XSLTProcessorQt.cpp b/src/3rdparty/webkit/WebCore/xml/XSLTProcessorQt.cpp new file mode 100644 index 0000000..523306a --- /dev/null +++ b/src/3rdparty/webkit/WebCore/xml/XSLTProcessorQt.cpp @@ -0,0 +1,149 @@ +/* + * This file is part of the XSL implementation. + * + * Copyright (C) 2009 Jakub Wieczorek <faw217@gmail.com> + * + * 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 "DOMWindow.h" +#include "Frame.h" +#include "TransformSource.h" +#include "loader.h" +#include "markup.h" +#include <wtf/Assertions.h> +#include <wtf/Platform.h> +#include <wtf/Vector.h> + +#include <qabstractmessagehandler.h> +#include <qbuffer.h> +#include <qsourcelocation.h> +#include <qxmlquery.h> + +namespace WebCore { + +class XSLTMessageHandler : public QAbstractMessageHandler { + +public: + XSLTMessageHandler(Document* document = 0); + virtual void handleMessage(QtMsgType type, const QString& description, + const QUrl& identifier, const QSourceLocation& sourceLocation); + +private: + Document* m_document; +}; + +XSLTMessageHandler::XSLTMessageHandler(Document* document) + : QAbstractMessageHandler() + , m_document(document) +{ +} + +void XSLTMessageHandler::handleMessage(QtMsgType type, const QString& description, + const QUrl& identifier, const QSourceLocation& sourceLocation) +{ + if (!m_document->frame()) + return; + + MessageLevel level; + switch (type) { + case QtDebugMsg: + level = TipMessageLevel; + break; + case QtWarningMsg: + level = WarningMessageLevel; + break; + case QtCriticalMsg: + case QtFatalMsg: + level = ErrorMessageLevel; + break; + default: + level = LogMessageLevel; + break; + } + + Console* console = m_document->frame()->domWindow()->console(); + console->addMessage(XMLMessageSource, LogMessageType, level, description, + sourceLocation.line(), sourceLocation.uri().toString()); +} + +bool XSLTProcessor::transformToString(Node* sourceNode, String& mimeType, String& resultString, String& resultEncoding) +{ + bool success = false; + + RefPtr<XSLStyleSheet> stylesheet = m_stylesheet; + if (!stylesheet && m_stylesheetRootNode) { + Node* node = m_stylesheetRootNode.get(); + stylesheet = XSLStyleSheet::create(node->parent() ? node->parent() : node, node->document()->url().string()); + stylesheet->parseString(createMarkup(node)); + } + + if (!stylesheet || stylesheet->sheetString().isEmpty()) + return success; + + RefPtr<Document> ownerDocument = sourceNode->document(); + bool sourceIsDocument = (sourceNode == ownerDocument.get()); + + QXmlQuery query(QXmlQuery::XSLT20); + + XSLTMessageHandler messageHandler(ownerDocument.get()); + query.setMessageHandler(&messageHandler); + + XSLTProcessor::ParameterMap::iterator end = m_parameters.end(); + for (XSLTProcessor::ParameterMap::iterator it = m_parameters.begin(); it != end; ++it) + query.bindVariable(QString(it->first), QXmlItem(QVariant(it->second))); + + QString source; + if (sourceIsDocument && ownerDocument->transformSource()) + source = ownerDocument->transformSource()->platformSource(); + if (!sourceIsDocument || source.isEmpty()) + source = createMarkup(sourceNode); + + QBuffer inputBuffer; + QBuffer styleSheetBuffer; + QBuffer outputBuffer; + + inputBuffer.setData(source.toUtf8()); + styleSheetBuffer.setData(QString(stylesheet->sheetString()).toUtf8()); + + inputBuffer.open(QIODevice::ReadOnly); + styleSheetBuffer.open(QIODevice::ReadOnly); + outputBuffer.open(QIODevice::ReadWrite); + + query.setFocus(&inputBuffer); + query.setQuery(&styleSheetBuffer, QUrl(stylesheet->href())); + success = query.evaluateTo(&outputBuffer); + outputBuffer.reset(); + resultString = QString::fromUtf8(outputBuffer.readAll()).trimmed(); + + if (m_stylesheet) { + m_stylesheet->clearDocuments(); + m_stylesheet = 0; + } + + return success; +} + +} // namespace WebCore + +#endif // ENABLE(XSLT) |