| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 #include "bindings/v8/V8Binding.h" | 38 #include "bindings/v8/V8Binding.h" |
| 39 #include "bindings/v8/V8HiddenPropertyName.h" | 39 #include "bindings/v8/V8HiddenPropertyName.h" |
| 40 #include "bindings/v8/V8PerContextData.h" | 40 #include "bindings/v8/V8PerContextData.h" |
| 41 #include "core/dom/ExecutionContext.h" | 41 #include "core/dom/ExecutionContext.h" |
| 42 #include "wtf/PassOwnPtr.h" | 42 #include "wtf/PassOwnPtr.h" |
| 43 | 43 |
| 44 namespace WebCore { | 44 namespace WebCore { |
| 45 | 45 |
| 46 #define CALLBACK_LIST(V) \ | 46 #define CALLBACK_LIST(V) \ |
| 47 V(created, Created) \ | 47 V(created, Created) \ |
| 48 V(enteredView, EnteredView) \ | 48 V(attached, Attached) \ |
| 49 V(leftView, LeftView) \ | 49 V(detached, Detached) \ |
| 50 V(attributeChanged, AttributeChanged) | 50 V(attributeChanged, AttributeChanged) |
| 51 | 51 |
| 52 PassRefPtr<V8CustomElementLifecycleCallbacks> V8CustomElementLifecycleCallbacks:
:create(ExecutionContext* executionContext, v8::Handle<v8::Object> prototype, v8
::Handle<v8::Function> created, v8::Handle<v8::Function> enteredView, v8::Handle
<v8::Function> leftView, v8::Handle<v8::Function> attributeChanged) | 52 PassRefPtr<V8CustomElementLifecycleCallbacks> V8CustomElementLifecycleCallbacks:
:create(ExecutionContext* executionContext, v8::Handle<v8::Object> prototype, v8
::Handle<v8::Function> created, v8::Handle<v8::Function> attached, v8::Handle<v8
::Function> detached, v8::Handle<v8::Function> attributeChanged) |
| 53 { | 53 { |
| 54 v8::Isolate* isolate = toIsolate(executionContext); | 54 v8::Isolate* isolate = toIsolate(executionContext); |
| 55 // A given object can only be used as a Custom Element prototype | 55 // A given object can only be used as a Custom Element prototype |
| 56 // once; see customElementIsInterfacePrototypeObject | 56 // once; see customElementIsInterfacePrototypeObject |
| 57 #define SET_HIDDEN_PROPERTY(Value, Name) \ | 57 #define SET_HIDDEN_PROPERTY(Value, Name) \ |
| 58 ASSERT(prototype->GetHiddenValue(V8HiddenPropertyName::customElement##Name(i
solate)).IsEmpty()); \ | 58 ASSERT(prototype->GetHiddenValue(V8HiddenPropertyName::customElement##Name(i
solate)).IsEmpty()); \ |
| 59 if (!Value.IsEmpty()) \ | 59 if (!Value.IsEmpty()) \ |
| 60 prototype->SetHiddenValue(V8HiddenPropertyName::customElement##Name(isol
ate), Value); | 60 prototype->SetHiddenValue(V8HiddenPropertyName::customElement##Name(isol
ate), Value); |
| 61 | 61 |
| 62 CALLBACK_LIST(SET_HIDDEN_PROPERTY) | 62 CALLBACK_LIST(SET_HIDDEN_PROPERTY) |
| 63 #undef SET_HIDDEN_PROPERTY | 63 #undef SET_HIDDEN_PROPERTY |
| 64 | 64 |
| 65 return adoptRef(new V8CustomElementLifecycleCallbacks(executionContext, prot
otype, created, enteredView, leftView, attributeChanged)); | 65 return adoptRef(new V8CustomElementLifecycleCallbacks(executionContext, prot
otype, created, attached, detached, attributeChanged)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 static CustomElementLifecycleCallbacks::CallbackType flagSet(v8::Handle<v8::Func
tion> enteredView, v8::Handle<v8::Function> leftView, v8::Handle<v8::Function> a
ttributeChanged) | 68 static CustomElementLifecycleCallbacks::CallbackType flagSet(v8::Handle<v8::Func
tion> attached, v8::Handle<v8::Function> detached, v8::Handle<v8::Function> attr
ibuteChanged) |
| 69 { | 69 { |
| 70 // V8 Custom Elements always run created to swizzle prototypes. | 70 // V8 Custom Elements always run created to swizzle prototypes. |
| 71 int flags = CustomElementLifecycleCallbacks::Created; | 71 int flags = CustomElementLifecycleCallbacks::Created; |
| 72 | 72 |
| 73 if (!enteredView.IsEmpty()) | 73 if (!attached.IsEmpty()) |
| 74 flags |= CustomElementLifecycleCallbacks::EnteredView; | 74 flags |= CustomElementLifecycleCallbacks::Attached; |
| 75 | 75 |
| 76 if (!leftView.IsEmpty()) | 76 if (!detached.IsEmpty()) |
| 77 flags |= CustomElementLifecycleCallbacks::LeftView; | 77 flags |= CustomElementLifecycleCallbacks::Detached; |
| 78 | 78 |
| 79 if (!attributeChanged.IsEmpty()) | 79 if (!attributeChanged.IsEmpty()) |
| 80 flags |= CustomElementLifecycleCallbacks::AttributeChanged; | 80 flags |= CustomElementLifecycleCallbacks::AttributeChanged; |
| 81 | 81 |
| 82 return CustomElementLifecycleCallbacks::CallbackType(flags); | 82 return CustomElementLifecycleCallbacks::CallbackType(flags); |
| 83 } | 83 } |
| 84 | 84 |
| 85 template <typename T> | 85 template <typename T> |
| 86 static void weakCallback(const v8::WeakCallbackData<T, ScopedPersistent<T> >& da
ta) | 86 static void weakCallback(const v8::WeakCallbackData<T, ScopedPersistent<T> >& da
ta) |
| 87 { | 87 { |
| 88 data.GetParameter()->clear(); | 88 data.GetParameter()->clear(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ExecutionCo
ntext* executionContext, v8::Handle<v8::Object> prototype, v8::Handle<v8::Functi
on> created, v8::Handle<v8::Function> enteredView, v8::Handle<v8::Function> left
View, v8::Handle<v8::Function> attributeChanged) | 91 V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ExecutionCo
ntext* executionContext, v8::Handle<v8::Object> prototype, v8::Handle<v8::Functi
on> created, v8::Handle<v8::Function> attached, v8::Handle<v8::Function> detache
d, v8::Handle<v8::Function> attributeChanged) |
| 92 : CustomElementLifecycleCallbacks(flagSet(enteredView, leftView, attributeCh
anged)) | 92 : CustomElementLifecycleCallbacks(flagSet(attached, detached, attributeChang
ed)) |
| 93 , ContextLifecycleObserver(executionContext) | 93 , ContextLifecycleObserver(executionContext) |
| 94 , m_owner(0) | 94 , m_owner(0) |
| 95 , m_world(DOMWrapperWorld::current()) | 95 , m_world(DOMWrapperWorld::current()) |
| 96 , m_prototype(toIsolate(executionContext), prototype) | 96 , m_prototype(toIsolate(executionContext), prototype) |
| 97 , m_created(toIsolate(executionContext), created) | 97 , m_created(toIsolate(executionContext), created) |
| 98 , m_enteredView(toIsolate(executionContext), enteredView) | 98 , m_attached(toIsolate(executionContext), attached) |
| 99 , m_leftView(toIsolate(executionContext), leftView) | 99 , m_detached(toIsolate(executionContext), detached) |
| 100 , m_attributeChanged(toIsolate(executionContext), attributeChanged) | 100 , m_attributeChanged(toIsolate(executionContext), attributeChanged) |
| 101 { | 101 { |
| 102 m_prototype.setWeak(&m_prototype, weakCallback<v8::Object>); | 102 m_prototype.setWeak(&m_prototype, weakCallback<v8::Object>); |
| 103 | 103 |
| 104 #define MAKE_WEAK(Var, _) \ | 104 #define MAKE_WEAK(Var, _) \ |
| 105 if (!m_##Var.isEmpty()) \ | 105 if (!m_##Var.isEmpty()) \ |
| 106 m_##Var.setWeak(&m_##Var, weakCallback<v8::Function>); | 106 m_##Var.setWeak(&m_##Var, weakCallback<v8::Function>); |
| 107 | 107 |
| 108 CALLBACK_LIST(MAKE_WEAK) | 108 CALLBACK_LIST(MAKE_WEAK) |
| 109 #undef MAKE_WEAK | 109 #undef MAKE_WEAK |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 if (receiver.IsEmpty()) | 183 if (receiver.IsEmpty()) |
| 184 receiver = toV8(element, context->Global(), isolate).As<v8::Object>(); | 184 receiver = toV8(element, context->Global(), isolate).As<v8::Object>(); |
| 185 | 185 |
| 186 ASSERT(!receiver.IsEmpty()); | 186 ASSERT(!receiver.IsEmpty()); |
| 187 | 187 |
| 188 v8::TryCatch exceptionCatcher; | 188 v8::TryCatch exceptionCatcher; |
| 189 exceptionCatcher.SetVerbose(true); | 189 exceptionCatcher.SetVerbose(true); |
| 190 ScriptController::callFunction(executionContext(), callback, receiver, 0, 0,
isolate); | 190 ScriptController::callFunction(executionContext(), callback, receiver, 0, 0,
isolate); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void V8CustomElementLifecycleCallbacks::enteredView(Element* element) | 193 void V8CustomElementLifecycleCallbacks::attached(Element* element) |
| 194 { | 194 { |
| 195 call(m_enteredView, element); | 195 call(m_attached, element); |
| 196 } | 196 } |
| 197 | 197 |
| 198 void V8CustomElementLifecycleCallbacks::leftView(Element* element) | 198 void V8CustomElementLifecycleCallbacks::detached(Element* element) |
| 199 { | 199 { |
| 200 call(m_leftView, element); | 200 call(m_detached, element); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void V8CustomElementLifecycleCallbacks::attributeChanged(Element* element, const
AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue) | 203 void V8CustomElementLifecycleCallbacks::attributeChanged(Element* element, const
AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue) |
| 204 { | 204 { |
| 205 // FIXME: callbacks while paused should be queued up for execution to | 205 // FIXME: callbacks while paused should be queued up for execution to |
| 206 // continue then be delivered in order rather than delivered immediately. | 206 // continue then be delivered in order rather than delivered immediately. |
| 207 // Bug 329665 tracks similar behavior for other synchronous events. | 207 // Bug 329665 tracks similar behavior for other synchronous events. |
| 208 if (!executionContext() || executionContext()->activeDOMObjectsAreStopped()) | 208 if (!executionContext() || executionContext()->activeDOMObjectsAreStopped()) |
| 209 return; | 209 return; |
| 210 | 210 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 | 256 |
| 257 v8::Handle<v8::Object> receiver = toV8(element, context->Global(), isolate).
As<v8::Object>(); | 257 v8::Handle<v8::Object> receiver = toV8(element, context->Global(), isolate).
As<v8::Object>(); |
| 258 ASSERT(!receiver.IsEmpty()); | 258 ASSERT(!receiver.IsEmpty()); |
| 259 | 259 |
| 260 v8::TryCatch exceptionCatcher; | 260 v8::TryCatch exceptionCatcher; |
| 261 exceptionCatcher.SetVerbose(true); | 261 exceptionCatcher.SetVerbose(true); |
| 262 ScriptController::callFunction(executionContext(), callback, receiver, 0, 0,
isolate); | 262 ScriptController::callFunction(executionContext(), callback, receiver, 0, 0,
isolate); |
| 263 } | 263 } |
| 264 | 264 |
| 265 } // namespace WebCore | 265 } // namespace WebCore |
| OLD | NEW |