initial import
[vuplus_webkit] / Source / WebCore / bindings / v8 / DOMDataStore.h
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();
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
81         void* getDOMWrapperMap(DOMWrapperMapType);
82
83         DOMNodeMapping& domNodeMap() { return *m_domNodeMap; }
84         DOMWrapperMap<void>& domObjectMap() { return *m_domObjectMap; }
85         DOMWrapperMap<void>& activeDomObjectMap() { return *m_activeDomObjectMap; }
86 #if ENABLE(SVG)
87         DOMWrapperMap<SVGElementInstance>& domSvgElementInstanceMap() { return *m_domSvgElementInstanceMap; }
88 #endif
89
90         // Need by V8GCController.
91         static void weakActiveDOMObjectCallback(v8::Persistent<v8::Value> v8Object, void* domObject);
92
93     protected:
94         static void weakNodeCallback(v8::Persistent<v8::Value> v8Object, void* domObject);
95         static void weakDOMObjectCallback(v8::Persistent<v8::Value> v8Object, void* domObject);
96 #if ENABLE(SVG)
97         static void weakSVGElementInstanceCallback(v8::Persistent<v8::Value> v8Object, void* domObject);
98 #endif
99         
100         DOMNodeMapping* m_domNodeMap;
101         DOMWrapperMap<void>* m_domObjectMap;
102         DOMWrapperMap<void>* m_activeDomObjectMap;
103 #if ENABLE(SVG)
104         DOMWrapperMap<SVGElementInstance>* m_domSvgElementInstanceMap;
105 #endif
106     };
107
108 } // namespace WebCore
109
110 #endif // DOMDataStore_h