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

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: Have MutationObserver keep weak references to its registrations 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)
haraken 2014/04/17 05:37:12 Nit: You can drop the ENABLE(OILPAN) flag from her
sof 2014/04/17 12:41:55 ok, done that instead.
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 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after
1935 newController->didAddWheelEventHandler(document()); 1944 newController->didAddWheelEventHandler(document());
1936 } 1945 }
1937 1946
1938 if (const TouchEventTargetSet* touchHandlers = oldDocument.touchEventTargets ()) { 1947 if (const TouchEventTargetSet* touchHandlers = oldDocument.touchEventTargets ()) {
1939 while (touchHandlers->contains(this)) { 1948 while (touchHandlers->contains(this)) {
1940 oldDocument.didRemoveTouchEventHandler(this); 1949 oldDocument.didRemoveTouchEventHandler(this);
1941 document().didAddTouchEventHandler(this); 1950 document().didAddTouchEventHandler(this);
1942 } 1951 }
1943 } 1952 }
1944 1953
1945 if (Vector<OwnPtr<MutationObserverRegistration> >* registry = mutationObserv erRegistry()) { 1954 if (WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* reg istry = mutationObserverRegistry()) {
1946 for (size_t i = 0; i < registry->size(); ++i) { 1955 for (size_t i = 0; i < registry->size(); ++i) {
1947 document().addMutationObserverTypes(registry->at(i)->mutationTypes() ); 1956 document().addMutationObserverTypes(registry->at(i)->mutationTypes() );
1948 } 1957 }
1949 } 1958 }
1950 1959
1951 if (HashSet<MutationObserverRegistration*>* transientRegistry = transientMut ationObserverRegistry()) { 1960 if (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >* tr ansientRegistry = transientMutationObserverRegistry()) {
1952 for (HashSet<MutationObserverRegistration*>::iterator iter = transientRe gistry->begin(); iter != transientRegistry->end(); ++iter) { 1961 for (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >::iterator iter = transientRegistry->begin(); iter != transientRegistry->end(); ++iter) {
1953 document().addMutationObserverTypes((*iter)->mutationTypes()); 1962 document().addMutationObserverTypes((*iter)->mutationTypes());
1954 } 1963 }
1955 } 1964 }
1956 } 1965 }
1957 1966
1958 static inline bool tryAddEventListener(Node* targetNode, const AtomicString& eve ntType, PassRefPtr<EventListener> listener, bool useCapture) 1967 static inline bool tryAddEventListener(Node* targetNode, const AtomicString& eve ntType, PassRefPtr<EventListener> listener, bool useCapture)
1959 { 1968 {
1960 if (!targetNode->EventTarget::addEventListener(eventType, listener, useCaptu re)) 1969 if (!targetNode->EventTarget::addEventListener(eventType, listener, useCaptu re))
1961 return false; 1970 return false;
1962 1971
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2032 EventTargetData* data = new EventTargetData; 2041 EventTargetData* data = new EventTargetData;
2033 eventTargetDataMap().set(this, adoptPtr(data)); 2042 eventTargetDataMap().set(this, adoptPtr(data));
2034 return *data; 2043 return *data;
2035 } 2044 }
2036 2045
2037 void Node::clearEventTargetData() 2046 void Node::clearEventTargetData()
2038 { 2047 {
2039 eventTargetDataMap().remove(this); 2048 eventTargetDataMap().remove(this);
2040 } 2049 }
2041 2050
2042 Vector<OwnPtr<MutationObserverRegistration> >* Node::mutationObserverRegistry() 2051 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* Node::mutat ionObserverRegistry()
2043 { 2052 {
2044 if (!hasRareData()) 2053 if (!hasRareData())
2045 return 0; 2054 return 0;
2046 NodeMutationObserverData* data = rareData()->mutationObserverData(); 2055 NodeMutationObserverData* data = rareData()->mutationObserverData();
2047 if (!data) 2056 if (!data)
2048 return 0; 2057 return 0;
2049 return &data->registry; 2058 return &data->registry;
2050 } 2059 }
2051 2060
2052 HashSet<MutationObserverRegistration*>* Node::transientMutationObserverRegistry( ) 2061 WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >* Node::tran sientMutationObserverRegistry()
2053 { 2062 {
2054 if (!hasRareData()) 2063 if (!hasRareData())
2055 return 0; 2064 return 0;
2056 NodeMutationObserverData* data = rareData()->mutationObserverData(); 2065 NodeMutationObserverData* data = rareData()->mutationObserverData();
2057 if (!data) 2066 if (!data)
2058 return 0; 2067 return 0;
2059 return &data->transientRegistry; 2068 return &data->transientRegistry;
2060 } 2069 }
2061 2070
2062 template<typename Registry> 2071 template<typename Registry>
2063 static inline void collectMatchingObserversForMutation(HashMap<MutationObserver* , MutationRecordDeliveryOptions>& observers, Registry* registry, Node& target, M utationObserver::MutationType type, const QualifiedName* attributeName) 2072 static inline void collectMatchingObserversForMutation(WillBeHeapHashMap<RawPtrW illBeMember<MutationObserver>, MutationRecordDeliveryOptions>& observers, Regist ry* registry, Node& target, MutationObserver::MutationType type, const Qualified Name* attributeName)
2064 { 2073 {
2065 if (!registry) 2074 if (!registry)
2066 return; 2075 return;
2067 for (typename Registry::iterator iter = registry->begin(); iter != registry- >end(); ++iter) { 2076 for (typename Registry::iterator iter = registry->begin(); iter != registry- >end(); ++iter) {
2068 const MutationObserverRegistration& registration = **iter; 2077 const MutationObserverRegistration& registration = **iter;
2069 if (registration.shouldReceiveMutationFrom(target, type, attributeName)) { 2078 if (registration.shouldReceiveMutationFrom(target, type, attributeName)) {
2070 MutationRecordDeliveryOptions deliveryOptions = registration.deliver yOptions(); 2079 MutationRecordDeliveryOptions deliveryOptions = registration.deliver yOptions();
2071 HashMap<MutationObserver*, MutationRecordDeliveryOptions>::AddResult result = observers.add(&registration.observer(), deliveryOptions); 2080 WillBeHeapHashMap<RawPtrWillBeMember<MutationObserver>, MutationReco rdDeliveryOptions>::AddResult result = observers.add(&registration.observer(), d eliveryOptions);
2072 if (!result.isNewEntry) 2081 if (!result.isNewEntry)
2073 result.storedValue->value |= deliveryOptions; 2082 result.storedValue->value |= deliveryOptions;
2074 } 2083 }
2075 } 2084 }
2076 } 2085 }
2077 2086
2078 void Node::getRegisteredMutationObserversOfType(HashMap<MutationObserver*, Mutat ionRecordDeliveryOptions>& observers, MutationObserver::MutationType type, const QualifiedName* attributeName) 2087 void Node::getRegisteredMutationObserversOfType(WillBeHeapHashMap<RawPtrWillBeMe mber<MutationObserver>, MutationRecordDeliveryOptions>& observers, MutationObser ver::MutationType type, const QualifiedName* attributeName)
2079 { 2088 {
2080 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute Name); 2089 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute Name);
2081 collectMatchingObserversForMutation(observers, mutationObserverRegistry(), * this, type, attributeName); 2090 collectMatchingObserversForMutation(observers, mutationObserverRegistry(), * this, type, attributeName);
2082 collectMatchingObserversForMutation(observers, transientMutationObserverRegi stry(), *this, type, attributeName); 2091 collectMatchingObserversForMutation(observers, transientMutationObserverRegi stry(), *this, type, attributeName);
2083 for (Node* node = parentNode(); node; node = node->parentNode()) { 2092 for (Node* node = parentNode(); node; node = node->parentNode()) {
2084 collectMatchingObserversForMutation(observers, node->mutationObserverReg istry(), *this, type, attributeName); 2093 collectMatchingObserversForMutation(observers, node->mutationObserverReg istry(), *this, type, attributeName);
2085 collectMatchingObserversForMutation(observers, node->transientMutationOb serverRegistry(), *this, type, attributeName); 2094 collectMatchingObserversForMutation(observers, node->transientMutationOb serverRegistry(), *this, type, attributeName);
2086 } 2095 }
2087 } 2096 }
2088 2097
2089 void Node::registerMutationObserver(MutationObserver& observer, MutationObserver Options options, const HashSet<AtomicString>& attributeFilter) 2098 void Node::registerMutationObserver(MutationObserver& observer, MutationObserver Options options, const HashSet<AtomicString>& attributeFilter)
2090 { 2099 {
2091 MutationObserverRegistration* registration = 0; 2100 MutationObserverRegistration* registration = 0;
2092 Vector<OwnPtr<MutationObserverRegistration> >& registry = ensureRareData().e nsureMutationObserverData().registry; 2101 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >& registr y = ensureRareData().ensureMutationObserverData().registry;
2093 for (size_t i = 0; i < registry.size(); ++i) { 2102 for (size_t i = 0; i < registry.size(); ++i) {
2094 if (&registry[i]->observer() == &observer) { 2103 if (&registry[i]->observer() == &observer) {
2095 registration = registry[i].get(); 2104 registration = registry[i].get();
2096 registration->resetObservation(options, attributeFilter); 2105 registration->resetObservation(options, attributeFilter);
2097 } 2106 }
2098 } 2107 }
2099 2108
2100 if (!registration) { 2109 if (!registration) {
2101 registry.append(MutationObserverRegistration::create(observer, *this, op tions, attributeFilter)); 2110 registry.append(MutationObserverRegistration::create(observer, *this, op tions, attributeFilter));
2102 registration = registry.last().get(); 2111 registration = registry.last().get();
2103 } 2112 }
2104 2113
2105 document().addMutationObserverTypes(registration->mutationTypes()); 2114 document().addMutationObserverTypes(registration->mutationTypes());
2106 } 2115 }
2107 2116
2108 void Node::unregisterMutationObserver(MutationObserverRegistration* registration ) 2117 void Node::unregisterMutationObserver(MutationObserverRegistration* registration )
2109 { 2118 {
2110 Vector<OwnPtr<MutationObserverRegistration> >* registry = mutationObserverRe gistry(); 2119 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* registr y = mutationObserverRegistry();
2111 ASSERT(registry); 2120 ASSERT(registry);
2112 if (!registry) 2121 if (!registry)
2113 return; 2122 return;
2114 2123
2115 size_t index = registry->find(registration); 2124 size_t index = registry->find(registration);
2116 ASSERT(index != kNotFound); 2125 ASSERT(index != kNotFound);
2117 if (index == kNotFound) 2126 if (index == kNotFound)
2118 return; 2127 return;
2119 2128
2120 // Deleting the registration may cause this node to be derefed, so we must m ake sure the Vector operation completes 2129 // Deleting the registration may cause this node to be derefed, so we must m ake sure the Vector operation completes
2121 // before that, in case |this| is destroyed (see MutationObserverRegistratio n::m_registrationNodeKeepAlive). 2130 // before that, in case |this| is destroyed (see MutationObserverRegistratio n::m_registrationNodeKeepAlive).
2122 // FIXME: Simplify the registration/transient registration logic to make thi s understandable by humans. 2131 // FIXME: Simplify the registration/transient registration logic to make thi s understandable by humans.
2123 RefPtr<Node> protect(this); 2132 RefPtr<Node> protect(this);
2133 #if ENABLE(OILPAN)
2134 // Promptly dispose of the MutationObserverRegistration object.
2135 registration->dispose();
haraken 2014/04/17 05:37:12 Help me understand: In my understanding, all Muta
sof 2014/04/17 12:41:55 If you explicitly disconnect() a MutationObserver,
haraken 2014/04/17 13:20:54 Makes sense!
2136 #endif
2124 registry->remove(index); 2137 registry->remove(index);
2125 } 2138 }
2126 2139
2127 void Node::registerTransientMutationObserver(MutationObserverRegistration* regis tration) 2140 void Node::registerTransientMutationObserver(MutationObserverRegistration* regis tration)
2128 { 2141 {
2129 ensureRareData().ensureMutationObserverData().transientRegistry.add(registra tion); 2142 ensureRareData().ensureMutationObserverData().transientRegistry.add(registra tion);
2130 } 2143 }
2131 2144
2132 void Node::unregisterTransientMutationObserver(MutationObserverRegistration* reg istration) 2145 void Node::unregisterTransientMutationObserver(MutationObserverRegistration* reg istration)
2133 { 2146 {
2134 HashSet<MutationObserverRegistration*>* transientRegistry = transientMutatio nObserverRegistry(); 2147 WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >* transi entRegistry = transientMutationObserverRegistry();
2135 ASSERT(transientRegistry); 2148 ASSERT(transientRegistry);
2136 if (!transientRegistry) 2149 if (!transientRegistry)
2137 return; 2150 return;
2138 2151
2139 ASSERT(transientRegistry->contains(registration)); 2152 ASSERT(transientRegistry->contains(registration));
2140 transientRegistry->remove(registration); 2153 transientRegistry->remove(registration);
2141 } 2154 }
2142 2155
2143 void Node::notifyMutationObserversNodeWillDetach() 2156 void Node::notifyMutationObserversNodeWillDetach()
2144 { 2157 {
2145 if (!document().hasMutationObservers()) 2158 if (!document().hasMutationObservers())
2146 return; 2159 return;
2147 2160
2148 for (Node* node = parentNode(); node; node = node->parentNode()) { 2161 for (Node* node = parentNode(); node; node = node->parentNode()) {
2149 if (Vector<OwnPtr<MutationObserverRegistration> >* registry = node->muta tionObserverRegistry()) { 2162 if (WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* registry = node->mutationObserverRegistry()) {
2150 const size_t size = registry->size(); 2163 const size_t size = registry->size();
2151 for (size_t i = 0; i < size; ++i) 2164 for (size_t i = 0; i < size; ++i)
2152 registry->at(i)->observedSubtreeNodeWillDetach(*this); 2165 registry->at(i)->observedSubtreeNodeWillDetach(*this);
2153 } 2166 }
2154 2167
2155 if (HashSet<MutationObserverRegistration*>* transientRegistry = node->tr ansientMutationObserverRegistry()) { 2168 if (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> > * transientRegistry = node->transientMutationObserverRegistry()) {
2156 for (HashSet<MutationObserverRegistration*>::iterator iter = transie ntRegistry->begin(); iter != transientRegistry->end(); ++iter) 2169 for (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistrati on> >::iterator iter = transientRegistry->begin(); iter != transientRegistry->en d(); ++iter)
2157 (*iter)->observedSubtreeNodeWillDetach(*this); 2170 (*iter)->observedSubtreeNodeWillDetach(*this);
2158 } 2171 }
2159 } 2172 }
2160 } 2173 }
2161 2174
2162 void Node::handleLocalEvents(Event* event) 2175 void Node::handleLocalEvents(Event* event)
2163 { 2176 {
2164 if (!hasEventTargetData()) 2177 if (!hasEventTargetData())
2165 return; 2178 return;
2166 2179
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
2540 node->showTreeForThis(); 2553 node->showTreeForThis();
2541 } 2554 }
2542 2555
2543 void showNodePath(const WebCore::Node* node) 2556 void showNodePath(const WebCore::Node* node)
2544 { 2557 {
2545 if (node) 2558 if (node)
2546 node->showNodePathForThis(); 2559 node->showNodePathForThis();
2547 } 2560 }
2548 2561
2549 #endif 2562 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698