OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2012 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 DartDOMData_h |
| 32 #define DartDOMData_h |
| 33 |
| 34 #include "bindings/core/dart/DartJsInteropData.h" |
| 35 #include "bindings/core/dart/DartLibraryIds.h" |
| 36 #include "bindings/core/dart/DartScriptState.h" |
| 37 #include "bindings/core/dart/DartStringCache.h" |
| 38 #include "bindings/dart/DartWebkitClassIds.h" |
| 39 |
| 40 #include "wtf/HashMap.h" |
| 41 #include "wtf/HashSet.h" |
| 42 #include "wtf/RefPtr.h" |
| 43 #include "wtf/Threading.h" |
| 44 #include "wtf/ThreadingPrimitives.h" |
| 45 #include "wtf/Vector.h" |
| 46 #include "wtf/text/WTFString.h" |
| 47 |
| 48 #include <dart_api.h> |
| 49 |
| 50 namespace blink { |
| 51 |
| 52 class ActiveDOMObject; |
| 53 class CustomElementDefinition; |
| 54 class DartApplicationLoader; |
| 55 class DartEventListener; |
| 56 class DartIsolateDestructionObserver; |
| 57 class EventTarget; |
| 58 class ExecutionContext; |
| 59 class LocalDOMWindow; |
| 60 class MessagePort; |
| 61 class Node; |
| 62 class ThreadSafeDartIsolateWrapper; |
| 63 |
| 64 typedef HashMap<void*, Dart_WeakPersistentHandle> DartDOMObjectMap; |
| 65 typedef HashMap<MessagePort*, Dart_WeakPersistentHandle> DartMessagePortMap; |
| 66 typedef HashSet<DartIsolateDestructionObserver*> DartIsolateDestructionObservers
; |
| 67 typedef Dart_PersistentHandle ClassTable[NumWebkitClassIds]; |
| 68 typedef Dart_PersistentHandle LibraryTable[NumDartLibraryIds]; |
| 69 typedef HashMap<Node*, Dart_WeakReferenceSet> WeakReferenceSetForRootMap; |
| 70 |
| 71 class DartDOMData { |
| 72 public: |
| 73 DartDOMData(ExecutionContext*, const char* scriptURL, const char* packageRoo
t, bool isDOMEnabled); |
| 74 ~DartDOMData(); |
| 75 |
| 76 static DartDOMData* current(); |
| 77 |
| 78 char* scriptURL() const { return m_scriptURL; } |
| 79 const char* packageRoot() const { return m_packageRoot; } |
| 80 ExecutionContext* scriptExecutionContext() { return m_scriptExecutionContext
; } |
| 81 bool isDOMEnabled() { return m_isDOMEnabled; } |
| 82 |
| 83 // We track the Dart specific recursion level here as well as the global |
| 84 // recursion level tracked by m_recursionScope due to dartbug.com/14183. |
| 85 int* recursion() { return &m_recursion; } |
| 86 DartStringCache& stringCache() { return m_stringCache; } |
| 87 |
| 88 void setThreadSafeIsolateWrapper(PassRefPtr<ThreadSafeDartIsolateWrapper>); |
| 89 PassRefPtr<ThreadSafeDartIsolateWrapper> threadSafeIsolateWrapper(); |
| 90 |
| 91 void setApplicationLoader(PassRefPtr<DartApplicationLoader>); |
| 92 PassRefPtr<DartApplicationLoader> applicationLoader(); |
| 93 |
| 94 Vector<uint8_t>* applicationSnapshot() { return &m_applicationSnapshot; } |
| 95 |
| 96 void setReachableWeakHandle(Dart_WeakPersistentHandle reachableWeakHandle) |
| 97 { |
| 98 m_reachableWeakHandle = reachableWeakHandle; |
| 99 } |
| 100 Dart_WeakPersistentHandle reachableWeakHandle() { return m_reachableWeakHand
le; } |
| 101 |
| 102 DartDOMObjectMap* objectMap() { return &m_objectMap; } |
| 103 DartMessagePortMap* messagePortMap() { return &m_messagePortMap; } |
| 104 DartIsolateDestructionObservers* isolateDestructionObservers() |
| 105 { |
| 106 return &m_isolateDestructionObservers; |
| 107 } |
| 108 ClassTable* classHandleCache() { return &m_classHandleCache; } |
| 109 |
| 110 Dart_PersistentHandle library(int libraryId) const { return m_libraryHandleC
ache[libraryId]; } |
| 111 |
| 112 Dart_PersistentHandle blinkLibrary() const |
| 113 { |
| 114 return m_libraryHandleCache[DartBlinkLibraryId]; |
| 115 } |
| 116 void setBlinkLibrary(Dart_PersistentHandle lib) |
| 117 { |
| 118 m_libraryHandleCache[DartBlinkLibraryId] = lib; |
| 119 } |
| 120 |
| 121 Dart_PersistentHandle htmlLibrary() const |
| 122 { |
| 123 return m_libraryHandleCache[DartHtmlLibraryId]; |
| 124 } |
| 125 void setHtmlLibrary(Dart_PersistentHandle lib) |
| 126 { |
| 127 m_libraryHandleCache[DartHtmlLibraryId] = lib; |
| 128 } |
| 129 |
| 130 Dart_PersistentHandle svgLibrary() |
| 131 { |
| 132 Dart_PersistentHandle lib = m_libraryHandleCache[DartSvgLibraryId]; |
| 133 if (!lib) { |
| 134 lib = getLibrary(DartSvgLibraryId, "dart:svg"); |
| 135 m_libraryHandleCache[DartSvgLibraryId] = lib; |
| 136 } |
| 137 return lib; |
| 138 } |
| 139 void setSvgLibrary(Dart_PersistentHandle lib) |
| 140 { |
| 141 m_libraryHandleCache[DartSvgLibraryId] = lib; |
| 142 } |
| 143 |
| 144 Dart_PersistentHandle jsLibrary() const |
| 145 { |
| 146 return m_libraryHandleCache[DartJsLibraryId]; |
| 147 } |
| 148 void setJsLibrary(Dart_PersistentHandle lib) |
| 149 { |
| 150 m_libraryHandleCache[DartJsLibraryId] = lib; |
| 151 } |
| 152 |
| 153 Dart_Handle emptyString() const |
| 154 { |
| 155 return Dart_EmptyString(); |
| 156 } |
| 157 |
| 158 Dart_PersistentHandle functionType() const |
| 159 { |
| 160 return m_functionType; |
| 161 } |
| 162 void setFunctionType(Dart_PersistentHandle functionType) |
| 163 { |
| 164 m_functionType = functionType; |
| 165 } |
| 166 |
| 167 DartJsInteropData* jsInteropData() |
| 168 { |
| 169 return &m_jsInteropData; |
| 170 } |
| 171 |
| 172 DartScriptState* rootScriptState() |
| 173 { |
| 174 return m_rootScriptState; |
| 175 } |
| 176 |
| 177 void setRootScriptState(DartScriptState* scriptState) |
| 178 { |
| 179 m_rootScriptState = scriptState; |
| 180 } |
| 181 |
| 182 Dart_PersistentHandle currentException() const |
| 183 { |
| 184 return m_currentException; |
| 185 } |
| 186 void setCurrentException(Dart_PersistentHandle exception) |
| 187 { |
| 188 m_currentException = exception; |
| 189 } |
| 190 |
| 191 WeakReferenceSetForRootMap* weakReferenceSetForRootMap() const |
| 192 { |
| 193 return m_weakReferenceSetForRootMap; |
| 194 } |
| 195 void setWeakReferenceSetForRootMap(WeakReferenceSetForRootMap* map) |
| 196 { |
| 197 m_weakReferenceSetForRootMap = map; |
| 198 } |
| 199 |
| 200 Dart_WeakReferenceSet documentWeakReferenceSet() const |
| 201 { |
| 202 return m_documentWeakReferenceSet; |
| 203 } |
| 204 void setDocumentWeakReferenceSet(Dart_WeakReferenceSet set) |
| 205 { |
| 206 m_documentWeakReferenceSet = set; |
| 207 } |
| 208 |
| 209 Dart_WeakReferenceSetBuilder weakReferenceSetBuilder() const |
| 210 { |
| 211 return m_weakReferenceSetBuilder; |
| 212 } |
| 213 void setWeakReferenceSetBuilder(Dart_WeakReferenceSetBuilder setBuilder) |
| 214 { |
| 215 m_weakReferenceSetBuilder = setBuilder; |
| 216 } |
| 217 |
| 218 private: |
| 219 Dart_PersistentHandle getLibrary(int libraryId, const char* name); |
| 220 |
| 221 char* m_scriptURL; |
| 222 const char* m_packageRoot; |
| 223 ExecutionContext* m_scriptExecutionContext; |
| 224 bool m_isDOMEnabled; |
| 225 int m_recursion; |
| 226 DartStringCache m_stringCache; |
| 227 RefPtr<ThreadSafeDartIsolateWrapper> m_threadSafeIsolateWrapper; |
| 228 Mutex m_isolateWrapperMutex; |
| 229 RefPtr<DartApplicationLoader> m_applicationLoader; |
| 230 Vector<uint8_t> m_applicationSnapshot; |
| 231 Dart_WeakPersistentHandle m_reachableWeakHandle; |
| 232 |
| 233 DartJsInteropData m_jsInteropData; |
| 234 DartDOMObjectMap m_objectMap; |
| 235 DartMessagePortMap m_messagePortMap; |
| 236 DartIsolateDestructionObservers m_isolateDestructionObservers; |
| 237 ClassTable m_classHandleCache; |
| 238 LibraryTable m_libraryHandleCache; |
| 239 Dart_PersistentHandle m_functionType; |
| 240 Dart_PersistentHandle m_currentException; |
| 241 DartScriptState* m_rootScriptState; |
| 242 |
| 243 WeakReferenceSetForRootMap* m_weakReferenceSetForRootMap; |
| 244 Dart_WeakReferenceSet m_documentWeakReferenceSet; |
| 245 Dart_WeakReferenceSetBuilder m_weakReferenceSetBuilder; |
| 246 }; |
| 247 |
| 248 } |
| 249 |
| 250 #endif // DartDOMData_h |
OLD | NEW |