| 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 #include "config.h" | |
| 32 #include "bindings/core/dart/DartDOMData.h" | |
| 33 | |
| 34 #include "bindings/core/dart/DartApplicationLoader.h" | |
| 35 #include "bindings/core/dart/ThreadSafeDartIsolateWrapper.h" | |
| 36 #include "core/dom/ExecutionContext.h" | |
| 37 | |
| 38 namespace blink { | |
| 39 | |
| 40 DartDOMData::DartDOMData(ExecutionContext* context, const char* scriptURL, bool
isDOMEnabled) | |
| 41 : m_scriptURL(strdup(scriptURL)) | |
| 42 , m_scriptExecutionContext(context) | |
| 43 , m_isDOMEnabled(isDOMEnabled) | |
| 44 , m_recursion(0) | |
| 45 , m_stringCache() | |
| 46 , m_threadSafeIsolateWrapper() | |
| 47 , m_isolateWrapperMutex() | |
| 48 , m_applicationLoader() | |
| 49 , m_applicationSnapshot() | |
| 50 , m_reachableWeakHandle(0) | |
| 51 , m_objectMap() | |
| 52 , m_messagePortMap() | |
| 53 , m_isolateDestructionObservers() | |
| 54 , m_customElementBindings() | |
| 55 , m_classHandleCache() | |
| 56 , m_libraryHandleCache() | |
| 57 , m_functionType(0) | |
| 58 , m_currentException(0) | |
| 59 , m_rootScriptState(0) | |
| 60 , m_weakReferenceSetForRootMap(0) | |
| 61 , m_documentWeakReferenceSet(0) | |
| 62 , m_weakReferenceSetBuilder(0) | |
| 63 , m_isObservatoryFakeDartDOMData(false) | |
| 64 { | |
| 65 } | |
| 66 | |
| 67 DartDOMData::~DartDOMData() | |
| 68 { | |
| 69 ASSERT(m_objectMap.isEmpty()); | |
| 70 ASSERT(m_messagePortMap.isEmpty()); | |
| 71 | |
| 72 free(m_scriptURL); | |
| 73 setApplicationLoader(nullptr); | |
| 74 } | |
| 75 | |
| 76 DartDOMData* DartDOMData::current() | |
| 77 { | |
| 78 ASSERT(Dart_CurrentIsolate()); | |
| 79 return static_cast<DartDOMData*>(Dart_CurrentIsolateData()); | |
| 80 } | |
| 81 | |
| 82 void DartDOMData::setApplicationLoader(PassRefPtr<DartApplicationLoader> applica
tionLoader) | |
| 83 { | |
| 84 ASSERT(!m_applicationLoader || !applicationLoader); | |
| 85 m_applicationLoader = applicationLoader; | |
| 86 } | |
| 87 | |
| 88 PassRefPtr<DartApplicationLoader> DartDOMData::applicationLoader() | |
| 89 { | |
| 90 ASSERT(m_applicationLoader); | |
| 91 return m_applicationLoader; | |
| 92 } | |
| 93 | |
| 94 void DartDOMData::setThreadSafeIsolateWrapper(PassRefPtr<ThreadSafeDartIsolateWr
apper> threadSafeIsolateWrapper) | |
| 95 { | |
| 96 ASSERT(!m_threadSafeIsolateWrapper); | |
| 97 MutexLocker locker(m_isolateWrapperMutex); | |
| 98 m_threadSafeIsolateWrapper = threadSafeIsolateWrapper; | |
| 99 } | |
| 100 | |
| 101 PassRefPtr<ThreadSafeDartIsolateWrapper> DartDOMData::threadSafeIsolateWrapper() | |
| 102 { | |
| 103 ASSERT(m_threadSafeIsolateWrapper); | |
| 104 MutexLocker locker(m_isolateWrapperMutex); | |
| 105 return m_threadSafeIsolateWrapper; | |
| 106 } | |
| 107 | |
| 108 void DartDOMData::addCustomElementBinding(CustomElementDefinition* definition, P
assOwnPtr<DartCustomElementBinding> binding) | |
| 109 { | |
| 110 ASSERT(!m_customElementBindings.contains(definition)); | |
| 111 m_customElementBindings.add(definition, binding); | |
| 112 } | |
| 113 | |
| 114 void DartDOMData::clearCustomElementBinding(CustomElementDefinition* definition) | |
| 115 { | |
| 116 DartCustomElementBindingMap::iterator it = m_customElementBindings.find(defi
nition); | |
| 117 ASSERT(it != m_customElementBindings.end()); | |
| 118 m_customElementBindings.remove(it); | |
| 119 } | |
| 120 | |
| 121 DartCustomElementBinding* DartDOMData::customElementBinding(CustomElementDefinit
ion* definition) | |
| 122 { | |
| 123 DartCustomElementBindingMap::const_iterator it = m_customElementBindings.fin
d(definition); | |
| 124 if (it == m_customElementBindings.end()) | |
| 125 return 0; | |
| 126 return it->value.get(); | |
| 127 } | |
| 128 | |
| 129 Dart_PersistentHandle DartDOMData::getLibrary(int libraryId, const char* name) | |
| 130 { | |
| 131 Dart_Handle lib = Dart_LookupLibrary(Dart_NewStringFromCString(name)); | |
| 132 ASSERT(!Dart_IsError(lib)); | |
| 133 Dart_PersistentHandle persistentLib = Dart_NewPersistentHandle(lib); | |
| 134 m_libraryHandleCache[libraryId] = persistentLib; | |
| 135 return persistentLib; | |
| 136 } | |
| 137 | |
| 138 } | |
| OLD | NEW |