Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Unified Diff: Source/bindings/dart/DartCustomElementLifecycleCallbacks.cpp

Issue 24294002: Dartium changes for custom element lifecycle events. (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..ad94a67e5edff8fadc12ca90e195e19e5e299aca
--- /dev/null
+++ b/Source/bindings/dart/DartCustomElementLifecycleCallbacks.cpp
@@ -0,0 +1,177 @@
+/*
+ * 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)
+{
+ // FIXME: implement lifecycle callbacks.
+// call(m_enteredDocument, element);
+}
+
+void DartCustomElementLifecycleCallbacks::leftDocument(Element* element)
+{
+ // FIXME: implement lifecycle callbacks.
+// call(m_leftDocument, element);
+}
+
+void DartCustomElementLifecycleCallbacks::attributeChanged(Element* element, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue)
+{
+ // FIXME: implement lifecycle callbacks.
+/*
+ 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

Powered by Google App Engine
This is Rietveld 408576698