Title: [97964] trunk/Source/WebCore
Revision
97964
Author
kenn...@webkit.org
Date
2011-10-20 04:36:17 -0700 (Thu, 20 Oct 2011)

Log Message

Properly suspend/resume Geolocation/DeviceMotion/DeviceOrientation objects
https://bugs.webkit.org/show_bug.cgi?id=70328

Reviewed by Simon Hausmann.

Based on code from iOS and the N9.

No new tests, as the suspend/resume functionality is not fully working yet.

* dom/DeviceMotionController.cpp:
(WebCore::DeviceMotionController::suspend):
(WebCore::DeviceMotionController::resume):
* dom/DeviceMotionController.h:
* dom/DeviceOrientationController.cpp:
(WebCore::DeviceOrientationController::addListener):
(WebCore::DeviceOrientationController::removeListener):
(WebCore::DeviceOrientationController::removeAllListeners):
(WebCore::DeviceOrientationController::suspend):
(WebCore::DeviceOrientationController::resume):
* dom/DeviceOrientationController.h:
* dom/Document.cpp:
(WebCore::Document::suspendActiveDOMObjects):
(WebCore::Document::resumeActiveDOMObjects):
(WebCore::Document::stopActiveDOMObjects):
* dom/Document.h:
* dom/ScriptExecutionContext.h:
* page/GeolocationController.cpp:
(WebCore::GeolocationController::suspend):
(WebCore::GeolocationController::resume):
* page/GeolocationController.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (97963 => 97964)


--- trunk/Source/WebCore/ChangeLog	2011-10-20 11:36:04 UTC (rev 97963)
+++ trunk/Source/WebCore/ChangeLog	2011-10-20 11:36:17 UTC (rev 97964)
@@ -1,3 +1,36 @@
+2011-10-20  Kenneth Rohde Christiansen  <kenn...@webkit.org>
+
+        Properly suspend/resume Geolocation/DeviceMotion/DeviceOrientation objects
+        https://bugs.webkit.org/show_bug.cgi?id=70328
+
+        Reviewed by Simon Hausmann.
+
+        Based on code from iOS and the N9.
+
+        No new tests, as the suspend/resume functionality is not fully working yet.
+
+        * dom/DeviceMotionController.cpp:
+        (WebCore::DeviceMotionController::suspend):
+        (WebCore::DeviceMotionController::resume):
+        * dom/DeviceMotionController.h:
+        * dom/DeviceOrientationController.cpp:
+        (WebCore::DeviceOrientationController::addListener):
+        (WebCore::DeviceOrientationController::removeListener):
+        (WebCore::DeviceOrientationController::removeAllListeners):
+        (WebCore::DeviceOrientationController::suspend):
+        (WebCore::DeviceOrientationController::resume):
+        * dom/DeviceOrientationController.h:
+        * dom/Document.cpp:
+        (WebCore::Document::suspendActiveDOMObjects):
+        (WebCore::Document::resumeActiveDOMObjects):
+        (WebCore::Document::stopActiveDOMObjects):
+        * dom/Document.h:
+        * dom/ScriptExecutionContext.h:
+        * page/GeolocationController.cpp:
+        (WebCore::GeolocationController::suspend):
+        (WebCore::GeolocationController::resume):
+        * page/GeolocationController.h:
+
 2011-10-20  Antti Koivisto  <an...@apple.com>
 
         Move rule matching and applying to separate functions from CSSStyleSelector::styleForElement

Modified: trunk/Source/WebCore/dom/DeviceMotionController.cpp (97963 => 97964)


--- trunk/Source/WebCore/dom/DeviceMotionController.cpp	2011-10-20 11:36:04 UTC (rev 97963)
+++ trunk/Source/WebCore/dom/DeviceMotionController.cpp	2011-10-20 11:36:17 UTC (rev 97964)
@@ -97,6 +97,18 @@
         m_client->stopUpdating();
 }
 
+void DeviceMotionController::suspend()
+{
+    if (m_client)
+        m_client->stopUpdating();
+}
+
+void DeviceMotionController::resume()
+{
+    if (m_client && !m_listeners.isEmpty())
+        m_client->startUpdating();
+}
+
 void DeviceMotionController::didChangeDeviceMotion(DeviceMotionData* deviceMotionData)
 {
     RefPtr<DeviceMotionEvent> event = DeviceMotionEvent::create(eventNames().devicemotionEvent, deviceMotionData);

Modified: trunk/Source/WebCore/dom/DeviceMotionController.h (97963 => 97964)


--- trunk/Source/WebCore/dom/DeviceMotionController.h	2011-10-20 11:36:04 UTC (rev 97963)
+++ trunk/Source/WebCore/dom/DeviceMotionController.h	2011-10-20 11:36:17 UTC (rev 97964)
@@ -44,6 +44,9 @@
     void removeListener(DOMWindow*);
     void removeAllListeners(DOMWindow*);
 
+    void suspend();
+    void resume();
+
     void didChangeDeviceMotion(DeviceMotionData*);
 
     bool isActive() { return !m_listeners.isEmpty(); }

Modified: trunk/Source/WebCore/dom/DeviceOrientationController.cpp (97963 => 97964)


--- trunk/Source/WebCore/dom/DeviceOrientationController.cpp	2011-10-20 11:36:04 UTC (rev 97963)
+++ trunk/Source/WebCore/dom/DeviceOrientationController.cpp	2011-10-20 11:36:17 UTC (rev 97964)
@@ -99,6 +99,17 @@
         m_client->stopUpdating();
 }
 
+void DeviceOrientationController::suspend()
+{
+    m_client->stopUpdating();
+}
+
+void DeviceOrientationController::resume()
+{
+    if (!m_listeners.isEmpty())
+        m_client->startUpdating();
+}
+
 void DeviceOrientationController::didChangeDeviceOrientation(DeviceOrientation* orientation)
 {
     RefPtr<DeviceOrientationEvent> event = DeviceOrientationEvent::create(eventNames().deviceorientationEvent, orientation);

Modified: trunk/Source/WebCore/dom/DeviceOrientationController.h (97963 => 97964)


--- trunk/Source/WebCore/dom/DeviceOrientationController.h	2011-10-20 11:36:04 UTC (rev 97963)
+++ trunk/Source/WebCore/dom/DeviceOrientationController.h	2011-10-20 11:36:17 UTC (rev 97964)
@@ -46,6 +46,9 @@
     void removeListener(DOMWindow*);
     void removeAllListeners(DOMWindow*);
 
+    void suspend();
+    void resume();
+
     void didChangeDeviceOrientation(DeviceOrientation*);
 
     bool isActive() { return !m_listeners.isEmpty(); }

Modified: trunk/Source/WebCore/dom/Document.cpp (97963 => 97964)


--- trunk/Source/WebCore/dom/Document.cpp	2011-10-20 11:36:04 UTC (rev 97963)
+++ trunk/Source/WebCore/dom/Document.cpp	2011-10-20 11:36:17 UTC (rev 97964)
@@ -47,6 +47,10 @@
 #include "DOMImplementation.h"
 #include "DOMWindow.h"
 #include "DateComponents.h"
+#include "DeviceMotionController.h"
+#include "DeviceMotionEvent.h"
+#include "DeviceOrientationController.h"
+#include "DeviceOrientationEvent.h"
 #include "DocumentFragment.h"
 #include "DocumentLoader.h"
 #include "DocumentMarkerController.h"
@@ -70,6 +74,7 @@
 #include "FrameSelection.h"
 #include "FrameTree.h"
 #include "FrameView.h"
+#include "GeolocationController.h"
 #include "HashChangeEvent.h"
 #include "HTMLAllCollection.h"
 #include "HTMLAnchorElement.h"
@@ -1835,6 +1840,66 @@
         node->removeAllEventListeners();
 }
 
+void Document::suspendActiveDOMObjects(ActiveDOMObject::ReasonForSuspension why)
+{
+    ScriptExecutionContext::suspendActiveDOMObjects(why);
+
+    if (!page())
+        return;
+
+#if ENABLE(CLIENT_BASED_GEOLOCATION)
+    if (page()->geolocationController() && usingGeolocation())
+        page()->geolocationController()->suspend();
+#endif
+
+#if ENABLE(DEVICE_ORIENTATION)
+    if (page()->deviceMotionController())
+        page()->deviceMotionController()->suspend();
+    if (page()->deviceOrientationController())
+        page()->deviceOrientationController()->suspend();
+#endif
+}
+
+void Document::resumeActiveDOMObjects()
+{
+    ScriptExecutionContext::resumeActiveDOMObjects();
+
+    if (!page())
+        return;
+
+#if ENABLE(CLIENT_BASED_GEOLOCATION)
+    if (page()->geolocationController() && usingGeolocation())
+        page()->geolocationController()->resume();
+#endif
+
+#if ENABLE(DEVICE_ORIENTATION)
+    if (page()->deviceMotionController())
+        page()->deviceMotionController()->resume();
+    if (page()->deviceOrientationController())
+        page()->deviceOrientationController()->resume();
+#endif
+}
+
+void Document::stopActiveDOMObjects()
+{
+    ScriptExecutionContext::stopActiveDOMObjects();
+
+    if (!page())
+        return;
+
+#if ENABLE(CLIENT_BASED_GEOLOCATION)
+    if (page()->geolocationController() && usingGeolocation())
+        page()->geolocationController()->suspend();
+#endif
+
+#if ENABLE(DEVICE_ORIENTATION)
+    if (page()->deviceMotionController())
+        page()->deviceMotionController()->suspend();
+    if (page()->deviceOrientationController())
+        page()->deviceOrientationController()->suspend();
+#endif
+}
+
 RenderView* Document::renderView() const
 {
     return toRenderView(renderer());

Modified: trunk/Source/WebCore/dom/Document.h (97963 => 97964)


--- trunk/Source/WebCore/dom/Document.h	2011-10-20 11:36:04 UTC (rev 97963)
+++ trunk/Source/WebCore/dom/Document.h	2011-10-20 11:36:17 UTC (rev 97964)
@@ -564,6 +564,11 @@
     virtual void attach();
     virtual void detach();
 
+    // Override ScriptExecutionContext methods to do additional work
+    virtual void suspendActiveDOMObjects(ActiveDOMObject::ReasonForSuspension) OVERRIDE;
+    virtual void resumeActiveDOMObjects() OVERRIDE;
+    virtual void stopActiveDOMObjects() OVERRIDE;
+
     RenderArena* renderArena() { return m_renderArena.get(); }
 
     RenderView* renderView() const;

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (97963 => 97964)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.h	2011-10-20 11:36:04 UTC (rev 97963)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h	2011-10-20 11:36:17 UTC (rev 97964)
@@ -109,9 +109,10 @@
         bool canSuspendActiveDOMObjects();
         // Active objects can be asked to suspend even if canSuspendActiveDOMObjects() returns 'false' -
         // step-by-step JS debugging is one example.
-        void suspendActiveDOMObjects(ActiveDOMObject::ReasonForSuspension);
-        void resumeActiveDOMObjects();
-        void stopActiveDOMObjects();
+        virtual void suspendActiveDOMObjects(ActiveDOMObject::ReasonForSuspension);
+        virtual void resumeActiveDOMObjects();
+        virtual void stopActiveDOMObjects();
+
         void createdActiveDOMObject(ActiveDOMObject*, void* upcastPointer);
         void destroyedActiveDOMObject(ActiveDOMObject*);
         typedef const HashMap<ActiveDOMObject*, void*> ActiveDOMObjectsMap;

Modified: trunk/Source/WebCore/page/GeolocationController.cpp (97963 => 97964)


--- trunk/Source/WebCore/page/GeolocationController.cpp	2011-10-20 11:36:04 UTC (rev 97963)
+++ trunk/Source/WebCore/page/GeolocationController.cpp	2011-10-20 11:36:17 UTC (rev 97964)
@@ -80,6 +80,18 @@
     }
 }
 
+void GeolocationController::suspend()
+{
+    if (m_client)
+        m_client->stopUpdating();
+}
+
+void GeolocationController::resume()
+{
+    if (m_client && !m_observers.isEmpty())
+        m_client->startUpdating();
+}
+
 void GeolocationController::requestPermission(Geolocation* geolocation)
 {
     if (m_client)

Modified: trunk/Source/WebCore/page/GeolocationController.h (97963 => 97964)


--- trunk/Source/WebCore/page/GeolocationController.h	2011-10-20 11:36:04 UTC (rev 97963)
+++ trunk/Source/WebCore/page/GeolocationController.h	2011-10-20 11:36:17 UTC (rev 97964)
@@ -49,6 +49,9 @@
     void addObserver(Geolocation*, bool enableHighAccuracy);
     void removeObserver(Geolocation*);
 
+    void suspend();
+    void resume();
+
     void requestPermission(Geolocation*);
     void cancelPermissionRequest(Geolocation*);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to