<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[193885] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/193885">193885</a></dd>
<dt>Author</dt> <dd>dbates@webkit.org</dd>
<dt>Date</dt> <dd>2015-12-09 18:53:12 -0800 (Wed, 09 Dec 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>[iOS] Suspend and resume device motion and device orientation updates when page is hidden and visible, respectively
https://bugs.webkit.org/show_bug.cgi?id=151840
<rdar://problem/23753931>
Reviewed by Simon Fraser.
.:
Add a manual test that can be used to verify that we suspend dispatching device motion and
device orientation events when the page is hidden.
* ManualTests/ios/resources/suspend-orientation-and-motion-events-when-page-becomes-hidden.js: Added.
(resetTest):
(checkEvent):
(handleVisibilityChange):
* ManualTests/ios/suspend-orientation-and-motion-events-when-page-becomes-hidden.html: Added.
Source/WebCore:
* dom/Document.cpp:
(WebCore::Document::suspendDeviceMotionAndOrientationUpdates): Added.
(WebCore::Document::resumeDeviceMotionAndOrientationUpdates): Added.
(WebCore::Document::platformSuspendOrStopActiveDOMObjects): Moved logic to suspend device motion and
orientation updates from here to Document::suspendDeviceMotionAndOrientationUpdates().
(WebCore::Document::suspendActiveDOMObjects): Modified to call Document::suspendDeviceMotionAndOrientationUpdates().
(WebCore::Document::resumeActiveDOMObjects): Modified to call Document::resumeDeviceMotionAndOrientationUpdates().
* dom/Document.h:
* page/Page.cpp:
(WebCore::Page::setIsVisibleInternal): Suspend device motion and orientation updates when the page is hidden and
resume updates when the page is visible.
(WebCore::Page::suspendDeviceMotionAndOrientationUpdates): Added.
(WebCore::Page::resumeDeviceMotionAndOrientationUpdates): Added.
* page/Page.h:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkChangeLog">trunk/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomDocumentcpp">trunk/Source/WebCore/dom/Document.cpp</a></li>
<li><a href="#trunkSourceWebCoredomDocumenth">trunk/Source/WebCore/dom/Document.h</a></li>
<li><a href="#trunkSourceWebCorepagePagecpp">trunk/Source/WebCore/page/Page.cpp</a></li>
<li><a href="#trunkSourceWebCorepagePageh">trunk/Source/WebCore/page/Page.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li>trunk/ManualTests/ios/resources/</li>
<li><a href="#trunkManualTestsiosresourcessuspendorientationandmotioneventswhenpagebecomeshiddenjs">trunk/ManualTests/ios/resources/suspend-orientation-and-motion-events-when-page-becomes-hidden.js</a></li>
<li><a href="#trunkManualTestsiossuspendorientationandmotioneventswhenpagebecomeshiddenhtml">trunk/ManualTests/ios/suspend-orientation-and-motion-events-when-page-becomes-hidden.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/ChangeLog (193884 => 193885)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/ChangeLog        2015-12-10 02:51:11 UTC (rev 193884)
+++ trunk/ChangeLog        2015-12-10 02:53:12 UTC (rev 193885)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2015-12-09 Daniel Bates <dabates@apple.com>
+
+ [iOS] Suspend and resume device motion and device orientation updates when page is hidden and visible, respectively
+ https://bugs.webkit.org/show_bug.cgi?id=151840
+ <rdar://problem/23753931>
+
+ Reviewed by Simon Fraser.
+
+ Add a manual test that can be used to verify that we suspend dispatching device motion and
+ device orientation events when the page is hidden.
+
+ * ManualTests/ios/resources/suspend-orientation-and-motion-events-when-page-becomes-hidden.js: Added.
+ (resetTest):
+ (checkEvent):
+ (handleVisibilityChange):
+ * ManualTests/ios/suspend-orientation-and-motion-events-when-page-becomes-hidden.html: Added.
+
</ins><span class="cx"> 2015-12-07 Alex Christensen <achristensen@webkit.org>
</span><span class="cx">
</span><span class="cx"> Fix internal Windows build
</span></span></pre></div>
<a id="trunkManualTestsiosresourcessuspendorientationandmotioneventswhenpagebecomeshiddenjs"></a>
<div class="addfile"><h4>Added: trunk/ManualTests/ios/resources/suspend-orientation-and-motion-events-when-page-becomes-hidden.js (0 => 193885)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/ManualTests/ios/resources/suspend-orientation-and-motion-events-when-page-becomes-hidden.js         (rev 0)
+++ trunk/ManualTests/ios/resources/suspend-orientation-and-motion-events-when-page-becomes-hidden.js        2015-12-10 02:53:12 UTC (rev 193885)
</span><span class="lines">@@ -0,0 +1,41 @@
</span><ins>+var eventFrequencyTable;
+
+function resetTest()
+{
+ eventFrequencyTable = {};
+}
+
+function log(message)
+{
+ document.getElementById("console").appendChild(document.createTextNode(message + "\n"));
+}
+
+function checkEvent(event)
+{
+ if (document.visibilityState === "visible")
+ return;
+ var type = event.type;
+ if (!eventFrequencyTable[type])
+ eventFrequencyTable[type] = 0;
+ ++eventFrequencyTable[type];
+}
+
+function handleVisibilityChange()
+{
+ if (document.visibilityState === "hidden")
+ return;
+ var receivedEventsMessageParts = [];
+ for (var type in eventFrequencyTable)
+ receivedEventsMessageParts.push(type + " (\u00D7 " + eventFrequencyTable[type] + ")");
+ if (receivedEventsMessageParts.length)
+ log("Expected to receive no events when the page was hidden, but received: " + receivedEventsMessageParts.join(", ") + ".");
+ else
+ log("Received no events when the page was hidden.");
+ resetTest();
+}
+
+resetTest();
+
+window.addEventListener("devicemotion", checkEvent, false);
+window.addEventListener("deviceorientation", checkEvent, false);
+document.addEventListener("visibilitychange", handleVisibilityChange, false);
</ins></span></pre></div>
<a id="trunkManualTestsiossuspendorientationandmotioneventswhenpagebecomeshiddenhtml"></a>
<div class="addfile"><h4>Added: trunk/ManualTests/ios/suspend-orientation-and-motion-events-when-page-becomes-hidden.html (0 => 193885)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/ManualTests/ios/suspend-orientation-and-motion-events-when-page-becomes-hidden.html         (rev 0)
+++ trunk/ManualTests/ios/suspend-orientation-and-motion-events-when-page-becomes-hidden.html        2015-12-10 02:53:12 UTC (rev 193885)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+<script src="resources/suspend-orientation-and-motion-events-when-page-becomes-hidden.js"></script>
+</head>
+<body>
+<p>This test can be used to verify that <code>devicemotion</code> and <code>deviceorientation</code> events are not dispatched when the page is hidden.</p>
+<button onclick="window.open('suspend-orientation-and-motion-events-when-page-becomes-hidden.html')">Open this page in a child window to verify that this page does not receive events when the child window is the front-most window</button>
+<pre id="console"></pre>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (193884 => 193885)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-12-10 02:51:11 UTC (rev 193884)
+++ trunk/Source/WebCore/ChangeLog        2015-12-10 02:53:12 UTC (rev 193885)
</span><span class="lines">@@ -1,5 +1,28 @@
</span><span class="cx"> 2015-12-09 Daniel Bates <dabates@apple.com>
</span><span class="cx">
</span><ins>+ [iOS] Suspend and resume device motion and device orientation updates when page is hidden and visible, respectively
+ https://bugs.webkit.org/show_bug.cgi?id=151840
+ <rdar://problem/23753931>
+
+ Reviewed by Simon Fraser.
+
+ * dom/Document.cpp:
+ (WebCore::Document::suspendDeviceMotionAndOrientationUpdates): Added.
+ (WebCore::Document::resumeDeviceMotionAndOrientationUpdates): Added.
+ (WebCore::Document::platformSuspendOrStopActiveDOMObjects): Moved logic to suspend device motion and
+ orientation updates from here to Document::suspendDeviceMotionAndOrientationUpdates().
+ (WebCore::Document::suspendActiveDOMObjects): Modified to call Document::suspendDeviceMotionAndOrientationUpdates().
+ (WebCore::Document::resumeActiveDOMObjects): Modified to call Document::resumeDeviceMotionAndOrientationUpdates().
+ * dom/Document.h:
+ * page/Page.cpp:
+ (WebCore::Page::setIsVisibleInternal): Suspend device motion and orientation updates when the page is hidden and
+ resume updates when the page is visible.
+ (WebCore::Page::suspendDeviceMotionAndOrientationUpdates): Added.
+ (WebCore::Page::resumeDeviceMotionAndOrientationUpdates): Added.
+ * page/Page.h:
+
+2015-12-09 Daniel Bates <dabates@apple.com>
+
</ins><span class="cx"> Unify iOS Frame::setTimersPaused() logic and Frame::{suspend, resume}ActiveDOMObjectsAndAnimations()
</span><span class="cx"> https://bugs.webkit.org/show_bug.cgi?id=152006
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.cpp (193884 => 193885)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.cpp        2015-12-10 02:51:11 UTC (rev 193884)
+++ trunk/Source/WebCore/dom/Document.cpp        2015-12-10 02:53:12 UTC (rev 193885)
</span><span class="lines">@@ -2345,16 +2345,35 @@
</span><span class="cx"> node->removeAllEventListeners();
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void Document::platformSuspendOrStopActiveDOMObjects()
</del><ins>+void Document::suspendDeviceMotionAndOrientationUpdates()
</ins><span class="cx"> {
</span><del>-#if PLATFORM(IOS)
-#if ENABLE(DEVICE_ORIENTATION)
</del><ins>+ if (m_areDeviceMotionAndOrientationUpdatesSuspended)
+ return;
+ m_areDeviceMotionAndOrientationUpdatesSuspended = true;
+#if ENABLE(DEVICE_ORIENTATION) && PLATFORM(IOS)
</ins><span class="cx"> if (m_deviceMotionController)
</span><span class="cx"> m_deviceMotionController->suspendUpdates();
</span><span class="cx"> if (m_deviceOrientationController)
</span><span class="cx"> m_deviceOrientationController->suspendUpdates();
</span><span class="cx"> #endif
</span><ins>+}
</ins><span class="cx">
</span><ins>+void Document::resumeDeviceMotionAndOrientationUpdates()
+{
+ if (!m_areDeviceMotionAndOrientationUpdatesSuspended)
+ return;
+ m_areDeviceMotionAndOrientationUpdatesSuspended = false;
+#if ENABLE(DEVICE_ORIENTATION) && PLATFORM(IOS)
+ if (m_deviceMotionController)
+ m_deviceMotionController->resumeUpdates();
+ if (m_deviceOrientationController)
+ m_deviceOrientationController->resumeUpdates();
+#endif
+}
+
+void Document::platformSuspendOrStopActiveDOMObjects()
+{
+#if PLATFORM(IOS)
</ins><span class="cx"> if (WebThreadCountOfObservedContentModifiers() > 0) {
</span><span class="cx"> Frame* frame = this->frame();
</span><span class="cx"> if (Page* page = frame ? frame->page() : nullptr)
</span><span class="lines">@@ -2366,19 +2385,14 @@
</span><span class="cx"> void Document::suspendActiveDOMObjects(ActiveDOMObject::ReasonForSuspension why)
</span><span class="cx"> {
</span><span class="cx"> ScriptExecutionContext::suspendActiveDOMObjects(why);
</span><ins>+ suspendDeviceMotionAndOrientationUpdates();
</ins><span class="cx"> platformSuspendOrStopActiveDOMObjects();
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void Document::resumeActiveDOMObjects(ActiveDOMObject::ReasonForSuspension why)
</span><span class="cx"> {
</span><span class="cx"> ScriptExecutionContext::resumeActiveDOMObjects(why);
</span><del>-
-#if ENABLE(DEVICE_ORIENTATION) && PLATFORM(IOS)
- if (m_deviceMotionController)
- m_deviceMotionController->resumeUpdates();
- if (m_deviceOrientationController)
- m_deviceOrientationController->resumeUpdates();
-#endif
</del><ins>+ resumeDeviceMotionAndOrientationUpdates();
</ins><span class="cx"> // FIXME: For iOS, do we need to add content change observers that were removed in Document::suspendActiveDOMObjects()?
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.h (193884 => 193885)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.h        2015-12-10 02:51:11 UTC (rev 193884)
+++ trunk/Source/WebCore/dom/Document.h        2015-12-10 02:53:12 UTC (rev 193885)
</span><span class="lines">@@ -604,6 +604,9 @@
</span><span class="cx"> virtual void resumeActiveDOMObjects(ActiveDOMObject::ReasonForSuspension) override final;
</span><span class="cx"> virtual void stopActiveDOMObjects() override final;
</span><span class="cx">
</span><ins>+ void suspendDeviceMotionAndOrientationUpdates();
+ void resumeDeviceMotionAndOrientationUpdates();
+
</ins><span class="cx"> RenderView* renderView() const { return m_renderView.get(); }
</span><span class="cx">
</span><span class="cx"> bool renderTreeBeingDestroyed() const { return m_renderTreeBeingDestroyed; }
</span><span class="lines">@@ -1775,6 +1778,7 @@
</span><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span><span class="cx"> RefPtr<MediaSession> m_defaultMediaSession;
</span><span class="cx"> #endif
</span><ins>+ bool m_areDeviceMotionAndOrientationUpdatesSuspended { false };
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> inline void Document::notifyRemovePendingSheetIfNeeded()
</span></span></pre></div>
<a id="trunkSourceWebCorepagePagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Page.cpp (193884 => 193885)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Page.cpp        2015-12-10 02:51:11 UTC (rev 193884)
+++ trunk/Source/WebCore/page/Page.cpp        2015-12-10 02:53:12 UTC (rev 193885)
</span><span class="lines">@@ -1312,6 +1312,9 @@
</span><span class="cx"> m_isPrerender = false;
</span><span class="cx">
</span><span class="cx"> resumeScriptedAnimations();
</span><ins>+#if PLATFORM(IOS)
+ resumeDeviceMotionAndOrientationUpdates();
+#endif
</ins><span class="cx">
</span><span class="cx"> if (FrameView* view = mainFrame().view())
</span><span class="cx"> view->show();
</span><span class="lines">@@ -1333,6 +1336,9 @@
</span><span class="cx"> if (m_settings->hiddenPageCSSAnimationSuspensionEnabled())
</span><span class="cx"> mainFrame().animation().suspendAnimations();
</span><span class="cx">
</span><ins>+#if PLATFORM(IOS)
+ suspendDeviceMotionAndOrientationUpdates();
+#endif
</ins><span class="cx"> suspendScriptedAnimations();
</span><span class="cx">
</span><span class="cx"> if (FrameView* view = mainFrame().view())
</span><span class="lines">@@ -1556,6 +1562,22 @@
</span><span class="cx"> m_relevantUnpaintedRegion.unite(snappedIntRect(objectPaintRect));
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void Page::suspendDeviceMotionAndOrientationUpdates()
+{
+ for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
+ if (Document* document = frame->document())
+ document->suspendDeviceMotionAndOrientationUpdates();
+ }
+}
+
+void Page::resumeDeviceMotionAndOrientationUpdates()
+{
+ for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
+ if (Document* document = frame->document())
+ document->resumeDeviceMotionAndOrientationUpdates();
+ }
+}
+
</ins><span class="cx"> void Page::suspendActiveDOMObjectsAndAnimations()
</span><span class="cx"> {
</span><span class="cx"> for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext())
</span></span></pre></div>
<a id="trunkSourceWebCorepagePageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Page.h (193884 => 193885)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Page.h        2015-12-10 02:51:11 UTC (rev 193884)
+++ trunk/Source/WebCore/page/Page.h        2015-12-10 02:53:12 UTC (rev 193885)
</span><span class="lines">@@ -394,6 +394,9 @@
</span><span class="cx">
</span><span class="cx"> WEBCORE_EXPORT void suspendActiveDOMObjectsAndAnimations();
</span><span class="cx"> WEBCORE_EXPORT void resumeActiveDOMObjectsAndAnimations();
</span><ins>+ void suspendDeviceMotionAndOrientationUpdates();
+ void resumeDeviceMotionAndOrientationUpdates();
+
</ins><span class="cx"> #ifndef NDEBUG
</span><span class="cx"> void setIsPainting(bool painting) { m_isPainting = painting; }
</span><span class="cx"> bool isPainting() const { return m_isPainting; }
</span></span></pre>
</div>
</div>
</body>
</html>