Changeset 171188 in webkit


Ignore:
Timestamp:
Jul 17, 2014 10:35:35 AM (10 years ago)
Author:
weinig@apple.com
Message:

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.

Location:
trunk/Source/WebCore
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r171184 r171188  
     12014-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
    1372014-07-17  Jer Noble  <jer.noble@apple.com>
    238
  • trunk/Source/WebCore/Modules/geolocation/GeolocationController.cpp

    r168166 r171188  
    3535namespace WebCore {
    3636
    37 GeolocationController::GeolocationController(GeolocationClient* client)
    38     : m_client(client)
     37GeolocationController::GeolocationController(Page& page, GeolocationClient* client)
     38    : m_page(page)
     39    , m_client(client)
    3940{
     41    m_page.addViewStateChangeObserver(*this);
    4042}
    4143
     
    4345{
    4446    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.
    4551
    4652    if (m_client)
     
    8389void GeolocationController::requestPermission(Geolocation* geolocation)
    8490{
     91    if (!m_page.isVisible()) {
     92        m_pendedPermissionRequest.add(geolocation);
     93        return;
     94    }
     95
    8596    if (m_client)
    8697        m_client->requestPermission(geolocation);
     
    89100void GeolocationController::cancelPermissionRequest(Geolocation* geolocation)
    90101{
     102    if (m_pendedPermissionRequest.remove(geolocation))
     103        return;
     104
    91105    if (m_client)
    92106        m_client->cancelPermissionRequest(geolocation);
     
    121135}
    122136
     137void 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
    123147const char* GeolocationController::supplementName()
    124148{
     
    128152void provideGeolocationTo(Page* page, GeolocationClient* client)
    129153{
    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));
    131155}
    132156   
  • trunk/Source/WebCore/Modules/geolocation/GeolocationController.h

    r168166 r171188  
    3131#include "Geolocation.h"
    3232#include "Page.h"
     33#include "ViewStateChangeObserver.h"
    3334#include <wtf/HashSet.h>
    3435#include <wtf/Noncopyable.h>
     
    4243class Page;
    4344
    44 class GeolocationController : public Supplement<Page> {
     45class GeolocationController : public Supplement<Page>, private ViewStateChangeObserver {
    4546    WTF_MAKE_NONCOPYABLE(GeolocationController);
    4647public:
    47     explicit GeolocationController(GeolocationClient*);
     48    explicit GeolocationController(Page&, GeolocationClient*);
    4849    ~GeolocationController();
    4950
     
    6566
    6667private:
     68    Page& m_page;
    6769    GeolocationClient* m_client;
    6870
     71    virtual void viewStateDidChange(ViewState::Flags oldViewState, ViewState::Flags newViewState) override;
     72
    6973    RefPtr<GeolocationPosition> m_lastPosition;
     74
    7075    typedef HashSet<RefPtr<Geolocation>> ObserversSet;
    7176    // All observers; both those requesting high accuracy and those not.
    7277    ObserversSet m_observers;
    7378    ObserversSet m_highAccuracyObservers;
     79
     80    // While the page is not visible, we pend permission requests.
     81    HashSet<RefPtr<Geolocation>> m_pendedPermissionRequest;
    7482};
    7583
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r171069 r171188  
    24262426                7CC69941191EC5F500AF2270 /* JSWebKitNamespace.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CC6993F191EC5F500AF2270 /* JSWebKitNamespace.h */; };
    24272427                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, ); }; };
    24282429                7CE68344192143A800F4D928 /* UserMessageHandlerDescriptor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CE68342192143A800F4D928 /* UserMessageHandlerDescriptor.cpp */; };
    24292430                7CE68345192143A800F4D928 /* UserMessageHandlerDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CE68343192143A800F4D928 /* UserMessageHandlerDescriptor.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    95829583                7CC6993F191EC5F500AF2270 /* JSWebKitNamespace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWebKitNamespace.h; sourceTree = "<group>"; };
    95839584                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>"; };
    95849586                7CE68342192143A800F4D928 /* UserMessageHandlerDescriptor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UserMessageHandlerDescriptor.cpp; sourceTree = "<group>"; };
    95859587                7CE68343192143A800F4D928 /* UserMessageHandlerDescriptor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserMessageHandlerDescriptor.h; sourceTree = "<group>"; };
     
    1671716719                                E1271A0A0EEEC77A00F61213 /* WorkerNavigator.h */,
    1671816720                                E1271A510EEECD1C00F61213 /* WorkerNavigator.idl */,
     16721                                7CDEEE1D197610D700E352CD /* ViewStateChangeObserver.h */,
    1671916722                        );
    1672016723                        path = page;
     
    2629026293                                B2227ABB0D00BF220071B782 /* SVGSVGElement.h in Headers */,
    2629126294                                B2227ABE0D00BF220071B782 /* SVGSwitchElement.h in Headers */,
     26295                                7CDEEE1E197610D700E352CD /* ViewStateChangeObserver.h in Headers */,
    2629226296                                B2227AC10D00BF220071B782 /* SVGSymbolElement.h in Headers */,
    2629326297                                B2227AC50D00BF220071B782 /* SVGTests.h in Headers */,
  • trunk/Source/WebCore/page/Page.cpp

    r170774 r171188  
    8484#include "UserContentController.h"
    8585#include "UserInputBridge.h"
     86#include "ViewStateChangeObserver.h"
    8687#include "VisitedLinkState.h"
    8788#include "VisitedLinkStore.h"
     
    902903}
    903904
     905void Page::addViewStateChangeObserver(ViewStateChangeObserver& observer)
     906{
     907    m_viewStateChangeObservers.add(&observer);
     908}
     909
     910void Page::removeViewStateChangeObserver(ViewStateChangeObserver& observer)
     911{
     912    m_viewStateChangeObservers.remove(&observer);
     913}
     914
    904915void Page::suspendScriptedAnimations()
    905916{
     
    11971208        return;
    11981209
     1210    ViewState::Flags oldViewState = m_viewState;
     1211
    11991212    m_viewState = viewState;
    12001213    m_focusController->setViewState(viewState);
     
    12081221    if (changed & ViewState::IsVisuallyIdle)
    12091222        setIsVisuallyIdleInternal(viewState & ViewState::IsVisuallyIdle);
     1223
     1224    for (auto* observer : m_viewStateChangeObservers)
     1225        observer->viewStateDidChange(oldViewState, m_viewState);
    12101226}
    12111227
  • trunk/Source/WebCore/page/Page.h

    r170235 r171188  
    103103class UserContentController;
    104104class ValidationMessageClient;
     105class ViewStateChangeObserver;
    105106class VisitedLinkStore;
    106107
     
    320321    bool isInWindow() const { return m_viewState & ViewState::IsInWindow; }
    321322
     323    void addViewStateChangeObserver(ViewStateChangeObserver&);
     324    void removeViewStateChangeObserver(ViewStateChangeObserver&);
     325
    322326    void suspendScriptedAnimations();
    323327    void resumeScriptedAnimations();
     
    579583    RefPtr<VisitedLinkStore> m_visitedLinkStore;
    580584
     585    HashSet<ViewStateChangeObserver*> m_viewStateChangeObservers;
     586
    581587    SessionID m_sessionID;
    582588};
Note: See TracChangeset for help on using the changeset viewer.