<!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>[188068] 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/188068">188068</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2015-08-06 15:37:47 -0700 (Thu, 06 Aug 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Toggle GPS state based on page visibility to save battery
https://bugs.webkit.org/show_bug.cgi?id=147685

Reviewed by Benjamin Poulain.

Source/WebCore:

Toggle GPS state based on page visibility to save battery. Previously,
if the site you were viewing was watching your position and you
switched tab, the GPS would stay on. This was bad for battery life.

Tests: fast/dom/Geolocation/startUpdatingOnlyWhenPageVisible.html
       fast/dom/Geolocation/stopUpdatingForHiddenPage.html

* Modules/geolocation/GeolocationController.cpp:
(WebCore::GeolocationController::addObserver):
(WebCore::GeolocationController::viewStateDidChange):

Tools:

Add testRunner.isGeolocationProviderActive() test support function.

* DumpRenderTree/TestRunner.cpp:
(isGeolocationProviderActiveCallback):
(TestRunner::staticFunctions):
* DumpRenderTree/TestRunner.h:
* DumpRenderTree/mac/MockGeolocationProvider.h:
* DumpRenderTree/mac/MockGeolocationProvider.mm:
(-[MockGeolocationProvider isActive]):
* DumpRenderTree/mac/TestRunnerMac.mm:
(TestRunner::isGeolocationProviderActive):
* DumpRenderTree/win/TestRunnerWin.cpp:
(TestRunner::isGeolocationProviderActive):
* WebKitTestRunner/GeolocationProviderMock.h:
(WTR::GeolocationProviderMock::isActive):
* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::isGeolocationProviderActive):
* WebKitTestRunner/InjectedBundle/InjectedBundle.h:
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::isGeolocationProviderActive):
* WebKitTestRunner/InjectedBundle/TestRunner.h:
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::isGeolocationProviderActive):
* WebKitTestRunner/TestController.h:
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):

LayoutTests:

Add layout tests to check that the GeolocationClient starts and stops
updating when page visibility changes.

* fast/dom/Geolocation/startUpdatingOnlyWhenPageVisible-expected.txt: Added.
* fast/dom/Geolocation/startUpdatingOnlyWhenPageVisible.html: Added.
* fast/dom/Geolocation/stopUpdatingForHiddenPage-expected.txt: Added.
* fast/dom/Geolocation/stopUpdatingForHiddenPage.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesgeolocationGeolocationControllercpp">trunk/Source/WebCore/Modules/geolocation/GeolocationController.cpp</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsDumpRenderTreeTestRunnercpp">trunk/Tools/DumpRenderTree/TestRunner.cpp</a></li>
<li><a href="#trunkToolsDumpRenderTreeTestRunnerh">trunk/Tools/DumpRenderTree/TestRunner.h</a></li>
<li><a href="#trunkToolsDumpRenderTreemacMockGeolocationProviderh">trunk/Tools/DumpRenderTree/mac/MockGeolocationProvider.h</a></li>
<li><a href="#trunkToolsDumpRenderTreemacMockGeolocationProvidermm">trunk/Tools/DumpRenderTree/mac/MockGeolocationProvider.mm</a></li>
<li><a href="#trunkToolsDumpRenderTreemacTestRunnerMacmm">trunk/Tools/DumpRenderTree/mac/TestRunnerMac.mm</a></li>
<li><a href="#trunkToolsDumpRenderTreewinTestRunnerWincpp">trunk/Tools/DumpRenderTree/win/TestRunnerWin.cpp</a></li>
<li><a href="#trunkToolsWebKitTestRunnerGeolocationProviderMockh">trunk/Tools/WebKitTestRunner/GeolocationProviderMock.h</a></li>
<li><a href="#trunkToolsWebKitTestRunnerInjectedBundleBindingsTestRunneridl">trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl</a></li>
<li><a href="#trunkToolsWebKitTestRunnerInjectedBundleInjectedBundlecpp">trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp</a></li>
<li><a href="#trunkToolsWebKitTestRunnerInjectedBundleInjectedBundleh">trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h</a></li>
<li><a href="#trunkToolsWebKitTestRunnerInjectedBundleTestRunnercpp">trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp</a></li>
<li><a href="#trunkToolsWebKitTestRunnerInjectedBundleTestRunnerh">trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h</a></li>
<li><a href="#trunkToolsWebKitTestRunnerTestControllercpp">trunk/Tools/WebKitTestRunner/TestController.cpp</a></li>
<li><a href="#trunkToolsWebKitTestRunnerTestControllerh">trunk/Tools/WebKitTestRunner/TestController.h</a></li>
<li><a href="#trunkToolsWebKitTestRunnerTestInvocationcpp">trunk/Tools/WebKitTestRunner/TestInvocation.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastdomGeolocationstartUpdatingOnlyWhenPageVisibleexpectedtxt">trunk/LayoutTests/fast/dom/Geolocation/startUpdatingOnlyWhenPageVisible-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomGeolocationstartUpdatingOnlyWhenPageVisiblehtml">trunk/LayoutTests/fast/dom/Geolocation/startUpdatingOnlyWhenPageVisible.html</a></li>
<li><a href="#trunkLayoutTestsfastdomGeolocationstopUpdatingForHiddenPageexpectedtxt">trunk/LayoutTests/fast/dom/Geolocation/stopUpdatingForHiddenPage-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomGeolocationstopUpdatingForHiddenPagehtml">trunk/LayoutTests/fast/dom/Geolocation/stopUpdatingForHiddenPage.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (188067 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-08-06 22:36:34 UTC (rev 188067)
+++ trunk/LayoutTests/ChangeLog        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2015-08-06  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Toggle GPS state based on page visibility to save battery
+        https://bugs.webkit.org/show_bug.cgi?id=147685
+
+        Reviewed by Benjamin Poulain.
+
+        Add layout tests to check that the GeolocationClient starts and stops
+        updating when page visibility changes.
+
+        * fast/dom/Geolocation/startUpdatingOnlyWhenPageVisible-expected.txt: Added.
+        * fast/dom/Geolocation/startUpdatingOnlyWhenPageVisible.html: Added.
+        * fast/dom/Geolocation/stopUpdatingForHiddenPage-expected.txt: Added.
+        * fast/dom/Geolocation/stopUpdatingForHiddenPage.html: Added.
+
</ins><span class="cx"> 2015-08-06  Brian Burg  &lt;bburg@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Inspector: move http/tests/inspector-protocol/ contents to http/tests/inspector/
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomGeolocationstartUpdatingOnlyWhenPageVisibleexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/Geolocation/startUpdatingOnlyWhenPageVisible-expected.txt (0 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Geolocation/startUpdatingOnlyWhenPageVisible-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/dom/Geolocation/startUpdatingOnlyWhenPageVisible-expected.txt        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -0,0 +1,20 @@
</span><ins>+Tests that the GeolocationClient only starts updating when the page becomes visible
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+Page is initially visible
+PASS document.hidden is false
+PASS testRunner.isGeolocationProviderActive() is false
+Changing page visibility to 'hidden'
+Page visibility changed to false
+PASS testRunner.isGeolocationProviderActive() is false
+Adding Geolocation watcher
+PASS testRunner.isGeolocationProviderActive() is false
+Changing page visibility to 'visible'
+Page visibility changed to true
+PASS testRunner.isGeolocationProviderActive() became true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastdomGeolocationstartUpdatingOnlyWhenPageVisiblehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/Geolocation/startUpdatingOnlyWhenPageVisible.html (0 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Geolocation/startUpdatingOnlyWhenPageVisible.html                                (rev 0)
+++ trunk/LayoutTests/fast/dom/Geolocation/startUpdatingOnlyWhenPageVisible.html        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -0,0 +1,54 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;runTest()&quot;&gt;
+&lt;script&gt;
+
+description(&quot;Tests that the GeolocationClient only starts updating when the page becomes visible&quot;);
+window.jsTestIsAsync = true;
+
+function geolocationWatchFunction()
+{
+}
+
+function checkNotUpdatingAndShowPage()
+{
+    shouldBeFalse(&quot;testRunner.isGeolocationProviderActive()&quot;);
+    debug(&quot;Changing page visibility to 'visible'&quot;);
+    testRunner.setPageVisibility(&quot;visible&quot;);
+}
+
+function onVisibilityChange() {
+    debug(&quot;Page visibility changed to &quot; + !document.hidden);
+    if (document.hidden) {
+        shouldBeFalse(&quot;testRunner.isGeolocationProviderActive()&quot;);
+        debug(&quot;Adding Geolocation watcher&quot;);
+        navigator.geolocation.watchPosition(geolocationWatchFunction);
+        setTimeout(checkNotUpdatingAndShowPage, 50);
+    } else
+        shouldBecomeEqual(&quot;testRunner.isGeolocationProviderActive()&quot;, &quot;true&quot;, finishJSTest);
+}
+
+document.addEventListener(&quot;visibilitychange&quot;, onVisibilityChange, false)
+
+if (window.testRunner) {
+    testRunner.setGeolocationPermission(true);
+    testRunner.setMockGeolocationPosition(1, 2, 3);
+}
+
+function runTest()
+{
+    debug(&quot;Page is initially visible&quot;);
+    shouldBeFalse(&quot;document.hidden&quot;);
+    shouldBeFalse(&quot;testRunner.isGeolocationProviderActive()&quot;);
+
+    debug(&quot;Changing page visibility to 'hidden'&quot;);
+    if (window.testRunner)
+        testRunner.setPageVisibility(&quot;hidden&quot;);
+}
+&lt;/script&gt;
+&lt;script src=&quot;../../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastdomGeolocationstopUpdatingForHiddenPageexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/Geolocation/stopUpdatingForHiddenPage-expected.txt (0 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Geolocation/stopUpdatingForHiddenPage-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/dom/Geolocation/stopUpdatingForHiddenPage-expected.txt        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -0,0 +1,20 @@
</span><ins>+Tests that the GeolocationClient stops updating when the page becomes hidden
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+Page is initially visible
+PASS document.hidden is false
+PASS testRunner.isGeolocationProviderActive() is false
+Adding Geolocation watcher
+PASS testRunner.isGeolocationProviderActive() became true
+Changing page visibility to 'hidden'
+Page visibility changed to false
+PASS testRunner.isGeolocationProviderActive() became false
+Changing page visibility to 'visible'
+Page visibility changed to true
+PASS testRunner.isGeolocationProviderActive() became true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastdomGeolocationstopUpdatingForHiddenPagehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/Geolocation/stopUpdatingForHiddenPage.html (0 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Geolocation/stopUpdatingForHiddenPage.html                                (rev 0)
+++ trunk/LayoutTests/fast/dom/Geolocation/stopUpdatingForHiddenPage.html        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -0,0 +1,58 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;runTest()&quot;&gt;
+&lt;script&gt;
+
+description(&quot;Tests that the GeolocationClient stops updating when the page becomes hidden&quot;);
+window.jsTestIsAsync = true;
+
+function geolocationWatchFunction()
+{
+}
+
+function showPage()
+{
+    debug(&quot;Changing page visibility to 'visible'&quot;);
+    testRunner.setPageVisibility(&quot;visible&quot;);
+}
+
+function onVisibilityChange() {
+    debug(&quot;Page visibility changed to &quot; + !document.hidden);
+    if (document.hidden)
+        shouldBecomeEqual(&quot;testRunner.isGeolocationProviderActive()&quot;, &quot;false&quot;, showPage);
+    else
+        shouldBecomeEqual(&quot;testRunner.isGeolocationProviderActive()&quot;, &quot;true&quot;, finishJSTest);
+}
+
+document.addEventListener(&quot;visibilitychange&quot;, onVisibilityChange, false)
+
+if (window.testRunner) {
+    testRunner.setGeolocationPermission(true);
+    testRunner.setMockGeolocationPosition(1, 2, 3);
+}
+
+function hidePage()
+{
+    debug(&quot;Changing page visibility to 'hidden'&quot;);
+    if (window.testRunner)
+        testRunner.setPageVisibility(&quot;hidden&quot;);
+}
+
+function runTest()
+{
+    debug(&quot;Page is initially visible&quot;);
+    shouldBeFalse(&quot;document.hidden&quot;);
+    shouldBeFalse(&quot;testRunner.isGeolocationProviderActive()&quot;);
+
+    debug(&quot;Adding Geolocation watcher&quot;);
+    navigator.geolocation.watchPosition(geolocationWatchFunction);
+
+    shouldBecomeEqual(&quot;testRunner.isGeolocationProviderActive()&quot;, &quot;true&quot;, hidePage);
+}
+&lt;/script&gt;
+&lt;script src=&quot;../../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (188067 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-08-06 22:36:34 UTC (rev 188067)
+++ trunk/Source/WebCore/ChangeLog        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2015-08-06  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Toggle GPS state based on page visibility to save battery
+        https://bugs.webkit.org/show_bug.cgi?id=147685
+
+        Reviewed by Benjamin Poulain.
+
+        Toggle GPS state based on page visibility to save battery. Previously,
+        if the site you were viewing was watching your position and you
+        switched tab, the GPS would stay on. This was bad for battery life.
+
+        Tests: fast/dom/Geolocation/startUpdatingOnlyWhenPageVisible.html
+               fast/dom/Geolocation/stopUpdatingForHiddenPage.html
+
+        * Modules/geolocation/GeolocationController.cpp:
+        (WebCore::GeolocationController::addObserver):
+        (WebCore::GeolocationController::viewStateDidChange):
+
</ins><span class="cx"> 2015-08-06  Anders Carlsson  &lt;andersca@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         SQLStatementBackend doesn't need to be refcounted
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesgeolocationGeolocationControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/geolocation/GeolocationController.cpp (188067 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/geolocation/GeolocationController.cpp        2015-08-06 22:36:34 UTC (rev 188067)
+++ trunk/Source/WebCore/Modules/geolocation/GeolocationController.cpp        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -63,7 +63,7 @@
</span><span class="cx"> 
</span><span class="cx">     if (enableHighAccuracy)
</span><span class="cx">         m_client.setEnableHighAccuracy(true);
</span><del>-    if (wasEmpty)
</del><ins>+    if (wasEmpty &amp;&amp; m_page.isVisible())
</ins><span class="cx">         m_client.startUpdating();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -124,8 +124,17 @@
</span><span class="cx">     return m_client.lastPosition();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void GeolocationController::viewStateDidChange(ViewState::Flags, ViewState::Flags)
</del><ins>+void GeolocationController::viewStateDidChange(ViewState::Flags oldViewState, ViewState::Flags newViewState)
</ins><span class="cx"> {
</span><ins>+    // Toggle GPS based on page visibility to save battery.
+    ViewState::Flags changed = oldViewState ^ newViewState;
+    if (changed &amp; ViewState::IsVisible &amp;&amp; !m_observers.isEmpty()) {
+        if (newViewState &amp; ViewState::IsVisible)
+            m_client.startUpdating();
+        else
+            m_client.stopUpdating();
+    }
+
</ins><span class="cx">     if (!m_page.isVisible())
</span><span class="cx">         return;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (188067 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2015-08-06 22:36:34 UTC (rev 188067)
+++ trunk/Tools/ChangeLog        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -1,3 +1,38 @@
</span><ins>+2015-08-06  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Toggle GPS state based on page visibility to save battery
+        https://bugs.webkit.org/show_bug.cgi?id=147685
+
+        Reviewed by Benjamin Poulain.
+
+        Add testRunner.isGeolocationProviderActive() test support function.
+
+        * DumpRenderTree/TestRunner.cpp:
+        (isGeolocationProviderActiveCallback):
+        (TestRunner::staticFunctions):
+        * DumpRenderTree/TestRunner.h:
+        * DumpRenderTree/mac/MockGeolocationProvider.h:
+        * DumpRenderTree/mac/MockGeolocationProvider.mm:
+        (-[MockGeolocationProvider isActive]):
+        * DumpRenderTree/mac/TestRunnerMac.mm:
+        (TestRunner::isGeolocationProviderActive):
+        * DumpRenderTree/win/TestRunnerWin.cpp:
+        (TestRunner::isGeolocationProviderActive):
+        * WebKitTestRunner/GeolocationProviderMock.h:
+        (WTR::GeolocationProviderMock::isActive):
+        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
+        (WTR::InjectedBundle::isGeolocationProviderActive):
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.h:
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::isGeolocationProviderActive):
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::isGeolocationProviderActive):
+        * WebKitTestRunner/TestController.h:
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
+
</ins><span class="cx"> 2015-08-06  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Automate JSBench with run-benchmark
</span></span></pre></div>
<a id="trunkToolsDumpRenderTreeTestRunnercpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/DumpRenderTree/TestRunner.cpp (188067 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/DumpRenderTree/TestRunner.cpp        2015-08-06 22:36:34 UTC (rev 188067)
+++ trunk/Tools/DumpRenderTree/TestRunner.cpp        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -646,6 +646,12 @@
</span><span class="cx">     return JSValueMakeNumber(context, controller-&gt;numberOfPendingGeolocationPermissionRequests());
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static JSValueRef isGeolocationProviderActiveCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    TestRunner* controller = static_cast&lt;TestRunner*&gt;(JSObjectGetPrivate(thisObject));
+    return JSValueMakeBoolean(context, controller-&gt;isGeolocationProviderActive());
+}
+
</ins><span class="cx"> static JSValueRef queueBackNavigationCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
</span><span class="cx"> {
</span><span class="cx">     // Has mac &amp; windows implementation
</span><span class="lines">@@ -2033,6 +2039,7 @@
</span><span class="cx">         { &quot;originsWithApplicationCache&quot;, originsWithApplicationCacheCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
</span><span class="cx">         { &quot;goBack&quot;, goBackCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, 
</span><span class="cx">         { &quot;ignoreLegacyWebNotificationPermissionRequests&quot;, ignoreLegacyWebNotificationPermissionRequestsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
</span><ins>+        { &quot;isGeolocationProviderActive&quot;, isGeolocationProviderActiveCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
</ins><span class="cx">         { &quot;isCommandEnabled&quot;, isCommandEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
</span><span class="cx">         { &quot;keepWebHistory&quot;, keepWebHistoryCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
</span><span class="cx">         { &quot;numberOfPendingGeolocationPermissionRequests&quot;, numberOfPendingGeolocationPermissionRequestsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
</span></span></pre></div>
<a id="trunkToolsDumpRenderTreeTestRunnerh"></a>
<div class="modfile"><h4>Modified: trunk/Tools/DumpRenderTree/TestRunner.h (188067 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/DumpRenderTree/TestRunner.h        2015-08-06 22:36:34 UTC (rev 188067)
+++ trunk/Tools/DumpRenderTree/TestRunner.h        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -76,6 +76,7 @@
</span><span class="cx">     void keepWebHistory();
</span><span class="cx">     void notifyDone();
</span><span class="cx">     int numberOfPendingGeolocationPermissionRequests();
</span><ins>+    bool isGeolocationProviderActive();
</ins><span class="cx">     void overridePreference(JSStringRef key, JSStringRef value);
</span><span class="cx">     JSStringRef pathToLocalResource(JSContextRef, JSStringRef url);
</span><span class="cx">     void queueBackNavigation(int howFarBackward);
</span></span></pre></div>
<a id="trunkToolsDumpRenderTreemacMockGeolocationProviderh"></a>
<div class="modfile"><h4>Modified: trunk/Tools/DumpRenderTree/mac/MockGeolocationProvider.h (188067 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/DumpRenderTree/mac/MockGeolocationProvider.h        2015-08-06 22:36:34 UTC (rev 188067)
+++ trunk/Tools/DumpRenderTree/mac/MockGeolocationProvider.h        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -44,6 +44,7 @@
</span><span class="cx"> - (void)setPositionUnavailableErrorWithMessage:(NSString *)errorMessage;
</span><span class="cx"> 
</span><span class="cx"> - (void)stopTimer;
</span><ins>+- (BOOL)isActive;
</ins><span class="cx"> 
</span><span class="cx"> @end
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkToolsDumpRenderTreemacMockGeolocationProvidermm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/DumpRenderTree/mac/MockGeolocationProvider.mm (188067 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/DumpRenderTree/mac/MockGeolocationProvider.mm        2015-08-06 22:36:34 UTC (rev 188067)
+++ trunk/Tools/DumpRenderTree/mac/MockGeolocationProvider.mm        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -115,6 +115,11 @@
</span><span class="cx">     _timer = 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (BOOL)isActive
+{
+    return !_registeredViews.isEmpty();
+}
+
</ins><span class="cx"> - (void)timerFired
</span><span class="cx"> {
</span><span class="cx">     _timer = 0;
</span></span></pre></div>
<a id="trunkToolsDumpRenderTreemacTestRunnerMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/DumpRenderTree/mac/TestRunnerMac.mm (188067 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/DumpRenderTree/mac/TestRunnerMac.mm        2015-08-06 22:36:34 UTC (rev 188067)
+++ trunk/Tools/DumpRenderTree/mac/TestRunnerMac.mm        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -254,6 +254,11 @@
</span><span class="cx">     return [(UIDelegate *)[[mainFrame webView] UIDelegate] numberOfPendingGeolocationPermissionRequests];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool TestRunner::isGeolocationProviderActive()
+{
+    return MockGeolocationProvider.shared.isActive;
+}
+
</ins><span class="cx"> size_t TestRunner::webHistoryItemCount()
</span><span class="cx"> {
</span><span class="cx">     return [[[WebHistory optionalSharedHistory] allItems] count];
</span></span></pre></div>
<a id="trunkToolsDumpRenderTreewinTestRunnerWincpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/DumpRenderTree/win/TestRunnerWin.cpp (188067 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/DumpRenderTree/win/TestRunnerWin.cpp        2015-08-06 22:36:34 UTC (rev 188067)
+++ trunk/Tools/DumpRenderTree/win/TestRunnerWin.cpp        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -241,6 +241,13 @@
</span><span class="cx">     return -1;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool TestRunner::isGeolocationProviderActive()
+{
+    // FIXME: Implement for Geolocation layout tests.
+    printf(&quot;ERROR: TestRunner::isGeolocationProviderActive() not implemented\n&quot;);
+    return false;
+}
+
</ins><span class="cx"> size_t TestRunner::webHistoryItemCount()
</span><span class="cx"> {
</span><span class="cx">     COMPtr&lt;IWebHistory&gt; history;
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerGeolocationProviderMockh"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/GeolocationProviderMock.h (188067 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/GeolocationProviderMock.h        2015-08-06 22:36:34 UTC (rev 188067)
+++ trunk/Tools/WebKitTestRunner/GeolocationProviderMock.h        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -41,6 +41,8 @@
</span><span class="cx">     void startUpdating(WKGeolocationManagerRef);
</span><span class="cx">     void stopUpdating(WKGeolocationManagerRef);
</span><span class="cx"> 
</span><ins>+    bool isActive() const { return m_isActive; }
+
</ins><span class="cx"> private:
</span><span class="cx">     void sendPositionIfNeeded();
</span><span class="cx">     void sendErrorIfNeeded();
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerInjectedBundleBindingsTestRunneridl"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl (188067 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl        2015-08-06 22:36:34 UTC (rev 188067)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -169,6 +169,7 @@
</span><span class="cx">     void setGeolocationPermission(boolean value);
</span><span class="cx">     void setMockGeolocationPosition(double latitude, double longitude, double accuracy, [Default=Undefined] optional object altitude, optional object altitudeAccuracy, optional object heading, optional object speed);
</span><span class="cx">     void setMockGeolocationPositionUnavailableError(DOMString errorMessage);
</span><ins>+    boolean isGeolocationProviderActive();
</ins><span class="cx"> 
</span><span class="cx">     // MediaStream
</span><span class="cx">     void setUserMediaPermission(boolean value);
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerInjectedBundleInjectedBundlecpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp (188067 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp        2015-08-06 22:36:34 UTC (rev 188067)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -464,6 +464,16 @@
</span><span class="cx">     WKBundlePagePostMessage(page()-&gt;page(), messageName.get(), errorMessage);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool InjectedBundle::isGeolocationProviderActive() const
+{
+    WKRetainPtr&lt;WKStringRef&gt; messageName(AdoptWK, WKStringCreateWithUTF8CString(&quot;IsGeolocationClientActive&quot;));
+    WKTypeRef resultToPass = 0;
+    WKBundlePagePostSynchronousMessage(page()-&gt;page(), messageName.get(), 0, &amp;resultToPass);
+    WKRetainPtr&lt;WKBooleanRef&gt; isActive(AdoptWK, static_cast&lt;WKBooleanRef&gt;(resultToPass));
+
+    return WKBooleanGetValue(isActive.get());
+}
+
</ins><span class="cx"> void InjectedBundle::setUserMediaPermission(bool enabled)
</span><span class="cx"> {
</span><span class="cx">     auto messageName = adoptWK(WKStringCreateWithUTF8CString(&quot;SetUserMediaPermission&quot;));
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerInjectedBundleInjectedBundleh"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h (188067 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h        2015-08-06 22:36:34 UTC (rev 188067)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -91,6 +91,7 @@
</span><span class="cx">     void setGeolocationPermission(bool);
</span><span class="cx">     void setMockGeolocationPosition(double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed);
</span><span class="cx">     void setMockGeolocationPositionUnavailableError(WKStringRef errorMessage);
</span><ins>+    bool isGeolocationProviderActive() const;
</ins><span class="cx"> 
</span><span class="cx">     // MediaStream.
</span><span class="cx">     void setUserMediaPermission(bool);
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerInjectedBundleTestRunnercpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp (188067 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp        2015-08-06 22:36:34 UTC (rev 188067)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -699,6 +699,11 @@
</span><span class="cx">     InjectedBundle::singleton().setGeolocationPermission(enabled);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool TestRunner::isGeolocationProviderActive()
+{
+    return InjectedBundle::singleton().isGeolocationProviderActive();
+}
+
</ins><span class="cx"> void TestRunner::setMockGeolocationPosition(double latitude, double longitude, double accuracy, JSValueRef jsAltitude, JSValueRef jsAltitudeAccuracy, JSValueRef jsHeading, JSValueRef jsSpeed)
</span><span class="cx"> {
</span><span class="cx">     auto&amp; injectedBundle = InjectedBundle::singleton();
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerInjectedBundleTestRunnerh"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h (188067 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h        2015-08-06 22:36:34 UTC (rev 188067)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -256,6 +256,7 @@
</span><span class="cx">     void setGeolocationPermission(bool);
</span><span class="cx">     void setMockGeolocationPosition(double latitude, double longitude, double accuracy, JSValueRef altitude, JSValueRef altitudeAccuracy, JSValueRef heading, JSValueRef speed);
</span><span class="cx">     void setMockGeolocationPositionUnavailableError(JSStringRef message);
</span><ins>+    bool isGeolocationProviderActive();
</ins><span class="cx"> 
</span><span class="cx">     // MediaStream
</span><span class="cx">     void setUserMediaPermission(bool);
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerTestControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (188067 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/TestController.cpp        2015-08-06 22:36:34 UTC (rev 188067)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -1478,6 +1478,11 @@
</span><span class="cx">     decidePolicyForGeolocationPermissionRequestIfPossible();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool TestController::isGeolocationProviderActive() const
+{
+    return m_geolocationProvider-&gt;isActive();
+}
+
</ins><span class="cx"> void TestController::setUserMediaPermission(bool enabled)
</span><span class="cx"> {
</span><span class="cx">     m_isUserMediaPermissionSet = true;
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerTestControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/TestController.h (188067 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/TestController.h        2015-08-06 22:36:34 UTC (rev 188067)
+++ trunk/Tools/WebKitTestRunner/TestController.h        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -89,6 +89,7 @@
</span><span class="cx">     void setMockGeolocationPosition(double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed);
</span><span class="cx">     void setMockGeolocationPositionUnavailableError(WKStringRef errorMessage);
</span><span class="cx">     void handleGeolocationPermissionRequest(WKGeolocationPermissionRequestRef);
</span><ins>+    bool isGeolocationProviderActive() const;
</ins><span class="cx"> 
</span><span class="cx">     // MediaStream.
</span><span class="cx">     void setUserMediaPermission(bool);
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerTestInvocationcpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/TestInvocation.cpp (188067 => 188068)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp        2015-08-06 22:36:34 UTC (rev 188067)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp        2015-08-06 22:37:47 UTC (rev 188068)
</span><span class="lines">@@ -642,6 +642,12 @@
</span><span class="cx">         return 0;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    if (WKStringIsEqualToUTF8CString(messageName, &quot;IsGeolocationClientActive&quot;)) {
+        bool isActive = TestController::singleton().isGeolocationProviderActive();
+        WKRetainPtr&lt;WKTypeRef&gt; result(AdoptWK, WKBooleanCreate(isActive));
+        return result;
+    }
+
</ins><span class="cx">     if (WKStringIsEqualToUTF8CString(messageName, &quot;IsWorkQueueEmpty&quot;)) {
</span><span class="cx">         bool isEmpty = TestController::singleton().workQueueManager().isWorkQueueEmpty();
</span><span class="cx">         WKRetainPtr&lt;WKTypeRef&gt; result(AdoptWK, WKBooleanCreate(isEmpty));
</span></span></pre>
</div>
</div>

</body>
</html>