| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef V8DOMMap_h | 31 #ifndef V8DOMMap_h |
| 32 #define V8DOMMap_h | 32 #define V8DOMMap_h |
| 33 | 33 |
| 34 #include <wtf/HashMap.h> | 34 #include <wtf/HashMap.h> |
| 35 #include <wtf/OwnPtr.h> |
| 35 #include <v8.h> | 36 #include <v8.h> |
| 36 | 37 |
| 37 namespace WebCore { | 38 namespace WebCore { |
| 38 class Node; | 39 class Node; |
| 39 #if ENABLE(SVG) | 40 #if ENABLE(SVG) |
| 40 class SVGElementInstance; | 41 class SVGElementInstance; |
| 41 #endif | 42 #endif |
| 42 | 43 |
| 43 // A table of wrappers with weak pointers. | 44 // A table of wrappers with weak pointers. |
| 44 // This table allows us to avoid track wrapped objects for debugging | 45 // This table allows us to avoid track wrapped objects for debugging |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 83 |
| 83 bool contains(KeyType* obj) { return m_map.contains(obj); } | 84 bool contains(KeyType* obj) { return m_map.contains(obj); } |
| 84 | 85 |
| 85 HashMap<KeyType*, ValueType*>& impl() { return m_map; } | 86 HashMap<KeyType*, ValueType*>& impl() { return m_map; } |
| 86 | 87 |
| 87 protected: | 88 protected: |
| 88 HashMap<KeyType*, ValueType*> m_map; | 89 HashMap<KeyType*, ValueType*> m_map; |
| 89 v8::WeakReferenceCallback m_weakReferenceCallback; | 90 v8::WeakReferenceCallback m_weakReferenceCallback; |
| 90 }; | 91 }; |
| 91 | 92 |
| 92 | |
| 93 template <class KeyType> class DOMWrapperMap : public WeakReferenceMap<KeyTy
pe, v8::Object> { | 93 template <class KeyType> class DOMWrapperMap : public WeakReferenceMap<KeyTy
pe, v8::Object> { |
| 94 public: | 94 public: |
| 95 DOMWrapperMap(v8::WeakReferenceCallback callback) : WeakReferenceMap<Key
Type, v8::Object>(callback) { } | 95 DOMWrapperMap(v8::WeakReferenceCallback callback) : WeakReferenceMap<Key
Type, v8::Object>(callback) { } |
| 96 |
| 97 class Visitor { |
| 98 public: |
| 99 virtual void visitDOMWrapper(KeyType* key, v8::Persistent<v8::Object>
object) = 0; |
| 100 }; |
| 101 }; |
| 102 |
| 103 // An opaque class that represents a set of DOM wrappers. |
| 104 class DOMDataStore; |
| 105 |
| 106 // A utility class to manage the lifetime of set of DOM wrappers. |
| 107 class DOMDataStoreHandle { |
| 108 public: |
| 109 DOMDataStoreHandle(); |
| 110 ~DOMDataStoreHandle(); |
| 111 |
| 112 DOMDataStore* getStore() const { return m_store.get(); } |
| 113 |
| 114 private: |
| 115 OwnPtr<DOMDataStore> m_store; |
| 96 }; | 116 }; |
| 97 | 117 |
| 98 // Callback when JS wrapper of active DOM object is dead. | 118 // Callback when JS wrapper of active DOM object is dead. |
| 99 void weakActiveDOMObjectCallback(v8::Persistent<v8::Value> v8Object, void* d
omObject); | 119 void weakActiveDOMObjectCallback(v8::Persistent<v8::Value> v8Object, void* d
omObject); |
| 100 | 120 |
| 101 // A map from DOM node to its JS wrapper. | 121 // A map from DOM node to its JS wrapper. |
| 102 DOMWrapperMap<Node>& getDOMNodeMap(); | 122 DOMWrapperMap<Node>& getDOMNodeMap(); |
| 123 void visitDOMNodesInCurrentThread(DOMWrapperMap<Node>::Visitor*); |
| 103 | 124 |
| 104 // A map from a DOM object (non-node) to its JS wrapper. This map does not c
ontain the DOM objects which can have pending activity (active dom objects). | 125 // A map from a DOM object (non-node) to its JS wrapper. This map does not c
ontain the DOM objects which can have pending activity (active dom objects). |
| 105 DOMWrapperMap<void>& getDOMObjectMap(); | 126 DOMWrapperMap<void>& getDOMObjectMap(); |
| 127 void visitDOMObjectsInCurrentThread(DOMWrapperMap<void>::Visitor*); |
| 106 | 128 |
| 107 // A map from a DOM object to its JS wrapper for DOM objects which can have
pending activity. | 129 // A map from a DOM object to its JS wrapper for DOM objects which can have
pending activity. |
| 108 DOMWrapperMap<void>& getActiveDOMObjectMap(); | 130 DOMWrapperMap<void>& getActiveDOMObjectMap(); |
| 131 void visitActiveDOMObjectsInCurrentThread(DOMWrapperMap<void>::Visitor*); |
| 109 | 132 |
| 110 // This should be called to remove all DOM objects associated with the curre
nt thread when it is tearing down. | 133 // This should be called to remove all DOM objects associated with the curre
nt thread when it is tearing down. |
| 111 void removeAllDOMObjectsInCurrentThread(); | 134 void removeAllDOMObjectsInCurrentThread(); |
| 112 | 135 |
| 113 #if ENABLE(SVG) | 136 #if ENABLE(SVG) |
| 114 // A map for SVGElementInstances to its JS wrapper. | 137 // A map for SVGElementInstances to its JS wrapper. |
| 115 DOMWrapperMap<SVGElementInstance>& getDOMSVGElementInstanceMap(); | 138 DOMWrapperMap<SVGElementInstance>& getDOMSVGElementInstanceMap(); |
| 139 void visitSVGElementInstancesInCurrentThread(DOMWrapperMap<SVGElementInstanc
e>::Visitor*); |
| 116 | 140 |
| 117 // Map of SVG objects with contexts to V8 objects. | 141 // Map of SVG objects with contexts to V8 objects. |
| 118 DOMWrapperMap<void>& getDOMSVGObjectWithContextMap(); | 142 DOMWrapperMap<void>& getDOMSVGObjectWithContextMap(); |
| 143 void visitDOMSVGObjectsInCurrentThread(DOMWrapperMap<void>::Visitor*); |
| 119 #endif | 144 #endif |
| 120 } // namespace WebCore | 145 } // namespace WebCore |
| 121 | 146 |
| 122 #endif // V8DOMMap_h | 147 #endif // V8DOMMap_h |
| OLD | NEW |