Chromium Code Reviews| Index: Source/bindings/dart/DartCustomElementLifecycleCallbacks.cpp |
| diff --git a/Source/bindings/dart/DartCustomElementLifecycleCallbacks.cpp b/Source/bindings/dart/DartCustomElementLifecycleCallbacks.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1f7d8f72c5884df8d1d03150e6c1b6496813c926 |
| --- /dev/null |
| +++ b/Source/bindings/dart/DartCustomElementLifecycleCallbacks.cpp |
| @@ -0,0 +1,174 @@ |
| +/* |
| + * Copyright (C) 2013 Google Inc. All rights reserved. |
| + * |
| + * Redistribution and use in source and binary forms, with or without |
| + * modification, are permitted provided that the following conditions are |
| + * met: |
| + * |
| + * * Redistributions of source code must retain the above copyright |
| + * notice, this list of conditions and the following disclaimer. |
| + * * Redistributions in binary form must reproduce the above |
| + * copyright notice, this list of conditions and the following disclaimer |
| + * in the documentation and/or other materials provided with the |
| + * distribution. |
| + * * Neither the name of Google Inc. nor the names of its |
| + * contributors may be used to endorse or promote products derived from |
| + * this software without specific prior written permission. |
| + * |
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + */ |
| + |
| +#include "config.h" |
| +#include "bindings/dart/DartCustomElementLifecycleCallbacks.h" |
| + |
| +#include "bindings/dart/DartCustomElementWrapper.h" |
| +#include "bindings/dart/DartDOMData.h" |
| +#include "bindings/dart/DartUtilities.h" |
| +#include "bindings/v8/V8Binding.h" |
| +#include "core/dom/Element.h" |
| +#include "core/dom/ScriptExecutionContext.h" |
| +#include "wtf/PassOwnPtr.h" |
| + |
| + |
| +namespace WebCore { |
| + |
| +#define CALLBACK_LIST(V) \ |
| + V(created, Created) \ |
| + V(enteredDocument, EnteredDocument) \ |
| + V(leftDocument, LeftDocument) \ |
| + V(attributeChanged, AttributeChanged) |
| + |
| +PassRefPtr<DartCustomElementLifecycleCallbacks> DartCustomElementLifecycleCallbacks::create(Dart_Isolate isolate, ScriptExecutionContext* scriptExecutionContext) |
| +{ |
| + return adoptRef(new DartCustomElementLifecycleCallbacks(isolate, scriptExecutionContext)); |
| +} |
| + |
| +static CustomElementLifecycleCallbacks::CallbackType flagSet() |
| +{ |
| + int flags = CustomElementLifecycleCallbacks::Created | CustomElementLifecycleCallbacks::EnteredDocument | CustomElementLifecycleCallbacks::LeftDocument | CustomElementLifecycleCallbacks::AttributeChanged; |
| + |
| + return CustomElementLifecycleCallbacks::CallbackType(flags); |
| +} |
| + |
| +DartCustomElementLifecycleCallbacks::DartCustomElementLifecycleCallbacks(Dart_Isolate isolate, ScriptExecutionContext* scriptExecutionContext) |
| + : CustomElementLifecycleCallbacks(flagSet()) |
| + , m_scriptExecutionContext(scriptExecutionContext) |
| + , m_world(DOMWrapperWorld::current()) |
| + , m_owner(0) |
| + , m_isolate(isolate) |
| +{ |
| +} |
| + |
| +DartCustomElementLifecycleCallbacks::~DartCustomElementLifecycleCallbacks() |
| +{ |
| + if (!m_owner) |
| + return; |
| + |
| + DartDOMData::current()->clearCustomElementBinding(m_owner); |
| +} |
| + |
| + |
| +bool DartCustomElementLifecycleCallbacks::setBinding(CustomElementDefinition* owner, PassOwnPtr<DartCustomElementBinding> binding) |
| +{ |
| + ASSERT(!m_owner); |
| + m_owner = owner; |
| + |
| + DartDOMData::current()->addCustomElementBinding(owner, binding); |
| + return true; |
| +} |
| + |
| +void DartCustomElementLifecycleCallbacks::created(Element* element) |
| +{ |
| + DartIsolateScope isolateScope(m_isolate); |
| + DartApiScope dartApiScope; |
| + |
| + v8::HandleScope handleScope; |
| + v8::Handle<v8::Context> context = toV8Context(m_scriptExecutionContext, m_world.get()); |
| + if (context.IsEmpty()) |
| + return; |
| + v8::Context::Scope scope(context); |
| + |
| + element->setCustomElementState(Element::Upgraded); |
| + |
| + DartCustomElementWrapper<HTMLElement>::upgradeDartWrapper(reinterpret_cast<HTMLElement*>(element)); |
| +} |
| + |
| +void DartCustomElementLifecycleCallbacks::enteredDocument(Element* element) |
| +{ |
| +// call(m_enteredDocument, element); |
|
vsm
2013/09/19 23:12:26
Can you either delete or add FIXMEs to commented o
blois
2013/09/20 00:10:25
Done.
|
| +} |
| + |
| +void DartCustomElementLifecycleCallbacks::leftDocument(Element* element) |
| +{ |
| +// call(m_leftDocument, element); |
| +} |
| + |
| +void DartCustomElementLifecycleCallbacks::attributeChanged(Element* element, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue) |
| +{ |
| +/* |
| + if (!canInvokeCallback()) |
| + return; |
| + |
| + v8::HandleScope handleScope; |
| + v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_world.get()); |
| + if (context.IsEmpty()) |
| + return; |
| + |
| + v8::Context::Scope scope(context); |
| + v8::Isolate* isolate = context->GetIsolate(); |
| + |
| + v8::Handle<v8::Object> receiver = toV8(element, context->Global(), isolate).As<v8::Object>(); |
| + ASSERT(!receiver.IsEmpty()); |
| + |
| + v8::Handle<v8::Function> callback = m_attributeChanged.newLocal(isolate); |
| + if (callback.IsEmpty()) |
| + return; |
| + |
| + v8::Handle<v8::Value> argv[] = { |
| + v8String(name, isolate), |
| + oldValue.isNull() ? v8::Handle<v8::Value>(v8::Null()) : v8::Handle<v8::Value>(v8String(oldValue, isolate)), |
| + newValue.isNull() ? v8::Handle<v8::Value>(v8::Null()) : v8::Handle<v8::Value>(v8String(newValue, isolate)) |
| + }; |
| + |
| + v8::TryCatch exceptionCatcher; |
| + exceptionCatcher.SetVerbose(true); |
| + ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(), callback, receiver, WTF_ARRAY_LENGTH(argv), argv); |
| +*/ |
| +} |
| +/* |
| +void DartCustomElementLifecycleCallbacks::call(const ScopedPersistent<v8::Function>& weakCallback, Element* element) |
| +{ |
| + if (!canInvokeCallback()) |
| + return; |
| + |
| + v8::HandleScope handleScope; |
| + v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_world.get()); |
| + if (context.IsEmpty()) |
| + return; |
| + |
| + v8::Context::Scope scope(context); |
| + v8::Isolate* isolate = context->GetIsolate(); |
| + |
| + v8::Handle<v8::Function> callback = weakCallback.newLocal(isolate); |
| + if (callback.IsEmpty()) |
| + return; |
| + |
| + v8::Handle<v8::Object> receiver = toV8(element, context->Global(), isolate).As<v8::Object>(); |
| + ASSERT(!receiver.IsEmpty()); |
| + |
| + v8::TryCatch exceptionCatcher; |
| + exceptionCatcher.SetVerbose(true); |
| + ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(), callback, receiver, 0, 0); |
| +}*/ |
| + |
| +} // namespace WebCore |