Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(347)

Side by Side Diff: Source/core/dom/Node.cpp

Issue 236653002: Oilpan: move mutation observers to the Oilpan heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Tidy up disposal Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved.
6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 setFlag(HasRareDataFlag); 321 setFlag(HasRareDataFlag);
322 return *data; 322 return *data;
323 } 323 }
324 324
325 void Node::clearRareData() 325 void Node::clearRareData()
326 { 326 {
327 ASSERT(hasRareData()); 327 ASSERT(hasRareData());
328 ASSERT(!transientMutationObserverRegistry() || transientMutationObserverRegi stry()->isEmpty()); 328 ASSERT(!transientMutationObserverRegistry() || transientMutationObserverRegi stry()->isEmpty());
329 329
330 RenderObject* renderer = m_data.m_rareData->renderer(); 330 RenderObject* renderer = m_data.m_rareData->renderer();
331 if (isElementNode()) 331 if (isElementNode()) {
332 delete static_cast<ElementRareData*>(m_data.m_rareData); 332 ElementRareData* rareData = static_cast<ElementRareData*>(m_data.m_rareD ata);
333 else 333 #if ENABLE(OILPAN)
334 delete static_cast<NodeRareData*>(m_data.m_rareData); 334 rareData->dispose();
335 #endif
336 delete rareData;
337 } else {
338 NodeRareData* rareData = static_cast<NodeRareData*>(m_data.m_rareData);
339 #if ENABLE(OILPAN)
340 rareData->dispose();
341 #endif
342 delete rareData;
343 }
335 m_data.m_renderer = renderer; 344 m_data.m_renderer = renderer;
336 clearFlag(HasRareDataFlag); 345 clearFlag(HasRareDataFlag);
337 } 346 }
338 347
339 Node* Node::toNode() 348 Node* Node::toNode()
340 { 349 {
341 return this; 350 return this;
342 } 351 }
343 352
344 short Node::tabIndex() const 353 short Node::tabIndex() const
(...skipping 1588 matching lines...) Expand 10 before | Expand all | Expand 10 after
1933 newController->didAddWheelEventHandler(document()); 1942 newController->didAddWheelEventHandler(document());
1934 } 1943 }
1935 1944
1936 if (const TouchEventTargetSet* touchHandlers = oldDocument.touchEventTargets ()) { 1945 if (const TouchEventTargetSet* touchHandlers = oldDocument.touchEventTargets ()) {
1937 while (touchHandlers->contains(this)) { 1946 while (touchHandlers->contains(this)) {
1938 oldDocument.didRemoveTouchEventHandler(this); 1947 oldDocument.didRemoveTouchEventHandler(this);
1939 document().didAddTouchEventHandler(this); 1948 document().didAddTouchEventHandler(this);
1940 } 1949 }
1941 } 1950 }
1942 1951
1943 if (Vector<OwnPtr<MutationObserverRegistration> >* registry = mutationObserv erRegistry()) { 1952 if (WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* reg istry = mutationObserverRegistry()) {
1944 for (size_t i = 0; i < registry->size(); ++i) { 1953 for (size_t i = 0; i < registry->size(); ++i) {
1945 document().addMutationObserverTypes(registry->at(i)->mutationTypes() ); 1954 document().addMutationObserverTypes(registry->at(i)->mutationTypes() );
1946 } 1955 }
1947 } 1956 }
1948 1957
1949 if (HashSet<MutationObserverRegistration*>* transientRegistry = transientMut ationObserverRegistry()) { 1958 if (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >* tr ansientRegistry = transientMutationObserverRegistry()) {
1950 for (HashSet<MutationObserverRegistration*>::iterator iter = transientRe gistry->begin(); iter != transientRegistry->end(); ++iter) { 1959 for (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >::iterator iter = transientRegistry->begin(); iter != transientRegistry->end(); ++iter) {
1951 document().addMutationObserverTypes((*iter)->mutationTypes()); 1960 document().addMutationObserverTypes((*iter)->mutationTypes());
1952 } 1961 }
1953 } 1962 }
1954 } 1963 }
1955 1964
1956 static inline bool tryAddEventListener(Node* targetNode, const AtomicString& eve ntType, PassRefPtr<EventListener> listener, bool useCapture) 1965 static inline bool tryAddEventListener(Node* targetNode, const AtomicString& eve ntType, PassRefPtr<EventListener> listener, bool useCapture)
1957 { 1966 {
1958 if (!targetNode->EventTarget::addEventListener(eventType, listener, useCaptu re)) 1967 if (!targetNode->EventTarget::addEventListener(eventType, listener, useCaptu re))
1959 return false; 1968 return false;
1960 1969
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2030 EventTargetData* data = new EventTargetData; 2039 EventTargetData* data = new EventTargetData;
2031 eventTargetDataMap().set(this, adoptPtr(data)); 2040 eventTargetDataMap().set(this, adoptPtr(data));
2032 return *data; 2041 return *data;
2033 } 2042 }
2034 2043
2035 void Node::clearEventTargetData() 2044 void Node::clearEventTargetData()
2036 { 2045 {
2037 eventTargetDataMap().remove(this); 2046 eventTargetDataMap().remove(this);
2038 } 2047 }
2039 2048
2040 Vector<OwnPtr<MutationObserverRegistration> >* Node::mutationObserverRegistry() 2049 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* Node::mutat ionObserverRegistry()
2041 { 2050 {
2042 if (!hasRareData()) 2051 if (!hasRareData())
2043 return 0; 2052 return 0;
2044 NodeMutationObserverData* data = rareData()->mutationObserverData(); 2053 NodeMutationObserverData* data = rareData()->mutationObserverData();
2045 if (!data) 2054 if (!data)
2046 return 0; 2055 return 0;
2047 return &data->registry; 2056 return &data->registry;
2048 } 2057 }
2049 2058
2050 HashSet<MutationObserverRegistration*>* Node::transientMutationObserverRegistry( ) 2059 WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >* Node::tran sientMutationObserverRegistry()
2051 { 2060 {
2052 if (!hasRareData()) 2061 if (!hasRareData())
2053 return 0; 2062 return 0;
2054 NodeMutationObserverData* data = rareData()->mutationObserverData(); 2063 NodeMutationObserverData* data = rareData()->mutationObserverData();
2055 if (!data) 2064 if (!data)
2056 return 0; 2065 return 0;
2057 return &data->transientRegistry; 2066 return &data->transientRegistry;
2058 } 2067 }
2059 2068
2060 template<typename Registry> 2069 template<typename Registry>
2061 static inline void collectMatchingObserversForMutation(HashMap<MutationObserver* , MutationRecordDeliveryOptions>& observers, Registry* registry, Node& target, M utationObserver::MutationType type, const QualifiedName* attributeName) 2070 static inline void collectMatchingObserversForMutation(WillBeHeapHashMap<RawPtrW illBeMember<MutationObserver>, MutationRecordDeliveryOptions>& observers, Regist ry* registry, Node& target, MutationObserver::MutationType type, const Qualified Name* attributeName)
2062 { 2071 {
2063 if (!registry) 2072 if (!registry)
2064 return; 2073 return;
2065 for (typename Registry::iterator iter = registry->begin(); iter != registry- >end(); ++iter) { 2074 for (typename Registry::iterator iter = registry->begin(); iter != registry- >end(); ++iter) {
2066 const MutationObserverRegistration& registration = **iter; 2075 const MutationObserverRegistration& registration = **iter;
2067 if (registration.shouldReceiveMutationFrom(target, type, attributeName)) { 2076 if (registration.shouldReceiveMutationFrom(target, type, attributeName)) {
2068 MutationRecordDeliveryOptions deliveryOptions = registration.deliver yOptions(); 2077 MutationRecordDeliveryOptions deliveryOptions = registration.deliver yOptions();
2069 HashMap<MutationObserver*, MutationRecordDeliveryOptions>::AddResult result = observers.add(&registration.observer(), deliveryOptions); 2078 WillBeHeapHashMap<RawPtrWillBeMember<MutationObserver>, MutationReco rdDeliveryOptions>::AddResult result = observers.add(&registration.observer(), d eliveryOptions);
2070 if (!result.isNewEntry) 2079 if (!result.isNewEntry)
2071 result.storedValue->value |= deliveryOptions; 2080 result.storedValue->value |= deliveryOptions;
2072 } 2081 }
2073 } 2082 }
2074 } 2083 }
2075 2084
2076 void Node::getRegisteredMutationObserversOfType(HashMap<MutationObserver*, Mutat ionRecordDeliveryOptions>& observers, MutationObserver::MutationType type, const QualifiedName* attributeName) 2085 void Node::getRegisteredMutationObserversOfType(WillBeHeapHashMap<RawPtrWillBeMe mber<MutationObserver>, MutationRecordDeliveryOptions>& observers, MutationObser ver::MutationType type, const QualifiedName* attributeName)
2077 { 2086 {
2078 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute Name); 2087 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute Name);
2079 collectMatchingObserversForMutation(observers, mutationObserverRegistry(), * this, type, attributeName); 2088 collectMatchingObserversForMutation(observers, mutationObserverRegistry(), * this, type, attributeName);
2080 collectMatchingObserversForMutation(observers, transientMutationObserverRegi stry(), *this, type, attributeName); 2089 collectMatchingObserversForMutation(observers, transientMutationObserverRegi stry(), *this, type, attributeName);
2081 for (Node* node = parentNode(); node; node = node->parentNode()) { 2090 for (Node* node = parentNode(); node; node = node->parentNode()) {
2082 collectMatchingObserversForMutation(observers, node->mutationObserverReg istry(), *this, type, attributeName); 2091 collectMatchingObserversForMutation(observers, node->mutationObserverReg istry(), *this, type, attributeName);
2083 collectMatchingObserversForMutation(observers, node->transientMutationOb serverRegistry(), *this, type, attributeName); 2092 collectMatchingObserversForMutation(observers, node->transientMutationOb serverRegistry(), *this, type, attributeName);
2084 } 2093 }
2085 } 2094 }
2086 2095
2087 void Node::registerMutationObserver(MutationObserver& observer, MutationObserver Options options, const HashSet<AtomicString>& attributeFilter) 2096 void Node::registerMutationObserver(MutationObserver& observer, MutationObserver Options options, const HashSet<AtomicString>& attributeFilter)
2088 { 2097 {
2089 MutationObserverRegistration* registration = 0; 2098 MutationObserverRegistration* registration = 0;
2090 Vector<OwnPtr<MutationObserverRegistration> >& registry = ensureRareData().e nsureMutationObserverData().registry; 2099 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >& registr y = ensureRareData().ensureMutationObserverData().registry;
2091 for (size_t i = 0; i < registry.size(); ++i) { 2100 for (size_t i = 0; i < registry.size(); ++i) {
2092 if (&registry[i]->observer() == &observer) { 2101 if (&registry[i]->observer() == &observer) {
2093 registration = registry[i].get(); 2102 registration = registry[i].get();
2094 registration->resetObservation(options, attributeFilter); 2103 registration->resetObservation(options, attributeFilter);
2095 } 2104 }
2096 } 2105 }
2097 2106
2098 if (!registration) { 2107 if (!registration) {
2099 registry.append(MutationObserverRegistration::create(observer, *this, op tions, attributeFilter)); 2108 registry.append(MutationObserverRegistration::create(observer, *this, op tions, attributeFilter));
2100 registration = registry.last().get(); 2109 registration = registry.last().get();
2101 } 2110 }
2102 2111
2103 document().addMutationObserverTypes(registration->mutationTypes()); 2112 document().addMutationObserverTypes(registration->mutationTypes());
2104 } 2113 }
2105 2114
2106 void Node::unregisterMutationObserver(MutationObserverRegistration* registration ) 2115 void Node::unregisterMutationObserver(MutationObserverRegistration* registration )
2107 { 2116 {
2108 Vector<OwnPtr<MutationObserverRegistration> >* registry = mutationObserverRe gistry(); 2117 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* registr y = mutationObserverRegistry();
2109 ASSERT(registry); 2118 ASSERT(registry);
2110 if (!registry) 2119 if (!registry)
2111 return; 2120 return;
2112 2121
2113 size_t index = registry->find(registration); 2122 size_t index = registry->find(registration);
2114 ASSERT(index != kNotFound); 2123 ASSERT(index != kNotFound);
2115 if (index == kNotFound) 2124 if (index == kNotFound)
2116 return; 2125 return;
2117 2126
2118 // Deleting the registration may cause this node to be derefed, so we must m ake sure the Vector operation completes 2127 // Deleting the registration may cause this node to be derefed, so we must m ake sure the Vector operation completes
2119 // before that, in case |this| is destroyed (see MutationObserverRegistratio n::m_registrationNodeKeepAlive). 2128 // before that, in case |this| is destroyed (see MutationObserverRegistratio n::m_registrationNodeKeepAlive).
2120 // FIXME: Simplify the registration/transient registration logic to make thi s understandable by humans. 2129 // FIXME: Simplify the registration/transient registration logic to make thi s understandable by humans.
2121 RefPtr<Node> protect(this); 2130 RefPtr<Node> protect(this);
2122 registry->remove(index); 2131 registry->remove(index);
2132 #if ENABLE(OILPAN)
2133 // Promptly dispose of the MutationObserverRegistration object.
2134 registration->dispose();
haraken 2014/04/15 02:33:25 This looks dangerous. As far as I read a comment i
sof 2014/04/15 22:00:53 This only applies in the Oilpan case and 'registra
2135 #endif
2123 } 2136 }
2124 2137
2125 void Node::registerTransientMutationObserver(MutationObserverRegistration* regis tration) 2138 void Node::registerTransientMutationObserver(MutationObserverRegistration* regis tration)
2126 { 2139 {
2127 ensureRareData().ensureMutationObserverData().transientRegistry.add(registra tion); 2140 ensureRareData().ensureMutationObserverData().transientRegistry.add(registra tion);
2128 } 2141 }
2129 2142
2130 void Node::unregisterTransientMutationObserver(MutationObserverRegistration* reg istration) 2143 void Node::unregisterTransientMutationObserver(MutationObserverRegistration* reg istration)
2131 { 2144 {
2132 HashSet<MutationObserverRegistration*>* transientRegistry = transientMutatio nObserverRegistry(); 2145 WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >* transi entRegistry = transientMutationObserverRegistry();
2133 ASSERT(transientRegistry); 2146 ASSERT(transientRegistry);
2134 if (!transientRegistry) 2147 if (!transientRegistry)
2135 return; 2148 return;
2136 2149
2137 ASSERT(transientRegistry->contains(registration)); 2150 ASSERT(transientRegistry->contains(registration));
2138 transientRegistry->remove(registration); 2151 transientRegistry->remove(registration);
2139 } 2152 }
2140 2153
2141 void Node::notifyMutationObserversNodeWillDetach() 2154 void Node::notifyMutationObserversNodeWillDetach()
2142 { 2155 {
2143 if (!document().hasMutationObservers()) 2156 if (!document().hasMutationObservers())
2144 return; 2157 return;
2145 2158
2146 for (Node* node = parentNode(); node; node = node->parentNode()) { 2159 for (Node* node = parentNode(); node; node = node->parentNode()) {
2147 if (Vector<OwnPtr<MutationObserverRegistration> >* registry = node->muta tionObserverRegistry()) { 2160 if (WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* registry = node->mutationObserverRegistry()) {
2148 const size_t size = registry->size(); 2161 const size_t size = registry->size();
2149 for (size_t i = 0; i < size; ++i) 2162 for (size_t i = 0; i < size; ++i)
2150 registry->at(i)->observedSubtreeNodeWillDetach(*this); 2163 registry->at(i)->observedSubtreeNodeWillDetach(*this);
2151 } 2164 }
2152 2165
2153 if (HashSet<MutationObserverRegistration*>* transientRegistry = node->tr ansientMutationObserverRegistry()) { 2166 if (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> > * transientRegistry = node->transientMutationObserverRegistry()) {
2154 for (HashSet<MutationObserverRegistration*>::iterator iter = transie ntRegistry->begin(); iter != transientRegistry->end(); ++iter) 2167 for (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistrati on> >::iterator iter = transientRegistry->begin(); iter != transientRegistry->en d(); ++iter)
2155 (*iter)->observedSubtreeNodeWillDetach(*this); 2168 (*iter)->observedSubtreeNodeWillDetach(*this);
2156 } 2169 }
2157 } 2170 }
2158 } 2171 }
2159 2172
2160 void Node::handleLocalEvents(Event* event) 2173 void Node::handleLocalEvents(Event* event)
2161 { 2174 {
2162 if (!hasEventTargetData()) 2175 if (!hasEventTargetData())
2163 return; 2176 return;
2164 2177
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
2538 node->showTreeForThis(); 2551 node->showTreeForThis();
2539 } 2552 }
2540 2553
2541 void showNodePath(const WebCore::Node* node) 2554 void showNodePath(const WebCore::Node* node)
2542 { 2555 {
2543 if (node) 2556 if (node)
2544 node->showNodePathForThis(); 2557 node->showNodePathForThis();
2545 } 2558 }
2546 2559
2547 #endif 2560 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698