OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 15 matching lines...) Expand all Loading... |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 | 32 |
33 #include "bindings/v8/CustomElementHelpers.h" | 33 #include "bindings/v8/CustomElementHelpers.h" |
34 | 34 |
35 #include "HTMLNames.h" | 35 #include "HTMLNames.h" |
| 36 #include "SVGNames.h" |
36 #include "V8CustomElementConstructor.h" | 37 #include "V8CustomElementConstructor.h" |
37 #include "V8HTMLElementWrapperFactory.h" | 38 #include "V8HTMLElementWrapperFactory.h" |
| 39 #include "V8SVGElementWrapperFactory.h" |
38 #include "bindings/v8/DOMDataStore.h" | 40 #include "bindings/v8/DOMDataStore.h" |
39 #include "bindings/v8/DOMWrapperWorld.h" | 41 #include "bindings/v8/DOMWrapperWorld.h" |
40 #include "bindings/v8/ScriptController.h" | 42 #include "bindings/v8/ScriptController.h" |
41 #include "core/dom/CustomElementRegistry.h" | 43 #include "core/dom/CustomElementRegistry.h" |
42 #include "core/dom/Node.h" | 44 #include "core/dom/Node.h" |
43 #include "core/html/HTMLElement.h" | 45 #include "core/html/HTMLElement.h" |
44 #include "core/html/HTMLUnknownElement.h" | 46 #include "core/html/HTMLUnknownElement.h" |
45 | |
46 #if ENABLE(SVG) | |
47 #include "V8SVGElementWrapperFactory.h" | |
48 #include "SVGNames.h" | |
49 #include "core/svg/SVGElement.h" | 47 #include "core/svg/SVGElement.h" |
50 #endif | |
51 | 48 |
52 namespace WebCore { | 49 namespace WebCore { |
53 | 50 |
54 v8::Handle<v8::Object> CustomElementHelpers::createWrapper(PassRefPtr<Element> i
mpl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate, const CreateW
rapperFunction& createTypeExtensionUpgradeCandidateWrapper) | 51 v8::Handle<v8::Object> CustomElementHelpers::createWrapper(PassRefPtr<Element> i
mpl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate, const CreateW
rapperFunction& createTypeExtensionUpgradeCandidateWrapper) |
55 { | 52 { |
56 ASSERT(impl); | 53 ASSERT(impl); |
57 | 54 |
58 // The constructor and registered lifecycle callbacks should be visible only
from main world. | 55 // The constructor and registered lifecycle callbacks should be visible only
from main world. |
59 // FIXME: This shouldn't be needed once each custom element has its own Func
tionTemplate | 56 // FIXME: This shouldn't be needed once each custom element has its own Func
tionTemplate |
60 // https://bugs.webkit.org/show_bug.cgi?id=108138 | 57 // https://bugs.webkit.org/show_bug.cgi?id=108138 |
(...skipping 29 matching lines...) Expand all Loading... |
90 V8DOMWrapper::associateObjectWithWrapper(impl, typeInfo, wrapper, isolate, W
rapperConfiguration::Dependent); | 87 V8DOMWrapper::associateObjectWithWrapper(impl, typeInfo, wrapper, isolate, W
rapperConfiguration::Dependent); |
91 return wrapper; | 88 return wrapper; |
92 } | 89 } |
93 | 90 |
94 v8::Handle<v8::Object> CustomElementHelpers::CreateWrapperFunction::invoke(Eleme
nt* element, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) const | 91 v8::Handle<v8::Object> CustomElementHelpers::CreateWrapperFunction::invoke(Eleme
nt* element, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) const |
95 { | 92 { |
96 if (element->isHTMLElement()) { | 93 if (element->isHTMLElement()) { |
97 if (m_html) | 94 if (m_html) |
98 return m_html(toHTMLElement(element), creationContext, isolate); | 95 return m_html(toHTMLElement(element), creationContext, isolate); |
99 return createV8HTMLFallbackWrapper(toHTMLUnknownElement(toHTMLElement(el
ement)), creationContext, isolate); | 96 return createV8HTMLFallbackWrapper(toHTMLUnknownElement(toHTMLElement(el
ement)), creationContext, isolate); |
100 } | 97 } else if (element->isSVGElement()) { |
101 #if ENABLE(SVG) | |
102 else if (element->isSVGElement()) { | |
103 if (m_svg) | 98 if (m_svg) |
104 return m_svg(toSVGElement(element), creationContext, isolate); | 99 return m_svg(toSVGElement(element), creationContext, isolate); |
105 return createV8SVGFallbackWrapper(toSVGElement(element), creationContext
, isolate); | 100 return createV8SVGFallbackWrapper(toSVGElement(element), creationContext
, isolate); |
106 } | 101 } |
107 #endif | 102 |
108 ASSERT(0); | 103 ASSERT(0); |
109 return v8::Handle<v8::Object>(); | 104 return v8::Handle<v8::Object>(); |
110 } | 105 } |
111 | 106 |
112 v8::Handle<v8::Object> CustomElementHelpers::createUpgradeCandidateWrapper(PassR
efPtr<Element> element, v8::Handle<v8::Object> creationContext, v8::Isolate* iso
late, const CreateWrapperFunction& createTypeExtensionUpgradeCandidateWrapper) | 107 v8::Handle<v8::Object> CustomElementHelpers::createUpgradeCandidateWrapper(PassR
efPtr<Element> element, v8::Handle<v8::Object> creationContext, v8::Isolate* iso
late, const CreateWrapperFunction& createTypeExtensionUpgradeCandidateWrapper) |
113 { | 108 { |
114 if (CustomElementRegistry::isCustomTagName(element->localName())) { | 109 if (CustomElementRegistry::isCustomTagName(element->localName())) { |
115 if (element->isHTMLElement()) | 110 if (element->isHTMLElement()) |
116 return createV8HTMLDirectWrapper(toHTMLElement(element.get()), creat
ionContext, isolate); | 111 return createV8HTMLDirectWrapper(toHTMLElement(element.get()), creat
ionContext, isolate); |
117 #if ENABLE(SVG) | |
118 else if (element->isSVGElement()) | 112 else if (element->isSVGElement()) |
119 return createV8SVGDirectWrapper(toSVGElement(element.get()), creatio
nContext, isolate); | 113 return createV8SVGDirectWrapper(toSVGElement(element.get()), creatio
nContext, isolate); |
120 #endif | |
121 else { | 114 else { |
122 ASSERT(0); | 115 ASSERT(0); |
123 return v8::Handle<v8::Object>(); | 116 return v8::Handle<v8::Object>(); |
124 } | 117 } |
125 } else { | 118 } else { |
126 // It's a type extension | 119 // It's a type extension |
127 return createTypeExtensionUpgradeCandidateWrapper.invoke(element.get(),
creationContext, isolate); | 120 return createTypeExtensionUpgradeCandidateWrapper.invoke(element.get(),
creationContext, isolate); |
128 } | 121 } |
129 } | 122 } |
130 | 123 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 { | 171 { |
179 if (prototype.v8Value().IsEmpty() || !prototype.v8Value()->IsObject()) | 172 if (prototype.v8Value().IsEmpty() || !prototype.v8Value()->IsObject()) |
180 return false; | 173 return false; |
181 | 174 |
182 v8::Handle<v8::Object> prototypeObject = v8::Handle<v8::Object>::Cast(protot
ype.v8Value()); | 175 v8::Handle<v8::Object> prototypeObject = v8::Handle<v8::Object>::Cast(protot
ype.v8Value()); |
183 if (hasValidPrototypeChainFor(prototypeObject, &V8HTMLElement::info, state->
context())) { | 176 if (hasValidPrototypeChainFor(prototypeObject, &V8HTMLElement::info, state->
context())) { |
184 namespaceURI = HTMLNames::xhtmlNamespaceURI; | 177 namespaceURI = HTMLNames::xhtmlNamespaceURI; |
185 return true; | 178 return true; |
186 } | 179 } |
187 | 180 |
188 #if ENABLE(SVG) | |
189 if (hasValidPrototypeChainFor(prototypeObject, &V8SVGElement::info, state->c
ontext())) { | 181 if (hasValidPrototypeChainFor(prototypeObject, &V8SVGElement::info, state->c
ontext())) { |
190 namespaceURI = SVGNames::svgNamespaceURI; | 182 namespaceURI = SVGNames::svgNamespaceURI; |
191 return true; | 183 return true; |
192 } | 184 } |
193 #endif | |
194 | 185 |
195 if (hasValidPrototypeChainFor(prototypeObject, &V8Element::info, state->cont
ext())) { | 186 if (hasValidPrototypeChainFor(prototypeObject, &V8Element::info, state->cont
ext())) { |
196 namespaceURI = nullAtom; | 187 namespaceURI = nullAtom; |
197 return true; | 188 return true; |
198 } | 189 } |
199 | 190 |
200 return false; | 191 return false; |
201 } | 192 } |
202 | 193 |
203 bool CustomElementHelpers::isFeatureAllowed(ScriptState* state) | 194 bool CustomElementHelpers::isFeatureAllowed(ScriptState* state) |
(...skipping 29 matching lines...) Expand all Loading... |
233 } | 224 } |
234 | 225 |
235 // This can return null. In that case, we should take the element name as its lo
cal name. | 226 // This can return null. In that case, we should take the element name as its lo
cal name. |
236 const QualifiedName* CustomElementHelpers::findLocalName(v8::Handle<v8::Object>
chain) | 227 const QualifiedName* CustomElementHelpers::findLocalName(v8::Handle<v8::Object>
chain) |
237 { | 228 { |
238 WrapperTypeInfo* type = CustomElementHelpers::findWrapperType(chain); | 229 WrapperTypeInfo* type = CustomElementHelpers::findWrapperType(chain); |
239 if (!type) | 230 if (!type) |
240 return 0; | 231 return 0; |
241 if (const QualifiedName* htmlName = findHTMLTagNameOfV8Type(type)) | 232 if (const QualifiedName* htmlName = findHTMLTagNameOfV8Type(type)) |
242 return htmlName; | 233 return htmlName; |
243 #if ENABLE(SVG) | |
244 if (const QualifiedName* svgName = findSVGTagNameOfV8Type(type)) | 234 if (const QualifiedName* svgName = findSVGTagNameOfV8Type(type)) |
245 return svgName; | 235 return svgName; |
246 #endif | |
247 return 0; | 236 return 0; |
248 } | 237 } |
249 | 238 |
250 void CustomElementHelpers::upgradeWrappers(ScriptExecutionContext* executionCont
ext, const HashSet<Element*>& elements, const ScriptValue& prototype) | 239 void CustomElementHelpers::upgradeWrappers(ScriptExecutionContext* executionCont
ext, const HashSet<Element*>& elements, const ScriptValue& prototype) |
251 { | 240 { |
252 if (elements.isEmpty()) | 241 if (elements.isEmpty()) |
253 return; | 242 return; |
254 | 243 |
255 v8::HandleScope handleScope; | 244 v8::HandleScope handleScope; |
256 v8::Handle<v8::Context> context = toV8Context(executionContext, mainThreadNo
rmalWorld()); | 245 v8::Handle<v8::Context> context = toV8Context(executionContext, mainThreadNo
rmalWorld()); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 return; | 290 return; |
302 v8::Context::Scope scope(context); | 291 v8::Context::Scope scope(context); |
303 | 292 |
304 for (size_t i = 0; i < invocations.size(); ++i) { | 293 for (size_t i = 0; i < invocations.size(); ++i) { |
305 ASSERT(executionContext == invocations[i].element()->document()); | 294 ASSERT(executionContext == invocations[i].element()->document()); |
306 invokeReadyCallbackIfNeeded(invocations[i].element(), context); | 295 invokeReadyCallbackIfNeeded(invocations[i].element(), context); |
307 } | 296 } |
308 } | 297 } |
309 | 298 |
310 } // namespace WebCore | 299 } // namespace WebCore |
OLD | NEW |