| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef InspectorWrapper_h | 5 #ifndef InspectorWrapper_h |
| 6 #define InspectorWrapper_h | 6 #define InspectorWrapper_h |
| 7 | 7 |
| 8 #include "platform/inspector_protocol/Collections.h" |
| 8 #include "wtf/PassOwnPtr.h" | 9 #include "wtf/PassOwnPtr.h" |
| 9 #include "wtf/Vector.h" | |
| 10 #include <v8.h> | 10 #include <v8.h> |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 class V8DebuggerClient; | 14 class V8DebuggerClient; |
| 15 | 15 |
| 16 class InspectorWrapperBase { | 16 class InspectorWrapperBase { |
| 17 public: | 17 public: |
| 18 struct V8MethodConfiguration { | 18 struct V8MethodConfiguration { |
| 19 const char* name; | 19 const char* name; |
| 20 v8::FunctionCallback callback; | 20 v8::FunctionCallback callback; |
| 21 }; | 21 }; |
| 22 | 22 |
| 23 struct V8AttributeConfiguration { | 23 struct V8AttributeConfiguration { |
| 24 const char* name; | 24 const char* name; |
| 25 v8::AccessorNameGetterCallback callback; | 25 v8::AccessorNameGetterCallback callback; |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 static v8::Local<v8::FunctionTemplate> createWrapperTemplate(v8::Isolate*, c
onst char* className, const Vector<V8MethodConfiguration>& methods, const Vector
<V8AttributeConfiguration>& attributes); | 28 static v8::Local<v8::FunctionTemplate> createWrapperTemplate(v8::Isolate*, c
onst char* className, const protocol::Vector<V8MethodConfiguration>& methods, co
nst protocol::Vector<V8AttributeConfiguration>& attributes); |
| 29 | 29 |
| 30 protected: | 30 protected: |
| 31 static v8::Local<v8::Object> createWrapper(V8DebuggerClient*, v8::Local<v8::
FunctionTemplate>, v8::Local<v8::Context>); | 31 static v8::Local<v8::Object> createWrapper(V8DebuggerClient*, v8::Local<v8::
FunctionTemplate>, v8::Local<v8::Context>); |
| 32 static void* unwrap(v8::Local<v8::Context>, v8::Local<v8::Object>, const cha
r* name); | 32 static void* unwrap(v8::Local<v8::Context>, v8::Local<v8::Object>, const cha
r* name); |
| 33 | 33 |
| 34 static v8::Local<v8::String> v8InternalizedString(v8::Isolate*, const char*
name); | 34 static v8::Local<v8::String> v8InternalizedString(v8::Isolate*, const char*
name); |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 template<class T, char* const hiddenPropertyName, char* const className> | 37 template<class T, char* const hiddenPropertyName, char* const className> |
| 38 class InspectorWrapper final : public InspectorWrapperBase { | 38 class InspectorWrapper final : public InspectorWrapperBase { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 static void weakCallback(const v8::WeakCallbackInfo<WeakCallbackData>& i
nfo) | 61 static void weakCallback(const v8::WeakCallbackInfo<WeakCallbackData>& i
nfo) |
| 62 { | 62 { |
| 63 delete info.GetParameter(); | 63 delete info.GetParameter(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 v8::Global<v8::Object> m_persistent; | 66 v8::Global<v8::Object> m_persistent; |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 static v8::Local<v8::FunctionTemplate> createWrapperTemplate(v8::Isolate* is
olate, const Vector<V8MethodConfiguration>& methods, const Vector<V8AttributeCon
figuration>& attributes) | 69 static v8::Local<v8::FunctionTemplate> createWrapperTemplate(v8::Isolate* is
olate, const protocol::Vector<V8MethodConfiguration>& methods, const protocol::V
ector<V8AttributeConfiguration>& attributes) |
| 70 { | 70 { |
| 71 return InspectorWrapperBase::createWrapperTemplate(isolate, className, m
ethods, attributes); | 71 return InspectorWrapperBase::createWrapperTemplate(isolate, className, m
ethods, attributes); |
| 72 } | 72 } |
| 73 | 73 |
| 74 static v8::Local<v8::Object> wrap(V8DebuggerClient* client, v8::Local<v8::Fu
nctionTemplate> constructorTemplate, v8::Local<v8::Context> context, T* object) | 74 static v8::Local<v8::Object> wrap(V8DebuggerClient* client, v8::Local<v8::Fu
nctionTemplate> constructorTemplate, v8::Local<v8::Context> context, T* object) |
| 75 { | 75 { |
| 76 v8::Context::Scope contextScope(context); | 76 v8::Context::Scope contextScope(context); |
| 77 v8::Local<v8::Object> result = InspectorWrapperBase::createWrapper(clien
t, constructorTemplate, context); | 77 v8::Local<v8::Object> result = InspectorWrapperBase::createWrapper(clien
t, constructorTemplate, context); |
| 78 if (result.IsEmpty()) | 78 if (result.IsEmpty()) |
| 79 return v8::Local<v8::Object>(); | 79 return v8::Local<v8::Object>(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 104 void* data = InspectorWrapperBase::unwrap(context, object, hiddenPropert
yName); | 104 void* data = InspectorWrapperBase::unwrap(context, object, hiddenPropert
yName); |
| 105 if (!data) | 105 if (!data) |
| 106 return nullptr; | 106 return nullptr; |
| 107 return reinterpret_cast<WeakCallbackData*>(data)->m_impl; | 107 return reinterpret_cast<WeakCallbackData*>(data)->m_impl; |
| 108 } | 108 } |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 } // namespace blink | 111 } // namespace blink |
| 112 | 112 |
| 113 #endif // InspectorWrapper_h | 113 #endif // InspectorWrapper_h |
| OLD | NEW |