Changeset 143865 in webkit
- Timestamp:
- Feb 24, 2013 5:21:42 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 20 added
- 23 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r143862 r143865 1 2013-02-24 Hajime Morrita <morrita@google.com> 2 3 [Custom Elements] Implement bare-bone document.register() 4 https://bugs.webkit.org/show_bug.cgi?id=100229 5 6 Reviewed by Adam Barth. 7 8 * fast/dom/custom/document-register-basic-expected.txt: Added. 9 * fast/dom/custom/document-register-basic.html: Added. 10 * fast/dom/custom/document-register-reentrant-null-constructor-expected.txt: Added. 11 * fast/dom/custom/document-register-reentrant-null-constructor.html: Added. 12 * fast/dom/custom/document-register-reentrant-returning-fake-expected.txt: Added. 13 * fast/dom/custom/document-register-reentrant-returning-fake.html: Added. 14 * fast/dom/custom/document-register-reentrant-throwing-constructor-expected.txt: Added. 15 * fast/dom/custom/document-register-reentrant-throwing-constructor.html: Added. 16 * fast/dom/custom/resources/document-register-fuzz.js: Added. 17 * platform/mac/TestExpectations: 18 1 19 2013-02-24 Benjamin Poulain <benjamin@webkit.org> 2 20 -
trunk/LayoutTests/platform/mac/TestExpectations
r143849 r143865 1113 1113 webkit.org/b/76439 [ Debug ] fast/dom/shadow/content-element-outside-shadow.html [ Failure ] 1114 1114 1115 # ENABLE(CUSTOM_ELEMENTS) is disabled. 1116 fast/dom/custom 1117 1115 1118 # CSS Variables are not yet enabled. 1116 1119 webkit.org/b/85580 fast/css/variables -
trunk/Source/WebCore/ChangeLog
r143864 r143865 1 2013-02-24 Hajime Morrita <morrita@google.com> 2 3 [Custom Elements] Implement bare-bone document.register() 4 https://bugs.webkit.org/show_bug.cgi?id=100229 5 6 Reviewed by Adam Barth. 7 8 This change implements a prefixed version of document.register(), with minimal feature support. 9 - The feature is guarded by ENABLE(CUSTOM_ELEMENTS) and RuntimeEnabledFeatures::customDOMElementsEnabled(). 10 - This bare-bone version only recognizes "name" and "prototype" parameters. It doesn't support default value of "prototype" parameter. 11 - Currently only V8 is supported. JSC binding needs its own binding implementation. 12 13 = Major new classes under dom/: 14 15 The dom module gets two new classes: 16 - CustomElementConstructor: A return value of document.register() 17 which holds the custom element definition. 18 - CustomElementRegistry: A collection of CustomElementConstructor objects. 19 CustomElementRegistry instance is created per Document and is owned by the Document. 20 21 CustomElementConstructor knows the definition of each custom 22 element, which is registered by document.register(). The name and 23 other options are held by this object. CustomElementRegistry owns a set 24 of the registered constructors. The registry guarantees invariants 25 like validity and uniqueness of the element names. 26 27 = A change on make_names.pl 28 29 This change tweaks make_names.pl (or generated HTMLElementFactory) 30 to hook the creations of unknown elements. Some of element names 31 which come to the fallback path can be one of registered custom 32 element. 33 34 = [V8WrapAsFunction] extended attribute: 35 36 The document.register() API returns a constructor 37 function. However, the V8 binding currently doesn't support it. To 38 make it possible, this change introduces "V8WrapAsFunction" 39 extended attribute for annotating CustomElementConstructor IDL 40 interface. 41 42 V8WrapAsFunction wraps the annotated interface with a JavaScript 43 function, which calls the original object as a function, or as a 44 constructor depends on the context. 45 46 With this wrapper function, there are two levels of indirection 47 between native C++ object and author-visible JS function: 48 49 [JS Adaptor Function] <-(hidden property)-> [JS Wrapper Object] -(internal field)-> [C++ Native object] 50 51 The code generator generates the binding code which deals with 52 this indirection. Also, there is a set of helper functions in 53 V8AdaptorFunction.h/cpp which takes care of this indirection. 54 V8DOMWrapper.cpp/h works as a facade for these APIs and is used from 55 the generated code. 56 57 This redundancy comes from limitations of both V8 bindings and V8 58 embedding API. See bug 108138 for details. 59 60 = V8HTMLCustomElement 61 62 Unlike built-in HTML elements, any custom element has no 63 corresponding C++ class. Instead, document.register() should allow 64 passing a prototype object for the elements being registered. 65 66 V8HTMLCustomElement handles this lack of native class. It behaves 67 like a native side proxy of non-native HTMLElement subclasses. It 68 connects each custom element to an appropriate native element, 69 which is HTMLElement at this time. This restriction will be 70 relaxed later. See Bug 110436 for details. 71 72 = Custom DOM elements and multiple worlds 73 74 In this patch, custom element registration and instantiation is not allowed 75 in non-main world and document.register() API just fails there. 76 77 Reviewed by Adam Barth. 78 79 Tests: fast/dom/custom/document-register-basic.html 80 fast/dom/custom/document-register-reentrant-null-constructor.html 81 fast/dom/custom/document-register-reentrant-returning-fake.html 82 fast/dom/custom/document-register-reentrant-throwing-constructor.html 83 84 * DerivedSources.make: 85 * WebCore.gypi: 86 * bindings/generic/RuntimeEnabledFeatures.cpp: 87 * bindings/generic/RuntimeEnabledFeatures.h: 88 (RuntimeEnabledFeatures): 89 (WebCore::RuntimeEnabledFeatures::customDOMElementsEnabled): 90 (WebCore::RuntimeEnabledFeatures::setCustomDOMElements): 91 * bindings/scripts/CodeGeneratorV8.pm: 92 (GenerateHeader): 93 * bindings/scripts/IDLAttributes.txt: 94 * bindings/v8/CustomElementHelpers.cpp: Added. 95 (WebCore::CustomElementHelpers::initializeConstructorWrapper): 96 (WebCore::hasNoBuiltinsInPrototype): 97 (WebCore::CustomElementHelpers::isValidPrototypeParameter): 98 (WebCore::CustomElementHelpers::isFeatureAllowed): 99 * bindings/v8/CustomElementHelpers.h: Copied from Source/WebCore/bindings/v8/V8HiddenPropertyName.h. 100 (CustomElementHelpers): 101 * bindings/v8/V8AdaptorFunction.cpp: Added. 102 (WebCore::V8AdaptorFunction::getTemplate): 103 (WebCore::V8AdaptorFunction::configureTemplate): 104 (WebCore::V8AdaptorFunction::invocationCallback): 105 (WebCore::V8AdaptorFunction::wrap): 106 * bindings/v8/V8AdaptorFunction.h: Added. 107 (V8AdaptorFunction): 108 (WebCore::V8AdaptorFunction::unwrap): 109 (WebCore::V8AdaptorFunction::get): 110 * bindings/v8/V8DOMConfiguration.cpp: 111 (WebCore::V8DOMConfiguration::configureTemplate): 112 * bindings/v8/V8DOMWrapper.cpp: 113 (WebCore::V8DOMWrapper::toFunction): 114 (WebCore::V8DOMWrapper::fromFunction): 115 * bindings/v8/V8DOMWrapper.h: 116 (V8DOMWrapper): 117 * bindings/v8/V8HTMLCustomElement.cpp: Added. 118 (WebCore::V8HTMLCustomElement::createWrapper): 119 * bindings/v8/V8HTMLCustomElement.h: Copied from Source/WebCore/bindings/v8/V8HiddenPropertyName.h. 120 (V8HTMLCustomElement): 121 (WebCore::V8HTMLCustomElement::toV8): 122 (WebCore::HTMLCustomElement::toV8): 123 * bindings/v8/V8HiddenPropertyName.h: 124 * bindings/v8/custom/V8CustomElementConstructorCustom.cpp: Added. 125 (WebCore::V8CustomElementConstructor::callAsFunctionCallback): 126 * dom/CustomElementConstructor.cpp: Copied from Source/WebCore/bindings/v8/V8HiddenPropertyName.h. 127 (WebCore::CustomElementConstructor::create): 128 (WebCore::CustomElementConstructor::CustomElementConstructor): 129 (WebCore::CustomElementConstructor::~CustomElementConstructor): 130 (WebCore::CustomElementConstructor::createElement): 131 * dom/CustomElementConstructor.h: Copied from Source/WebCore/bindings/v8/V8HiddenPropertyName.h. 132 (CustomElementConstructor): 133 (WebCore::CustomElementConstructor::document): 134 (WebCore::CustomElementConstructor::tagName): 135 (WebCore::CustomElementConstructor::name): 136 * dom/CustomElementConstructor.idl: Added. 137 * dom/CustomElementRegistry.cpp: Added. 138 (WebCore::CustomElementRegistry::CustomElementRegistry): 139 (WebCore::CustomElementRegistry::~CustomElementRegistry): 140 (WebCore::CustomElementRegistry::constructorOf): 141 (WebCore::CustomElementRegistry::isValidName): 142 (WebCore::CustomElementRegistry::registerElement): 143 (WebCore::CustomElementRegistry::find): 144 (WebCore::CustomElementRegistry::createElement): 145 (WebCore::CustomElementRegistry::document): 146 * dom/CustomElementRegistry.h: Added. 147 (CustomElementRegistry): 148 * dom/Document.cpp: 149 (WebCore::Document::removedLastRef): 150 (WebCore::Document::registerElement): 151 (WebCore::Document::registry): 152 * dom/Document.h: 153 (Document): 154 * dom/make_names.pl: 155 (printWrapperFactoryCppFile): 156 * html/HTMLDocument.idl: 157 1 158 2013-02-24 Eugene Klyuchnikov <eustas@chromium.org> 2 159 -
trunk/Source/WebCore/DerivedSources.make
r143820 r143865 221 221 $(WebCore)/dom/Comment.idl \ 222 222 $(WebCore)/dom/CompositionEvent.idl \ 223 $(WebCore)/dom/CustomElementConstructor.idl \ 223 224 $(WebCore)/dom/CustomEvent.idl \ 224 225 $(WebCore)/dom/DOMCoreException.idl \ -
trunk/Source/WebCore/WebCore.gypi
r143854 r143865 201 201 'dom/Comment.idl', 202 202 'dom/CompositionEvent.idl', 203 'dom/CustomElementConstructor.idl', 203 204 'dom/CustomEvent.idl', 204 205 'dom/DOMCoreException.idl', … … 1192 1193 'bindings/v8/BindingState.cpp', 1193 1194 'bindings/v8/BindingState.h', 1195 'bindings/v8/CustomElementHelpers.cpp', 1196 'bindings/v8/CustomElementHelpers.h', 1194 1197 'bindings/v8/DOMDataStore.cpp', 1195 1198 'bindings/v8/DOMDataStore.h', … … 1260 1263 'bindings/v8/V8AbstractEventListener.cpp', 1261 1264 'bindings/v8/V8AbstractEventListener.h', 1265 'bindings/v8/V8AdaptorFunction.cpp', 1266 'bindings/v8/V8AdaptorFunction.h', 1262 1267 'bindings/v8/V8Binding.cpp', 1263 1268 'bindings/v8/V8Binding.h', … … 1281 1286 'bindings/v8/V8GCForContextDispose.cpp', 1282 1287 'bindings/v8/V8GCForContextDispose.h', 1288 'bindings/v8/V8HTMLCustomElement.cpp', 1289 'bindings/v8/V8HTMLCustomElement.h', 1283 1290 'bindings/v8/V8HiddenPropertyName.cpp', 1284 1291 'bindings/v8/V8HiddenPropertyName.h', … … 1341 1348 'bindings/v8/custom/V8CoordinatesCustom.cpp', 1342 1349 'bindings/v8/custom/V8CryptoCustom.cpp', 1350 'bindings/v8/custom/V8CustomElementConstructorCustom.cpp', 1343 1351 'bindings/v8/custom/V8CustomEventCustom.cpp', 1344 1352 'bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp', … … 2774 2782 'dom/ContextFeatures.h', 2775 2783 'dom/CrossThreadTask.h', 2784 'dom/CustomElementConstructor.cpp', 2785 'dom/CustomElementConstructor.h', 2786 'dom/CustomElementRegistry.cpp', 2787 'dom/CustomElementRegistry.h', 2776 2788 'dom/CustomEvent.cpp', 2777 2789 'dom/CustomEvent.h', -
trunk/Source/WebCore/bindings/generic/RuntimeEnabledFeatures.cpp
r143502 r143865 191 191 #endif 192 192 193 #if ENABLE(CUSTOM_ELEMENTS) 194 bool RuntimeEnabledFeatures::isCustomDOMElementsEnabled = false; 195 #endif 196 193 197 #if ENABLE(STYLE_SCOPED) 194 198 bool RuntimeEnabledFeatures::isStyleScopedEnabled = false; -
trunk/Source/WebCore/bindings/generic/RuntimeEnabledFeatures.h
r143502 r143865 219 219 #endif 220 220 221 #if ENABLE(CUSTOM_ELEMENTS) 222 static bool customDOMElementsEnabled() { return isCustomDOMElementsEnabled; } 223 static void setCustomDOMElements(bool isEnabled) { isCustomDOMElementsEnabled = isEnabled; } 224 #endif 225 221 226 #if ENABLE(STYLE_SCOPED) 222 227 static bool styleScopedEnabled() { return isStyleScopedEnabled; } … … 344 349 #endif 345 350 351 #if ENABLE(CUSTOM_ELEMENTS) 352 static bool isCustomDOMElementsEnabled; 353 #endif 354 346 355 #if ENABLE(STYLE_SCOPED) 347 356 static bool isStyleScopedEnabled; -
trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm
r143856 r143865 353 353 } 354 354 355 my $fromFunctionOpening = ""; 356 my $fromFunctionClosing = ""; 357 if ($interface->extendedAttributes->{"V8WrapAsFunction"}) { 358 $fromFunctionOpening = "V8DOMWrapper::fromFunction("; 359 $fromFunctionClosing = ")"; 360 } 361 355 362 push(@headerContent, <<END); 356 363 static bool HasInstance(v8::Handle<v8::Value>, v8::Isolate*); … … 359 366 static ${nativeType}* toNative(v8::Handle<v8::Object> object) 360 367 { 361 return reinterpret_cast<${nativeType}*>( object->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex));368 return reinterpret_cast<${nativeType}*>(${fromFunctionOpening}object${fromFunctionClosing}->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex)); 362 369 } 363 370 static void derefObject(void*); … … 540 547 541 548 my $createWrapperCall = $customWrap ? "${v8InterfaceName}::wrap" : "${v8InterfaceName}::createWrapper"; 549 my $returningWrapper = $interface->extendedAttributes->{"V8WrapAsFunction"} ? "V8DOMWrapper::toFunction(wrapper)" : "wrapper"; 550 my $returningCreatedWrapperOpening = $interface->extendedAttributes->{"V8WrapAsFunction"} ? "V8DOMWrapper::toFunction(" : ""; 551 my $returningCreatedWrapperClosing = $interface->extendedAttributes->{"V8WrapAsFunction"} ? ", impl->name(), isolate)" : ""; 542 552 543 553 if ($customWrap) { … … 553 563 ASSERT(impl); 554 564 ASSERT(DOMDataStore::getWrapper(impl, isolate).IsEmpty()); 555 return $ createWrapperCall(impl, creationContext, isolate);565 return ${returningCreatedWrapperOpening}$createWrapperCall(impl, creationContext, isolate)${returningCreatedWrapperClosing}; 556 566 } 557 567 END … … 566 576 v8::Handle<v8::Value> wrapper = DOMDataStore::getWrapper(impl, isolate); 567 577 if (!wrapper.IsEmpty()) 568 return wrapper;578 return $returningWrapper; 569 579 return wrap(impl, creationContext, isolate); 570 580 } … … 577 587 v8::Handle<v8::Object> wrapper = DOMDataStore::getWrapperFast(impl, container, wrappable); 578 588 if (!wrapper.IsEmpty()) 579 return wrapper;589 return $returningWrapper; 580 590 return wrap(impl, container.Holder(), container.GetIsolate()); 581 591 } -
trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt
r141034 r143865 130 130 V8SkipVTableValidation 131 131 V8Unforgeable 132 V8WrapAsFunction -
trunk/Source/WebCore/bindings/v8/CustomElementHelpers.h
r143864 r143865 29 29 */ 30 30 31 #ifndef V8HiddenPropertyName_h32 #define V8HiddenPropertyName_h31 #ifndef CustomElementHelpers_h 32 #define CustomElementHelpers_h 33 33 34 #include <v8.h> 34 #include "ExceptionCode.h" 35 #include "ScriptValue.h" 35 36 36 37 namespace WebCore { 37 38 38 #define V8_HIDDEN_PROPERTIES(V) \ 39 V(attributeListener) \ 40 V(callback) \ 41 V(detail) \ 42 V(document) \ 43 V(event) \ 44 V(listener) \ 45 V(scriptState) \ 46 V(sleepFunction) \ 47 V(state) \ 48 V(toStringString) \ 49 V(typedArrayHiddenCopyMethod) 39 #if ENABLE(CUSTOM_ELEMENTS) 50 40 51 class V8HiddenPropertyName { 41 class CustomElementConstructor; 42 class ScriptState; 43 44 class CustomElementHelpers { 52 45 public: 53 V8HiddenPropertyName() { } 54 #define V8_DECLARE_PROPERTY(name) static v8::Handle<v8::String> name(); 55 V8_HIDDEN_PROPERTIES(V8_DECLARE_PROPERTY); 56 #undef V8_DECLARE_PROPERTY 46 static bool initializeConstructorWrapper(CustomElementConstructor*, const ScriptValue& prototype, ScriptState*); 47 static bool isValidPrototypeParameter(const ScriptValue&, ScriptState*); 48 static bool isFeatureAllowed(ScriptState*); 57 49 58 static void setNamedHiddenReference(v8::Handle<v8::Object> parent, const char* name, v8::Handle<v8::Value> child); 59 60 private: 61 static v8::Persistent<v8::String> createString(const char* key); 62 #define V8_DECLARE_FIELD(name) v8::Persistent<v8::String> m_##name; 63 V8_HIDDEN_PROPERTIES(V8_DECLARE_FIELD); 64 #undef V8_DECLARE_FIELD 50 static bool isFeatureAllowed(v8::Handle<v8::Context>); 65 51 }; 66 52 67 } 53 #endif // ENABLE(CUSTOM_ELEMENTS) 68 54 69 #endif // V8HiddenPropertyName_h 55 } // namespace WebCore 56 57 #endif // CustomElementHelpers_h -
trunk/Source/WebCore/bindings/v8/V8DOMConfiguration.cpp
r141862 r143865 34 34 namespace WebCore { 35 35 36 const int prototypeInternalFieldcount = 1; 37 36 38 void V8DOMConfiguration::batchConfigureAttributes(v8::Handle<v8::ObjectTemplate> instance, v8::Handle<v8::ObjectTemplate> prototype, const BatchedAttribute* attributes, size_t attributeCount, v8::Isolate* isolate) 37 39 { … … 61 63 v8::Local<v8::ObjectTemplate> instance = functionDescriptor->InstanceTemplate(); 62 64 instance->SetInternalFieldCount(fieldCount); 63 if (!parentClass.IsEmpty()) 65 if (!parentClass.IsEmpty()) { 64 66 functionDescriptor->Inherit(parentClass); 67 // Marks the prototype object as one of native-backed objects. 68 // This is needed since bug 110436 asks WebKit to tell native-initiated prototypes from pure-JS ones. 69 // This doesn't mark kinds "root" classes like Node, where setting this changes prototype chain structure. 70 v8::Local<v8::ObjectTemplate> prototype = functionDescriptor->PrototypeTemplate(); 71 prototype->SetInternalFieldCount(prototypeInternalFieldcount); 72 } 73 65 74 if (attributeCount) 66 75 batchConfigureAttributes(instance, functionDescriptor->PrototypeTemplate(), attributes, attributeCount, isolate); -
trunk/Source/WebCore/bindings/v8/V8DOMWrapper.cpp
r142217 r143865 32 32 #include "V8DOMWrapper.h" 33 33 34 #include "V8AdaptorFunction.h" 34 35 #include "V8Binding.h" 35 36 #include "V8DOMWindow.h" … … 138 139 } 139 140 141 #if ENABLE(CUSTOM_ELEMENTS) 142 143 v8::Handle<v8::Function> V8DOMWrapper::toFunction(v8::Handle<v8::Value> object) 144 { 145 return V8AdaptorFunction::get(v8::Handle<v8::Object>::Cast(object)); 146 } 147 148 v8::Handle<v8::Function> V8DOMWrapper::toFunction(v8::Handle<v8::Object> object, const AtomicString& name, v8::Isolate* isolate) 149 { 150 return V8AdaptorFunction::wrap(object, name, isolate); 151 } 152 153 v8::Handle<v8::Object> V8DOMWrapper::fromFunction(v8::Handle<v8::Object> object) 154 { 155 if (!object->IsFunction()) 156 return object; 157 return V8AdaptorFunction::unwrap(v8::Handle<v8::Function>::Cast(object)); 158 } 159 160 #endif // ENABLE(CUSTOM_ELEMENTS) 161 140 162 } // namespace WebCore -
trunk/Source/WebCore/bindings/v8/V8DOMWrapper.h
r142217 r143865 63 63 static bool isDOMWrapper(v8::Handle<v8::Value>); 64 64 static bool isWrapperOfType(v8::Handle<v8::Value>, WrapperTypeInfo*); 65 66 #if ENABLE(CUSTOM_ELEMENTS) 67 // Used for V8WrapAsFunction, which is used only by CUSTOM_ELEMENTS 68 static v8::Handle<v8::Function> toFunction(v8::Handle<v8::Value>); 69 static v8::Handle<v8::Function> toFunction(v8::Handle<v8::Object>, const AtomicString& name, v8::Isolate*); 70 static v8::Handle<v8::Object> fromFunction(v8::Handle<v8::Object>); 71 #endif // ENABLE(CUSTOM_ELEMENTS) 65 72 }; 66 73 -
trunk/Source/WebCore/bindings/v8/V8HiddenPropertyName.h
r142226 r143865 46 46 V(sleepFunction) \ 47 47 V(state) \ 48 V(adaptorFunctionPeer) \ 48 49 V(toStringString) \ 49 50 V(typedArrayHiddenCopyMethod) -
trunk/Source/WebCore/dom/CustomElementConstructor.cpp
r143864 r143865 29 29 */ 30 30 31 #ifndef V8HiddenPropertyName_h 32 #define V8HiddenPropertyName_h 31 #include "config.h" 33 32 34 #include <v8.h> 33 #if ENABLE(CUSTOM_ELEMENTS) 34 35 #include "CustomElementConstructor.h" 36 37 #include "CustomElementHelpers.h" 38 #include "Document.h" 39 #include "HTMLElement.h" 40 #include <wtf/Assertions.h> 35 41 36 42 namespace WebCore { 37 43 38 #define V8_HIDDEN_PROPERTIES(V) \ 39 V(attributeListener) \ 40 V(callback) \ 41 V(detail) \ 42 V(document) \ 43 V(event) \ 44 V(listener) \ 45 V(scriptState) \ 46 V(sleepFunction) \ 47 V(state) \ 48 V(toStringString) \ 49 V(typedArrayHiddenCopyMethod) 44 PassRefPtr<CustomElementConstructor> CustomElementConstructor::create(ScriptState* state, Document* document, const QualifiedName& tagName, const String& name, const ScriptValue& prototype) 45 { 46 RefPtr<CustomElementConstructor> created = adoptRef(new CustomElementConstructor(document, tagName, name)); 47 if (!CustomElementHelpers::initializeConstructorWrapper(created.get(), prototype, state)) 48 return 0; 49 return created.release(); 50 } 50 51 51 class V8HiddenPropertyName { 52 public: 53 V8HiddenPropertyName() { }54 #define V8_DECLARE_PROPERTY(name) static v8::Handle<v8::String> name(); 55 V8_HIDDEN_PROPERTIES(V8_DECLARE_PROPERTY); 56 #undef V8_DECLARE_PROPERTY 52 CustomElementConstructor::CustomElementConstructor(Document* document, const QualifiedName& tagName, const String& name) 53 : ContextDestructionObserver(document) 54 , m_tagName(tagName) 55 , m_name(name) 56 { 57 } 57 58 58 static void setNamedHiddenReference(v8::Handle<v8::Object> parent, const char* name, v8::Handle<v8::Value> child); 59 CustomElementConstructor::~CustomElementConstructor() 60 { 61 } 59 62 60 private: 61 static v8::Persistent<v8::String> createString(const char* key); 62 #define V8_DECLARE_FIELD(name) v8::Persistent<v8::String> m_##name; 63 V8_HIDDEN_PROPERTIES(V8_DECLARE_FIELD);64 #undef V8_DECLARE_FIELD 65 } ;63 PassRefPtr<HTMLElement> CustomElementConstructor::createElement() const 64 { 65 if (!document()) 66 return 0; 67 return HTMLElement::create(m_tagName, document()); 68 } 66 69 67 70 } 68 71 69 #endif // V8HiddenPropertyName_h72 #endif // ENABLE(CUSTOM_ELEMENTS) -
trunk/Source/WebCore/dom/CustomElementConstructor.h
r143864 r143865 29 29 */ 30 30 31 #ifndef V8HiddenPropertyName_h32 #define V8HiddenPropertyName_h31 #ifndef CustomElementConstructor_h 32 #define CustomElementConstructor_h 33 33 34 #include <v8.h> 34 #if ENABLE(CUSTOM_ELEMENTS) 35 36 #include "ContextDestructionObserver.h" 37 #include "Document.h" 38 #include "QualifiedName.h" 39 #include <wtf/Forward.h> 40 #include <wtf/PassRefPtr.h> 41 #include <wtf/RefCounted.h> 42 #include <wtf/text/AtomicString.h> 35 43 36 44 namespace WebCore { 37 45 38 #define V8_HIDDEN_PROPERTIES(V) \ 39 V(attributeListener) \ 40 V(callback) \ 41 V(detail) \ 42 V(document) \ 43 V(event) \ 44 V(listener) \ 45 V(scriptState) \ 46 V(sleepFunction) \ 47 V(state) \ 48 V(toStringString) \ 49 V(typedArrayHiddenCopyMethod) 46 class Document; 47 class HTMLElement; 48 class ScriptState; 49 class ScriptValue; 50 50 51 class V8HiddenPropertyName{51 class CustomElementConstructor : public RefCounted<CustomElementConstructor> , public ContextDestructionObserver { 52 52 public: 53 V8HiddenPropertyName() { } 54 #define V8_DECLARE_PROPERTY(name) static v8::Handle<v8::String> name(); 55 V8_HIDDEN_PROPERTIES(V8_DECLARE_PROPERTY); 56 #undef V8_DECLARE_PROPERTY 53 static PassRefPtr<CustomElementConstructor> create(ScriptState*, Document*, const QualifiedName&, const String&, const ScriptValue&); 57 54 58 static void setNamedHiddenReference(v8::Handle<v8::Object> parent, const char* name, v8::Handle<v8::Value> child);55 virtual ~CustomElementConstructor(); 59 56 57 Document* document() const { return static_cast<Document*>(m_scriptExecutionContext); } 58 const QualifiedName& tagName() const { return m_tagName; } 59 const AtomicString& name() const { return m_name; } 60 61 PassRefPtr<HTMLElement> createElement() const; 62 60 63 private: 61 static v8::Persistent<v8::String> createString(const char* key);62 #define V8_DECLARE_FIELD(name) v8::Persistent<v8::String> m_##name; 63 V8_HIDDEN_PROPERTIES(V8_DECLARE_FIELD);64 #undef V8_DECLARE_FIELD 64 CustomElementConstructor(Document*, const QualifiedName&, const String&); 65 66 QualifiedName m_tagName; 67 AtomicString m_name; 65 68 }; 66 69 67 70 } 68 71 69 #endif // V8HiddenPropertyName_h 72 #endif // ENABLE(CUSTOM_ELEMENTS) 73 74 #endif // CustomElementConstructor_h -
trunk/Source/WebCore/dom/Document.cpp
r143840 r143865 47 47 #include "ContextFeatures.h" 48 48 #include "CookieJar.h" 49 #include "CustomElementConstructor.h" 50 #include "CustomElementRegistry.h" 49 51 #include "DOMImplementation.h" 50 52 #include "DOMNamedFlowCollection.h" … … 52 54 #include "DOMWindow.h" 53 55 #include "DateComponents.h" 56 #include "Dictionary.h" 54 57 #include "DocumentEventQueue.h" 55 58 #include "DocumentFragment.h" … … 670 673 detachParser(); 671 674 675 #if ENABLE(CUSTOM_ELEMENTS) 676 m_registry.clear(); 677 #endif 678 672 679 // removeDetachedChildren() doesn't always unregister IDs, 673 680 // so tear down scope information upfront to avoid having stale references in the map. … … 823 830 return createElement(QualifiedName(nullAtom, name, nullAtom), false); 824 831 } 832 833 #if ENABLE(CUSTOM_ELEMENTS) 834 PassRefPtr<CustomElementConstructor> Document::registerElement(WebCore::ScriptState* state, const AtomicString& name, ExceptionCode& ec) 835 { 836 return registerElement(state, name, Dictionary(), ec); 837 } 838 839 PassRefPtr<CustomElementConstructor> Document::registerElement(WebCore::ScriptState* state, const AtomicString& name, const Dictionary& options, ExceptionCode& ec) 840 { 841 if (!m_registry) 842 m_registry = adoptRef(new CustomElementRegistry(this)); 843 return m_registry->registerElement(state, name, options, ec); 844 } 845 846 PassRefPtr<CustomElementRegistry> Document::registry() const 847 { 848 return m_registry; 849 } 850 #endif // ENABLE(CUSTOM_ELEMENTS) 825 851 826 852 PassRefPtr<DocumentFragment> Document::createDocumentFragment() -
trunk/Source/WebCore/dom/Document.h
r143840 r143865 72 72 class Comment; 73 73 class ContextFeatures; 74 class CustomElementConstructor; 75 class CustomElementRegistry; 74 76 class DOMImplementation; 75 77 class DOMNamedFlowCollection; … … 1143 1145 #endif 1144 1146 1147 #if ENABLE(CUSTOM_ELEMENTS) 1148 PassRefPtr<CustomElementConstructor> registerElement(WebCore::ScriptState*, const AtomicString& name, ExceptionCode&); 1149 PassRefPtr<CustomElementConstructor> registerElement(WebCore::ScriptState*, const AtomicString& name, const Dictionary& options, ExceptionCode&); 1150 PassRefPtr<CustomElementRegistry> registry() const; 1151 #endif 1152 1145 1153 void adjustFloatQuadsForScrollAndAbsoluteZoomAndFrameScale(Vector<FloatQuad>&, RenderObject*); 1146 1154 void adjustFloatRectForScrollAndAbsoluteZoomAndFrameScale(FloatRect&, RenderObject*); … … 1519 1527 #endif 1520 1528 1529 #if ENABLE(CUSTOM_ELEMENTS) 1530 RefPtr<CustomElementRegistry> m_registry; 1531 #endif 1532 1521 1533 bool m_scheduledTasksAreSuspended; 1522 1534 -
trunk/Source/WebCore/dom/make_names.pl
r143398 r143865 1173 1173 } elsif ($wrapperFactoryType eq "V8") { 1174 1174 print F <<END 1175 #include "V8HTMLCustomElement.h" 1175 1176 #include "V8$parameters{namespace}Element.h" 1176 1177 1177 1178 #include <v8.h> 1178 1179 END … … 1273 1274 print F <<END 1274 1275 return V8SVGElement::createWrapper(element, creationContext, isolate); 1276 END 1277 ; 1278 } elsif ($parameters{namespace} eq "HTML") { 1279 print F <<END 1280 return V8HTMLCustomElement::wrap(element, creationContext, isolate); 1275 1281 END 1276 1282 ; -
trunk/Source/WebCore/html/HTMLDocument.idl
r141034 r143865 54 54 boolean hasFocus(); 55 55 56 #if defined(ENABLE_CUSTOM_ELEMENTS) && ENABLE_CUSTOM_ELEMENTS 57 [V8EnabledAtRuntime=customDOMElements, Conditional=CUSTOM_ELEMENTS, ImplementedAs=registerElement, CallWith=ScriptState] 58 CustomElementConstructor webkitRegister(in DOMString name, in [Optional] Dictionary options) raises(DOMException); 59 #endif 60 56 61 // Deprecated attributes 57 62 [TreatNullAs=NullString] attribute DOMString bgColor; -
trunk/Source/WebKit/chromium/ChangeLog
r143846 r143865 1 2013-02-24 Hajime Morrita <morrita@google.com> 2 3 [Custom Elements] Implement bare-bone document.register() 4 https://bugs.webkit.org/show_bug.cgi?id=100229 5 6 Reviewed by Adam Barth. 7 8 Added enableCustomDOMElements flag. 9 10 * features.gypi: 11 * public/WebRuntimeFeatures.h: 12 (WebRuntimeFeatures): 13 * src/WebRuntimeFeatures.cpp: 14 (WebKit::WebRuntimeFeatures::enableCustomDOMElements): 15 (WebKit): 16 (WebKit::WebRuntimeFeatures::isCustomDOMElementsEnabled): 17 1 18 2013-02-23 Mark Pilgrim <pilgrim@chromium.org> 2 19 -
trunk/Source/WebKit/chromium/features.gypi
r143511 r143865 55 55 'ENABLE_CSS_VARIABLES=1', 56 56 'ENABLE_CSS_STICKY_POSITION=1', 57 'ENABLE_CUSTOM_ELEMENTS=1', 57 58 'ENABLE_CUSTOM_SCHEME_HANDLER=0', 58 59 'ENABLE_DASHBOARD_SUPPORT=0', -
trunk/Source/WebKit/chromium/public/WebRuntimeFeatures.h
r143502 r143865 126 126 WEBKIT_EXPORT static bool isShadowDOMEnabled(); 127 127 128 WEBKIT_EXPORT static void enableCustomDOMElements(bool); 129 WEBKIT_EXPORT static bool isCustomDOMElementsEnabled(); 130 128 131 WEBKIT_EXPORT static void enableStyleScoped(bool); 129 132 WEBKIT_EXPORT static bool isStyleScopedEnabled(); -
trunk/Source/WebKit/chromium/src/WebRuntimeFeatures.cpp
r143502 r143865 482 482 } 483 483 484 void WebRuntimeFeatures::enableCustomDOMElements(bool enable) 485 { 486 #if ENABLE(CUSTOM_ELEMENTS) 487 RuntimeEnabledFeatures::setCustomDOMElements(enable); 488 #else 489 UNUSED_PARAM(enable); 490 #endif 491 } 492 493 bool WebRuntimeFeatures::isCustomDOMElementsEnabled() 494 { 495 #if ENABLE(CUSTOM_ELEMENTS) 496 return RuntimeEnabledFeatures::customDOMElementsEnabled(); 497 #else 498 return false; 499 #endif 500 } 501 502 484 503 void WebRuntimeFeatures::enableStyleScoped(bool enable) 485 504 { -
trunk/Tools/ChangeLog
r143852 r143865 1 2013-02-24 Hajime Morrita <morrita@google.com> 2 3 [Custom Elements] Implement bare-bone document.register() 4 https://bugs.webkit.org/show_bug.cgi?id=100229 5 6 Reviewed by Adam Barth. 7 8 Added enableCustomDOMElements flag. 9 10 * DumpRenderTree/chromium/TestShell.cpp: 11 (TestShell::TestShell): 12 1 13 2013-02-23 Mark Pilgrim <pilgrim@chromium.org> 2 14 -
trunk/Tools/DumpRenderTree/chromium/TestShell.cpp
r143852 r143865 146 146 WebRuntimeFeatures::enableGamepad(true); 147 147 WebRuntimeFeatures::enableShadowDOM(true); 148 WebRuntimeFeatures::enableCustomDOMElements(true); 148 149 WebRuntimeFeatures::enableStyleScoped(true); 149 150 WebRuntimeFeatures::enableScriptedSpeech(true);
Note: See TracChangeset
for help on using the changeset viewer.