OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 19 matching lines...) Expand all Loading... |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "bindings/core/v8/CustomElementConstructorBuilder.h" | 32 #include "bindings/core/v8/CustomElementConstructorBuilder.h" |
33 | 33 |
34 #include "bindings/core/v8/CustomElementBinding.h" | 34 #include "bindings/core/v8/CustomElementBinding.h" |
35 #include "bindings/core/v8/DOMWrapperWorld.h" | 35 #include "bindings/core/v8/DOMWrapperWorld.h" |
36 #include "bindings/core/v8/Dictionary.h" | 36 #include "bindings/core/v8/Dictionary.h" |
37 #include "bindings/core/v8/ExceptionState.h" | 37 #include "bindings/core/v8/ExceptionState.h" |
38 #include "bindings/core/v8/V8Binding.h" | 38 #include "bindings/core/v8/V8Binding.h" |
39 #include "bindings/core/v8/V8Document.h" | 39 #include "bindings/core/v8/V8Document.h" |
| 40 #include "bindings/core/v8/V8HTMLElement.h" |
40 #include "bindings/core/v8/V8HiddenValue.h" | 41 #include "bindings/core/v8/V8HiddenValue.h" |
41 #include "bindings/core/v8/V8PerContextData.h" | 42 #include "bindings/core/v8/V8PerContextData.h" |
| 43 #include "bindings/core/v8/V8SVGElement.h" |
42 #include "core/HTMLNames.h" | 44 #include "core/HTMLNames.h" |
43 #include "core/SVGNames.h" | 45 #include "core/SVGNames.h" |
44 #include "core/V8HTMLElementWrapperFactory.h" // FIXME: should be bindings/core/
v8 | |
45 #include "core/V8SVGElementWrapperFactory.h" // FIXME: should be bindings/core/v
8 | |
46 #include "core/dom/Document.h" | 46 #include "core/dom/Document.h" |
47 #include "core/dom/custom/CustomElementDefinition.h" | 47 #include "core/dom/custom/CustomElementDefinition.h" |
48 #include "core/dom/custom/CustomElementDescriptor.h" | 48 #include "core/dom/custom/CustomElementDescriptor.h" |
49 #include "core/dom/custom/CustomElementException.h" | 49 #include "core/dom/custom/CustomElementException.h" |
50 #include "core/dom/custom/CustomElementProcessingStack.h" | 50 #include "core/dom/custom/CustomElementProcessingStack.h" |
51 #include "wtf/Assertions.h" | 51 #include "wtf/Assertions.h" |
52 | 52 |
53 namespace blink { | 53 namespace blink { |
54 | 54 |
55 static void constructCustomElement(const v8::FunctionCallbackInfo<v8::Value>&); | 55 static void constructCustomElement(const v8::FunctionCallbackInfo<v8::Value>&); |
56 | 56 |
57 CustomElementConstructorBuilder::CustomElementConstructorBuilder(ScriptState* sc
riptState, const Dictionary* options) | 57 CustomElementConstructorBuilder::CustomElementConstructorBuilder(ScriptState* sc
riptState, const Dictionary* options) |
58 : m_scriptState(scriptState) | 58 : m_scriptState(scriptState) |
59 , m_options(options) | 59 , m_options(options) |
60 , m_wrapperType(0) | |
61 { | 60 { |
62 ASSERT(m_scriptState->context() == m_scriptState->isolate()->GetCurrentConte
xt()); | 61 ASSERT(m_scriptState->context() == m_scriptState->isolate()->GetCurrentConte
xt()); |
63 } | 62 } |
64 | 63 |
65 bool CustomElementConstructorBuilder::isFeatureAllowed() const | 64 bool CustomElementConstructorBuilder::isFeatureAllowed() const |
66 { | 65 { |
67 return m_scriptState->world().isMainWorld(); | 66 return m_scriptState->world().isMainWorld(); |
68 } | 67 } |
69 | 68 |
70 bool CustomElementConstructorBuilder::validateOptions(const AtomicString& type,
QualifiedName& tagName, ExceptionState& exceptionState) | 69 bool CustomElementConstructorBuilder::validateOptions(const AtomicString& type,
QualifiedName& tagName, ExceptionState& exceptionState) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } | 131 } |
133 } else { | 132 } else { |
134 if (namespaceURI == SVGNames::svgNamespaceURI) { | 133 if (namespaceURI == SVGNames::svgNamespaceURI) { |
135 CustomElementException::throwException(CustomElementException::Exten
dsIsInvalidName, type, exceptionState); | 134 CustomElementException::throwException(CustomElementException::Exten
dsIsInvalidName, type, exceptionState); |
136 tryCatch.ReThrow(); | 135 tryCatch.ReThrow(); |
137 return false; | 136 return false; |
138 } | 137 } |
139 localName = type; | 138 localName = type; |
140 } | 139 } |
141 | 140 |
142 if (!extendsProvidedAndNonNull) | |
143 m_wrapperType = &V8HTMLElement::wrapperTypeInfo; | |
144 else if (namespaceURI == HTMLNames::xhtmlNamespaceURI) | |
145 m_wrapperType = findWrapperTypeForHTMLTagName(localName); | |
146 else | |
147 m_wrapperType = findWrapperTypeForSVGTagName(localName); | |
148 | |
149 ASSERT(!tryCatch.HasCaught()); | 141 ASSERT(!tryCatch.HasCaught()); |
150 ASSERT(m_wrapperType); | |
151 tagName = QualifiedName(nullAtom, localName, namespaceURI); | 142 tagName = QualifiedName(nullAtom, localName, namespaceURI); |
152 return m_wrapperType; | 143 return true; |
153 } | 144 } |
154 | 145 |
155 PassRefPtr<CustomElementLifecycleCallbacks> CustomElementConstructorBuilder::cre
ateCallbacks() | 146 PassRefPtr<CustomElementLifecycleCallbacks> CustomElementConstructorBuilder::cre
ateCallbacks() |
156 { | 147 { |
157 ASSERT(!m_prototype.IsEmpty()); | 148 ASSERT(!m_prototype.IsEmpty()); |
158 | 149 |
159 v8::TryCatch exceptionCatcher; | 150 v8::TryCatch exceptionCatcher; |
160 exceptionCatcher.SetVerbose(true); | 151 exceptionCatcher.SetVerbose(true); |
161 | 152 |
162 v8::Isolate* isolate = m_scriptState->isolate(); | 153 v8::Isolate* isolate = m_scriptState->isolate(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 return false; | 232 return false; |
242 } | 233 } |
243 | 234 |
244 return true; | 235 return true; |
245 } | 236 } |
246 | 237 |
247 bool CustomElementConstructorBuilder::didRegisterDefinition(CustomElementDefinit
ion* definition) const | 238 bool CustomElementConstructorBuilder::didRegisterDefinition(CustomElementDefinit
ion* definition) const |
248 { | 239 { |
249 ASSERT(!m_constructor.IsEmpty()); | 240 ASSERT(!m_constructor.IsEmpty()); |
250 | 241 |
251 return m_callbacks->setBinding(definition, CustomElementBinding::create(m_sc
riptState->isolate(), m_prototype, m_wrapperType)); | 242 return m_callbacks->setBinding(definition, CustomElementBinding::create(m_sc
riptState->isolate(), m_prototype)); |
252 } | 243 } |
253 | 244 |
254 ScriptValue CustomElementConstructorBuilder::bindingsReturnValue() const | 245 ScriptValue CustomElementConstructorBuilder::bindingsReturnValue() const |
255 { | 246 { |
256 return ScriptValue(m_scriptState.get(), m_constructor); | 247 return ScriptValue(m_scriptState.get(), m_constructor); |
257 } | 248 } |
258 | 249 |
259 bool CustomElementConstructorBuilder::hasValidPrototypeChainFor(const WrapperTyp
eInfo* type) const | 250 bool CustomElementConstructorBuilder::hasValidPrototypeChainFor(const WrapperTyp
eInfo* type) const |
260 { | 251 { |
261 v8::Handle<v8::Object> elementPrototype = m_scriptState->perContextData()->p
rototypeForType(type); | 252 v8::Handle<v8::Object> elementPrototype = m_scriptState->perContextData()->p
rototypeForType(type); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 | 285 |
295 ExceptionState exceptionState(ExceptionState::ConstructionContext, "CustomEl
ement", info.Holder(), info.GetIsolate()); | 286 ExceptionState exceptionState(ExceptionState::ConstructionContext, "CustomEl
ement", info.Holder(), info.GetIsolate()); |
296 CustomElementProcessingStack::CallbackDeliveryScope deliveryScope; | 287 CustomElementProcessingStack::CallbackDeliveryScope deliveryScope; |
297 RefPtrWillBeRawPtr<Element> element = document->createElementNS(namespaceURI
, tagName, maybeType->IsNull() ? nullAtom : type, exceptionState); | 288 RefPtrWillBeRawPtr<Element> element = document->createElementNS(namespaceURI
, tagName, maybeType->IsNull() ? nullAtom : type, exceptionState); |
298 if (exceptionState.throwIfNeeded()) | 289 if (exceptionState.throwIfNeeded()) |
299 return; | 290 return; |
300 v8SetReturnValueFast(info, element.release(), document); | 291 v8SetReturnValueFast(info, element.release(), document); |
301 } | 292 } |
302 | 293 |
303 } // namespace blink | 294 } // namespace blink |
OLD | NEW |