Title: [98784] trunk/Source/WebCore
- Revision
- 98784
- Author
- [email protected]
- Date
- 2011-10-28 16:57:21 -0700 (Fri, 28 Oct 2011)
Log Message
Factor ContextDestructionObserver out of ActiveDOMObject
https://bugs.webkit.org/show_bug.cgi?id=71153
Reviewed by Sam Weinig.
This patch paves the way to make more objects observe the destruction
of ScriptExecutioContext without needing to add ifdefs to
ScriptExecutionContext.h/cpp. (As an example, see DOMURL.)
* dom/ActiveDOMObject.cpp:
(WebCore::ContextDestructionObserver::ContextDestructionObserver):
(WebCore::ContextDestructionObserver::~ContextDestructionObserver):
(WebCore::ContextDestructionObserver::contextDestroyed):
(WebCore::ActiveDOMObject::ActiveDOMObject):
(WebCore::ActiveDOMObject::~ActiveDOMObject):
* dom/ActiveDOMObject.h:
(WebCore::ContextDestructionObserver::scriptExecutionContext):
* dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::~ScriptExecutionContext):
(WebCore::ScriptExecutionContext::didCreateActiveDOMObject):
(WebCore::ScriptExecutionContext::willDestroyActiveDOMObject):
(WebCore::didCreateDestructionObserver):
(WebCore::willDestroyDestructionObserver):
* dom/ScriptExecutionContext.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (98783 => 98784)
--- trunk/Source/WebCore/ChangeLog 2011-10-28 23:51:12 UTC (rev 98783)
+++ trunk/Source/WebCore/ChangeLog 2011-10-28 23:57:21 UTC (rev 98784)
@@ -1,3 +1,30 @@
+2011-10-28 Adam Barth <[email protected]>
+
+ Factor ContextDestructionObserver out of ActiveDOMObject
+ https://bugs.webkit.org/show_bug.cgi?id=71153
+
+ Reviewed by Sam Weinig.
+
+ This patch paves the way to make more objects observe the destruction
+ of ScriptExecutioContext without needing to add ifdefs to
+ ScriptExecutionContext.h/cpp. (As an example, see DOMURL.)
+
+ * dom/ActiveDOMObject.cpp:
+ (WebCore::ContextDestructionObserver::ContextDestructionObserver):
+ (WebCore::ContextDestructionObserver::~ContextDestructionObserver):
+ (WebCore::ContextDestructionObserver::contextDestroyed):
+ (WebCore::ActiveDOMObject::ActiveDOMObject):
+ (WebCore::ActiveDOMObject::~ActiveDOMObject):
+ * dom/ActiveDOMObject.h:
+ (WebCore::ContextDestructionObserver::scriptExecutionContext):
+ * dom/ScriptExecutionContext.cpp:
+ (WebCore::ScriptExecutionContext::~ScriptExecutionContext):
+ (WebCore::ScriptExecutionContext::didCreateActiveDOMObject):
+ (WebCore::ScriptExecutionContext::willDestroyActiveDOMObject):
+ (WebCore::didCreateDestructionObserver):
+ (WebCore::willDestroyDestructionObserver):
+ * dom/ScriptExecutionContext.h:
+
2011-10-28 Tim Horton <[email protected]>
One more unreviewed build fix due to r98775.
Modified: trunk/Source/WebCore/dom/ActiveDOMObject.cpp (98783 => 98784)
--- trunk/Source/WebCore/dom/ActiveDOMObject.cpp 2011-10-28 23:51:12 UTC (rev 98783)
+++ trunk/Source/WebCore/dom/ActiveDOMObject.cpp 2011-10-28 23:57:21 UTC (rev 98784)
@@ -33,22 +33,48 @@
namespace WebCore {
+ContextDestructionObserver::ContextDestructionObserver(ScriptExecutionContext* scriptExecutionContext)
+ : m_scriptExecutionContext(scriptExecutionContext)
+{
+ if (!m_scriptExecutionContext)
+ return;
+
+ ASSERT(m_scriptExecutionContext->isContextThread());
+ m_scriptExecutionContext->didCreateDestructionObserver(this);
+}
+
+ContextDestructionObserver::~ContextDestructionObserver()
+{
+ if (!m_scriptExecutionContext)
+ return;
+
+ ASSERT(m_scriptExecutionContext->isContextThread());
+ m_scriptExecutionContext->willDestroyDestructionObserver(this);
+}
+
+void ContextDestructionObserver::contextDestroyed()
+{
+ m_scriptExecutionContext = 0;
+}
+
ActiveDOMObject::ActiveDOMObject(ScriptExecutionContext* scriptExecutionContext, void* upcastPointer)
- : m_scriptExecutionContext(scriptExecutionContext)
+ : ContextDestructionObserver(scriptExecutionContext)
, m_pendingActivityCount(0)
{
- if (m_scriptExecutionContext) {
- ASSERT(m_scriptExecutionContext->isContextThread());
- m_scriptExecutionContext->createdActiveDOMObject(this, upcastPointer);
- }
+ if (!m_scriptExecutionContext)
+ return;
+
+ ASSERT(m_scriptExecutionContext->isContextThread());
+ m_scriptExecutionContext->didCreateActiveDOMObject(this, upcastPointer);
}
ActiveDOMObject::~ActiveDOMObject()
{
- if (m_scriptExecutionContext) {
- ASSERT(m_scriptExecutionContext->isContextThread());
- m_scriptExecutionContext->destroyedActiveDOMObject(this);
- }
+ if (!m_scriptExecutionContext)
+ return;
+
+ ASSERT(m_scriptExecutionContext->isContextThread());
+ m_scriptExecutionContext->willDestroyActiveDOMObject(this);
}
bool ActiveDOMObject::hasPendingActivity() const
@@ -56,11 +82,6 @@
return m_pendingActivityCount;
}
-void ActiveDOMObject::contextDestroyed()
-{
- m_scriptExecutionContext = 0;
-}
-
bool ActiveDOMObject::canSuspend() const
{
return false;
Modified: trunk/Source/WebCore/dom/ActiveDOMObject.h (98783 => 98784)
--- trunk/Source/WebCore/dom/ActiveDOMObject.h 2011-10-28 23:51:12 UTC (rev 98783)
+++ trunk/Source/WebCore/dom/ActiveDOMObject.h 2011-10-28 23:57:21 UTC (rev 98784)
@@ -33,15 +33,26 @@
class ScriptExecutionContext;
- class ActiveDOMObject {
+ // FIXME: Move this class to it's own file.
+ class ContextDestructionObserver {
public:
+ ContextDestructionObserver(ScriptExecutionContext*);
+ virtual void contextDestroyed();
+
+ ScriptExecutionContext* scriptExecutionContext() const { return m_scriptExecutionContext; }
+
+ protected:
+ virtual ~ContextDestructionObserver();
+
+ ScriptExecutionContext* m_scriptExecutionContext;
+ };
+
+ class ActiveDOMObject : public ContextDestructionObserver {
+ public:
ActiveDOMObject(ScriptExecutionContext*, void* upcastPointer);
- ScriptExecutionContext* scriptExecutionContext() const { return m_scriptExecutionContext; }
virtual bool hasPendingActivity() const;
- virtual void contextDestroyed();
-
// canSuspend() is used by the caller if there is a choice between suspending and stopping.
// For example, a page won't be suspended and placed in the back/forward cache if it has
// the objects that can not be suspended.
@@ -76,7 +87,6 @@
virtual ~ActiveDOMObject();
private:
- ScriptExecutionContext* m_scriptExecutionContext;
unsigned m_pendingActivityCount;
};
Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.cpp (98783 => 98784)
--- trunk/Source/WebCore/dom/ScriptExecutionContext.cpp 2011-10-28 23:51:12 UTC (rev 98783)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.cpp 2011-10-28 23:57:21 UTC (rev 98784)
@@ -104,11 +104,12 @@
ScriptExecutionContext::~ScriptExecutionContext()
{
m_inDestructor = true;
- for (HashMap<ActiveDOMObject*, void*>::iterator iter = m_activeDOMObjects.begin(); iter != m_activeDOMObjects.end(); iter = m_activeDOMObjects.begin()) {
- ActiveDOMObject* object = iter->first;
- m_activeDOMObjects.remove(iter);
- ASSERT(object->scriptExecutionContext() == this);
- object->contextDestroyed();
+
+ for (HashSet<ContextDestructionObserver*>::iterator iter = m_destructionObservers.begin(); iter != m_destructionObservers.end(); iter = m_destructionObservers.begin()) {
+ ContextDestructionObserver* observer = *iter;
+ m_destructionObservers.remove(observer);
+ ASSERT(observer->scriptExecutionContext() == this);
+ observer->contextDestroyed();
}
HashSet<MessagePort*>::iterator messagePortsEnd = m_messagePorts.end();
@@ -288,7 +289,7 @@
closeMessagePorts();
}
-void ScriptExecutionContext::createdActiveDOMObject(ActiveDOMObject* object, void* upcastPointer)
+void ScriptExecutionContext::didCreateActiveDOMObject(ActiveDOMObject* object, void* upcastPointer)
{
ASSERT(object);
ASSERT(upcastPointer);
@@ -298,7 +299,7 @@
m_activeDOMObjects.add(object, upcastPointer);
}
-void ScriptExecutionContext::destroyedActiveDOMObject(ActiveDOMObject* object)
+void ScriptExecutionContext::willDestroyActiveDOMObject(ActiveDOMObject* object)
{
ASSERT(object);
if (m_iteratingActiveDOMObjects)
@@ -306,6 +307,19 @@
m_activeDOMObjects.remove(object);
}
+void ScriptExecutionContext::didCreateDestructionObserver(ContextDestructionObserver* observer)
+{
+ ASSERT(observer);
+ ASSERT(!m_inDestructor);
+ m_destructionObservers.add(observer);
+}
+
+void ScriptExecutionContext::willDestroyDestructionObserver(ContextDestructionObserver* observer)
+{
+ ASSERT(observer);
+ m_destructionObservers.remove(observer);
+}
+
void ScriptExecutionContext::closeMessagePorts() {
HashSet<MessagePort*>::iterator messagePortsEnd = m_messagePorts.end();
for (HashSet<MessagePort*>::iterator iter = m_messagePorts.begin(); iter != messagePortsEnd; ++iter) {
Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (98783 => 98784)
--- trunk/Source/WebCore/dom/ScriptExecutionContext.h 2011-10-28 23:51:12 UTC (rev 98783)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h 2011-10-28 23:57:21 UTC (rev 98784)
@@ -114,11 +114,15 @@
virtual void resumeActiveDOMObjects();
virtual void stopActiveDOMObjects();
- void createdActiveDOMObject(ActiveDOMObject*, void* upcastPointer);
- void destroyedActiveDOMObject(ActiveDOMObject*);
+ void didCreateActiveDOMObject(ActiveDOMObject*, void* upcastPointer);
+ void willDestroyActiveDOMObject(ActiveDOMObject*);
+
typedef const HashMap<ActiveDOMObject*, void*> ActiveDOMObjectsMap;
ActiveDOMObjectsMap& activeDOMObjects() const { return m_activeDOMObjects; }
+ void didCreateDestructionObserver(ContextDestructionObserver*);
+ void willDestroyDestructionObserver(ContextDestructionObserver*);
+
virtual void suspendScriptedAnimationControllerCallbacks() { }
virtual void resumeScriptedAnimationControllerCallbacks() { }
@@ -199,7 +203,7 @@
RefPtr<ContentSecurityPolicy> m_contentSecurityPolicy;
HashSet<MessagePort*> m_messagePorts;
-
+ HashSet<ContextDestructionObserver*> m_destructionObservers;
HashMap<ActiveDOMObject*, void*> m_activeDOMObjects;
bool m_iteratingActiveDOMObjects;
bool m_inDestructor;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes