<!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>[194096] branches/safari-601.1.46-branch</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/194096">194096</a></dd>
<dt>Author</dt> <dd>matthew_hanson@apple.com</dd>
<dt>Date</dt> <dd>2015-12-14 23:03:25 -0800 (Mon, 14 Dec 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/193885">r193885</a>. rdar://problem/23860425</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari601146branchChangeLog">branches/safari-601.1.46-branch/ChangeLog</a></li>
<li><a href="#branchessafari601146branchSourceWebCoreChangeLog">branches/safari-601.1.46-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari601146branchSourceWebCoredomDocumentcpp">branches/safari-601.1.46-branch/Source/WebCore/dom/Document.cpp</a></li>
<li><a href="#branchessafari601146branchSourceWebCoredomDocumenth">branches/safari-601.1.46-branch/Source/WebCore/dom/Document.h</a></li>
<li><a href="#branchessafari601146branchSourceWebCorepagePagecpp">branches/safari-601.1.46-branch/Source/WebCore/page/Page.cpp</a></li>
<li><a href="#branchessafari601146branchSourceWebCorepagePageh">branches/safari-601.1.46-branch/Source/WebCore/page/Page.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>branches/safari-601.1.46-branch/ManualTests/ios/resources/</li>
<li><a href="#branchessafari601146branchManualTestsiosresourcessuspendorientationandmotioneventswhenpagebecomeshiddenjs">branches/safari-601.1.46-branch/ManualTests/ios/resources/suspend-orientation-and-motion-events-when-page-becomes-hidden.js</a></li>
<li><a href="#branchessafari601146branchManualTestsiossuspendorientationandmotioneventswhenpagebecomeshiddenhtml">branches/safari-601.1.46-branch/ManualTests/ios/suspend-orientation-and-motion-events-when-page-becomes-hidden.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari601146branchChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/ChangeLog (194095 => 194096)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/ChangeLog        2015-12-15 06:49:03 UTC (rev 194095)
+++ branches/safari-601.1.46-branch/ChangeLog        2015-12-15 07:03:25 UTC (rev 194096)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2015-12-14  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
+
+        Merge r193885. rdar://problem/23860425
+
+    2015-12-09  Daniel Bates  &lt;dabates@apple.com&gt;
+
+            [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
+            &lt;rdar://problem/23753931&gt;
+
+            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-10-14  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Merge r191008. rdar://problem/23110743
</span></span></pre></div>
<a id="branchessafari601146branchManualTestsiosresourcessuspendorientationandmotioneventswhenpagebecomeshiddenjs"></a>
<div class="addfile"><h4>Added: branches/safari-601.1.46-branch/ManualTests/ios/resources/suspend-orientation-and-motion-events-when-page-becomes-hidden.js (0 => 194096)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/ManualTests/ios/resources/suspend-orientation-and-motion-events-when-page-becomes-hidden.js                                (rev 0)
+++ branches/safari-601.1.46-branch/ManualTests/ios/resources/suspend-orientation-and-motion-events-when-page-becomes-hidden.js        2015-12-15 07:03:25 UTC (rev 194096)
</span><span class="lines">@@ -0,0 +1,41 @@
</span><ins>+var eventFrequencyTable;
+
+function resetTest()
+{
+    eventFrequencyTable = {};
+}
+
+function log(message)
+{
+    document.getElementById(&quot;console&quot;).appendChild(document.createTextNode(message + &quot;\n&quot;));
+}
+
+function checkEvent(event)
+{
+    if (document.visibilityState === &quot;visible&quot;)
+        return;
+    var type = event.type;
+    if (!eventFrequencyTable[type])
+        eventFrequencyTable[type] = 0;
+    ++eventFrequencyTable[type];
+}
+
+function handleVisibilityChange()
+{
+    if (document.visibilityState === &quot;hidden&quot;)
+        return;
+    var receivedEventsMessageParts = [];
+    for (var type in eventFrequencyTable)
+        receivedEventsMessageParts.push(type + &quot; (\u00D7 &quot; + eventFrequencyTable[type] + &quot;)&quot;);
+    if (receivedEventsMessageParts.length)
+        log(&quot;Expected to receive no events when the page was hidden, but received: &quot; + receivedEventsMessageParts.join(&quot;, &quot;) + &quot;.&quot;);
+    else
+        log(&quot;Received no events when the page was hidden.&quot;);
+    resetTest();
+}
+
+resetTest();
+
+window.addEventListener(&quot;devicemotion&quot;, checkEvent, false);
+window.addEventListener(&quot;deviceorientation&quot;, checkEvent, false);
+document.addEventListener(&quot;visibilitychange&quot;, handleVisibilityChange, false);
</ins></span></pre></div>
<a id="branchessafari601146branchManualTestsiossuspendorientationandmotioneventswhenpagebecomeshiddenhtml"></a>
<div class="addfile"><h4>Added: branches/safari-601.1.46-branch/ManualTests/ios/suspend-orientation-and-motion-events-when-page-becomes-hidden.html (0 => 194096)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/ManualTests/ios/suspend-orientation-and-motion-events-when-page-becomes-hidden.html                                (rev 0)
+++ branches/safari-601.1.46-branch/ManualTests/ios/suspend-orientation-and-motion-events-when-page-becomes-hidden.html        2015-12-15 07:03:25 UTC (rev 194096)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;resources/suspend-orientation-and-motion-events-when-page-becomes-hidden.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;p&gt;This test can be used to verify that &lt;code&gt;devicemotion&lt;/code&gt; and &lt;code&gt;deviceorientation&lt;/code&gt; events are not dispatched when the page is hidden.&lt;/p&gt;
+&lt;button onclick=&quot;window.open('suspend-orientation-and-motion-events-when-page-becomes-hidden.html')&quot;&gt;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&lt;/button&gt;
+&lt;pre id=&quot;console&quot;&gt;&lt;/pre&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="branchessafari601146branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/ChangeLog (194095 => 194096)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/ChangeLog        2015-12-15 06:49:03 UTC (rev 194095)
+++ branches/safari-601.1.46-branch/Source/WebCore/ChangeLog        2015-12-15 07:03:25 UTC (rev 194096)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2015-12-14  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
+
+        Merge r193885. rdar://problem/23860425
+
+    2015-12-09  Daniel Bates  &lt;dabates@apple.com&gt;
+
+            [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
+            &lt;rdar://problem/23753931&gt;
+
+            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:
+
</ins><span class="cx"> 2015-12-10  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Merge r193876. rdar://problem/23305376
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCoredomDocumentcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/dom/Document.cpp (194095 => 194096)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/dom/Document.cpp        2015-12-15 06:49:03 UTC (rev 194095)
+++ branches/safari-601.1.46-branch/Source/WebCore/dom/Document.cpp        2015-12-15 07:03:25 UTC (rev 194096)
</span><span class="lines">@@ -2314,16 +2314,35 @@
</span><span class="cx">         node-&gt;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) &amp;&amp; PLATFORM(IOS)
</ins><span class="cx">     if (m_deviceMotionController)
</span><span class="cx">         m_deviceMotionController-&gt;suspendUpdates();
</span><span class="cx">     if (m_deviceOrientationController)
</span><span class="cx">         m_deviceOrientationController-&gt;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) &amp;&amp; PLATFORM(IOS)
+    if (m_deviceMotionController)
+        m_deviceMotionController-&gt;resumeUpdates();
+    if (m_deviceOrientationController)
+        m_deviceOrientationController-&gt;resumeUpdates();
+#endif
+}
+
+void Document::platformSuspendOrStopActiveDOMObjects()
+{
+#if PLATFORM(IOS)
</ins><span class="cx">     if (WebThreadCountOfObservedContentModifiers() &gt; 0) {
</span><span class="cx">         Frame* frame = this-&gt;frame();
</span><span class="cx">         if (Page* page = frame ? frame-&gt;page() : nullptr)
</span><span class="lines">@@ -2335,19 +2354,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) &amp;&amp; PLATFORM(IOS)
-    if (m_deviceMotionController)
-        m_deviceMotionController-&gt;resumeUpdates();
-    if (m_deviceOrientationController)
-        m_deviceOrientationController-&gt;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="branchessafari601146branchSourceWebCoredomDocumenth"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/dom/Document.h (194095 => 194096)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/dom/Document.h        2015-12-15 06:49:03 UTC (rev 194095)
+++ branches/safari-601.1.46-branch/Source/WebCore/dom/Document.h        2015-12-15 07:03:25 UTC (rev 194096)
</span><span class="lines">@@ -583,6 +583,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">@@ -1745,6 +1748,7 @@
</span><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span><span class="cx">     RefPtr&lt;MediaSession&gt; 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="branchessafari601146branchSourceWebCorepagePagecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/page/Page.cpp (194095 => 194096)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/page/Page.cpp        2015-12-15 06:49:03 UTC (rev 194095)
+++ branches/safari-601.1.46-branch/Source/WebCore/page/Page.cpp        2015-12-15 07:03:25 UTC (rev 194096)
</span><span class="lines">@@ -1291,6 +1291,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-&gt;show();
</span><span class="lines">@@ -1312,6 +1315,9 @@
</span><span class="cx">         if (m_settings-&gt;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">@@ -1525,6 +1531,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 = &amp;mainFrame(); frame; frame = frame-&gt;tree().traverseNext()) {
+        if (Document* document = frame-&gt;document())
+            document-&gt;suspendDeviceMotionAndOrientationUpdates();
+    }
+}
+
+void Page::resumeDeviceMotionAndOrientationUpdates()
+{
+    for (Frame* frame = &amp;mainFrame(); frame; frame = frame-&gt;tree().traverseNext()) {
+        if (Document* document = frame-&gt;document())
+            document-&gt;resumeDeviceMotionAndOrientationUpdates();
+    }
+}
+
</ins><span class="cx"> void Page::suspendActiveDOMObjectsAndAnimations()
</span><span class="cx"> {
</span><span class="cx">     for (Frame* frame = &amp;mainFrame(); frame; frame = frame-&gt;tree().traverseNext())
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCorepagePageh"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/page/Page.h (194095 => 194096)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/page/Page.h        2015-12-15 06:49:03 UTC (rev 194095)
+++ branches/safari-601.1.46-branch/Source/WebCore/page/Page.h        2015-12-15 07:03:25 UTC (rev 194096)
</span><span class="lines">@@ -378,6 +378,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>