15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* 25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All Rights Reserved. 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright 2010, The Android Open Source Project 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * are met: 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 1. Redistributions of source code must retain the above copyright 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer in the 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * documentation and/or other materials provided with the distribution. 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */ 265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef Geolocation_h 285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define Geolocation_h 295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "bindings/v8/ScriptWrappable.h" 3153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/dom/ActiveDOMObject.h" 3253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/geolocation/Geoposition.h" 3353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/geolocation/PositionCallback.h" 3453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/geolocation/PositionError.h" 3553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/geolocation/PositionErrorCallback.h" 3653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/geolocation/PositionOptions.h" 371e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/Timer.h" 3810f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch#include "platform/heap/Handle.h" 395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace WebCore { 415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class Document; 43d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)class LocalFrame; 445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class GeolocationController; 455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class GeolocationError; 465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class GeolocationPosition; 471e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)class ExecutionContext; 485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 495d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)class Geolocation FINAL 505d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) : public GarbageCollectedFinalized<Geolocation> 515d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) , public ScriptWrappable 525d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) , public ActiveDOMObject { 535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public: 545d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) static Geolocation* create(ExecutionContext*); 5509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) virtual ~Geolocation(); 5609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) void trace(Visitor*); 575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) virtual void stop() OVERRIDE; 595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) Document* document() const; 60d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) LocalFrame* frame() const; 615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 62a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Creates a oneshot and attempts to obtain a position that meets the 63a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // constraints of the options. 645d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) void getCurrentPosition(PassOwnPtr<PositionCallback>, PassOwnPtr<PositionErrorCallback>, PositionOptions*); 65a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 66a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Creates a watcher that will be notified whenever a new position is 67a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // available that meets the constraints of the options. 685d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) int watchPosition(PassOwnPtr<PositionCallback>, PassOwnPtr<PositionErrorCallback>, PositionOptions*); 69a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 70a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Removes all references to the watcher, it will not be updated again. 71926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) void clearWatch(int watchID); 725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void setIsAllowed(bool); 74a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) bool isAllowed() const { return m_allowGeolocation == Yes; } 765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 77a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Notifies this that a new position is available. Must never be called 78a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // before permission is granted by the user. 795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void positionChanged(); 80a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 81a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Notifies this that an error has occurred, it must be handled immediately. 825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void setError(GeolocationError*); 835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)private: 85a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Returns the last known position, if any. May return null. 865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) Geoposition* lastPosition(); 875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) bool isDenied() const { return m_allowGeolocation == No; } 895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 901e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) explicit Geolocation(ExecutionContext*); 915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 92a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Holds the success and error callbacks and the options that were provided 93a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // when a oneshot or watcher were created. Also, if specified in the 94a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // options, manages a timer to limit the time to wait for the system to 95a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // obtain a position. 965d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) class GeoNotifier : public GarbageCollectedFinalized<GeoNotifier> { 975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) public: 985d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) static GeoNotifier* create(Geolocation* geolocation, PassOwnPtr<PositionCallback> positionCallback, PassOwnPtr<PositionErrorCallback> positionErrorCallback, PositionOptions* options) 9909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) { 1005d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) return new GeoNotifier(geolocation, positionCallback, positionErrorCallback, options); 10109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 10209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) void trace(Visitor*); 1035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) PositionOptions* options() const { return m_options.get(); }; 105a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 106a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Sets the given error as the fatal error if there isn't one yet. 107a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Starts the timer with an interval of 0. 1085d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) void setFatalError(PositionError*); 1095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) bool useCachedPosition() const { return m_useCachedPosition; } 111a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 112a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Tells the notifier to use a cached position and starts its timer with 113a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // an interval of 0. 1145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void setUseCachedPosition(); 1155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void runSuccessCallback(Geoposition*); 1175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void runErrorCallback(PositionError*); 1185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 119f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles) void startTimer(); 1205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void stopTimer(); 121a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 122a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Runs the error callback if there is a fatal error. Otherwise, if a 123a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // cached position must be used, registers itself for receiving one. 124a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Otherwise, the notifier has expired, and its error callback is run. 1255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void timerFired(Timer<GeoNotifier>*); 126a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 1275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) private: 1285d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) GeoNotifier(Geolocation*, PassOwnPtr<PositionCallback>, PassOwnPtr<PositionErrorCallback>, PositionOptions*); 1295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1305d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) Member<Geolocation> m_geolocation; 131a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) OwnPtr<PositionCallback> m_successCallback; 132a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) OwnPtr<PositionErrorCallback> m_errorCallback; 1335d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) Member<PositionOptions> m_options; 1345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) Timer<GeoNotifier> m_timer; 1355d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) Member<PositionError> m_fatalError; 1365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) bool m_useCachedPosition; 1375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) }; 1385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1395d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) typedef HeapVector<Member<GeoNotifier> > GeoNotifierVector; 1405d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) typedef HeapHashSet<Member<GeoNotifier> > GeoNotifierSet; 1415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) class Watchers { 143323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) DISALLOW_ALLOCATION(); 1445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) public: 14509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) void trace(Visitor*); 1465d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) bool add(int id, GeoNotifier*); 1475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) GeoNotifier* find(int id); 1485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void remove(int id); 1495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void remove(GeoNotifier*); 1505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) bool contains(GeoNotifier*) const; 1515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void clear(); 1525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) bool isEmpty() const; 1535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void getNotifiersVector(GeoNotifierVector&) const; 1545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) private: 1555d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) typedef HeapHashMap<int, Member<GeoNotifier> > IdToNotifierMap; 1565d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) typedef HeapHashMap<Member<GeoNotifier>, int> NotifierToIdMap; 1575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) IdToNotifierMap m_idToNotifierMap; 1585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) NotifierToIdMap m_notifierToIdMap; 1595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) }; 1605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) bool hasListeners() const { return !m_oneShots.isEmpty() || !m_watchers.isEmpty(); } 1625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void sendError(GeoNotifierVector&, PositionError*); 1645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void sendPosition(GeoNotifierVector&, Geoposition*); 1655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 166a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Removes notifiers that use a cached position from |notifiers| and 167a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // if |cached| is not null they are added to it. 1685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) static void extractNotifiersWithCachedPosition(GeoNotifierVector& notifiers, GeoNotifierVector* cached); 169a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 170a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Copies notifiers from |src| vector to |dest| set. 171a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) static void copyToSet(const GeoNotifierVector& src, GeoNotifierSet& dest); 1725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) static void stopTimer(GeoNotifierVector&); 1745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void stopTimersForOneShots(); 1755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void stopTimersForWatchers(); 1765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void stopTimers(); 1775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 178a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Sets a fatal error on the given notifiers. 1795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void cancelRequests(GeoNotifierVector&); 180a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 181a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Sets a fatal error on all notifiers. 1825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void cancelAllRequests(); 1835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 184a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Runs the success callbacks on all notifiers. A position must be available 185a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // and the user must have given permission. 1865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void makeSuccessCallbacks(); 187a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 188a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Sends the given error to all notifiers, unless the error is not fatal and 189a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // the notifier is due to receive a cached position. Clears the oneshots, 190a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // and also clears the watchers if the error is fatal. 1915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void handleError(PositionError*); 1925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 193a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Requests permission to share positions with the page. 1945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void requestPermission(); 1955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 196a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Attempts to register this with the controller for receiving updates. 197a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Returns false if there is no controller to register with. 1985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) bool startUpdating(GeoNotifier*); 199a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 2005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void stopUpdating(); 2015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 202a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Processes the notifiers that were waiting for a permission decision. If 203a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // granted and this can be registered with the controller then the 204a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // notifier's timers are started. Otherwise, a fatal error is set on them. 2055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void handlePendingPermissionNotifiers(); 2065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 207a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Attempts to obtain a position for the given notifier, either by using 208a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // the cached position or by requesting one from the controller. Sets a 209a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // fatal error if permission is denied or no position can be obtained. 2105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void startRequest(GeoNotifier*); 2115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 212a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Discards the notifier because a fatal error occurred for it. 2135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void fatalErrorOccurred(GeoNotifier*); 214a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 215a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Discards the notifier if it is a oneshot because it timed it. 2165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void requestTimedOut(GeoNotifier*); 217a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 218a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Adds the notifier to the set awaiting a cached position. Runs the success 219a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // callbacks for them if permission has been granted. Requests permission if 220a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // it is unknown. 2215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void requestUsesCachedPosition(GeoNotifier*); 222a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 2235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) bool haveSuitableCachedPosition(PositionOptions*); 224a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 225a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Runs the success callbacks for the set of notifiers awaiting a cached 226a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // position, the set is then cleared. The oneshots are removed everywhere. 2275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void makeCachedPositionCallbacks(); 2285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) GeoNotifierSet m_oneShots; 2305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) Watchers m_watchers; 2315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) GeoNotifierSet m_pendingForPermissionNotifiers; 2325d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) Member<Geoposition> m_lastPosition; 2335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) enum { 2355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) Unknown, 2365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) InProgress, 2375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) Yes, 2385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) No 2395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } m_allowGeolocation; 2405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) GeoNotifierSet m_requestsAwaitingCachedPosition; 2425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}; 24302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 2445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} // namespace WebCore 2455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif // Geolocation_h 247