Changeset 98784 in webkit
- Timestamp:
- Oct 28, 2011, 4:57:21 PM (15 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
-
ChangeLog (modified) (1 diff)
-
dom/ActiveDOMObject.cpp (modified) (2 diffs)
-
dom/ActiveDOMObject.h (modified) (2 diffs)
-
dom/ScriptExecutionContext.cpp (modified) (4 diffs)
-
dom/ScriptExecutionContext.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r98779 r98784 1 2011-10-28 Adam Barth <abarth@webkit.org> 2 3 Factor ContextDestructionObserver out of ActiveDOMObject 4 https://bugs.webkit.org/show_bug.cgi?id=71153 5 6 Reviewed by Sam Weinig. 7 8 This patch paves the way to make more objects observe the destruction 9 of ScriptExecutioContext without needing to add ifdefs to 10 ScriptExecutionContext.h/cpp. (As an example, see DOMURL.) 11 12 * dom/ActiveDOMObject.cpp: 13 (WebCore::ContextDestructionObserver::ContextDestructionObserver): 14 (WebCore::ContextDestructionObserver::~ContextDestructionObserver): 15 (WebCore::ContextDestructionObserver::contextDestroyed): 16 (WebCore::ActiveDOMObject::ActiveDOMObject): 17 (WebCore::ActiveDOMObject::~ActiveDOMObject): 18 * dom/ActiveDOMObject.h: 19 (WebCore::ContextDestructionObserver::scriptExecutionContext): 20 * dom/ScriptExecutionContext.cpp: 21 (WebCore::ScriptExecutionContext::~ScriptExecutionContext): 22 (WebCore::ScriptExecutionContext::didCreateActiveDOMObject): 23 (WebCore::ScriptExecutionContext::willDestroyActiveDOMObject): 24 (WebCore::didCreateDestructionObserver): 25 (WebCore::willDestroyDestructionObserver): 26 * dom/ScriptExecutionContext.h: 27 1 28 2011-10-28 Tim Horton <timothy_horton@apple.com> 2 29 -
trunk/Source/WebCore/dom/ActiveDOMObject.cpp
r67432 r98784 34 34 namespace WebCore { 35 35 36 ContextDestructionObserver::ContextDestructionObserver(ScriptExecutionContext* scriptExecutionContext) 37 : m_scriptExecutionContext(scriptExecutionContext) 38 { 39 if (!m_scriptExecutionContext) 40 return; 41 42 ASSERT(m_scriptExecutionContext->isContextThread()); 43 m_scriptExecutionContext->didCreateDestructionObserver(this); 44 } 45 46 ContextDestructionObserver::~ContextDestructionObserver() 47 { 48 if (!m_scriptExecutionContext) 49 return; 50 51 ASSERT(m_scriptExecutionContext->isContextThread()); 52 m_scriptExecutionContext->willDestroyDestructionObserver(this); 53 } 54 55 void ContextDestructionObserver::contextDestroyed() 56 { 57 m_scriptExecutionContext = 0; 58 } 59 36 60 ActiveDOMObject::ActiveDOMObject(ScriptExecutionContext* scriptExecutionContext, void* upcastPointer) 37 : m_scriptExecutionContext(scriptExecutionContext)61 : ContextDestructionObserver(scriptExecutionContext) 38 62 , m_pendingActivityCount(0) 39 63 { 40 if (m_scriptExecutionContext) { 41 ASSERT(m_scriptExecutionContext->isContextThread()); 42 m_scriptExecutionContext->createdActiveDOMObject(this, upcastPointer); 43 } 64 if (!m_scriptExecutionContext) 65 return; 66 67 ASSERT(m_scriptExecutionContext->isContextThread()); 68 m_scriptExecutionContext->didCreateActiveDOMObject(this, upcastPointer); 44 69 } 45 70 46 71 ActiveDOMObject::~ActiveDOMObject() 47 72 { 48 if (m_scriptExecutionContext) { 49 ASSERT(m_scriptExecutionContext->isContextThread()); 50 m_scriptExecutionContext->destroyedActiveDOMObject(this); 51 } 73 if (!m_scriptExecutionContext) 74 return; 75 76 ASSERT(m_scriptExecutionContext->isContextThread()); 77 m_scriptExecutionContext->willDestroyActiveDOMObject(this); 52 78 } 53 79 … … 55 81 { 56 82 return m_pendingActivityCount; 57 }58 59 void ActiveDOMObject::contextDestroyed()60 {61 m_scriptExecutionContext = 0;62 83 } 63 84 -
trunk/Source/WebCore/dom/ActiveDOMObject.h
r67432 r98784 34 34 class ScriptExecutionContext; 35 35 36 class ActiveDOMObject { 36 // FIXME: Move this class to it's own file. 37 class ContextDestructionObserver { 38 public: 39 ContextDestructionObserver(ScriptExecutionContext*); 40 virtual void contextDestroyed(); 41 42 ScriptExecutionContext* scriptExecutionContext() const { return m_scriptExecutionContext; } 43 44 protected: 45 virtual ~ContextDestructionObserver(); 46 47 ScriptExecutionContext* m_scriptExecutionContext; 48 }; 49 50 class ActiveDOMObject : public ContextDestructionObserver { 37 51 public: 38 52 ActiveDOMObject(ScriptExecutionContext*, void* upcastPointer); 39 53 40 ScriptExecutionContext* scriptExecutionContext() const { return m_scriptExecutionContext; }41 54 virtual bool hasPendingActivity() const; 42 43 virtual void contextDestroyed();44 55 45 56 // canSuspend() is used by the caller if there is a choice between suspending and stopping. … … 77 88 78 89 private: 79 ScriptExecutionContext* m_scriptExecutionContext;80 90 unsigned m_pendingActivityCount; 81 91 }; -
trunk/Source/WebCore/dom/ScriptExecutionContext.cpp
r98196 r98784 105 105 { 106 106 m_inDestructor = true; 107 for (HashMap<ActiveDOMObject*, void*>::iterator iter = m_activeDOMObjects.begin(); iter != m_activeDOMObjects.end(); iter = m_activeDOMObjects.begin()) { 108 ActiveDOMObject* object = iter->first; 109 m_activeDOMObjects.remove(iter); 110 ASSERT(object->scriptExecutionContext() == this); 111 object->contextDestroyed(); 107 108 for (HashSet<ContextDestructionObserver*>::iterator iter = m_destructionObservers.begin(); iter != m_destructionObservers.end(); iter = m_destructionObservers.begin()) { 109 ContextDestructionObserver* observer = *iter; 110 m_destructionObservers.remove(observer); 111 ASSERT(observer->scriptExecutionContext() == this); 112 observer->contextDestroyed(); 112 113 } 113 114 … … 289 290 } 290 291 291 void ScriptExecutionContext:: createdActiveDOMObject(ActiveDOMObject* object, void* upcastPointer)292 void ScriptExecutionContext::didCreateActiveDOMObject(ActiveDOMObject* object, void* upcastPointer) 292 293 { 293 294 ASSERT(object); … … 299 300 } 300 301 301 void ScriptExecutionContext:: destroyedActiveDOMObject(ActiveDOMObject* object)302 void ScriptExecutionContext::willDestroyActiveDOMObject(ActiveDOMObject* object) 302 303 { 303 304 ASSERT(object); … … 305 306 CRASH(); 306 307 m_activeDOMObjects.remove(object); 308 } 309 310 void ScriptExecutionContext::didCreateDestructionObserver(ContextDestructionObserver* observer) 311 { 312 ASSERT(observer); 313 ASSERT(!m_inDestructor); 314 m_destructionObservers.add(observer); 315 } 316 317 void ScriptExecutionContext::willDestroyDestructionObserver(ContextDestructionObserver* observer) 318 { 319 ASSERT(observer); 320 m_destructionObservers.remove(observer); 307 321 } 308 322 -
trunk/Source/WebCore/dom/ScriptExecutionContext.h
r98770 r98784 115 115 virtual void stopActiveDOMObjects(); 116 116 117 void createdActiveDOMObject(ActiveDOMObject*, void* upcastPointer); 118 void destroyedActiveDOMObject(ActiveDOMObject*); 117 void didCreateActiveDOMObject(ActiveDOMObject*, void* upcastPointer); 118 void willDestroyActiveDOMObject(ActiveDOMObject*); 119 119 120 typedef const HashMap<ActiveDOMObject*, void*> ActiveDOMObjectsMap; 120 121 ActiveDOMObjectsMap& activeDOMObjects() const { return m_activeDOMObjects; } 122 123 void didCreateDestructionObserver(ContextDestructionObserver*); 124 void willDestroyDestructionObserver(ContextDestructionObserver*); 121 125 122 126 virtual void suspendScriptedAnimationControllerCallbacks() { } … … 200 204 201 205 HashSet<MessagePort*> m_messagePorts; 202 206 HashSet<ContextDestructionObserver*> m_destructionObservers; 203 207 HashMap<ActiveDOMObject*, void*> m_activeDOMObjects; 204 208 bool m_iteratingActiveDOMObjects;
Note:
See TracChangeset
for help on using the changeset viewer.