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 22 matching lines...) Expand all Loading... |
33 | 33 |
34 #include "V8Element.h" | 34 #include "V8Element.h" |
35 #include "bindings/v8/ScriptController.h" | 35 #include "bindings/v8/ScriptController.h" |
36 #include "bindings/v8/V8Binding.h" | 36 #include "bindings/v8/V8Binding.h" |
37 #include "bindings/v8/V8HiddenPropertyName.h" | 37 #include "bindings/v8/V8HiddenPropertyName.h" |
38 #include "core/dom/ScriptExecutionContext.h" | 38 #include "core/dom/ScriptExecutionContext.h" |
39 #include "wtf/PassRefPtr.h" | 39 #include "wtf/PassRefPtr.h" |
40 | 40 |
41 namespace WebCore { | 41 namespace WebCore { |
42 | 42 |
43 PassRefPtr<V8CustomElementCallback> V8CustomElementCallback::create(ScriptExecut
ionContext* scriptExecutionContext, v8::Handle<v8::Object> owner, v8::Handle<v8:
:Function> ready) | 43 PassRefPtr<V8CustomElementCallback> V8CustomElementCallback::create(ScriptExecut
ionContext* scriptExecutionContext, v8::Handle<v8::Object> owner, v8::Handle<v8:
:Function> ready, v8::Handle<v8::Function> inserted, v8::Handle<v8::Function> re
moved) |
44 { | 44 { |
45 if (!ready.IsEmpty()) | 45 if (!ready.IsEmpty()) |
46 owner->SetHiddenValue(V8HiddenPropertyName::customElementReady(), ready)
; | 46 owner->SetHiddenValue(V8HiddenPropertyName::customElementReady(), ready)
; |
47 return adoptRef(new V8CustomElementCallback(scriptExecutionContext, ready)); | 47 if (!inserted.IsEmpty()) |
| 48 owner->SetHiddenValue(V8HiddenPropertyName::customElementInserted(), ins
erted); |
| 49 if (!removed.IsEmpty()) |
| 50 owner->SetHiddenValue(V8HiddenPropertyName::customElementRemoved(), remo
ved); |
| 51 return adoptRef(new V8CustomElementCallback(scriptExecutionContext, ready, i
nserted, removed)); |
48 } | 52 } |
49 | 53 |
50 static void weakCallback(v8::Isolate*, v8::Persistent<v8::Function>*, ScopedPers
istent<v8::Function>* handle) | 54 static void weakCallback(v8::Isolate*, v8::Persistent<v8::Function>*, ScopedPers
istent<v8::Function>* handle) |
51 { | 55 { |
52 handle->clear(); | 56 handle->clear(); |
53 } | 57 } |
54 | 58 |
55 V8CustomElementCallback::V8CustomElementCallback(ScriptExecutionContext* scriptE
xecutionContext, v8::Handle<v8::Function> ready) | 59 V8CustomElementCallback::V8CustomElementCallback(ScriptExecutionContext* scriptE
xecutionContext, v8::Handle<v8::Function> ready, v8::Handle<v8::Function> insert
ed, v8::Handle<v8::Function> removed) |
56 : CustomElementCallback(ready.IsEmpty() ? None : Ready) | 60 : CustomElementCallback(CallbackType((ready.IsEmpty() ? None : Ready) | (ins
erted.IsEmpty() ? None : Inserted) | (removed.IsEmpty() ? None : Removed))) |
57 , ActiveDOMCallback(scriptExecutionContext) | 61 , ActiveDOMCallback(scriptExecutionContext) |
58 , m_world(DOMWrapperWorld::current()) | 62 , m_world(DOMWrapperWorld::current()) |
59 , m_ready(ready) | 63 , m_ready(ready) |
| 64 , m_inserted(inserted) |
| 65 , m_removed(removed) |
60 { | 66 { |
61 if (!m_ready.isEmpty()) | 67 if (!m_ready.isEmpty()) |
62 m_ready.makeWeak(&m_ready, weakCallback); | 68 m_ready.makeWeak(&m_ready, weakCallback); |
| 69 if (!m_inserted.isEmpty()) |
| 70 m_inserted.makeWeak(&m_inserted, weakCallback); |
| 71 if (!m_removed.isEmpty()) |
| 72 m_removed.makeWeak(&m_removed, weakCallback); |
63 } | 73 } |
64 | 74 |
65 void V8CustomElementCallback::ready(Element* element) | 75 void V8CustomElementCallback::ready(Element* element) |
66 { | 76 { |
| 77 invoke(m_ready, element); |
| 78 } |
| 79 |
| 80 void V8CustomElementCallback::inserted(Element* element) |
| 81 { |
| 82 invoke(m_inserted, element); |
| 83 } |
| 84 |
| 85 void V8CustomElementCallback::removed(Element* element) |
| 86 { |
| 87 invoke(m_removed, element); |
| 88 } |
| 89 |
| 90 void V8CustomElementCallback::invoke(const ScopedPersistent<v8::Function>& callb
ack, Element* element) |
| 91 { |
67 if (!canInvokeCallback()) | 92 if (!canInvokeCallback()) |
68 return; | 93 return; |
69 | 94 |
70 v8::HandleScope handleScope; | 95 v8::HandleScope handleScope; |
71 | 96 |
72 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo
rld.get()); | 97 v8::Handle<v8::Context> context = toV8Context(scriptExecutionContext(), m_wo
rld.get()); |
73 if (context.IsEmpty()) | 98 if (context.IsEmpty()) |
74 return; | 99 return; |
75 | 100 |
76 v8::Context::Scope scope(context); | 101 v8::Context::Scope scope(context); |
77 v8::Isolate* isolate = context->GetIsolate(); | 102 v8::Isolate* isolate = context->GetIsolate(); |
78 | 103 |
79 v8::Handle<v8::Function> callback = m_ready.newLocal(isolate); | 104 v8::Handle<v8::Function> localCallback = callback.newLocal(isolate); |
80 if (callback.IsEmpty()) | 105 if (localCallback.IsEmpty()) |
81 return; | 106 return; |
82 | 107 |
83 v8::Handle<v8::Value> elementHandle = toV8(element, context->Global(), isola
te); | 108 v8::Handle<v8::Value> elementHandle = toV8(element, context->Global(), isola
te); |
84 if (elementHandle.IsEmpty()) { | 109 if (elementHandle.IsEmpty()) { |
85 if (!isScriptControllerTerminating()) | 110 if (!isScriptControllerTerminating()) |
86 CRASH(); | 111 CRASH(); |
87 return; | 112 return; |
88 } | 113 } |
89 | 114 |
90 ASSERT(elementHandle->IsObject()); | 115 ASSERT(elementHandle->IsObject()); |
91 v8::Handle<v8::Object> receiver = v8::Handle<v8::Object>::Cast(elementHandle
); | 116 v8::Handle<v8::Object> receiver = v8::Handle<v8::Object>::Cast(elementHandle
); |
92 | 117 |
93 v8::TryCatch exceptionCatcher; | 118 v8::TryCatch exceptionCatcher; |
94 exceptionCatcher.SetVerbose(true); | 119 exceptionCatcher.SetVerbose(true); |
95 ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(),
callback, receiver, 0, 0); | 120 ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(),
localCallback, receiver, 0, 0); |
96 } | 121 } |
97 | 122 |
98 } // namespace WebCore | 123 } // namespace WebCore |
99 | 124 |
OLD | NEW |