Source/WebCore/ChangeLog

 12013-01-29 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 NOBODY (OOPS!).
 7
 8 This change implements 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" parameter and ignores any other optional parameters.
 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 has 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
 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 Fiction] <-(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 take 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 Although this first version doesn't support the optional prototype
 67 parameter yet, V8HTMLCustomElement class is made for a plumbing
 68 for supporting such features in coming changes. This class
 69 encapsulates JS wrapper object creation for custom element
 70 instances. For example, it takes care of prototype chain setup. As
 71 we support the "prototype" optional parameter for document.register(),
 72 this plumbing will be extended.
 73
 74 = Custom DOM elements and multiple worlds
 75
 76 In this patch, custom element registration and instantiation is not allowed
 77 in non-main world and document.register() API just fails there.
 78
 79 Test: fast/dom/custom/document-register-basic.html
 80
 81 * DerivedSources.make:
 82 * WebCore.gypi:
 83 * bindings/generic/RuntimeEnabledFeatures.cpp:
 84 * bindings/generic/RuntimeEnabledFeatures.h:
 85 (RuntimeEnabledFeatures):
 86 (WebCore::RuntimeEnabledFeatures::customDOMElementsEnabled):
 87 (WebCore::RuntimeEnabledFeatures::setCustomDOMElements):
 88 * bindings/scripts/CodeGeneratorV8.pm:
 89 (GenerateHeader):
 90 * bindings/scripts/IDLAttributes.txt:
 91 * bindings/v8/CustomElementHelpers.cpp: Added.
 92 (WebCore::CustomElementHelpers::initializeConstructorWrapper):
 93 (WebCore::CustomElementHelpers::defaultPrototypeOf):
 94 (WebCore::CustomElementHelpers::isCustomElementsAllowed):
 95 * bindings/v8/CustomElementHelpers.h: Copied from Source/WebCore/bindings/v8/V8HiddenPropertyName.h.
 96 (CustomElementHelpers):
 97 * bindings/v8/V8AdaptorFunction.cpp: Added.
 98 (WebCore::V8AdaptorFunction::getTemplate):
 99 (WebCore::V8AdaptorFunction::configureTemplate):
 100 (WebCore::V8AdaptorFunction::invocationCallback):
 101 (WebCore::V8AdaptorFunction::wrap):
 102 * bindings/v8/V8AdaptorFunction.h: Added.
 103 (V8AdaptorFunction):
 104 (WebCore::V8AdaptorFunction::unwrap):
 105 (WebCore::V8AdaptorFunction::get):
 106 * bindings/v8/V8DOMWrapper.cpp:
 107 (WebCore::V8DOMWrapper::toFunction):
 108 (WebCore::V8DOMWrapper::fromFunction):
 109 * bindings/v8/V8DOMWrapper.h:
 110 (V8DOMWrapper):
 111 * bindings/v8/V8HTMLCustomElement.cpp: Added.
 112 (WebCore::V8HTMLCustomElement::createWrapper):
 113 * bindings/v8/V8HTMLCustomElement.h: Copied from Source/WebCore/bindings/v8/V8HiddenPropertyName.h.
 114 (V8HTMLCustomElement):
 115 (WebCore::V8HTMLCustomElement::toV8):
 116 (WebCore::HTMLCustomElement::toV8):
 117 * bindings/v8/V8HiddenPropertyName.h:
 118 * bindings/v8/custom/V8CustomElementConstructorCustom.cpp: Added.
 119 (WebCore::V8CustomElementConstructor::callAsFunctionCallback):
 120 * dom/CustomElementConstructor.cpp: Copied from Source/WebCore/bindings/v8/V8HiddenPropertyName.h.
 121 (WebCore::CustomElementConstructor::create):
 122 (WebCore::CustomElementConstructor::CustomElementConstructor):
 123 (WebCore::CustomElementConstructor::~CustomElementConstructor):
 124 (WebCore::CustomElementConstructor::willDestroyDocument):
 125 (WebCore::CustomElementConstructor::createElement):
 126 * dom/CustomElementConstructor.h: Copied from Source/WebCore/bindings/v8/V8HiddenPropertyName.h.
 127 (CustomElementConstructor):
 128 (WebCore::CustomElementConstructor::document):
 129 (WebCore::CustomElementConstructor::tagName):
 130 (WebCore::CustomElementConstructor::name):
 131 * dom/CustomElementConstructor.idl: Added.
 132 * dom/CustomElementRegistry.cpp: Added.
 133 (WebCore::CustomElementRegistry::CustomElementRegistry):
 134 (WebCore::CustomElementRegistry::~CustomElementRegistry):
 135 (WebCore::CustomElementRegistry::constructorOf):
 136 (WebCore::CustomElementRegistry::isValidName):
 137 (WebCore::CustomElementRegistry::registerElement):
 138 (WebCore::CustomElementRegistry::find):
 139 (WebCore::CustomElementRegistry::createElement):
 140 * dom/CustomElementRegistry.h: Added.
 141 (CustomElementRegistry):
 142 * dom/Document.cpp:
 143 (WebCore::Document::removedLastRef):
 144 (WebCore::Document::registerElement):
 145 * dom/Document.h:
 146 (WebCore::Document::registry):
 147 * dom/make_names.pl:
 148 (printWrapperFactoryCppFile):
 149 * html/HTMLDocument.idl:
 150
11512013-01-29 James Robinson <jamesr@chromium.org>
2152
3153 Scrollbar and scroll corner composited layers positioned incorrectly

Source/WebKit/chromium/ChangeLog

 12013-01-27 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 NOBODY (OOPS!).
 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
1182013-01-29 Mark Lam <mark.lam@apple.com>
219
320 Rename AbstractDatabase to DatabaseBackend.

Source/WebCore/DerivedSources.make

@@BINDING_IDLS = \
214214 $(WebCore)/dom/Clipboard.idl \
215215 $(WebCore)/dom/Comment.idl \
216216 $(WebCore)/dom/CompositionEvent.idl \
 217 $(WebCore)/dom/CustomElementConstructor.idl \
217218 $(WebCore)/dom/CustomEvent.idl \
218219 $(WebCore)/dom/DOMCoreException.idl \
219220 $(WebCore)/dom/DOMError.idl \

Source/WebCore/WebCore.gypi

203203 'dom/Clipboard.idl',
204204 'dom/Comment.idl',
205205 'dom/CompositionEvent.idl',
 206 'dom/CustomElementConstructor.idl',
206207 'dom/CustomEvent.idl',
207208 'dom/DOMCoreException.idl',
208209 'dom/DOMError.idl',

11761177 'bindings/v8/ArrayValue.h',
11771178 'bindings/v8/BindingState.cpp',
11781179 'bindings/v8/BindingState.h',
 1180 'bindings/v8/CustomElementHelpers.cpp',
 1181 'bindings/v8/CustomElementHelpers.h',
11791182 'bindings/v8/DOMDataStore.cpp',
11801183 'bindings/v8/DOMDataStore.h',
11811184 'bindings/v8/DOMRequestState.h',

12441247 'bindings/v8/SharedPersistent.h',
12451248 'bindings/v8/V8AbstractEventListener.cpp',
12461249 'bindings/v8/V8AbstractEventListener.h',
 1250 'bindings/v8/V8AdaptorFunction.cpp',
 1251 'bindings/v8/V8AdaptorFunction.h',
12471252 'bindings/v8/V8Binding.cpp',
12481253 'bindings/v8/V8Binding.h',
12491254 'bindings/v8/V8BindingMacros.h',

12651270 'bindings/v8/V8GCController.h',
12661271 'bindings/v8/V8GCForContextDispose.cpp',
12671272 'bindings/v8/V8GCForContextDispose.h',
 1273 'bindings/v8/V8HTMLCustomElement.cpp',
 1274 'bindings/v8/V8HTMLCustomElement.h',
12681275 'bindings/v8/V8HiddenPropertyName.cpp',
12691276 'bindings/v8/V8HiddenPropertyName.h',
12701277 'bindings/v8/V8Initializer.cpp',

13251332 'bindings/v8/custom/V8ConsoleCustom.cpp',
13261333 'bindings/v8/custom/V8CoordinatesCustom.cpp',
13271334 'bindings/v8/custom/V8CryptoCustom.cpp',
 1335 'bindings/v8/custom/V8CustomElementConstructorCustom.cpp',
13281336 'bindings/v8/custom/V8CustomEventCustom.cpp',
13291337 'bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp',
13301338 'bindings/v8/custom/V8CustomXPathNSResolver.cpp',

27502758 'dom/ContextFeatures.cpp',
27512759 'dom/ContextFeatures.h',
27522760 'dom/CrossThreadTask.h',
 2761 'dom/CustomElementConstructor.cpp',
 2762 'dom/CustomElementConstructor.h',
 2763 'dom/CustomElementRegistry.cpp',
 2764 'dom/CustomElementRegistry.h',
27532765 'dom/CustomEvent.cpp',
27542766 'dom/CustomEvent.h',
27552767 'dom/DOMAllInOne.cpp',

Source/WebCore/bindings/generic/RuntimeEnabledFeatures.cpp

@@bool RuntimeEnabledFeatures::isShadowDOMEnabled = false;
189189bool RuntimeEnabledFeatures::isAuthorShadowDOMForAnyElementEnabled = false;
190190#endif
191191
 192#if ENABLE(CUSTOM_ELEMENTS)
 193bool RuntimeEnabledFeatures::isCustomDOMElementsEnabled = false;
 194#endif
 195
192196#if ENABLE(STYLE_SCOPED)
193197bool RuntimeEnabledFeatures::isStyleScopedEnabled = false;
194198#endif

Source/WebCore/bindings/generic/RuntimeEnabledFeatures.h

@@public:
210210 static void setAuthorShadowDOMForAnyElementEnabled(bool isEnabled) { isAuthorShadowDOMForAnyElementEnabled = isEnabled; }
211211#endif
212212
 213#if ENABLE(CUSTOM_ELEMENTS)
 214 static bool customDOMElementsEnabled() { return isCustomDOMElementsEnabled; }
 215 static void setCustomDOMElements(bool isEnabled) { isCustomDOMElementsEnabled = isEnabled; }
 216#endif
 217
213218#if ENABLE(STYLE_SCOPED)
214219 static bool styleScopedEnabled() { return isStyleScopedEnabled; }
215220 static void setStyleScopedEnabled(bool isEnabled) { isStyleScopedEnabled = isEnabled; }

@@private:
341346 static bool isAuthorShadowDOMForAnyElementEnabled;
342347#endif
343348
 349#if ENABLE(CUSTOM_ELEMENTS)
 350 static bool isCustomDOMElementsEnabled;
 351#endif
 352
344353#if ENABLE(STYLE_SCOPED)
345354 static bool isStyleScopedEnabled;
346355#endif

Source/WebCore/bindings/scripts/CodeGeneratorV8.pm

@@END
352352 push(@headerContent, "false;\n");
353353 }
354354
 355 my $fromFunctionOpening = "";
 356 my $fromFunctionClosing = "";
 357 if ($interface->extendedAttributes->{"V8WrapAsFunction"}) {
 358 $fromFunctionOpening = "V8DOMWrapper::fromFunction(";
 359 $fromFunctionClosing = ")";
 360 }
 361
355362 push(@headerContent, <<END);
356363 static bool HasInstance(v8::Handle<v8::Value>);
357364 static v8::Persistent<v8::FunctionTemplate> GetRawTemplate(v8::Isolate* = 0);
358365 static v8::Persistent<v8::FunctionTemplate> GetTemplate(v8::Isolate* = 0);
359366 static ${nativeType}* toNative(v8::Handle<v8::Object> object)
360367 {
361  return reinterpret_cast<${nativeType}*>(object->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex));
 368 return reinterpret_cast<${nativeType}*>(${fromFunctionOpening}object${fromFunctionClosing}->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex));
362369 }
363370 static void derefObject(void*);
364371 static WrapperTypeInfo info;

@@END
543550 } else {
544551
545552 my $createWrapperCall = $customWrap ? "${v8InterfaceName}::wrap" : "${v8InterfaceName}::createWrapper";
 553 my $returningWrapper = $interface->extendedAttributes->{"V8WrapAsFunction"} ? "V8DOMWrapper::toFunction(wrapper)" : "wrapper";
 554 my $returningCreatedWrapperOpening = $interface->extendedAttributes->{"V8WrapAsFunction"} ? "V8DOMWrapper::toFunction(" : "";
 555 my $returningCreatedWrapperClosing = $interface->extendedAttributes->{"V8WrapAsFunction"} ? ", impl->name(), isolate)" : "";
546556
547557 if ($customWrap) {
548558 push(@headerContent, <<END);

@@inline v8::Handle<v8::Object> wrap(${nativeType}* impl, v8::Handle<v8::Object> c
556566{
557567 ASSERT(impl);
558568 ASSERT(DOMDataStore::getWrapper(impl, isolate).IsEmpty());
559  return $createWrapperCall(impl, creationContext, isolate);
 569 return ${returningCreatedWrapperOpening}$createWrapperCall(impl, creationContext, isolate)${returningCreatedWrapperClosing};
560570}
561571END
562572 }

@@inline v8::Handle<v8::Value> toV8(${nativeType}* impl, v8::Handle<v8::Object> cr
569579 return v8NullWithCheck(isolate);
570580 v8::Handle<v8::Value> wrapper = DOMDataStore::getWrapper(impl, isolate);
571581 if (!wrapper.IsEmpty())
572  return wrapper;
 582 return $returningWrapper;
573583 return wrap(impl, creationContext, isolate);
574584}
575585

@@inline v8::Handle<v8::Value> toV8Fast(${nativeType}* impl, const HolderContainer
580590 return v8Null(container.GetIsolate());
581591 v8::Handle<v8::Object> wrapper = DOMDataStore::getWrapperFast(impl, container, wrappable);
582592 if (!wrapper.IsEmpty())
583  return wrapper;
 593 return $returningWrapper;
584594 return wrap(impl, container.Holder(), container.GetIsolate());
585595}
586596END

Source/WebCore/bindings/scripts/IDLAttributes.txt

@@V8MeasureAs=*
129129V8ReadOnly
130130V8SkipVTableValidation
131131V8Unforgeable
 132V8WrapAsFunction

Source/WebCore/bindings/v8/CustomElementHelpers.cpp

 1/*
 2 * Copyright (C) 2012 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 "CustomElementHelpers.h"
 33
 34#include "DOMWrapperWorld.h"
 35#include "V8CustomElementConstructor.h"
 36
 37namespace WebCore {
 38
 39#if ENABLE(CUSTOM_ELEMENTS)
 40
 41void CustomElementHelpers::initializeConstructorWrapper(CustomElementConstructor* constructor, const ScriptValue& prototype, ScriptState* state)
 42{
 43 ASSERT(isCustomElementsAllowed(state));
 44
 45 v8::Handle<v8::Object> wrapper = v8::Handle<v8::Object>::Cast(WebCore::toV8(constructor, state->context()->Global(), state->context()->GetIsolate()));
 46 v8::Handle<v8::Value> prototypeValue = prototype.v8Value();
 47 if (!prototypeValue.IsEmpty() && prototypeValue->IsObject())
 48 wrapper->Set(v8String("prototype", state->context()->GetIsolate()), prototypeValue, v8::ReadOnly);
 49}
 50
 51ScriptValue CustomElementHelpers::defaultPrototypeOf(ScriptState* state)
 52{
 53 ASSERT(isCustomElementsAllowed(state));
 54
 55 v8::Handle<v8::Object> global = state->context()->Global();
 56 v8::Isolate* isolate = state->context()->GetIsolate();
 57 v8::Handle<v8::Value> interfaceObject = global->Get(v8String("HTMLSpanElement", isolate));
 58 if (interfaceObject.IsEmpty() || !interfaceObject->IsObject())
 59 return ScriptValue();
 60 v8::Handle<v8::Value> prototype = v8::Handle<v8::Object>::Cast(interfaceObject)->Get(v8String("prototype", isolate));
 61 if (prototype.IsEmpty() || !prototype->IsObject())
 62 return ScriptValue();
 63 return ScriptValue(prototype);
 64};
 65
 66bool CustomElementHelpers::isCustomElementsAllowed(ScriptState* state)
 67{
 68 return isCustomElementsAllowed(state->context());
 69}
 70
 71bool CustomElementHelpers::isCustomElementsAllowed(v8::Handle<v8::Context> context)
 72{
 73 return !DOMWrapperWorld::isolated(context);
 74}
 75
 76
 77#endif // ENABLE(CUSTOM_ELEMENTS)
 78
 79} // namespace WebCore

Source/WebCore/bindings/v8/CustomElementHelpers.h

 1/*
 2 * Copyright (C) 2012 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#ifndef CustomElementHelpers_h
 32#define CustomElementHelpers_h
 33
 34#include "ScriptValue.h"
 35
 36namespace WebCore {
 37
 38#if ENABLE(CUSTOM_ELEMENTS)
 39
 40class CustomElementConstructor;
 41class ScriptState;
 42
 43class CustomElementHelpers {
 44public:
 45 static void initializeConstructorWrapper(CustomElementConstructor*, const ScriptValue&, ScriptState*);
 46 static bool isCustomElementsAllowed(ScriptState*);
 47 static ScriptValue defaultPrototypeOf(ScriptState*);
 48
 49 static bool isCustomElementsAllowed(v8::Handle<v8::Context>);
 50};
 51
 52#endif // ENABLE(CUSTOM_ELEMENTS)
 53
 54} // namespace WebCore
 55
 56#endif // CustomElementHelpers_h

Source/WebCore/bindings/v8/V8AdaptorFunction.cpp

 1/*
 2 * Copyright (C) 2012 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 "V8AdaptorFunction.h"
 33
 34#include "V8PerIsolateData.h"
 35#include <wtf/Vector.h>
 36
 37#if ENABLE(CUSTOM_ELEMENTS)
 38
 39namespace WebCore {
 40
 41WrapperTypeInfo V8AdaptorFunction::info = { V8AdaptorFunction::getTemplate, 0, 0, 0, 0, 0, 0, WrapperTypeObjectPrototype };
 42
 43v8::Persistent<v8::FunctionTemplate> V8AdaptorFunction::getTemplate(v8::Isolate* isolate)
 44{
 45 if (!isolate)
 46 isolate = v8::Isolate::GetCurrent();
 47 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
 48 V8PerIsolateData::TemplateMap::iterator result = data->rawTemplateMap().find(&info);
 49 if (result != data->rawTemplateMap().end())
 50 return result->value;
 51 v8::Persistent<v8::FunctionTemplate> newTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New());
 52 data->rawTemplateMap().add(&info, configureTemplate(newTemplate));
 53 return newTemplate;
 54}
 55
 56v8::Persistent<v8::FunctionTemplate> V8AdaptorFunction::configureTemplate(v8::Persistent<v8::FunctionTemplate> functionTemplate)
 57{
 58 functionTemplate->SetCallHandler(&V8AdaptorFunction::invocationCallback);
 59 return functionTemplate;
 60}
 61
 62v8::Handle<v8::Value> V8AdaptorFunction::invocationCallback(const v8::Arguments& args)
 63{
 64 v8::Handle<v8::Object> wrapped = v8::Handle<v8::Object>::Cast(args.Callee()->GetHiddenValue(V8HiddenPropertyName::adaptorFunctionPeer()));
 65 // FIXME: This can be faster if we can access underlying native callback directly.
 66 // We won't need this once https://bugs.webkit.org/show_bug.cgi?id=108138 is addressed.
 67 Vector<v8::Handle<v8::Value> > argArray(args.Length());
 68 for (int i = 0; i < args.Length(); ++i)
 69 argArray.append(args[i]);
 70 if (args.IsConstructCall())
 71 return wrapped->CallAsConstructor(argArray.size(), argArray.data());
 72 return wrapped->CallAsFunction(args.This(), argArray.size(), argArray.data());
 73}
 74
 75v8::Handle<v8::Function> V8AdaptorFunction::wrap(v8::Handle<v8::Object> object, const AtomicString& name, v8::Isolate* isolate)
 76{
 77 v8::Handle<v8::Function> adaptor = v8::Handle<v8::Function>::Cast(getTemplate(isolate)->GetFunction());
 78 adaptor->SetName(v8String(name.string(), isolate));
 79 adaptor->SetHiddenValue(V8HiddenPropertyName::adaptorFunctionPeer(), object);
 80 object->SetHiddenValue(V8HiddenPropertyName::adaptorFunctionPeer(), adaptor);
 81 return adaptor;
 82}
 83
 84} // namespace WebCore
 85
 86#endif // ENABLE(CUSTOM_ELEMENTS)

Source/WebCore/bindings/v8/V8AdaptorFunction.h

 1/*
 2 * Copyright (C) 2012 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#ifndef V8AdaptorFunction_h
 32#define V8AdaptorFunction_h
 33
 34#include "V8Binding.h"
 35#include "V8HiddenPropertyName.h"
 36#include "WrapperTypeInfo.h"
 37#include <wtf/PassRefPtr.h>
 38
 39#if ENABLE(CUSTOM_ELEMENTS)
 40
 41namespace WebCore {
 42
 43//
 44// FIXME(https://bugs.webkit.org/show_bug.cgi?id=108138):
 45// V8AdaptorFunction class and V8WrapAsFunction IDL attribute are needed for two reasons:
 46// - 1) V8 doesn't allow expanding the internal field of function objects. https://code.google.com/p/v8/issues/detail?id=837
 47// WebKit need it to associate each wrapper to its backing C++ object. We store it in an internal field of the wrapped object.
 48// - 2) Binding codebase assumes every wrapper object is created through ObjectTemplate::NewInstance(), not FunctionTemplate::GetFunction().
 49// Once 1) is addresssed, we could attack 2) with it.
 50//
 51class V8AdaptorFunction {
 52public:
 53 static WrapperTypeInfo info;
 54 static v8::Handle<v8::Object> unwrap(v8::Handle<v8::Function>);
 55 static v8::Handle<v8::Function> wrap(v8::Handle<v8::Object>, const AtomicString& name, v8::Isolate*);
 56 static v8::Handle<v8::Function> get(v8::Handle<v8::Object>);
 57
 58 static v8::Persistent<v8::FunctionTemplate> getTemplate(v8::Isolate* = 0);
 59 static v8::Persistent<v8::FunctionTemplate> configureTemplate(v8::Persistent<v8::FunctionTemplate>);
 60 static v8::Handle<v8::Value> invocationCallback(const v8::Arguments&);
 61};
 62
 63inline v8::Handle<v8::Object> V8AdaptorFunction::unwrap(v8::Handle<v8::Function> function)
 64{
 65 v8::Handle<v8::Value> wrapped = function->GetHiddenValue(V8HiddenPropertyName::adaptorFunctionPeer());
 66 ASSERT(!wrapped.IsEmpty());
 67 ASSERT(wrapped->IsObject());
 68 return v8::Handle<v8::Object>::Cast(wrapped);
 69}
 70
 71inline v8::Handle<v8::Function> V8AdaptorFunction::get(v8::Handle<v8::Object> object)
 72{
 73 v8::Handle<v8::Value> adaptorFunction = object->GetHiddenValue(V8HiddenPropertyName::adaptorFunctionPeer());
 74 ASSERT(!adaptorFunction.IsEmpty());
 75 ASSERT(adaptorFunction->IsFunction());
 76 return v8::Handle<v8::Function>::Cast(adaptorFunction);
 77}
 78
 79} // namespace WebCore
 80
 81#endif // ENABLE(CUSTOM_ELEMENTS)
 82#endif // V8AdaptorFunction_h

Source/WebCore/bindings/v8/V8DOMWrapper.cpp

3131#include "config.h"
3232#include "V8DOMWrapper.h"
3333
 34#include "V8AdaptorFunction.h"
3435#include "V8Binding.h"
3536#include "V8DOMWindow.h"
3637#include "V8HTMLCollection.h"

@@bool V8DOMWrapper::isWrapperOfType(v8::Handle<v8::Value> value, WrapperTypeInfo*
143144 return typeInfo == type;
144145}
145146
 147#if ENABLE(CUSTOM_ELEMENTS)
 148
 149v8::Handle<v8::Function> V8DOMWrapper::toFunction(v8::Handle<v8::Value> object)
 150{
 151 return V8AdaptorFunction::get(v8::Handle<v8::Object>::Cast(object));
 152}
 153
 154v8::Handle<v8::Function> V8DOMWrapper::toFunction(v8::Handle<v8::Object> object, AtomicString name, v8::Isolate* isolate)
 155{
 156 return V8AdaptorFunction::wrap(object, name, isolate);
 157}
 158
 159v8::Handle<v8::Object> V8DOMWrapper::fromFunction(v8::Handle<v8::Object> object)
 160{
 161 if (!object->IsFunction())
 162 return object;
 163 return V8AdaptorFunction::unwrap(v8::Handle<v8::Function>::Cast(object));
 164}
 165
 166#endif // ENABLE(CUSTOM_ELEMENTS)
 167
146168} // namespace WebCore

Source/WebCore/bindings/v8/V8DOMWrapper.h

@@namespace WebCore {
6565 static bool isDOMWrapper(v8::Handle<v8::Value>);
6666 static bool isWrapperOfType(v8::Handle<v8::Value>, WrapperTypeInfo*);
6767
 68#if ENABLE(CUSTOM_ELEMENTS)
 69 // Used for V8WrapAsFunction, which is used only by CUSTOM_ELEMENTS
 70 static v8::Handle<v8::Function> toFunction(v8::Handle<v8::Value>);
 71 static v8::Handle<v8::Function> toFunction(v8::Handle<v8::Object>, AtomicString name, v8::Isolate*);
 72 static v8::Handle<v8::Object> fromFunction(v8::Handle<v8::Object>);
 73#endif // ENABLE(CUSTOM_ELEMENTS)
 74
6875 // FIXME: Why is this function in V8DOMWrapper?
6976 static void setNamedHiddenReference(v8::Handle<v8::Object> parent, const char* name, v8::Handle<v8::Value> child);
7077 };

Source/WebCore/bindings/v8/V8HTMLCustomElement.cpp

 1/*
 2 * Copyright (C) 2012 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 "V8HTMLCustomElement.h"
 33
 34#include "CustomElementHelpers.h"
 35#include "CustomElementRegistry.h"
 36#include "HTMLElement.h"
 37#include "V8CustomElementConstructor.h"
 38#include "V8HTMLSpanElement.h"
 39
 40namespace WebCore {
 41
 42#if ENABLE(CUSTOM_ELEMENTS)
 43
 44// FIXME: Each custom elements should have its own GetTemplate method so that it can be derived from different super element.
 45WrapperTypeInfo V8HTMLCustomElement::info = { &V8HTMLSpanElement::GetTemplate, V8HTMLElement::derefObject, 0, 0, 0, 0, &V8HTMLSpanElement::info, WrapperTypeObjectPrototype };
 46
 47v8::Handle<v8::Object> V8HTMLCustomElement::createWrapper(PassRefPtr<HTMLElement> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
 48{
 49 ASSERT(impl);
 50
 51 CustomElementConstructor* constructor = CustomElementRegistry::constructorOf(impl.get());
 52 if (!constructor)
 53 return v8::Handle<v8::Object>::Cast(WebCore::toV8(toHTMLUnknownElement(impl.get()), creationContext, isolate));
 54
 55 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &info, impl.get());
 56 if (wrapper.IsEmpty())
 57 return wrapper;
 58
 59 // The constructor and registered lifecycle callbacks should be visible only from main world.
 60 // FIXME: This shouldn't be needed once each custom element has its own FunctionTemplate
 61 // https://bugs.webkit.org/show_bug.cgi?id=108138
 62 if (CustomElementHelpers::isCustomElementsAllowed(creationContext->CreationContext())) {
 63 v8::Handle<v8::Object> constructorWapper = v8::Handle<v8::Object>::Cast(WebCore::toV8(constructor, creationContext, isolate));
 64 wrapper->SetPrototype(constructorWapper->Get(v8String("prototype", isolate)));
 65 wrapper->Set(v8String("constructor", isolate), constructorWapper);
 66 }
 67
 68 V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate);
 69
 70 return wrapper;
 71}
 72
 73#endif // ENABLE(CUSTOM_ELEMENTS)
 74
 75} // namespace WebCore

Source/WebCore/bindings/v8/V8HTMLCustomElement.h

 1/*
 2 * Copyright (C) 2012 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#ifndef V8HTMLCustomElement_h
 32#define V8HTMLCustomElement_h
 33
 34#include "V8Binding.h"
 35#include "V8DOMWrapper.h"
 36#include "V8HTMLElement.h"
 37#include "V8HTMLUnknownElement.h"
 38#include <wtf/PassRefPtr.h>
 39
 40namespace WebCore {
 41
 42class HTMLElement;
 43
 44#if ENABLE(CUSTOM_ELEMENTS)
 45
 46class V8HTMLCustomElement {
 47public:
 48 static WrapperTypeInfo info;
 49 static v8::Handle<v8::Object> toV8(HTMLElement*, v8::Handle<v8::Object> creationContext = v8::Handle<v8::Object>(), v8::Isolate* = 0);
 50 static v8::Handle<v8::Object> createWrapper(PassRefPtr<HTMLElement>, v8::Handle<v8::Object>, v8::Isolate*);
 51};
 52
 53inline v8::Handle<v8::Object> V8HTMLCustomElement::toV8(HTMLElement* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
 54{
 55 if (UNLIKELY(!impl))
 56 return v8::Handle<v8::Object>::Cast(v8NullWithCheck(isolate));
 57 v8::Handle<v8::Object> wrapper = DOMDataStore::getWrapper(impl, isolate);
 58 if (!wrapper.IsEmpty())
 59 return wrapper;
 60 return V8HTMLCustomElement::createWrapper(impl, creationContext, isolate);
 61}
 62
 63#else // ENABLE(CUSTOM_ELEMENTS)
 64
 65class V8HTMLCustomElement {
 66public:
 67 static v8::Handle<v8::Object> wrap(HTMLElement*, v8::Handle<v8::Object> creationContext = v8::Handle<v8::Object>(), v8::Isolate* = 0);
 68};
 69
 70inline v8::Handle<v8::Object> HTMLCustomElement::toV8(HTMLElement* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
 71{
 72 return toV8(toHTMLUnknownElement(impl), creationContext, isolate);
 73}
 74
 75#endif // ENABLE(CUSTOM_ELEMENTS)
 76
 77} // namespace WebCore
 78
 79#endif // V8HTMLCustomElement_h

Source/WebCore/bindings/v8/V8HiddenPropertyName.h

@@namespace WebCore {
4545 V(scriptState) \
4646 V(sleepFunction) \
4747 V(state) \
 48 V(adaptorFunctionPeer) \
4849 V(toStringString) \
4950 V(typedArrayHiddenCopyMethod)
5051

Source/WebCore/bindings/v8/custom/V8CustomElementConstructorCustom.cpp

 1/*
 2* Copyright (C) 2012 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 "V8CustomElementConstructor.h"
 33
 34#include "CustomElementConstructor.h"
 35#include "V8Binding.h"
 36#include "V8HTMLCustomElement.h"
 37
 38namespace WebCore {
 39
 40v8::Handle<v8::Value> V8CustomElementConstructor::callAsFunctionCallback(const v8::Arguments& args)
 41{
 42 if (!args.IsConstructCall())
 43 return throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());
 44 if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
 45 return args.Holder();
 46
 47 CustomElementConstructor* impl = toNative(args.Holder());
 48 RefPtr<HTMLElement> element = impl->createElement();
 49 if (!element)
 50 return v8Undefined();
 51 return V8HTMLCustomElement::toV8(element.get(), args.Holder(), args.GetIsolate());
 52}
 53
 54} // namespace WebCore

Source/WebCore/dom/CustomElementConstructor.cpp

 1/*
 2 * Copyright (C) 2012 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 "CustomElementConstructor.h"
 33
 34#if ENABLE(CUSTOM_ELEMENTS)
 35
 36#include "CustomElementHelpers.h"
 37#include "Document.h"
 38#include "HTMLElement.h"
 39#include <wtf/Assertions.h>
 40
 41namespace WebCore {
 42
 43PassRefPtr<CustomElementConstructor> CustomElementConstructor::create(ScriptState* state, Document* document, const QualifiedName& tagName, const String& name, const ScriptValue& prototype)
 44{
 45 RefPtr<CustomElementConstructor> created = adoptRef(new CustomElementConstructor(document, tagName, name));
 46 CustomElementHelpers::initializeConstructorWrapper(created.get(), prototype, state);
 47 return created.release();
 48}
 49
 50CustomElementConstructor::CustomElementConstructor(Document* document, const QualifiedName& tagName, const String& name)
 51 : m_document(document)
 52 , m_tagName(tagName)
 53 , m_name(name)
 54{
 55}
 56
 57CustomElementConstructor::~CustomElementConstructor()
 58{
 59}
 60
 61void CustomElementConstructor::willDestroyDocument()
 62{
 63 m_document = 0;
 64}
 65
 66PassRefPtr<HTMLElement> CustomElementConstructor::createElement() const
 67{
 68 if (!m_document)
 69 return 0;
 70 return HTMLElement::create(m_tagName, m_document);
 71}
 72
 73}
 74
 75#endif // ENABLE(CUSTOM_ELEMENTS)

Source/WebCore/dom/CustomElementConstructor.h

 1/*
 2 * Copyright (C) 2012 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#ifndef CustomElementConstructor_h
 32#define CustomElementConstructor_h
 33
 34#if ENABLE(CUSTOM_ELEMENTS)
 35
 36#include "QualifiedName.h"
 37#include <wtf/Forward.h>
 38#include <wtf/PassRefPtr.h>
 39#include <wtf/RefCounted.h>
 40#include <wtf/text/AtomicString.h>
 41
 42namespace WebCore {
 43
 44class Document;
 45class HTMLElement;
 46class ScriptState;
 47class ScriptValue;
 48
 49class CustomElementConstructor : public RefCounted<CustomElementConstructor> {
 50public:
 51 static PassRefPtr<CustomElementConstructor> create(ScriptState*, Document*, const QualifiedName&, const String&, const ScriptValue&);
 52
 53 virtual ~CustomElementConstructor();
 54
 55 Document* document() const { return m_document; }
 56 const QualifiedName& tagName() const { return m_tagName; }
 57 const AtomicString& name() const { return m_name; }
 58
 59 PassRefPtr<HTMLElement> createElement() const;
 60 void willDestroyDocument();
 61
 62private:
 63 CustomElementConstructor(Document*, const QualifiedName&, const String&);
 64
 65 Document* m_document;
 66 QualifiedName m_tagName;
 67 AtomicString m_name;
 68};
 69
 70}
 71
 72#endif // ENABLE(CUSTOM_ELEMENTS)
 73
 74#endif // CustomElementConstructor_h

Source/WebCore/dom/CustomElementConstructor.idl

 1/*
 2 * Copyright (C) 2012, 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
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 23 */
 24
 25[
 26 Conditional=CUSTOM_ELEMENTS,
 27 V8EnabledAtRuntime=customDOMElements,
 28 V8WrapAsFunction,
 29 CustomCall
 30] interface CustomElementConstructor {
 31};

Source/WebCore/dom/CustomElementRegistry.cpp

 1/*
 2 * Copyright (C) 2012 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
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer
 12 * in the documentation and/or other materials provided with the
 13 * distribution.
 14 * 3. Neither the name of Google Inc. nor the names of its contributors
 15 * may be used to endorse or promote products derived from this
 16 * 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 "CustomElementRegistry.h"
 33
 34#include "CustomElementConstructor.h"
 35#include "CustomElementHelpers.h"
 36#include "Dictionary.h"
 37#include "Document.h"
 38#include "HTMLElement.h"
 39#include "HTMLNames.h"
 40#include "RuntimeEnabledFeatures.h"
 41#include <wtf/ASCIICType.h>
 42
 43#if ENABLE(CUSTOM_ELEMENTS)
 44
 45namespace WebCore {
 46
 47CustomElementRegistry::CustomElementRegistry(Document* document)
 48 : m_document(document)
 49{
 50}
 51
 52CustomElementRegistry::~CustomElementRegistry()
 53{
 54 for (ConstructorMap::iterator i = m_constructors.begin(); i != m_constructors.end(); ++i)
 55 i->value->willDestroyDocument();
 56}
 57
 58CustomElementConstructor* CustomElementRegistry::constructorOf(HTMLElement* element)
 59{
 60 CustomElementRegistry* self = element->document()->registry();
 61 if (!self)
 62 return 0;
 63 return self->find(element->tagQName());
 64}
 65
 66bool CustomElementRegistry::isValidName(const AtomicString& name)
 67{
 68 size_t hyphenPosition = name.find('-');
 69 if (hyphenPosition == notFound)
 70 return false;
 71 return Document::isValidName(name.string());
 72}
 73
 74PassRefPtr<CustomElementConstructor> CustomElementRegistry::registerElement(ScriptState* state, const AtomicString& name, const Dictionary& options, ExceptionCode& ec)
 75{
 76 if (!CustomElementHelpers::isCustomElementsAllowed(state))
 77 return 0;
 78
 79 QualifiedName newName(nullAtom, name.lower(), HTMLNames::xhtmlNamespaceURI);
 80 if (!isValidName(newName.localName())) {
 81 ec = INVALID_CHARACTER_ERR;
 82 return 0;
 83 }
 84
 85 if (find(newName)) {
 86 ec = INVALID_STATE_ERR;
 87 return 0;
 88 }
 89
 90 ScriptValue defaultPrototype = CustomElementHelpers::defaultPrototypeOf(state);
 91 RefPtr<CustomElementConstructor> fresh = CustomElementConstructor::create(state, m_document, newName, "HTMLCustomElement", defaultPrototype);
 92 m_constructors.add(fresh->tagName().impl(), fresh);
 93 return fresh;
 94}
 95
 96CustomElementConstructor* CustomElementRegistry::find(const QualifiedName& name) const
 97{
 98 ConstructorMap::const_iterator found = m_constructors.find(name.impl());
 99 return (found != m_constructors.end()) ? found->value.get() : 0;
 100}
 101
 102PassRefPtr<HTMLElement> CustomElementRegistry::createElement(const QualifiedName& name) const
 103{
 104 if (CustomElementConstructor* found = find(name))
 105 return found->createElement();
 106 return 0;
 107}
 108
 109}
 110
 111#endif // ENABLE(CUSTOM_ELEMENTS)

Source/WebCore/dom/CustomElementRegistry.h

 1/*
 2 * Copyright (C) 2012 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
 6 * are met:
 7 *
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer
 12 * in the documentation and/or other materials provided with the
 13 * distribution.
 14 * 3. Neither the name of Google Inc. nor the names of its contributors
 15 * may be used to endorse or promote products derived from this
 16 * 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#ifndef CustomElementRegistry_h
 32#define CustomElementRegistry_h
 33
 34#if ENABLE(CUSTOM_ELEMENTS)
 35
 36#include "ExceptionCode.h"
 37#include "QualifiedName.h"
 38#include "ScriptValue.h"
 39#include "Supplementable.h"
 40#include <wtf/Forward.h>
 41#include <wtf/PassRefPtr.h>
 42#include <wtf/RefCounted.h>
 43#include <wtf/RefPtr.h>
 44
 45namespace WebCore {
 46
 47class CustomElementConstructor;
 48class Dictionary;
 49class Document;
 50class HTMLElement;
 51class ScriptExecutionContext;
 52class QualifiedName;
 53
 54class CustomElementRegistry : public RefCounted<CustomElementRegistry> {
 55public:
 56 explicit CustomElementRegistry(Document*);
 57 ~CustomElementRegistry();
 58
 59 PassRefPtr<CustomElementConstructor> registerElement(WebCore::ScriptState*, const AtomicString& name, const Dictionary& options, ExceptionCode&);
 60 CustomElementConstructor* find(const QualifiedName&) const;
 61 PassRefPtr<HTMLElement> createElement(const QualifiedName&) const;
 62
 63 static CustomElementConstructor* constructorOf(HTMLElement*);
 64
 65private:
 66 static bool isValidName(const AtomicString&);
 67
 68 typedef HashMap<QualifiedName::QualifiedNameImpl*, RefPtr<CustomElementConstructor> >ConstructorMap;
 69
 70 Document* m_document;
 71 ConstructorMap m_constructors;
 72};
 73
 74} // namespace WebCore
 75
 76#endif // ENABLE(CUSTOM_ELEMENTS)
 77#endif

Source/WebCore/dom/Document.cpp

4646#include "ContentSecurityPolicy.h"
4747#include "ContextFeatures.h"
4848#include "CookieJar.h"
 49#include "CustomElementConstructor.h"
 50#include "CustomElementRegistry.h"
4951#include "DOMImplementation.h"
5052#include "DOMNamedFlowCollection.h"
5153#include "DOMSelection.h"
5254#include "DOMWindow.h"
5355#include "DateComponents.h"
 56#include "Dictionary.h"
5457#include "DocumentEventQueue.h"
5558#include "DocumentFragment.h"
5659#include "DocumentLoader.h"

@@void Document::removedLastRef()
675678 m_fullScreenElementStack.clear();
676679#endif
677680
 681#if ENABLE(CUSTOM_ELEMENTS)
 682 m_registry.clear();
 683#endif
 684
678685 detachParser();
679686
680687 // removeDetachedChildren() doesn't always unregister IDs,

@@PassRefPtr<Element> Document::createElement(const AtomicString& name, ExceptionC
843850 return createElement(QualifiedName(nullAtom, name, nullAtom), false);
844851}
845852
 853#if ENABLE(CUSTOM_ELEMENTS)
 854PassRefPtr<CustomElementConstructor> Document::registerElement(WebCore::ScriptState* state, const AtomicString& name, ExceptionCode& ec)
 855{
 856 return registerElement(state, name, Dictionary(), ec);
 857}
 858
 859PassRefPtr<CustomElementConstructor> Document::registerElement(WebCore::ScriptState* state, const AtomicString& name, const Dictionary& options, ExceptionCode& ec)
 860{
 861 if (!m_registry)
 862 m_registry = adoptPtr(new CustomElementRegistry(this));
 863 return m_registry->registerElement(state, name, options, ec);
 864}
 865#endif // ENABLE(CUSTOM_ELEMENTS)
 866
846867PassRefPtr<DocumentFragment> Document::createDocumentFragment()
847868{
848869 return DocumentFragment::create(document());

Source/WebCore/dom/Document.h

@@class CanvasRenderingContext;
6969class CharacterData;
7070class Comment;
7171class ContextFeatures;
 72class CustomElementConstructor;
 73class CustomElementRegistry;
7274class DOMImplementation;
7375class DOMNamedFlowCollection;
7476class DOMSelection;

@@public:
11641166 TextAutosizer* textAutosizer() { return m_textAutosizer.get(); }
11651167#endif
11661168
 1169#if ENABLE(CUSTOM_ELEMENTS)
 1170 PassRefPtr<CustomElementConstructor> registerElement(WebCore::ScriptState*, const AtomicString& name, ExceptionCode&);
 1171 PassRefPtr<CustomElementConstructor> registerElement(WebCore::ScriptState*, const AtomicString& name, const Dictionary& options, ExceptionCode&);
 1172 PassRefPtr<Element> createCustomElement(const AtomicString& tagName);
 1173 CustomElementRegistry* registry() const { return m_registry.get(); }
 1174#endif
 1175
11671176 void adjustFloatQuadsForScrollAndAbsoluteZoomAndFrameScale(Vector<FloatQuad>&, RenderObject*);
11681177 void adjustFloatRectForScrollAndAbsoluteZoomAndFrameScale(FloatRect&, RenderObject*);
11691178

@@private:
15351544 OwnPtr<TextAutosizer> m_textAutosizer;
15361545#endif
15371546
 1547#if ENABLE(CUSTOM_ELEMENTS)
 1548 OwnPtr<CustomElementRegistry> m_registry;
 1549#endif
 1550
15381551 bool m_scheduledTasksAreSuspended;
15391552
15401553 bool m_visualUpdatesAllowed;

Source/WebCore/dom/make_names.pl

@@END
11721172;
11731173 } elsif ($wrapperFactoryType eq "V8") {
11741174 print F <<END
 1175#include "V8HTMLCustomElement.h"
11751176#include "V8$parameters{namespace}Element.h"
1176 
11771177#include <v8.h>
11781178END
11791179;

@@END
12741274 return V8SVGElement::createWrapper(element, creationContext, isolate);
12751275END
12761276;
 1277 } elsif ($parameters{namespace} eq "HTML") {
 1278 print F <<END
 1279 return V8HTMLCustomElement::toV8(element, creationContext, isolate);
 1280END
 1281;
12771282 } else {
12781283 print F <<END
12791284 return wrap(to$parameters{fallbackInterfaceName}(element), creationContext, isolate);

Source/WebCore/html/HTMLDocument.idl

5353 readonly attribute Element activeElement;
5454 boolean hasFocus();
5555
 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
5661 // Deprecated attributes
5762 [TreatNullAs=NullString] attribute DOMString bgColor;
5863 [TreatNullAs=NullString] attribute DOMString fgColor;

Source/WebKit/chromium/features.gypi

5454 'ENABLE_CSS_TRANSFORMS_ANIMATIONS_TRANSITIONS_UNPREFIXED=0',
5555 'ENABLE_CSS_VARIABLES=1',
5656 'ENABLE_CSS_STICKY_POSITION=1',
 57 'ENABLE_CUSTOM_ELEMENTS=1',
5758 'ENABLE_CUSTOM_SCHEME_HANDLER=0',
5859 'ENABLE_DASHBOARD_SUPPORT=0',
5960 'ENABLE_DATA_TRANSFER_ITEMS=1',

Source/WebKit/chromium/public/WebRuntimeFeatures.h

@@public:
125125 WEBKIT_EXPORT static void enableShadowDOM(bool);
126126 WEBKIT_EXPORT static bool isShadowDOMEnabled();
127127
 128 WEBKIT_EXPORT static void enableCustomDOMElements(bool);
 129 WEBKIT_EXPORT static bool isCustomDOMElementsEnabled();
 130
128131 WEBKIT_EXPORT static void enableStyleScoped(bool);
129132 WEBKIT_EXPORT static bool isStyleScopedEnabled();
130133

Source/WebKit/chromium/src/WebRuntimeFeatures.cpp

@@bool WebRuntimeFeatures::isShadowDOMEnabled()
467467#endif
468468}
469469
 470void WebRuntimeFeatures::enableCustomDOMElements(bool enable)
 471{
 472#if ENABLE(CUSTOM_ELEMENTS)
 473 RuntimeEnabledFeatures::setCustomDOMElements(enable);
 474#else
 475 UNUSED_PARAM(enable);
 476#endif
 477}
 478
 479bool WebRuntimeFeatures::isCustomDOMElementsEnabled()
 480{
 481#if ENABLE(CUSTOM_ELEMENTS)
 482 return RuntimeEnabledFeatures::customDOMElementsEnabled();
 483#else
 484 return false;
 485#endif
 486}
 487
 488
470489void WebRuntimeFeatures::enableStyleScoped(bool enable)
471490{
472491#if ENABLE(STYLE_SCOPED)

Tools/ChangeLog

 12013-01-27 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 NOBODY (OOPS!).
 7
 8 Added enableCustomDOMElements flag.
 9
 10 * DumpRenderTree/chromium/TestShell.cpp:
 11 (TestShell::TestShell):
 12
1132013-01-29 Alan Cutter <alancutter@chromium.org>
214
315 Need a cr-linux debug EWS bot

Tools/DumpRenderTree/chromium/TestShell.cpp

@@TestShell::TestShell()
144144 WebRuntimeFeatures::enableVideoTrack(true);
145145 WebRuntimeFeatures::enableGamepad(true);
146146 WebRuntimeFeatures::enableShadowDOM(true);
 147 WebRuntimeFeatures::enableCustomDOMElements(true);
147148 WebRuntimeFeatures::enableStyleScoped(true);
148149 WebRuntimeFeatures::enableScriptedSpeech(true);
149150 WebRuntimeFeatures::enableRequestAutocomplete(true);

LayoutTests/ChangeLog

 12013-01-27 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 NOBODY (OOPS!).
 7
 8 * fast/dom/custom/document-register-basic.html: Added.
 9 * fast/dom/custom/document-register-basic-expected.txt: Added.
 10 * platform/mac/TestExpectations:
 11
1122013-01-29 Gyuyoung Kim <gyuyoung.kim@samsung.com>
213
314 Unreviewed. EFL Gradening.

LayoutTests/fast/dom/custom/document-register-basic-expected.txt

 1Testing document.register() basic behaviors.
 2
 3On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 4
 5
 6PASS document.register('foo') threw exception Error: InvalidCharacterError: DOM Exception 5.
 7PASS document.register('xfoo') threw exception Error: InvalidCharacterError: DOM Exception 5.
 8PASS typeof fooConstructor is 'function'
 9PASS fooConstructor.prototype is HTMLSpanElement.prototype
 10PASS document.register('x-foo') threw exception Error: InvalidStateError: DOM Exception 11.
 11PASS document.register('X-FOO') threw exception Error: InvalidStateError: DOM Exception 11.
 12PASS fooConstructor() threw exception TypeError: DOM object constructor cannot be called as a function..
 13PASS createdFoo.__proto__ is fooConstructor.prototype
 14PASS createdFoo.constructor is fooConstructor
 15PASS createdFoo.tagName is 'X-FOO'
 16PASS createdFoo.textContent is 'Hello'
 17PASS createdFoo.lastChild is childDiv
 18PASS parsedFoo.__proto__ is fooConstructor.prototype
 19PASS parsedFoo.tagName is 'X-FOO'
 20PASS parsedFoo.someProperty is container.firstChild.someProperty
 21PASS createdBar.tagName is 'X-BAR'
 22PASS createdUpperBar.constructor is barConstructor
 23PASS createdUpperBar.tagName is 'X-BAR'
 24PASS createdMixedBar.constructor is barConstructor
 25PASS createdMixedBar.tagName is 'X-BAR'
 26PASS container.firstChild.constructor is barConstructor
 27PASS container.firstChild.tagName is 'X-BAR'
 28PASS container.lastChild.constructor is barConstructor
 29PASS container.lastChild.tagName is 'X-BAR'
 30PASS (new (document.register('y-bar'))()).tagName is 'Y-BAR'
 31PASS (new (document.register('yz-bar'))()).tagName is 'YZ-BAR'
 32PASS (new (document.register('y-z-bar'))()).tagName is 'Y-Z-BAR'
 33PASS (new (document.register('y--bar'))()).tagName is 'Y--BAR'
 34

LayoutTests/fast/dom/custom/document-register-basic.html

 1<!DOCTYPE html>
 2<html>
 3<head>
 4<script src="../../js/resources/js-test-pre.js"></script>
 5</head>
 6<body>
 7<div id="container"></div>
 8<script>
 9description("Testing document.register() basic behaviors.");
 10
 11if (window.testRunner)
 12 testRunner.dumpAsText();
 13document.register = document.register || document.webkitRegister;
 14
 15// Invalid names
 16shouldThrow("document.register('foo')", "'Error: InvalidCharacterError: DOM Exception 5'");
 17shouldThrow("document.register('xfoo')", "'Error: InvalidCharacterError: DOM Exception 5'");
 18
 19var fooConstructor = document.register("x-foo");
 20shouldBe("typeof fooConstructor", "'function'");
 21shouldBe("fooConstructor.prototype", "HTMLSpanElement.prototype");
 22
 23// Name conflicts
 24shouldThrow("document.register('x-foo')", "'Error: InvalidStateError: DOM Exception 11'");
 25shouldThrow("document.register('X-FOO')", "'Error: InvalidStateError: DOM Exception 11'");
 26
 27// Call as function
 28shouldThrow("fooConstructor()", "'TypeError: DOM object constructor cannot be called as a function.'")
 29
 30// Constructor initiated instantiation
 31var createdFoo = new fooConstructor();
 32
 33// JS built-in properties
 34shouldBe("createdFoo.__proto__", "fooConstructor.prototype");
 35shouldBe("createdFoo.constructor", "fooConstructor");
 36
 37// Native getter
 38shouldBe("createdFoo.tagName", "'X-FOO'");
 39
 40// Native setter
 41createdFoo.innerHTML = "Hello";
 42shouldBe("createdFoo.textContent", "'Hello'");
 43
 44// Native method
 45var childDiv = document.createElement("div");
 46createdFoo.appendChild(childDiv);
 47shouldBe("createdFoo.lastChild", "childDiv");
 48
 49// Parser initiated instantiation
 50var container = document.getElementById("container");
 51container.innerHTML = "<x-foo></x-foo>";
 52parsedFoo = container.firstChild;
 53
 54shouldBe("parsedFoo.__proto__", "fooConstructor.prototype");
 55shouldBe("parsedFoo.tagName", "'X-FOO'");
 56
 57// Ensuring the wrapper is retained
 58parsedFoo.someProperty = "hello";
 59shouldBe("parsedFoo.someProperty", "container.firstChild.someProperty");
 60
 61// Having another constructor
 62var barConstructor = document.register("x-bar");
 63var createdBar = new barConstructor();
 64shouldBe("createdBar.tagName", "'X-BAR'");
 65
 66// With irregular cases
 67var createdUpperBar = document.createElement("X-BAR");
 68var createdMixedBar = document.createElement("X-Bar");
 69shouldBe("createdUpperBar.constructor", "barConstructor");
 70shouldBe("createdUpperBar.tagName", "'X-BAR'");
 71shouldBe("createdMixedBar.constructor", "barConstructor");
 72shouldBe("createdMixedBar.tagName", "'X-BAR'");
 73
 74container.innerHTML = "<X-BAR></X-BAR><X-Bar></X-Bar>";
 75shouldBe("container.firstChild.constructor", "barConstructor");
 76shouldBe("container.firstChild.tagName", "'X-BAR'");
 77shouldBe("container.lastChild.constructor", "barConstructor");
 78shouldBe("container.lastChild.tagName", "'X-BAR'");
 79
 80// Strange but valid names
 81shouldBe("(new (document.register('y-bar'))()).tagName", "'Y-BAR'");
 82shouldBe("(new (document.register('yz-bar'))()).tagName", "'YZ-BAR'");
 83shouldBe("(new (document.register('y-z-bar'))()).tagName", "'Y-Z-BAR'");
 84shouldBe("(new (document.register('y--bar'))()).tagName", "'Y--BAR'");
 85
 86</script>
 87</body>
 88</html>

LayoutTests/platform/mac/TestExpectations

@@webkit.org/b/76489 compositing/webgl/webgl-reflection.html [ ImageOnlyFailure ]
10131013webkit.org/b/76439 [ Debug ] fast/dom/shadow/content-element-api.html [ Failure ]
10141014webkit.org/b/76439 [ Debug ] fast/dom/shadow/content-element-outside-shadow.html [ Failure ]
10151015
 1016# ENABLE(CUSTOM_ELEMENTS) is disabled.
 1017fast/dom/custom
 1018
10161019# CSS Variables are not yet enabled.
10171020webkit.org/b/85580 fast/css/variables
10181021webkit.org/b/85580 inspector/styles/variables