Changeset 171188 in webkit
- Timestamp:
- Jul 17, 2014 10:35:35 AM (10 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r171184 r171188 1 2014-07-16 Sam Weinig <sam@webkit.org> 2 3 Don't send geolocation permission requests when the page is not visible 4 <rdar://problem/17208715> 5 https://bugs.webkit.org/show_bug.cgi?id=134989 6 7 Reviewed by Darin Adler. 8 9 Instead of eagerly requesting geolocation permission for pages that aren't visible, 10 store a set of pending requests, and send them only once the page has become visible. 11 12 * Modules/geolocation/GeolocationController.cpp: 13 (WebCore::GeolocationController::GeolocationController): 14 (WebCore::GeolocationController::~GeolocationController): 15 (WebCore::GeolocationController::requestPermission): 16 (WebCore::GeolocationController::cancelPermissionRequest): 17 (WebCore::GeolocationController::viewStateDidChange): 18 (WebCore::provideGeolocationTo): 19 * Modules/geolocation/GeolocationController.h: 20 Store pending requests to be fired once the page is visible. 21 22 * WebCore.xcodeproj/project.pbxproj: 23 Add ViewStateChangeObserver.h 24 25 * page/Page.cpp: 26 (WebCore::Page::addViewStateChangeObserver): 27 (WebCore::Page::removeViewStateChangeObserver): 28 (WebCore::Page::setViewState): 29 * page/Page.h: 30 Add a set of registered view state observers, and notify them when the 31 view state changes. 32 33 * page/ViewStateChangeObserver.h: Added. 34 (WebCore::ViewStateChangeObserver::~ViewStateChangeObserver): 35 Add an observer that can register with the page for view state changes. 36 1 37 2014-07-17 Jer Noble <jer.noble@apple.com> 2 38 -
trunk/Source/WebCore/Modules/geolocation/GeolocationController.cpp
r168166 r171188 35 35 namespace WebCore { 36 36 37 GeolocationController::GeolocationController(GeolocationClient* client) 38 : m_client(client) 37 GeolocationController::GeolocationController(Page& page, GeolocationClient* client) 38 : m_page(page) 39 , m_client(client) 39 40 { 41 m_page.addViewStateChangeObserver(*this); 40 42 } 41 43 … … 43 45 { 44 46 ASSERT(m_observers.isEmpty()); 47 48 // NOTE: We don't have to remove ourselves from page's ViewStateChangeObserver set, since 49 // we are supplement of the Page, and our destructor getting called means the page is being 50 // torn down. 45 51 46 52 if (m_client) … … 83 89 void GeolocationController::requestPermission(Geolocation* geolocation) 84 90 { 91 if (!m_page.isVisible()) { 92 m_pendedPermissionRequest.add(geolocation); 93 return; 94 } 95 85 96 if (m_client) 86 97 m_client->requestPermission(geolocation); … … 89 100 void GeolocationController::cancelPermissionRequest(Geolocation* geolocation) 90 101 { 102 if (m_pendedPermissionRequest.remove(geolocation)) 103 return; 104 91 105 if (m_client) 92 106 m_client->cancelPermissionRequest(geolocation); … … 121 135 } 122 136 137 void GeolocationController::viewStateDidChange(ViewState::Flags, ViewState::Flags) 138 { 139 if (!m_page.isVisible()) 140 return; 141 142 HashSet<RefPtr<Geolocation>> pendedPermissionRequests = WTF::move(m_pendedPermissionRequest); 143 for (auto& permissionRequest : pendedPermissionRequests) 144 m_client->requestPermission(permissionRequest.get()); 145 } 146 123 147 const char* GeolocationController::supplementName() 124 148 { … … 128 152 void provideGeolocationTo(Page* page, GeolocationClient* client) 129 153 { 130 Supplement<Page>::provideTo(page, GeolocationController::supplementName(), std::make_unique<GeolocationController>( client));154 Supplement<Page>::provideTo(page, GeolocationController::supplementName(), std::make_unique<GeolocationController>(*page, client)); 131 155 } 132 156 -
trunk/Source/WebCore/Modules/geolocation/GeolocationController.h
r168166 r171188 31 31 #include "Geolocation.h" 32 32 #include "Page.h" 33 #include "ViewStateChangeObserver.h" 33 34 #include <wtf/HashSet.h> 34 35 #include <wtf/Noncopyable.h> … … 42 43 class Page; 43 44 44 class GeolocationController : public Supplement<Page> {45 class GeolocationController : public Supplement<Page>, private ViewStateChangeObserver { 45 46 WTF_MAKE_NONCOPYABLE(GeolocationController); 46 47 public: 47 explicit GeolocationController( GeolocationClient*);48 explicit GeolocationController(Page&, GeolocationClient*); 48 49 ~GeolocationController(); 49 50 … … 65 66 66 67 private: 68 Page& m_page; 67 69 GeolocationClient* m_client; 68 70 71 virtual void viewStateDidChange(ViewState::Flags oldViewState, ViewState::Flags newViewState) override; 72 69 73 RefPtr<GeolocationPosition> m_lastPosition; 74 70 75 typedef HashSet<RefPtr<Geolocation>> ObserversSet; 71 76 // All observers; both those requesting high accuracy and those not. 72 77 ObserversSet m_observers; 73 78 ObserversSet m_highAccuracyObservers; 79 80 // While the page is not visible, we pend permission requests. 81 HashSet<RefPtr<Geolocation>> m_pendedPermissionRequest; 74 82 }; 75 83 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r171069 r171188 2426 2426 7CC69941191EC5F500AF2270 /* JSWebKitNamespace.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CC6993F191EC5F500AF2270 /* JSWebKitNamespace.h */; }; 2427 2427 7CC7E3D717208C0F003C5277 /* IDNScriptWhiteList.txt in Resources */ = {isa = PBXBuildFile; fileRef = 7CC7E3D617208C0F003C5277 /* IDNScriptWhiteList.txt */; }; 2428 7CDEEE1E197610D700E352CD /* ViewStateChangeObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CDEEE1D197610D700E352CD /* ViewStateChangeObserver.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2428 2429 7CE68344192143A800F4D928 /* UserMessageHandlerDescriptor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CE68342192143A800F4D928 /* UserMessageHandlerDescriptor.cpp */; }; 2429 2430 7CE68345192143A800F4D928 /* UserMessageHandlerDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CE68343192143A800F4D928 /* UserMessageHandlerDescriptor.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 9582 9583 7CC6993F191EC5F500AF2270 /* JSWebKitNamespace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWebKitNamespace.h; sourceTree = "<group>"; }; 9583 9584 7CC7E3D617208C0F003C5277 /* IDNScriptWhiteList.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = IDNScriptWhiteList.txt; sourceTree = "<group>"; }; 9585 7CDEEE1D197610D700E352CD /* ViewStateChangeObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewStateChangeObserver.h; sourceTree = "<group>"; }; 9584 9586 7CE68342192143A800F4D928 /* UserMessageHandlerDescriptor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UserMessageHandlerDescriptor.cpp; sourceTree = "<group>"; }; 9585 9587 7CE68343192143A800F4D928 /* UserMessageHandlerDescriptor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserMessageHandlerDescriptor.h; sourceTree = "<group>"; }; … … 16717 16719 E1271A0A0EEEC77A00F61213 /* WorkerNavigator.h */, 16718 16720 E1271A510EEECD1C00F61213 /* WorkerNavigator.idl */, 16721 7CDEEE1D197610D700E352CD /* ViewStateChangeObserver.h */, 16719 16722 ); 16720 16723 path = page; … … 26290 26293 B2227ABB0D00BF220071B782 /* SVGSVGElement.h in Headers */, 26291 26294 B2227ABE0D00BF220071B782 /* SVGSwitchElement.h in Headers */, 26295 7CDEEE1E197610D700E352CD /* ViewStateChangeObserver.h in Headers */, 26292 26296 B2227AC10D00BF220071B782 /* SVGSymbolElement.h in Headers */, 26293 26297 B2227AC50D00BF220071B782 /* SVGTests.h in Headers */, -
trunk/Source/WebCore/page/Page.cpp
r170774 r171188 84 84 #include "UserContentController.h" 85 85 #include "UserInputBridge.h" 86 #include "ViewStateChangeObserver.h" 86 87 #include "VisitedLinkState.h" 87 88 #include "VisitedLinkStore.h" … … 902 903 } 903 904 905 void Page::addViewStateChangeObserver(ViewStateChangeObserver& observer) 906 { 907 m_viewStateChangeObservers.add(&observer); 908 } 909 910 void Page::removeViewStateChangeObserver(ViewStateChangeObserver& observer) 911 { 912 m_viewStateChangeObservers.remove(&observer); 913 } 914 904 915 void Page::suspendScriptedAnimations() 905 916 { … … 1197 1208 return; 1198 1209 1210 ViewState::Flags oldViewState = m_viewState; 1211 1199 1212 m_viewState = viewState; 1200 1213 m_focusController->setViewState(viewState); … … 1208 1221 if (changed & ViewState::IsVisuallyIdle) 1209 1222 setIsVisuallyIdleInternal(viewState & ViewState::IsVisuallyIdle); 1223 1224 for (auto* observer : m_viewStateChangeObservers) 1225 observer->viewStateDidChange(oldViewState, m_viewState); 1210 1226 } 1211 1227 -
trunk/Source/WebCore/page/Page.h
r170235 r171188 103 103 class UserContentController; 104 104 class ValidationMessageClient; 105 class ViewStateChangeObserver; 105 106 class VisitedLinkStore; 106 107 … … 320 321 bool isInWindow() const { return m_viewState & ViewState::IsInWindow; } 321 322 323 void addViewStateChangeObserver(ViewStateChangeObserver&); 324 void removeViewStateChangeObserver(ViewStateChangeObserver&); 325 322 326 void suspendScriptedAnimations(); 323 327 void resumeScriptedAnimations(); … … 579 583 RefPtr<VisitedLinkStore> m_visitedLinkStore; 580 584 585 HashSet<ViewStateChangeObserver*> m_viewStateChangeObservers; 586 581 587 SessionID m_sessionID; 582 588 };
Note: See TracChangeset
for help on using the changeset viewer.