| 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 24 matching lines...) Expand all Loading... |
| 35 #include "bindings/v8/CustomElementHelpers.h" | 35 #include "bindings/v8/CustomElementHelpers.h" |
| 36 #include "bindings/v8/DOMDataStore.h" | 36 #include "bindings/v8/DOMDataStore.h" |
| 37 #include "bindings/v8/ScriptController.h" | 37 #include "bindings/v8/ScriptController.h" |
| 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 "core/dom/ScriptExecutionContext.h" | 40 #include "core/dom/ScriptExecutionContext.h" |
| 41 #include "wtf/PassRefPtr.h" | 41 #include "wtf/PassRefPtr.h" |
| 42 | 42 |
| 43 namespace WebCore { | 43 namespace WebCore { |
| 44 | 44 |
| 45 PassRefPtr<V8CustomElementLifecycleCallbacks> V8CustomElementLifecycleCallbacks:
:create(ScriptExecutionContext* scriptExecutionContext, v8::Handle<v8::Object> p
rototype, v8::Handle<v8::Function> created) | 45 PassRefPtr<V8CustomElementLifecycleCallbacks> V8CustomElementLifecycleCallbacks:
:create(ScriptExecutionContext* scriptExecutionContext, v8::Handle<v8::Object> p
rototype, v8::Handle<v8::Function> created, v8::Handle<v8::Function> attributeCh
anged) |
| 46 { | 46 { |
| 47 // A given object can only be used as a Custom Element prototype once, see i
sCustomElementInterfacePrototypeObject | 47 // A given object can only be used as a Custom Element prototype once, see i
sCustomElementInterfacePrototypeObject |
| 48 ASSERT(prototype->GetHiddenValue(V8HiddenPropertyName::customElementCreated(
)).IsEmpty()); | 48 ASSERT(prototype->GetHiddenValue(V8HiddenPropertyName::customElementCreated(
)).IsEmpty() && prototype->GetHiddenValue(V8HiddenPropertyName::customElementAtt
ributeChanged()).IsEmpty()); |
| 49 if (!created.IsEmpty()) | 49 if (!created.IsEmpty()) |
| 50 prototype->SetHiddenValue(V8HiddenPropertyName::customElementCreated(),
created); | 50 prototype->SetHiddenValue(V8HiddenPropertyName::customElementCreated(),
created); |
| 51 return adoptRef(new V8CustomElementLifecycleCallbacks(scriptExecutionContext
, prototype, created)); | 51 if (!attributeChanged.IsEmpty()) |
| 52 prototype->SetHiddenValue(V8HiddenPropertyName::customElementAttributeCh
anged(), attributeChanged); |
| 53 return adoptRef(new V8CustomElementLifecycleCallbacks(scriptExecutionContext
, prototype, created, attributeChanged)); |
| 52 } | 54 } |
| 53 | 55 |
| 54 template <typename T> | 56 template <typename T> |
| 55 static void weakCallback(v8::Isolate*, v8::Persistent<T>*, ScopedPersistent<T>*
handle) | 57 static void weakCallback(v8::Isolate*, v8::Persistent<T>*, ScopedPersistent<T>*
handle) |
| 56 { | 58 { |
| 57 handle->clear(); | 59 handle->clear(); |
| 58 } | 60 } |
| 59 | 61 |
| 60 V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ScriptExecu
tionContext* scriptExecutionContext, v8::Handle<v8::Object> prototype, v8::Handl
e<v8::Function> created) | 62 V8CustomElementLifecycleCallbacks::V8CustomElementLifecycleCallbacks(ScriptExecu
tionContext* scriptExecutionContext, v8::Handle<v8::Object> prototype, v8::Handl
e<v8::Function> created, v8::Handle<v8::Function> attributeChanged) |
| 61 : CustomElementLifecycleCallbacks(Created) | 63 : CustomElementLifecycleCallbacks(CallbackType(Created | (attributeChanged.I
sEmpty() ? None : AttributeChanged))) |
| 62 , ActiveDOMCallback(scriptExecutionContext) | 64 , ActiveDOMCallback(scriptExecutionContext) |
| 63 , m_world(DOMWrapperWorld::current()) | 65 , m_world(DOMWrapperWorld::current()) |
| 64 , m_prototype(prototype) | 66 , m_prototype(prototype) |
| 65 , m_created(created) | 67 , m_created(created) |
| 68 , m_attributeChanged(attributeChanged) |
| 66 { | 69 { |
| 67 m_prototype.makeWeak(&m_prototype, weakCallback<v8::Object>); | 70 m_prototype.makeWeak(&m_prototype, weakCallback<v8::Object>); |
| 68 if (!m_created.isEmpty()) | 71 if (!m_created.isEmpty()) |
| 69 m_created.makeWeak(&m_created, weakCallback<v8::Function>); | 72 m_created.makeWeak(&m_created, weakCallback<v8::Function>); |
| 73 if (!m_attributeChanged.isEmpty()) |
| 74 m_attributeChanged.makeWeak(&m_attributeChanged, weakCallback<v8::Functi
on>); |
| 70 } | 75 } |
| 71 | 76 |
| 72 void V8CustomElementLifecycleCallbacks::created(Element* element) | 77 void V8CustomElementLifecycleCallbacks::created(Element* element) |
| 73 { | 78 { |
| 74 if (!canInvokeCallback()) | 79 if (!canInvokeCallback()) |
| 75 return; | 80 return; |
| 76 | 81 |
| 77 element->setIsUpgradedCustomElement(); | 82 element->setIsUpgradedCustomElement(); |
| 78 | 83 |
| 79 v8::HandleScope handleScope; | 84 v8::HandleScope handleScope; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 102 if (receiver.IsEmpty()) | 107 if (receiver.IsEmpty()) |
| 103 receiver = toV8(element, context->Global(), isolate).As<v8::Object>(); | 108 receiver = toV8(element, context->Global(), isolate).As<v8::Object>(); |
| 104 | 109 |
| 105 ASSERT(!receiver.IsEmpty()); | 110 ASSERT(!receiver.IsEmpty()); |
| 106 | 111 |
| 107 v8::TryCatch exceptionCatcher; | 112 v8::TryCatch exceptionCatcher; |
| 108 exceptionCatcher.SetVerbose(true); | 113 exceptionCatcher.SetVerbose(true); |
| 109 ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(),
callback, receiver, 0, 0); | 114 ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(),
callback, receiver, 0, 0); |
| 110 } | 115 } |
| 111 | 116 |
| 117 void V8CustomElementLifecycleCallbacks::attributeChanged(Element* element, const
AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue) |
| 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, sizeof(argv) / sizeof(v8::Handle<v8::Value>), argv); |
| 146 } |
| 147 |
| 112 } // namespace WebCore | 148 } // namespace WebCore |
| OLD | NEW |