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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 // 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.
109 }
110
111 void DartCustomElementLifecycleCallbacks::leftDocument(Element* element)
112 {
113 // call(m_leftDocument, element);
114 }
115
116 void DartCustomElementLifecycleCallbacks::attributeChanged(Element* element, con st AtomicString& name, const AtomicString& oldValue, const AtomicString& newValu e)
117 {
118 /*
119 if (!canInvokeCallback())
120 return;
121
122 v8::HandleScope handleScope;
123 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo rld.get());
124 if (context.IsEmpty())
125 return;
126
127 v8::Context::Scope scope(context);
128 v8::Isolate* isolate = context->GetIsolate();
129
130 v8::Handle<v8::Object> receiver = toV8(element, context->Global(), isolate). As<v8::Object>();
131 ASSERT(!receiver.IsEmpty());
132
133 v8::Handle<v8::Function> callback = m_attributeChanged.newLocal(isolate);
134 if (callback.IsEmpty())
135 return;
136
137 v8::Handle<v8::Value> argv[] = {
138 v8String(name, isolate),
139 oldValue.isNull() ? v8::Handle<v8::Value>(v8::Null()) : v8::Handle<v8::V alue>(v8String(oldValue, isolate)),
140 newValue.isNull() ? v8::Handle<v8::Value>(v8::Null()) : v8::Handle<v8::V alue>(v8String(newValue, isolate))
141 };
142
143 v8::TryCatch exceptionCatcher;
144 exceptionCatcher.SetVerbose(true);
145 ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(), callback, receiver, WTF_ARRAY_LENGTH(argv), argv);
146 */
147 }
148 /*
149 void DartCustomElementLifecycleCallbacks::call(const ScopedPersistent<v8::Functi on>& weakCallback, Element* element)
150 {
151 if (!canInvokeCallback())
152 return;
153
154 v8::HandleScope handleScope;
155 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo rld.get());
156 if (context.IsEmpty())
157 return;
158
159 v8::Context::Scope scope(context);
160 v8::Isolate* isolate = context->GetIsolate();
161
162 v8::Handle<v8::Function> callback = weakCallback.newLocal(isolate);
163 if (callback.IsEmpty())
164 return;
165
166 v8::Handle<v8::Object> receiver = toV8(element, context->Global(), isolate). As<v8::Object>();
167 ASSERT(!receiver.IsEmpty());
168
169 v8::TryCatch exceptionCatcher;
170 exceptionCatcher.SetVerbose(true);
171 ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(), callback, receiver, 0, 0);
172 }*/
173
174 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698