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