Diff
Modified: trunk/Source/WebCore/ChangeLog (171187 => 171188)
--- trunk/Source/WebCore/ChangeLog 2014-07-17 17:33:37 UTC (rev 171187)
+++ trunk/Source/WebCore/ChangeLog 2014-07-17 17:35:35 UTC (rev 171188)
@@ -1,3 +1,39 @@
+2014-07-16 Sam Weinig <s...@webkit.org>
+
+ Don't send geolocation permission requests when the page is not visible
+ <rdar://problem/17208715>
+ https://bugs.webkit.org/show_bug.cgi?id=134989
+
+ Reviewed by Darin Adler.
+
+ Instead of eagerly requesting geolocation permission for pages that aren't visible,
+ store a set of pending requests, and send them only once the page has become visible.
+
+ * Modules/geolocation/GeolocationController.cpp:
+ (WebCore::GeolocationController::GeolocationController):
+ (WebCore::GeolocationController::~GeolocationController):
+ (WebCore::GeolocationController::requestPermission):
+ (WebCore::GeolocationController::cancelPermissionRequest):
+ (WebCore::GeolocationController::viewStateDidChange):
+ (WebCore::provideGeolocationTo):
+ * Modules/geolocation/GeolocationController.h:
+ Store pending requests to be fired once the page is visible.
+
+ * WebCore.xcodeproj/project.pbxproj:
+ Add ViewStateChangeObserver.h
+
+ * page/Page.cpp:
+ (WebCore::Page::addViewStateChangeObserver):
+ (WebCore::Page::removeViewStateChangeObserver):
+ (WebCore::Page::setViewState):
+ * page/Page.h:
+ Add a set of registered view state observers, and notify them when the
+ view state changes.
+
+ * page/ViewStateChangeObserver.h: Added.
+ (WebCore::ViewStateChangeObserver::~ViewStateChangeObserver):
+ Add an observer that can register with the page for view state changes.
+
2014-07-17 Jer Noble <jer.no...@apple.com>
Enable legacy fullscreen API in media controls
Modified: trunk/Source/WebCore/Modules/geolocation/GeolocationController.cpp (171187 => 171188)
--- trunk/Source/WebCore/Modules/geolocation/GeolocationController.cpp 2014-07-17 17:33:37 UTC (rev 171187)
+++ trunk/Source/WebCore/Modules/geolocation/GeolocationController.cpp 2014-07-17 17:35:35 UTC (rev 171188)
@@ -34,15 +34,21 @@
namespace WebCore {
-GeolocationController::GeolocationController(GeolocationClient* client)
- : m_client(client)
+GeolocationController::GeolocationController(Page& page, GeolocationClient* client)
+ : m_page(page)
+ , m_client(client)
{
+ m_page.addViewStateChangeObserver(*this);
}
GeolocationController::~GeolocationController()
{
ASSERT(m_observers.isEmpty());
+ // NOTE: We don't have to remove ourselves from page's ViewStateChangeObserver set, since
+ // we are supplement of the Page, and our destructor getting called means the page is being
+ // torn down.
+
if (m_client)
m_client->geolocationDestroyed();
}
@@ -82,12 +88,20 @@
void GeolocationController::requestPermission(Geolocation* geolocation)
{
+ if (!m_page.isVisible()) {
+ m_pendedPermissionRequest.add(geolocation);
+ return;
+ }
+
if (m_client)
m_client->requestPermission(geolocation);
}
void GeolocationController::cancelPermissionRequest(Geolocation* geolocation)
{
+ if (m_pendedPermissionRequest.remove(geolocation))
+ return;
+
if (m_client)
m_client->cancelPermissionRequest(geolocation);
}
@@ -120,6 +134,16 @@
return m_client->lastPosition();
}
+void GeolocationController::viewStateDidChange(ViewState::Flags, ViewState::Flags)
+{
+ if (!m_page.isVisible())
+ return;
+
+ HashSet<RefPtr<Geolocation>> pendedPermissionRequests = WTF::move(m_pendedPermissionRequest);
+ for (auto& permissionRequest : pendedPermissionRequests)
+ m_client->requestPermission(permissionRequest.get());
+}
+
const char* GeolocationController::supplementName()
{
return "GeolocationController";
@@ -127,7 +151,7 @@
void provideGeolocationTo(Page* page, GeolocationClient* client)
{
- Supplement<Page>::provideTo(page, GeolocationController::supplementName(), std::make_unique<GeolocationController>(client));
+ Supplement<Page>::provideTo(page, GeolocationController::supplementName(), std::make_unique<GeolocationController>(*page, client));
}
} // namespace WebCore
Modified: trunk/Source/WebCore/Modules/geolocation/GeolocationController.h (171187 => 171188)
--- trunk/Source/WebCore/Modules/geolocation/GeolocationController.h 2014-07-17 17:33:37 UTC (rev 171187)
+++ trunk/Source/WebCore/Modules/geolocation/GeolocationController.h 2014-07-17 17:35:35 UTC (rev 171188)
@@ -30,6 +30,7 @@
#include "Geolocation.h"
#include "Page.h"
+#include "ViewStateChangeObserver.h"
#include <wtf/HashSet.h>
#include <wtf/Noncopyable.h>
#include <wtf/RefPtr.h>
@@ -41,10 +42,10 @@
class GeolocationPosition;
class Page;
-class GeolocationController : public Supplement<Page> {
+class GeolocationController : public Supplement<Page>, private ViewStateChangeObserver {
WTF_MAKE_NONCOPYABLE(GeolocationController);
public:
- explicit GeolocationController(GeolocationClient*);
+ explicit GeolocationController(Page&, GeolocationClient*);
~GeolocationController();
void addObserver(Geolocation*, bool enableHighAccuracy);
@@ -64,13 +65,20 @@
static GeolocationController* from(Page* page) { return static_cast<GeolocationController*>(Supplement<Page>::from(page, supplementName())); }
private:
+ Page& m_page;
GeolocationClient* m_client;
+ virtual void viewStateDidChange(ViewState::Flags oldViewState, ViewState::Flags newViewState) override;
+
RefPtr<GeolocationPosition> m_lastPosition;
+
typedef HashSet<RefPtr<Geolocation>> ObserversSet;
// All observers; both those requesting high accuracy and those not.
ObserversSet m_observers;
ObserversSet m_highAccuracyObservers;
+
+ // While the page is not visible, we pend permission requests.
+ HashSet<RefPtr<Geolocation>> m_pendedPermissionRequest;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (171187 => 171188)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2014-07-17 17:33:37 UTC (rev 171187)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2014-07-17 17:35:35 UTC (rev 171188)
@@ -2425,6 +2425,7 @@
7CC69940191EC5F500AF2270 /* JSWebKitNamespace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC6993E191EC5F500AF2270 /* JSWebKitNamespace.cpp */; };
7CC69941191EC5F500AF2270 /* JSWebKitNamespace.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CC6993F191EC5F500AF2270 /* JSWebKitNamespace.h */; };
7CC7E3D717208C0F003C5277 /* IDNScriptWhiteList.txt in Resources */ = {isa = PBXBuildFile; fileRef = 7CC7E3D617208C0F003C5277 /* IDNScriptWhiteList.txt */; };
+ 7CDEEE1E197610D700E352CD /* ViewStateChangeObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CDEEE1D197610D700E352CD /* ViewStateChangeObserver.h */; settings = {ATTRIBUTES = (Private, ); }; };
7CE68344192143A800F4D928 /* UserMessageHandlerDescriptor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CE68342192143A800F4D928 /* UserMessageHandlerDescriptor.cpp */; };
7CE68345192143A800F4D928 /* UserMessageHandlerDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CE68343192143A800F4D928 /* UserMessageHandlerDescriptor.h */; settings = {ATTRIBUTES = (Private, ); }; };
7CE683471921821500F4D928 /* UserMessageHandlerDescriptorTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CE683461921821500F4D928 /* UserMessageHandlerDescriptorTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -9581,6 +9582,7 @@
7CC6993E191EC5F500AF2270 /* JSWebKitNamespace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebKitNamespace.cpp; sourceTree = "<group>"; };
7CC6993F191EC5F500AF2270 /* JSWebKitNamespace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWebKitNamespace.h; sourceTree = "<group>"; };
7CC7E3D617208C0F003C5277 /* IDNScriptWhiteList.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = IDNScriptWhiteList.txt; sourceTree = "<group>"; };
+ 7CDEEE1D197610D700E352CD /* ViewStateChangeObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewStateChangeObserver.h; sourceTree = "<group>"; };
7CE68342192143A800F4D928 /* UserMessageHandlerDescriptor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UserMessageHandlerDescriptor.cpp; sourceTree = "<group>"; };
7CE68343192143A800F4D928 /* UserMessageHandlerDescriptor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserMessageHandlerDescriptor.h; sourceTree = "<group>"; };
7CE683461921821500F4D928 /* UserMessageHandlerDescriptorTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserMessageHandlerDescriptorTypes.h; sourceTree = "<group>"; };
@@ -16716,6 +16718,7 @@
E1271A130EEEC80400F61213 /* WorkerNavigator.cpp */,
E1271A0A0EEEC77A00F61213 /* WorkerNavigator.h */,
E1271A510EEECD1C00F61213 /* WorkerNavigator.idl */,
+ 7CDEEE1D197610D700E352CD /* ViewStateChangeObserver.h */,
);
path = page;
sourceTree = "<group>";
@@ -26289,6 +26292,7 @@
B2227AB80D00BF220071B782 /* SVGStyleElement.h in Headers */,
B2227ABB0D00BF220071B782 /* SVGSVGElement.h in Headers */,
B2227ABE0D00BF220071B782 /* SVGSwitchElement.h in Headers */,
+ 7CDEEE1E197610D700E352CD /* ViewStateChangeObserver.h in Headers */,
B2227AC10D00BF220071B782 /* SVGSymbolElement.h in Headers */,
B2227AC50D00BF220071B782 /* SVGTests.h in Headers */,
08F0BFC31255C53C00075185 /* SVGTextChunk.h in Headers */,
Modified: trunk/Source/WebCore/page/Page.cpp (171187 => 171188)
--- trunk/Source/WebCore/page/Page.cpp 2014-07-17 17:33:37 UTC (rev 171187)
+++ trunk/Source/WebCore/page/Page.cpp 2014-07-17 17:35:35 UTC (rev 171188)
@@ -83,6 +83,7 @@
#include "TextResourceDecoder.h"
#include "UserContentController.h"
#include "UserInputBridge.h"
+#include "ViewStateChangeObserver.h"
#include "VisitedLinkState.h"
#include "VisitedLinkStore.h"
#include "VoidCallback.h"
@@ -901,6 +902,16 @@
resumeAnimatingImages();
}
+void Page::addViewStateChangeObserver(ViewStateChangeObserver& observer)
+{
+ m_viewStateChangeObservers.add(&observer);
+}
+
+void Page::removeViewStateChangeObserver(ViewStateChangeObserver& observer)
+{
+ m_viewStateChangeObservers.remove(&observer);
+}
+
void Page::suspendScriptedAnimations()
{
m_scriptedAnimationsSuspended = true;
@@ -1196,6 +1207,8 @@
if (!changed)
return;
+ ViewState::Flags oldViewState = m_viewState;
+
m_viewState = viewState;
m_focusController->setViewState(viewState);
if (m_pageThrottler)
@@ -1207,6 +1220,9 @@
setIsInWindowInternal(viewState & ViewState::IsInWindow);
if (changed & ViewState::IsVisuallyIdle)
setIsVisuallyIdleInternal(viewState & ViewState::IsVisuallyIdle);
+
+ for (auto* observer : m_viewStateChangeObservers)
+ observer->viewStateDidChange(oldViewState, m_viewState);
}
void Page::setIsVisible(bool isVisible)
Modified: trunk/Source/WebCore/page/Page.h (171187 => 171188)
--- trunk/Source/WebCore/page/Page.h 2014-07-17 17:33:37 UTC (rev 171187)
+++ trunk/Source/WebCore/page/Page.h 2014-07-17 17:35:35 UTC (rev 171188)
@@ -102,6 +102,7 @@
class StorageNamespace;
class UserContentController;
class ValidationMessageClient;
+class ViewStateChangeObserver;
class VisitedLinkStore;
typedef uint64_t LinkHash;
@@ -319,6 +320,9 @@
void setIsInWindow(bool);
bool isInWindow() const { return m_viewState & ViewState::IsInWindow; }
+ void addViewStateChangeObserver(ViewStateChangeObserver&);
+ void removeViewStateChangeObserver(ViewStateChangeObserver&);
+
void suspendScriptedAnimations();
void resumeScriptedAnimations();
bool scriptedAnimationsSuspended() const { return m_scriptedAnimationsSuspended; }
@@ -578,6 +582,8 @@
RefPtr<UserContentController> m_userContentController;
RefPtr<VisitedLinkStore> m_visitedLinkStore;
+ HashSet<ViewStateChangeObserver*> m_viewStateChangeObservers;
+
SessionID m_sessionID;
};
Added: trunk/Source/WebCore/page/ViewStateChangeObserver.h (0 => 171188)
--- trunk/Source/WebCore/page/ViewStateChangeObserver.h (rev 0)
+++ trunk/Source/WebCore/page/ViewStateChangeObserver.h 2014-07-17 17:35:35 UTC (rev 171188)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ViewStateChangeObserver_h
+#define ViewStateChangeObserver_h
+
+#include "ViewState.h"
+
+namespace WebCore {
+
+class ViewStateChangeObserver {
+public:
+ virtual ~ViewStateChangeObserver()
+ {
+ }
+
+ virtual void viewStateDidChange(ViewState::Flags oldViewState, ViewState::Flags newViewState) = 0;
+};
+
+} // namespace WebCore
+
+#endif // ViewStateChangeObserver_h