• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of the XSL implementation.
3  *
4  * Copyright (C) 2004, 2006, 2008, 2012 Apple Inc. All rights reserved.
5  *
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.
10  *
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.
15  *
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.
20  *
21  */
22 
23 #ifndef XSLStyleSheet_h
24 #define XSLStyleSheet_h
25 
26 #include "core/css/StyleSheet.h"
27 #include "core/dom/ProcessingInstruction.h"
28 #include "platform/RuntimeEnabledFeatures.h"
29 #include "wtf/PassRefPtr.h"
30 #include <libxml/tree.h>
31 #include <libxslt/transform.h>
32 
33 namespace WebCore {
34 
35 class ResourceFetcher;
36 class XSLImportRule;
37 
38 class XSLStyleSheet FINAL : public StyleSheet {
39 public:
create(XSLImportRule * parentImport,const String & originalURL,const KURL & finalURL)40     static PassRefPtrWillBeRawPtr<XSLStyleSheet> create(XSLImportRule* parentImport, const String& originalURL, const KURL& finalURL)
41     {
42         ASSERT(RuntimeEnabledFeatures::xsltEnabled());
43         return adoptRefWillBeNoop(new XSLStyleSheet(parentImport, originalURL, finalURL));
44     }
create(ProcessingInstruction * parentNode,const String & originalURL,const KURL & finalURL)45     static PassRefPtrWillBeRawPtr<XSLStyleSheet> create(ProcessingInstruction* parentNode, const String& originalURL, const KURL& finalURL)
46     {
47         ASSERT(RuntimeEnabledFeatures::xsltEnabled());
48         return adoptRefWillBeNoop(new XSLStyleSheet(parentNode, originalURL, finalURL, false));
49     }
createEmbedded(ProcessingInstruction * parentNode,const KURL & finalURL)50     static PassRefPtrWillBeRawPtr<XSLStyleSheet> createEmbedded(ProcessingInstruction* parentNode, const KURL& finalURL)
51     {
52         ASSERT(RuntimeEnabledFeatures::xsltEnabled());
53         return adoptRefWillBeNoop(new XSLStyleSheet(parentNode, finalURL.string(), finalURL, true));
54     }
55 
56     // Taking an arbitrary node is unsafe, because owner node pointer can become
57     // stale. XSLTProcessor ensures that the stylesheet doesn't outlive its
58     // parent, in part by not exposing it to JavaScript.
createForXSLTProcessor(Node * parentNode,const String & originalURL,const KURL & finalURL)59     static PassRefPtrWillBeRawPtr<XSLStyleSheet> createForXSLTProcessor(Node* parentNode, const String& originalURL, const KURL& finalURL)
60     {
61         ASSERT(RuntimeEnabledFeatures::xsltEnabled());
62         return adoptRefWillBeNoop(new XSLStyleSheet(parentNode, originalURL, finalURL, false));
63     }
64 
65     virtual ~XSLStyleSheet();
66 
67     bool parseString(const String&);
68 
69     void checkLoaded();
70 
finalURL()71     const KURL& finalURL() const { return m_finalURL; }
72 
73     void loadChildSheets();
74     void loadChildSheet(const String& href);
75 
76     ResourceFetcher* fetcher();
77 
78     Document* ownerDocument();
parentStyleSheet()79     virtual XSLStyleSheet* parentStyleSheet() const OVERRIDE { return m_parentStyleSheet; }
80     void setParentStyleSheet(XSLStyleSheet*);
81 
82     xmlDocPtr document();
83     xsltStylesheetPtr compileStyleSheet();
84     xmlDocPtr locateStylesheetSubResource(xmlDocPtr parentDoc, const xmlChar* uri);
85 
86     void clearDocuments();
87 
88     void markAsProcessed();
processed()89     bool processed() const { return m_processed; }
90 
type()91     virtual String type() const OVERRIDE { return "text/xml"; }
disabled()92     virtual bool disabled() const OVERRIDE { return m_isDisabled; }
setDisabled(bool b)93     virtual void setDisabled(bool b) OVERRIDE { m_isDisabled = b; }
ownerNode()94     virtual Node* ownerNode() const OVERRIDE { return m_ownerNode; }
href()95     virtual String href() const OVERRIDE { return m_originalURL; }
title()96     virtual String title() const OVERRIDE { return emptyString(); }
97 
clearOwnerNode()98     virtual void clearOwnerNode() OVERRIDE { m_ownerNode = nullptr; }
baseURL()99     virtual KURL baseURL() const OVERRIDE { return m_finalURL; }
100     virtual bool isLoading() const OVERRIDE;
101 
102     virtual void trace(Visitor*) OVERRIDE;
103 
104 private:
105     XSLStyleSheet(Node* parentNode, const String& originalURL, const KURL& finalURL, bool embedded);
106     XSLStyleSheet(XSLImportRule* parentImport, const String& originalURL, const KURL& finalURL);
107 
108     RawPtrWillBeMember<Node> m_ownerNode;
109     String m_originalURL;
110     KURL m_finalURL;
111     bool m_isDisabled;
112 
113     WillBeHeapVector<OwnPtrWillBeMember<XSLImportRule> > m_children;
114 
115     bool m_embedded;
116     bool m_processed;
117 
118     xmlDocPtr m_stylesheetDoc;
119     bool m_stylesheetDocTaken;
120     bool m_compilationFailed;
121 
122     RawPtrWillBeMember<XSLStyleSheet> m_parentStyleSheet;
123 };
124 
125 DEFINE_TYPE_CASTS(XSLStyleSheet, StyleSheet, sheet, !sheet->isCSSStyleSheet(), !sheet.isCSSStyleSheet());
126 
127 } // namespace WebCore
128 
129 #endif // XSLStyleSheet_h
130