• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
29  */
30 
31 #ifndef DOMDataStore_h
32 #define DOMDataStore_h
33 
34 #include "V8DOMMap.h"
35 #include "V8Node.h"
36 
37 #include <v8.h>
38 #include <wtf/HashMap.h>
39 #include <wtf/MainThread.h>
40 #include <wtf/Noncopyable.h>
41 #include <wtf/OwnPtr.h>
42 #include <wtf/StdLibExtras.h>
43 #include <wtf/Threading.h>
44 #include <wtf/ThreadSpecific.h>
45 #include <wtf/Vector.h>
46 
47 namespace WebCore {
48 
49     class DOMData;
50     class DOMDataStore;
51 
52     typedef WTF::Vector<DOMDataStore*> DOMDataList;
53 
54     // DOMDataStore
55     //
56     // DOMDataStore is the backing store that holds the maps between DOM objects
57     // and JavaScript objects.  In general, each thread can have multiple backing
58     // stores, one per isolated world.
59     //
60     // This class doesn't manage the lifetime of the store.  The data store
61     // lifetime is managed by subclasses.
62     //
63     class DOMDataStore {
64         WTF_MAKE_NONCOPYABLE(DOMDataStore);
65     public:
66         enum DOMWrapperMapType {
67             DOMNodeMap,
68             DOMObjectMap,
69             ActiveDOMObjectMap,
70 #if ENABLE(SVG)
71             DOMSVGElementInstanceMap
72 #endif
73         };
74 
75         DOMDataStore(DOMData*);
76         virtual ~DOMDataStore();
77 
78         // A list of all DOMDataStore objects in the current V8 instance (thread). Normally, each World has a DOMDataStore.
79         static DOMDataList& allStores();
80         // Mutex to protect against concurrent access of DOMDataList.
81         static WTF::Mutex& allStoresMutex();
82 
domData()83         DOMData* domData() const { return m_domData; }
84 
85         void* getDOMWrapperMap(DOMWrapperMapType);
86 
domNodeMap()87         DOMNodeMapping& domNodeMap() { return *m_domNodeMap; }
domObjectMap()88         DOMWrapperMap<void>& domObjectMap() { return *m_domObjectMap; }
activeDomObjectMap()89         DOMWrapperMap<void>& activeDomObjectMap() { return *m_activeDomObjectMap; }
90 #if ENABLE(SVG)
domSvgElementInstanceMap()91         DOMWrapperMap<SVGElementInstance>& domSvgElementInstanceMap() { return *m_domSvgElementInstanceMap; }
92 #endif
93 
94         // Need by V8GCController.
95         static void weakActiveDOMObjectCallback(v8::Persistent<v8::Value> v8Object, void* domObject);
96 
97     protected:
98         static void weakNodeCallback(v8::Persistent<v8::Value> v8Object, void* domObject);
99         static void weakDOMObjectCallback(v8::Persistent<v8::Value> v8Object, void* domObject);
100 #if ENABLE(SVG)
101         static void weakSVGElementInstanceCallback(v8::Persistent<v8::Value> v8Object, void* domObject);
102 #endif
103 
104         DOMNodeMapping* m_domNodeMap;
105         DOMWrapperMap<void>* m_domObjectMap;
106         DOMWrapperMap<void>* m_activeDomObjectMap;
107 #if ENABLE(SVG)
108         DOMWrapperMap<SVGElementInstance>* m_domSvgElementInstanceMap;
109 #endif
110 
111     private:
112         // A back-pointer to the DOMData to which we belong.
113         DOMData* m_domData;
114     };
115 
116 } // namespace WebCore
117 
118 #endif // DOMDataStore_h
119