• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "config.h"
32 #include "XSLTProcessor.h"
33 
34 #include "Document.h"
35 #include "DocumentFragment.h"
36 #include "Node.h"
37 
38 #include "V8Binding.h"
39 #include "V8CustomBinding.h"
40 #include "V8Document.h"
41 #include "V8Node.h"
42 #include "V8Proxy.h"
43 
44 #include <wtf/RefPtr.h>
45 
46 namespace WebCore {
47 
CALLBACK_FUNC_DECL(XSLTProcessorConstructor)48 CALLBACK_FUNC_DECL(XSLTProcessorConstructor)
49 {
50     INC_STATS("DOM.XSLTProcessor.Constructor");
51     return V8Proxy::constructDOMObject<V8ClassIndex::XSLTPROCESSOR, XSLTProcessor>(args);
52 }
53 
54 
CALLBACK_FUNC_DECL(XSLTProcessorImportStylesheet)55 CALLBACK_FUNC_DECL(XSLTProcessorImportStylesheet)
56 {
57     INC_STATS("DOM.XSLTProcessor.importStylesheet");
58     if (!V8Node::HasInstance(args[0]))
59         return v8::Undefined();
60 
61     XSLTProcessor* imp = V8DOMWrapper::convertToNativeObject<XSLTProcessor>(V8ClassIndex::XSLTPROCESSOR, args.Holder());
62 
63     Node* node = V8DOMWrapper::convertDOMWrapperToNode<Node>(v8::Handle<v8::Object>::Cast(args[0]));
64     imp->importStylesheet(node);
65     return v8::Undefined();
66 }
67 
68 
CALLBACK_FUNC_DECL(XSLTProcessorTransformToFragment)69 CALLBACK_FUNC_DECL(XSLTProcessorTransformToFragment)
70 {
71     INC_STATS("DOM.XSLTProcessor.transformToFragment");
72     if (!V8Node::HasInstance(args[0]) || !V8Document::HasInstance(args[1]))
73         return v8::Undefined();
74 
75     XSLTProcessor* imp = V8DOMWrapper::convertToNativeObject<XSLTProcessor>(V8ClassIndex::XSLTPROCESSOR, args.Holder());
76 
77     Node* source = V8DOMWrapper::convertDOMWrapperToNode<Node>(v8::Handle<v8::Object>::Cast(args[0]));
78     Document* owner = V8DOMWrapper::convertDOMWrapperToNode<Document>(v8::Handle<v8::Object>::Cast(args[1]));
79     RefPtr<DocumentFragment> result = imp->transformToFragment(source, owner);
80     return V8DOMWrapper::convertNodeToV8Object(result.release());
81 }
82 
83 
CALLBACK_FUNC_DECL(XSLTProcessorTransformToDocument)84 CALLBACK_FUNC_DECL(XSLTProcessorTransformToDocument)
85 {
86     INC_STATS("DOM.XSLTProcessor.transformToDocument");
87 
88     if (!V8Node::HasInstance(args[0]))
89         return v8::Undefined();
90 
91     XSLTProcessor* imp = V8DOMWrapper::convertToNativeObject<XSLTProcessor>(V8ClassIndex::XSLTPROCESSOR, args.Holder());
92 
93     Node* source = V8DOMWrapper::convertDOMWrapperToNode<Node>(v8::Handle<v8::Object>::Cast(args[0]));
94     if (!source)
95         return v8::Undefined();
96 
97     RefPtr<Document> result = imp->transformToDocument(source);
98     if (!result)
99         return v8::Undefined();
100 
101     return V8DOMWrapper::convertNodeToV8Object(result.release());
102 }
103 
104 
CALLBACK_FUNC_DECL(XSLTProcessorSetParameter)105 CALLBACK_FUNC_DECL(XSLTProcessorSetParameter)
106 {
107     INC_STATS("DOM.XSLTProcessor.setParameter");
108     if (isUndefinedOrNull(args[1]) || isUndefinedOrNull(args[2]))
109         return v8::Undefined();
110 
111     XSLTProcessor* imp = V8DOMWrapper::convertToNativeObject<XSLTProcessor>(V8ClassIndex::XSLTPROCESSOR, args.Holder());
112 
113     String namespaceURI = toWebCoreString(args[0]);
114     String localName = toWebCoreString(args[1]);
115     String value = toWebCoreString(args[2]);
116     imp->setParameter(namespaceURI, localName, value);
117 
118     return v8::Undefined();
119 }
120 
121 
CALLBACK_FUNC_DECL(XSLTProcessorGetParameter)122 CALLBACK_FUNC_DECL(XSLTProcessorGetParameter)
123 {
124     INC_STATS("DOM.XSLTProcessor.getParameter");
125     if (isUndefinedOrNull(args[1]))
126         return v8::Undefined();
127 
128     XSLTProcessor* imp = V8DOMWrapper::convertToNativeObject<XSLTProcessor>(V8ClassIndex::XSLTPROCESSOR, args.Holder());
129 
130     String namespaceURI = toWebCoreString(args[0]);
131     String localName = toWebCoreString(args[1]);
132     String result = imp->getParameter(namespaceURI, localName);
133     if (result.isNull())
134         return v8::Undefined();
135 
136     return v8String(result);
137 }
138 
CALLBACK_FUNC_DECL(XSLTProcessorRemoveParameter)139 CALLBACK_FUNC_DECL(XSLTProcessorRemoveParameter)
140 {
141     INC_STATS("DOM.XSLTProcessor.removeParameter");
142     if (isUndefinedOrNull(args[1]))
143         return v8::Undefined();
144 
145     XSLTProcessor* imp = V8DOMWrapper::convertToNativeObject<XSLTProcessor>(V8ClassIndex::XSLTPROCESSOR, args.Holder());
146 
147     String namespaceURI = toWebCoreString(args[0]);
148     String localName = toWebCoreString(args[1]);
149     imp->removeParameter(namespaceURI, localName);
150     return v8::Undefined();
151 }
152 
153 } // namespace WebCore
154