[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:35:00 UTC 2009


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

    Rename XSLStyleSheet.cpp to XSLStyleSheetLibxslt.cpp.
    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, rename XSLStyleSheet.cpp to XSLStyleSheetLibxslt.cpp as we will
    have our own implementation which most likely will not share any code
    with the current one.
    
    Additionally, fix some coding style issues.
    
    * GNUmakefile.am:
    * WebCore.gypi:
    * WebCore.vcproj/WebCore.vcproj:
    * WebCore.xcodeproj/project.pbxproj:
    * WebCoreSources.bkl:
    * xml/XSLStyleSheet.cpp: Renamed to XSLStyleSheetLibxslt.cpp.
    * xml/XSLStyleSheetLibxslt.cpp: Added.
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@48815 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 2e26d83..76a724f 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,25 @@
+2009-09-28  Jakub Wieczorek  <faw217 at gmail.com>
+
+        Reviewed by Simon Hausmann.
+
+        Rename XSLStyleSheet.cpp to XSLStyleSheetLibxslt.cpp.
+        https://bugs.webkit.org/show_bug.cgi?id=28303
+
+        In preparation for adding XSLT support with QtXmlPatterns to the Qt
+        port, rename XSLStyleSheet.cpp to XSLStyleSheetLibxslt.cpp as we will
+        have our own implementation which most likely will not share any code
+        with the current one.
+
+        Additionally, fix some coding style issues.
+
+        * GNUmakefile.am:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * WebCoreSources.bkl:
+        * xml/XSLStyleSheet.cpp: Renamed to XSLStyleSheetLibxslt.cpp.
+        * xml/XSLStyleSheetLibxslt.cpp: Added.
+
 2009-09-28  Simon Hausmann  <simon.hausmann at nokia.com>
 
         Prospective build fix for r48812.
diff --git a/WebCore/GNUmakefile.am b/WebCore/GNUmakefile.am
index b1b4339..77b9dd3 100644
--- a/WebCore/GNUmakefile.am
+++ b/WebCore/GNUmakefile.am
@@ -2412,7 +2412,7 @@ webcore_cppflags += -DENABLE_XSLT=1
 webcore_sources += \
 	WebCore/xml/XSLImportRule.cpp \
 	WebCore/xml/XSLImportRule.h \
-	WebCore/xml/XSLStyleSheet.cpp \
+	WebCore/xml/XSLStyleSheetLibxslt.cpp \
 	WebCore/xml/XSLStyleSheet.h \
 	WebCore/xml/XSLTExtensions.cpp \
 	WebCore/xml/XSLTExtensions.h \
diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
index 3e180ee..6836b75 100644
--- a/WebCore/WebCore.gypi
+++ b/WebCore/WebCore.gypi
@@ -3514,7 +3514,7 @@
             'xml/XPathVariableReference.h',
             'xml/XSLImportRule.cpp',
             'xml/XSLImportRule.h',
-            'xml/XSLStyleSheet.cpp',
+            'xml/XSLStyleSheetLibxslt.cpp',
             'xml/XSLStyleSheet.h',
             'xml/XSLTExtensions.cpp',
             'xml/XSLTExtensions.h',
diff --git a/WebCore/WebCore.vcproj/WebCore.vcproj b/WebCore/WebCore.vcproj/WebCore.vcproj
index b02d525..3dd41cc 100644
--- a/WebCore/WebCore.vcproj/WebCore.vcproj
+++ b/WebCore/WebCore.vcproj/WebCore.vcproj
@@ -23808,7 +23808,7 @@
 				>
 			</File>
 			<File
-				RelativePath="..\xml\XSLStyleSheet.cpp"
+				RelativePath="..\xml\XSLStyleSheetLibxslt.cpp"
 				>
 			</File>
 			<File
diff --git a/WebCore/WebCore.xcodeproj/project.pbxproj b/WebCore/WebCore.xcodeproj/project.pbxproj
index 40078c8..36387e2 100644
--- a/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -2320,7 +2320,7 @@
 		93F19AF808245E59001E9ABC /* Position.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE91FC8C06133666005E3790 /* Position.cpp */; };
 		93F19AFD08245E59001E9ABC /* HTMLCanvasElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51F6A3D50663BF04004D2919 /* HTMLCanvasElement.cpp */; };
 		93F19AFF08245E59001E9ABC /* ClipboardMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D90660C0665D937006B6F1A /* ClipboardMac.mm */; };
-		93F19B0308245E59001E9ABC /* XSLStyleSheet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC06F24906D18A7E004A6FA3 /* XSLStyleSheet.cpp */; };
+		93F19B0308245E59001E9ABC /* XSLStyleSheetLibxslt.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC06F24906D18A7E004A6FA3 /* XSLStyleSheetLibxslt.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 */; };
@@ -9072,7 +9072,7 @@
 		BC06EDE20BFD6D0D00856E9D /* JSHTMLTableCellElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSHTMLTableCellElement.h; sourceTree = "<group>"; };
 		BC06EE020BFD71AA00856E9D /* JSHTMLTableElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLTableElement.cpp; sourceTree = "<group>"; };
 		BC06EE030BFD71AA00856E9D /* JSHTMLTableElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSHTMLTableElement.h; sourceTree = "<group>"; };
-		BC06F24906D18A7E004A6FA3 /* XSLStyleSheet.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XSLStyleSheet.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
+		BC06F24906D18A7E004A6FA3 /* XSLStyleSheetLibxslt.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XSLStyleSheetLibxslt.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
 		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; };
@@ -14840,7 +14840,7 @@
 				1AB7FC670A8B92EC00D9D37B /* XPathVariableReference.h */,
 				85217E000A5ECD4700DB8D00 /* XSLImportRule.cpp */,
 				85217E010A5ECD4700DB8D00 /* XSLImportRule.h */,
-				BC06F24906D18A7E004A6FA3 /* XSLStyleSheet.cpp */,
+				BC06F24906D18A7E004A6FA3 /* XSLStyleSheetLibxslt.cpp */,
 				BC06F24A06D18A7E004A6FA3 /* XSLStyleSheet.h */,
 				E1F1E82D0C3C2BB9006DB391 /* XSLTExtensions.cpp */,
 				E1F1E82E0C3C2BB9006DB391 /* XSLTExtensions.h */,
@@ -19912,7 +19912,7 @@
 				1AB7FC850A8B92EC00D9D37B /* XPathValue.cpp in Sources */,
 				1AB7FC870A8B92EC00D9D37B /* XPathVariableReference.cpp in Sources */,
 				85217E020A5ECD4700DB8D00 /* XSLImportRule.cpp in Sources */,
-				93F19B0308245E59001E9ABC /* XSLStyleSheet.cpp in Sources */,
+				93F19B0308245E59001E9ABC /* XSLStyleSheetLibxslt.cpp in Sources */,
 				E1F1E82F0C3C2BB9006DB391 /* XSLTExtensions.cpp in Sources */,
 				93F19B0408245E59001E9ABC /* XSLTProcessor.cpp in Sources */,
 				93F19B0508245E59001E9ABC /* XSLTProcessorLibxslt.cpp in Sources */,
diff --git a/WebCore/WebCoreSources.bkl b/WebCore/WebCoreSources.bkl
index 3716af3..e78b804 100644
--- a/WebCore/WebCoreSources.bkl
+++ b/WebCore/WebCoreSources.bkl
@@ -1083,7 +1083,7 @@ This file contains the list of files needed to build WebCore.
         xml/XPathValue.cpp
         xml/XPathVariableReference.cpp
         xml/XSLImportRule.cpp
-        xml/XSLStyleSheet.cpp
+        xml/XSLStyleSheetLibxslt.cpp
         xml/XSLTExtensions.cpp
         xml/XSLTUnicodeSort.cpp
         xml/XSLTProcessor.cpp
diff --git a/WebCore/xml/XSLStyleSheet.cpp b/WebCore/xml/XSLStyleSheet.cpp
deleted file mode 100644
index b7d52f8..0000000
--- a/WebCore/xml/XSLStyleSheet.cpp
+++ /dev/null
@@ -1,312 +0,0 @@
-/*
- * This file is part of the XSL implementation.
- *
- * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
- *
- * 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 "CString.h"
-#include "Console.h"
-#include "DOMWindow.h"
-#include "DocLoader.h"
-#include "Document.h"
-#include "Frame.h"
-#include "Node.h"
-#include "XMLTokenizer.h"
-#include "XMLTokenizerScope.h"
-#include "XSLImportRule.h"
-#include "XSLTProcessor.h"
-#include "loader.h"
-
-#include <libxml/uri.h>
-#include <libxslt/xsltutils.h>
-
-#if PLATFORM(MAC)
-#include "SoftLinking.h"
-#endif
-
-#if PLATFORM(MAC)
-SOFT_LINK_LIBRARY(libxslt)
-SOFT_LINK(libxslt, xsltIsBlank, int, (xmlChar *str), (str))
-SOFT_LINK(libxslt, xsltGetNsProp, xmlChar *, (xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace), (node, name, nameSpace))
-SOFT_LINK(libxslt, xsltParseStylesheetDoc, xsltStylesheetPtr, (xmlDocPtr doc), (doc))
-SOFT_LINK(libxslt, xsltLoadStylesheetPI, xsltStylesheetPtr, (xmlDocPtr doc), (doc))
-#endif
-
-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_stylesheetDocTaken(false)
-    , m_parentStyleSheet(0)
-{
-}
-
-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_stylesheetDocTaken(false)
-    , m_parentStyleSheet(0)
-{
-}
-
-XSLStyleSheet::~XSLStyleSheet()
-{
-    if (!m_stylesheetDocTaken)
-        xmlFreeDoc(m_stylesheetDoc);
-}
-
-bool XSLStyleSheet::isLoading()
-{
-    unsigned len = length();
-    for (unsigned i = 0; i < len; ++i) {
-        StyleBase* rule = item(i);
-        if (rule->isImportRule()) {
-            XSLImportRule* import = static_cast<XSLImportRule*>(rule);
-            if (import->isLoading())
-                return true;
-        }
-    }
-    return false;
-}
-
-void XSLStyleSheet::checkLoaded()
-{
-    if (isLoading()) 
-        return;
-    if (parent())
-        parent()->checkLoaded();
-    if (ownerNode())
-        ownerNode()->sheetLoaded();
-}
-
-xmlDocPtr XSLStyleSheet::document()
-{
-    if (m_embedded && ownerDocument())
-        return (xmlDocPtr)ownerDocument()->transformSource();
-    return m_stylesheetDoc;
-}
-
-void XSLStyleSheet::clearDocuments()
-{
-    m_stylesheetDoc = 0;
-    unsigned len = length();
-    for (unsigned i = 0; i < len; ++i) {
-        StyleBase* rule = item(i);
-        if (rule->isImportRule()) {
-            XSLImportRule* import = static_cast<XSLImportRule*>(rule);
-            if (import->styleSheet())
-                import->styleSheet()->clearDocuments();
-        }
-    }
-}
-
-DocLoader* XSLStyleSheet::docLoader()
-{
-    if (!m_ownerDocument)
-        return 0;
-    return m_ownerDocument->docLoader();
-}
-
-bool XSLStyleSheet::parseString(const String& string, bool)
-{
-    // Parse in a single chunk into an xmlDocPtr
-    const UChar BOM = 0xFEFF;
-    const unsigned char BOMHighByte = *reinterpret_cast<const unsigned char*>(&BOM);
-    if (!m_stylesheetDocTaken)
-        xmlFreeDoc(m_stylesheetDoc);
-    m_stylesheetDocTaken = false;
-
-    Console* console = 0;
-    if (Frame* frame = ownerDocument()->frame())
-        console = frame->domWindow()->console();
-
-    XMLTokenizerScope scope(docLoader(), XSLTProcessor::genericErrorFunc, XSLTProcessor::parseErrorFunc, console);
-
-    const char* buffer = reinterpret_cast<const char*>(string.characters());
-    int size = string.length() * sizeof(UChar);
-
-    xmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt(buffer, size);
-
-    if (m_parentStyleSheet) {
-        // The XSL transform may leave the newly-transformed document
-        // with references to the symbol dictionaries of the style sheet
-        // and any of its children. XML document disposal can corrupt memory
-        // if a document uses more than one symbol dictionary, so we
-        // ensure that all child stylesheets use the same dictionaries as their
-        // parents.
-        xmlDictFree(ctxt->dict);
-        ctxt->dict = m_parentStyleSheet->m_stylesheetDoc->dict;
-        xmlDictReference(ctxt->dict);
-    }
-
-    m_stylesheetDoc = xmlCtxtReadMemory(ctxt, buffer, size,
-        href().utf8().data(),
-        BOMHighByte == 0xFF ? "UTF-16LE" : "UTF-16BE", 
-        XML_PARSE_NOENT | XML_PARSE_DTDATTR | XML_PARSE_NOWARNING | XML_PARSE_NOCDATA);
-    xmlFreeParserCtxt(ctxt);
-
-    loadChildSheets();
-
-    return m_stylesheetDoc;
-}
-
-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 
-        // import/include list.
-        xmlAttrPtr idNode = xmlGetID(document(), (const xmlChar*)(href().utf8().data()));
-        if (!idNode)
-            return;
-        stylesheetRoot = idNode->parent;
-    } else {
-        // 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.
-        xmlNodePtr curr = stylesheetRoot->children;
-        while (curr) {
-            if (curr->type != XML_ELEMENT_NODE) {
-                curr = curr->next;
-                continue;
-            }
-            if (IS_XSLT_ELEM(curr) && IS_XSLT_NAME(curr, "import")) {
-                xmlChar* uriRef = xsltGetNsProp(curr, (const xmlChar*)"href", XSLT_NAMESPACE);                
-                loadChildSheet(String::fromUTF8((const char*)uriRef));
-                xmlFree(uriRef);
-            } else
-                break;
-            curr = curr->next;
-        }
-
-        // Now handle includes.
-        while (curr) {
-            if (curr->type == XML_ELEMENT_NODE && IS_XSLT_ELEM(curr) && IS_XSLT_NAME(curr, "include")) {
-                xmlChar* uriRef = xsltGetNsProp(curr, (const xmlChar*)"href", XSLT_NAMESPACE);
-                loadChildSheet(String::fromUTF8((const char*)uriRef));
-                xmlFree(uriRef);
-            }
-            curr = curr->next;
-        }
-    }
-}
-
-void XSLStyleSheet::loadChildSheet(const String& href)
-{
-    RefPtr<XSLImportRule> childRule = XSLImportRule::create(this, href);
-    append(childRule);
-    childRule->loadSheet();
-}
-
-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);
-    xsltStylesheetPtr result = xsltParseStylesheetDoc(m_stylesheetDoc);
-    if (result)
-        m_stylesheetDocTaken = true;
-    return result;
-}
-
-void XSLStyleSheet::setParentStyleSheet(XSLStyleSheet* parent)
-{
-    m_parentStyleSheet = parent;
-    if (parent)
-        m_ownerDocument = parent->ownerDocument();
-}
-
-xmlDocPtr XSLStyleSheet::locateStylesheetSubResource(xmlDocPtr parentDoc, const xmlChar* uri)
-{
-    bool matchedParent = (parentDoc == document());
-    unsigned len = length();
-    for (unsigned i = 0; i < len; ++i) {
-        StyleBase* rule = item(i);
-        if (rule->isImportRule()) {
-            XSLImportRule* import = static_cast<XSLImportRule*>(rule);
-            XSLStyleSheet* child = import->styleSheet();
-            if (!child)
-                continue;
-            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
-                // with the URI argument.
-                CString importHref = import->href().utf8();
-                xmlChar* base = xmlNodeGetBase(parentDoc, (xmlNodePtr)parentDoc);
-                xmlChar* childURI = xmlBuildURI((const xmlChar*)importHref.data(), base);
-                bool equalURIs = xmlStrEqual(uri, childURI);
-                xmlFree(base);
-                xmlFree(childURI);
-                if (equalURIs) {
-                    child->markAsProcessed();
-                    return child->document();
-                }
-            } else {
-                xmlDocPtr result = import->styleSheet()->locateStylesheetSubResource(parentDoc, uri);
-                if (result)
-                    return result;
-            }
-        }
-    }
-    
-    return 0;
-}
-
-void XSLStyleSheet::markAsProcessed()
-{
-    ASSERT(!m_processed);
-    ASSERT(!m_stylesheetDocTaken);
-    m_processed = true;
-    m_stylesheetDocTaken = true;
-}
-
-} // namespace WebCore
-
-#endif // ENABLE(XSLT)
diff --git a/WebCore/xml/XSLStyleSheetLibxslt.cpp b/WebCore/xml/XSLStyleSheetLibxslt.cpp
new file mode 100644
index 0000000..ed2753d
--- /dev/null
+++ b/WebCore/xml/XSLStyleSheetLibxslt.cpp
@@ -0,0 +1,312 @@
+/*
+ * This file is part of the XSL implementation.
+ *
+ * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
+ *
+ * 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 "CString.h"
+#include "Console.h"
+#include "DOMWindow.h"
+#include "DocLoader.h"
+#include "Document.h"
+#include "Frame.h"
+#include "Node.h"
+#include "XMLTokenizer.h"
+#include "XMLTokenizerScope.h"
+#include "XSLImportRule.h"
+#include "XSLTProcessor.h"
+#include "loader.h"
+
+#include <libxml/uri.h>
+#include <libxslt/xsltutils.h>
+
+#if PLATFORM(MAC)
+#include "SoftLinking.h"
+#endif
+
+#if PLATFORM(MAC)
+SOFT_LINK_LIBRARY(libxslt)
+SOFT_LINK(libxslt, xsltIsBlank, int, (xmlChar *str), (str))
+SOFT_LINK(libxslt, xsltGetNsProp, xmlChar *, (xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace), (node, name, nameSpace))
+SOFT_LINK(libxslt, xsltParseStylesheetDoc, xsltStylesheetPtr, (xmlDocPtr doc), (doc))
+SOFT_LINK(libxslt, xsltLoadStylesheetPI, xsltStylesheetPtr, (xmlDocPtr doc), (doc))
+#endif
+
+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_stylesheetDocTaken(false)
+    , m_parentStyleSheet(0)
+{
+}
+
+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_stylesheetDocTaken(false)
+    , m_parentStyleSheet(0)
+{
+}
+
+XSLStyleSheet::~XSLStyleSheet()
+{
+    if (!m_stylesheetDocTaken)
+        xmlFreeDoc(m_stylesheetDoc);
+}
+
+bool XSLStyleSheet::isLoading()
+{
+    unsigned len = length();
+    for (unsigned i = 0; i < len; ++i) {
+        StyleBase* rule = item(i);
+        if (rule->isImportRule()) {
+            XSLImportRule* import = static_cast<XSLImportRule*>(rule);
+            if (import->isLoading())
+                return true;
+        }
+    }
+    return false;
+}
+
+void XSLStyleSheet::checkLoaded()
+{
+    if (isLoading())
+        return;
+    if (parent())
+        parent()->checkLoaded();
+    if (ownerNode())
+        ownerNode()->sheetLoaded();
+}
+
+xmlDocPtr XSLStyleSheet::document()
+{
+    if (m_embedded && ownerDocument())
+        return (xmlDocPtr)ownerDocument()->transformSource();
+    return m_stylesheetDoc;
+}
+
+void XSLStyleSheet::clearDocuments()
+{
+    m_stylesheetDoc = 0;
+    unsigned len = length();
+    for (unsigned i = 0; i < len; ++i) {
+        StyleBase* rule = item(i);
+        if (rule->isImportRule()) {
+            XSLImportRule* import = static_cast<XSLImportRule*>(rule);
+            if (import->styleSheet())
+                import->styleSheet()->clearDocuments();
+        }
+    }
+}
+
+DocLoader* XSLStyleSheet::docLoader()
+{
+    if (!m_ownerDocument)
+        return 0;
+    return m_ownerDocument->docLoader();
+}
+
+bool XSLStyleSheet::parseString(const String& string, bool)
+{
+    // Parse in a single chunk into an xmlDocPtr
+    const UChar BOM = 0xFEFF;
+    const unsigned char BOMHighByte = *reinterpret_cast<const unsigned char*>(&BOM);
+    if (!m_stylesheetDocTaken)
+        xmlFreeDoc(m_stylesheetDoc);
+    m_stylesheetDocTaken = false;
+
+    Console* console = 0;
+    if (Frame* frame = ownerDocument()->frame())
+        console = frame->domWindow()->console();
+
+    XMLTokenizerScope scope(docLoader(), XSLTProcessor::genericErrorFunc, XSLTProcessor::parseErrorFunc, console);
+
+    const char* buffer = reinterpret_cast<const char*>(string.characters());
+    int size = string.length() * sizeof(UChar);
+
+    xmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt(buffer, size);
+
+    if (m_parentStyleSheet) {
+        // The XSL transform may leave the newly-transformed document
+        // with references to the symbol dictionaries of the style sheet
+        // and any of its children. XML document disposal can corrupt memory
+        // if a document uses more than one symbol dictionary, so we
+        // ensure that all child stylesheets use the same dictionaries as their
+        // parents.
+        xmlDictFree(ctxt->dict);
+        ctxt->dict = m_parentStyleSheet->m_stylesheetDoc->dict;
+        xmlDictReference(ctxt->dict);
+    }
+
+    m_stylesheetDoc = xmlCtxtReadMemory(ctxt, buffer, size,
+        href().utf8().data(),
+        BOMHighByte == 0xFF ? "UTF-16LE" : "UTF-16BE",
+        XML_PARSE_NOENT | XML_PARSE_DTDATTR | XML_PARSE_NOWARNING | XML_PARSE_NOCDATA);
+    xmlFreeParserCtxt(ctxt);
+
+    loadChildSheets();
+
+    return m_stylesheetDoc;
+}
+
+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
+        // import/include list.
+        xmlAttrPtr idNode = xmlGetID(document(), (const xmlChar*)(href().utf8().data()));
+        if (!idNode)
+            return;
+        stylesheetRoot = idNode->parent;
+    } else {
+        // 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.
+        xmlNodePtr curr = stylesheetRoot->children;
+        while (curr) {
+            if (curr->type != XML_ELEMENT_NODE) {
+                curr = curr->next;
+                continue;
+            }
+            if (IS_XSLT_ELEM(curr) && IS_XSLT_NAME(curr, "import")) {
+                xmlChar* uriRef = xsltGetNsProp(curr, (const xmlChar*)"href", XSLT_NAMESPACE);
+                loadChildSheet(String::fromUTF8((const char*)uriRef));
+                xmlFree(uriRef);
+            } else
+                break;
+            curr = curr->next;
+        }
+
+        // Now handle includes.
+        while (curr) {
+            if (curr->type == XML_ELEMENT_NODE && IS_XSLT_ELEM(curr) && IS_XSLT_NAME(curr, "include")) {
+                xmlChar* uriRef = xsltGetNsProp(curr, (const xmlChar*)"href", XSLT_NAMESPACE);
+                loadChildSheet(String::fromUTF8((const char*)uriRef));
+                xmlFree(uriRef);
+            }
+            curr = curr->next;
+        }
+    }
+}
+
+void XSLStyleSheet::loadChildSheet(const String& href)
+{
+    RefPtr<XSLImportRule> childRule = XSLImportRule::create(this, href);
+    append(childRule);
+    childRule->loadSheet();
+}
+
+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);
+    xsltStylesheetPtr result = xsltParseStylesheetDoc(m_stylesheetDoc);
+    if (result)
+        m_stylesheetDocTaken = true;
+    return result;
+}
+
+void XSLStyleSheet::setParentStyleSheet(XSLStyleSheet* parent)
+{
+    m_parentStyleSheet = parent;
+    if (parent)
+        m_ownerDocument = parent->ownerDocument();
+}
+
+xmlDocPtr XSLStyleSheet::locateStylesheetSubResource(xmlDocPtr parentDoc, const xmlChar* uri)
+{
+    bool matchedParent = (parentDoc == document());
+    unsigned len = length();
+    for (unsigned i = 0; i < len; ++i) {
+        StyleBase* rule = item(i);
+        if (rule->isImportRule()) {
+            XSLImportRule* import = static_cast<XSLImportRule*>(rule);
+            XSLStyleSheet* child = import->styleSheet();
+            if (!child)
+                continue;
+            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
+                // with the URI argument.
+                CString importHref = import->href().utf8();
+                xmlChar* base = xmlNodeGetBase(parentDoc, (xmlNodePtr)parentDoc);
+                xmlChar* childURI = xmlBuildURI((const xmlChar*)importHref.data(), base);
+                bool equalURIs = xmlStrEqual(uri, childURI);
+                xmlFree(base);
+                xmlFree(childURI);
+                if (equalURIs) {
+                    child->markAsProcessed();
+                    return child->document();
+                }
+            } else {
+                xmlDocPtr result = import->styleSheet()->locateStylesheetSubResource(parentDoc, uri);
+                if (result)
+                    return result;
+            }
+        }
+    }
+
+    return 0;
+}
+
+void XSLStyleSheet::markAsProcessed()
+{
+    ASSERT(!m_processed);
+    ASSERT(!m_stylesheetDocTaken);
+    m_processed = true;
+    m_stylesheetDocTaken = true;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(XSLT)

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list