2 * This file is part of the XSL implementation.
4 * Copyright (C) 2004, 2006, 2008, 2012 Apple Inc. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #ifndef XSLStyleSheet_h
24 #define XSLStyleSheet_h
26 #include "RuntimeEnabledFeatures.h"
27 #include "core/css/StyleSheet.h"
28 #include "core/dom/ProcessingInstruction.h"
29 #include "wtf/PassRefPtr.h"
31 #include <libxml/tree.h>
32 #include <libxslt/transform.h>
36 class ResourceFetcher;
39 class XSLStyleSheet FINAL : public StyleSheet {
41 static PassRefPtrWillBeRawPtr<XSLStyleSheet> create(XSLImportRule* parentImport, const String& originalURL, const KURL& finalURL)
43 ASSERT(RuntimeEnabledFeatures::xsltEnabled());
44 return adoptRefWillBeNoop(new XSLStyleSheet(parentImport, originalURL, finalURL));
46 static PassRefPtrWillBeRawPtr<XSLStyleSheet> create(ProcessingInstruction* parentNode, const String& originalURL, const KURL& finalURL)
48 ASSERT(RuntimeEnabledFeatures::xsltEnabled());
49 return adoptRefWillBeNoop(new XSLStyleSheet(parentNode, originalURL, finalURL, false));
51 static PassRefPtrWillBeRawPtr<XSLStyleSheet> createEmbedded(ProcessingInstruction* parentNode, const KURL& finalURL)
53 ASSERT(RuntimeEnabledFeatures::xsltEnabled());
54 return adoptRefWillBeNoop(new XSLStyleSheet(parentNode, finalURL.string(), finalURL, true));
57 // Taking an arbitrary node is unsafe, because owner node pointer can become stale.
58 // XSLTProcessor ensures that the stylesheet doesn't outlive its parent, in part by not exposing it to JavaScript.
59 static PassRefPtrWillBeRawPtr<XSLStyleSheet> createForXSLTProcessor(Node* parentNode, const String& originalURL, const KURL& finalURL)
61 ASSERT(RuntimeEnabledFeatures::xsltEnabled());
62 return adoptRefWillBeNoop(new XSLStyleSheet(parentNode, originalURL, finalURL, false));
65 virtual ~XSLStyleSheet();
67 bool parseString(const String&);
71 const KURL& finalURL() const { return m_finalURL; }
73 void loadChildSheets();
74 void loadChildSheet(const String& href);
76 ResourceFetcher* fetcher();
78 Document* ownerDocument();
79 virtual XSLStyleSheet* parentStyleSheet() const OVERRIDE { return m_parentStyleSheet; }
80 void setParentStyleSheet(XSLStyleSheet* parent);
83 xsltStylesheetPtr compileStyleSheet();
84 xmlDocPtr locateStylesheetSubResource(xmlDocPtr parentDoc, const xmlChar* uri);
86 void clearDocuments();
88 void markAsProcessed();
89 bool processed() const { return m_processed; }
91 virtual String type() const OVERRIDE { return "text/xml"; }
92 virtual bool disabled() const OVERRIDE { return m_isDisabled; }
93 virtual void setDisabled(bool b) OVERRIDE { m_isDisabled = b; }
94 virtual Node* ownerNode() const OVERRIDE { return m_ownerNode; }
95 virtual String href() const OVERRIDE { return m_originalURL; }
96 virtual String title() const OVERRIDE { return emptyString(); }
98 virtual void clearOwnerNode() OVERRIDE { m_ownerNode = 0; }
99 virtual KURL baseURL() const OVERRIDE { return m_finalURL; }
100 virtual bool isLoading() const OVERRIDE;
102 virtual void trace(Visitor*) OVERRIDE;
105 XSLStyleSheet(Node* parentNode, const String& originalURL, const KURL& finalURL, bool embedded);
106 XSLStyleSheet(XSLImportRule* parentImport, const String& originalURL, const KURL& finalURL);
109 String m_originalURL;
113 Vector<OwnPtr<XSLImportRule> > m_children;
118 xmlDocPtr m_stylesheetDoc;
119 bool m_stylesheetDocTaken;
120 bool m_compilationFailed;
122 RawPtrWillBeMember<XSLStyleSheet> m_parentStyleSheet;
125 DEFINE_TYPE_CASTS(XSLStyleSheet, StyleSheet, sheet, !sheet->isCSSStyleSheet(), !sheet.isCSSStyleSheet());
127 } // namespace WebCore
129 #endif // XSLStyleSheet_h