| OLD | NEW |
| (Empty) | |
| 1 /* |
| 2 * Copyright (C) 2013 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 "bindings/dart/DartCustomElementLifecycleCallbacks.h" |
| 33 |
| 34 #include "bindings/dart/DartCustomElementWrapper.h" |
| 35 #include "bindings/dart/DartDOMData.h" |
| 36 #include "bindings/dart/DartUtilities.h" |
| 37 #include "bindings/v8/V8Binding.h" |
| 38 #include "core/dom/Element.h" |
| 39 #include "core/dom/ScriptExecutionContext.h" |
| 40 #include "wtf/PassOwnPtr.h" |
| 41 |
| 42 |
| 43 namespace WebCore { |
| 44 |
| 45 #define CALLBACK_LIST(V) \ |
| 46 V(created, Created) \ |
| 47 V(enteredDocument, EnteredDocument) \ |
| 48 V(leftDocument, LeftDocument) \ |
| 49 V(attributeChanged, AttributeChanged) |
| 50 |
| 51 PassRefPtr<DartCustomElementLifecycleCallbacks> DartCustomElementLifecycleCallba
cks::create(Dart_Isolate isolate, ScriptExecutionContext* scriptExecutionContext
) |
| 52 { |
| 53 return adoptRef(new DartCustomElementLifecycleCallbacks(isolate, scriptExecu
tionContext)); |
| 54 } |
| 55 |
| 56 static CustomElementLifecycleCallbacks::CallbackType flagSet() |
| 57 { |
| 58 int flags = CustomElementLifecycleCallbacks::Created | CustomElementLifecycl
eCallbacks::EnteredDocument | CustomElementLifecycleCallbacks::LeftDocument | Cu
stomElementLifecycleCallbacks::AttributeChanged; |
| 59 |
| 60 return CustomElementLifecycleCallbacks::CallbackType(flags); |
| 61 } |
| 62 |
| 63 DartCustomElementLifecycleCallbacks::DartCustomElementLifecycleCallbacks(Dart_Is
olate isolate, ScriptExecutionContext* scriptExecutionContext) |
| 64 : CustomElementLifecycleCallbacks(flagSet()) |
| 65 , m_scriptExecutionContext(scriptExecutionContext) |
| 66 , m_world(DOMWrapperWorld::current()) |
| 67 , m_owner(0) |
| 68 , m_isolate(isolate) |
| 69 { |
| 70 } |
| 71 |
| 72 DartCustomElementLifecycleCallbacks::~DartCustomElementLifecycleCallbacks() |
| 73 { |
| 74 if (!m_owner) |
| 75 return; |
| 76 |
| 77 DartDOMData::current()->clearCustomElementBinding(m_owner); |
| 78 } |
| 79 |
| 80 |
| 81 bool DartCustomElementLifecycleCallbacks::setBinding(CustomElementDefinition* ow
ner, PassOwnPtr<DartCustomElementBinding> binding) |
| 82 { |
| 83 ASSERT(!m_owner); |
| 84 m_owner = owner; |
| 85 |
| 86 DartDOMData::current()->addCustomElementBinding(owner, binding); |
| 87 return true; |
| 88 } |
| 89 |
| 90 void DartCustomElementLifecycleCallbacks::created(Element* element) |
| 91 { |
| 92 DartIsolateScope isolateScope(m_isolate); |
| 93 DartApiScope dartApiScope; |
| 94 |
| 95 v8::HandleScope handleScope; |
| 96 v8::Handle<v8::Context> context = toV8Context(m_scriptExecutionContext, m_wo
rld.get()); |
| 97 if (context.IsEmpty()) |
| 98 return; |
| 99 v8::Context::Scope scope(context); |
| 100 |
| 101 element->setCustomElementState(Element::Upgraded); |
| 102 |
| 103 DartCustomElementWrapper<HTMLElement>::upgradeDartWrapper(reinterpret_cast<H
TMLElement*>(element)); |
| 104 } |
| 105 |
| 106 void DartCustomElementLifecycleCallbacks::enteredDocument(Element* element) |
| 107 { |
| 108 // FIXME: implement lifecycle callbacks. |
| 109 // call(m_enteredDocument, element); |
| 110 } |
| 111 |
| 112 void DartCustomElementLifecycleCallbacks::leftDocument(Element* element) |
| 113 { |
| 114 // FIXME: implement lifecycle callbacks. |
| 115 // call(m_leftDocument, element); |
| 116 } |
| 117 |
| 118 void DartCustomElementLifecycleCallbacks::attributeChanged(Element* element, con
st AtomicString& name, const AtomicString& oldValue, const AtomicString& newValu
e) |
| 119 { |
| 120 // FIXME: implement lifecycle callbacks. |
| 121 /* |
| 122 if (!canInvokeCallback()) |
| 123 return; |
| 124 |
| 125 v8::HandleScope handleScope; |
| 126 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo
rld.get()); |
| 127 if (context.IsEmpty()) |
| 128 return; |
| 129 |
| 130 v8::Context::Scope scope(context); |
| 131 v8::Isolate* isolate = context->GetIsolate(); |
| 132 |
| 133 v8::Handle<v8::Object> receiver = toV8(element, context->Global(), isolate).
As<v8::Object>(); |
| 134 ASSERT(!receiver.IsEmpty()); |
| 135 |
| 136 v8::Handle<v8::Function> callback = m_attributeChanged.newLocal(isolate); |
| 137 if (callback.IsEmpty()) |
| 138 return; |
| 139 |
| 140 v8::Handle<v8::Value> argv[] = { |
| 141 v8String(name, isolate), |
| 142 oldValue.isNull() ? v8::Handle<v8::Value>(v8::Null()) : v8::Handle<v8::V
alue>(v8String(oldValue, isolate)), |
| 143 newValue.isNull() ? v8::Handle<v8::Value>(v8::Null()) : v8::Handle<v8::V
alue>(v8String(newValue, isolate)) |
| 144 }; |
| 145 |
| 146 v8::TryCatch exceptionCatcher; |
| 147 exceptionCatcher.SetVerbose(true); |
| 148 ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(),
callback, receiver, WTF_ARRAY_LENGTH(argv), argv); |
| 149 */ |
| 150 } |
| 151 /* |
| 152 void DartCustomElementLifecycleCallbacks::call(const ScopedPersistent<v8::Functi
on>& weakCallback, Element* element) |
| 153 { |
| 154 if (!canInvokeCallback()) |
| 155 return; |
| 156 |
| 157 v8::HandleScope handleScope; |
| 158 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo
rld.get()); |
| 159 if (context.IsEmpty()) |
| 160 return; |
| 161 |
| 162 v8::Context::Scope scope(context); |
| 163 v8::Isolate* isolate = context->GetIsolate(); |
| 164 |
| 165 v8::Handle<v8::Function> callback = weakCallback.newLocal(isolate); |
| 166 if (callback.IsEmpty()) |
| 167 return; |
| 168 |
| 169 v8::Handle<v8::Object> receiver = toV8(element, context->Global(), isolate).
As<v8::Object>(); |
| 170 ASSERT(!receiver.IsEmpty()); |
| 171 |
| 172 v8::TryCatch exceptionCatcher; |
| 173 exceptionCatcher.SetVerbose(true); |
| 174 ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(),
callback, receiver, 0, 0); |
| 175 }*/ |
| 176 |
| 177 } // namespace WebCore |
| OLD | NEW |