| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All Rights Reserved. |
| 3 * Copyright 2010, The Android Open Source Project | 3 * Copyright 2010, The Android Open Source Project |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #ifndef Geolocation_h | 27 #ifndef Geolocation_h |
| 28 #define Geolocation_h | 28 #define Geolocation_h |
| 29 | 29 |
| 30 #include "bindings/core/v8/ScriptPromise.h" | 30 #include "bindings/core/v8/ScriptPromise.h" |
| 31 #include "bindings/core/v8/ScriptWrappable.h" | 31 #include "bindings/core/v8/ScriptWrappable.h" |
| 32 #include "core/dom/ActiveDOMObject.h" | 32 #include "core/dom/ActiveDOMObject.h" |
| 33 #include "modules/geolocation/GeoNotifier.h" |
| 33 #include "modules/geolocation/Geoposition.h" | 34 #include "modules/geolocation/Geoposition.h" |
| 34 #include "modules/geolocation/PositionCallback.h" | 35 #include "modules/geolocation/PositionCallback.h" |
| 35 #include "modules/geolocation/PositionError.h" | 36 #include "modules/geolocation/PositionError.h" |
| 36 #include "modules/geolocation/PositionErrorCallback.h" | 37 #include "modules/geolocation/PositionErrorCallback.h" |
| 37 #include "modules/geolocation/PositionOptions.h" | 38 #include "modules/geolocation/PositionOptions.h" |
| 38 #include "platform/Timer.h" | 39 #include "platform/Timer.h" |
| 39 #include "platform/heap/Handle.h" | 40 #include "platform/heap/Handle.h" |
| 40 | 41 |
| 41 namespace WebCore { | 42 namespace WebCore { |
| 42 | 43 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 78 |
| 78 bool isAllowed() const { return m_geolocationPermission == PermissionAllowed
; } | 79 bool isAllowed() const { return m_geolocationPermission == PermissionAllowed
; } |
| 79 | 80 |
| 80 // Notifies this that a new position is available. Must never be called | 81 // Notifies this that a new position is available. Must never be called |
| 81 // before permission is granted by the user. | 82 // before permission is granted by the user. |
| 82 void positionChanged(); | 83 void positionChanged(); |
| 83 | 84 |
| 84 // Notifies this that an error has occurred, it must be handled immediately. | 85 // Notifies this that an error has occurred, it must be handled immediately. |
| 85 void setError(GeolocationError*); | 86 void setError(GeolocationError*); |
| 86 | 87 |
| 88 // Discards the notifier because a fatal error occurred for it. |
| 89 void fatalErrorOccurred(GeoNotifier*); |
| 90 |
| 91 // Adds the notifier to the set awaiting a cached position. Runs the success |
| 92 // callbacks for them if permission has been granted. Requests permission if |
| 93 // it is unknown. |
| 94 void requestUsesCachedPosition(GeoNotifier*); |
| 95 |
| 96 // Discards the notifier if it is a oneshot because it timed it. |
| 97 void requestTimedOut(GeoNotifier*); |
| 98 |
| 87 ScriptPromise registerRegion(ScriptState*, GeofencingRegion*); | 99 ScriptPromise registerRegion(ScriptState*, GeofencingRegion*); |
| 88 ScriptPromise unregisterRegion(ScriptState*, const String& regionId); | 100 ScriptPromise unregisterRegion(ScriptState*, const String& regionId); |
| 89 ScriptPromise getRegisteredRegions(ScriptState*) const; | 101 ScriptPromise getRegisteredRegions(ScriptState*) const; |
| 90 | 102 |
| 91 private: | 103 private: |
| 92 // Returns the last known position, if any. May return null. | 104 // Returns the last known position, if any. May return null. |
| 93 Geoposition* lastPosition(); | 105 Geoposition* lastPosition(); |
| 94 | 106 |
| 95 bool isDenied() const { return m_geolocationPermission == PermissionDenied;
} | 107 bool isDenied() const { return m_geolocationPermission == PermissionDenied;
} |
| 96 | 108 |
| 97 explicit Geolocation(ExecutionContext*); | 109 explicit Geolocation(ExecutionContext*); |
| 98 | 110 |
| 99 // Holds the success and error callbacks and the options that were provided | |
| 100 // when a oneshot or watcher were created. Also, if specified in the | |
| 101 // options, manages a timer to limit the time to wait for the system to | |
| 102 // obtain a position. | |
| 103 class GeoNotifier : public GarbageCollectedFinalized<GeoNotifier> { | |
| 104 public: | |
| 105 static GeoNotifier* create(Geolocation* geolocation, PassOwnPtr<Position
Callback> positionCallback, PassOwnPtr<PositionErrorCallback> positionErrorCallb
ack, PositionOptions* options) | |
| 106 { | |
| 107 return new GeoNotifier(geolocation, positionCallback, positionErrorC
allback, options); | |
| 108 } | |
| 109 void trace(Visitor*); | |
| 110 | |
| 111 PositionOptions* options() const { return m_options.get(); }; | |
| 112 | |
| 113 // Sets the given error as the fatal error if there isn't one yet. | |
| 114 // Starts the timer with an interval of 0. | |
| 115 void setFatalError(PositionError*); | |
| 116 | |
| 117 bool useCachedPosition() const { return m_useCachedPosition; } | |
| 118 | |
| 119 // Tells the notifier to use a cached position and starts its timer with | |
| 120 // an interval of 0. | |
| 121 void setUseCachedPosition(); | |
| 122 | |
| 123 void runSuccessCallback(Geoposition*); | |
| 124 void runErrorCallback(PositionError*); | |
| 125 | |
| 126 void startTimer(); | |
| 127 void stopTimer(); | |
| 128 | |
| 129 // Runs the error callback if there is a fatal error. Otherwise, if a | |
| 130 // cached position must be used, registers itself for receiving one. | |
| 131 // Otherwise, the notifier has expired, and its error callback is run. | |
| 132 void timerFired(Timer<GeoNotifier>*); | |
| 133 | |
| 134 private: | |
| 135 GeoNotifier(Geolocation*, PassOwnPtr<PositionCallback>, PassOwnPtr<Posit
ionErrorCallback>, PositionOptions*); | |
| 136 | |
| 137 Member<Geolocation> m_geolocation; | |
| 138 OwnPtr<PositionCallback> m_successCallback; | |
| 139 OwnPtr<PositionErrorCallback> m_errorCallback; | |
| 140 Member<PositionOptions> m_options; | |
| 141 Timer<GeoNotifier> m_timer; | |
| 142 Member<PositionError> m_fatalError; | |
| 143 bool m_useCachedPosition; | |
| 144 }; | |
| 145 | |
| 146 typedef HeapVector<Member<GeoNotifier> > GeoNotifierVector; | 111 typedef HeapVector<Member<GeoNotifier> > GeoNotifierVector; |
| 147 typedef HeapHashSet<Member<GeoNotifier> > GeoNotifierSet; | 112 typedef HeapHashSet<Member<GeoNotifier> > GeoNotifierSet; |
| 148 | 113 |
| 149 class Watchers { | 114 class Watchers { |
| 150 DISALLOW_ALLOCATION(); | 115 DISALLOW_ALLOCATION(); |
| 151 public: | 116 public: |
| 152 void trace(Visitor*); | 117 void trace(Visitor*); |
| 153 bool add(int id, GeoNotifier*); | 118 bool add(int id, GeoNotifier*); |
| 154 GeoNotifier* find(int id); | 119 GeoNotifier* find(int id); |
| 155 void remove(int id); | 120 void remove(int id); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // Processes the notifiers that were waiting for a permission decision. If | 174 // Processes the notifiers that were waiting for a permission decision. If |
| 210 // granted and this can be registered with the controller then the | 175 // granted and this can be registered with the controller then the |
| 211 // notifier's timers are started. Otherwise, a fatal error is set on them. | 176 // notifier's timers are started. Otherwise, a fatal error is set on them. |
| 212 void handlePendingPermissionNotifiers(); | 177 void handlePendingPermissionNotifiers(); |
| 213 | 178 |
| 214 // Attempts to obtain a position for the given notifier, either by using | 179 // Attempts to obtain a position for the given notifier, either by using |
| 215 // the cached position or by requesting one from the controller. Sets a | 180 // the cached position or by requesting one from the controller. Sets a |
| 216 // fatal error if permission is denied or no position can be obtained. | 181 // fatal error if permission is denied or no position can be obtained. |
| 217 void startRequest(GeoNotifier*); | 182 void startRequest(GeoNotifier*); |
| 218 | 183 |
| 219 // Discards the notifier because a fatal error occurred for it. | |
| 220 void fatalErrorOccurred(GeoNotifier*); | |
| 221 | |
| 222 // Discards the notifier if it is a oneshot because it timed it. | |
| 223 void requestTimedOut(GeoNotifier*); | |
| 224 | |
| 225 // Adds the notifier to the set awaiting a cached position. Runs the success | |
| 226 // callbacks for them if permission has been granted. Requests permission if | |
| 227 // it is unknown. | |
| 228 void requestUsesCachedPosition(GeoNotifier*); | |
| 229 | |
| 230 bool haveSuitableCachedPosition(PositionOptions*); | 184 bool haveSuitableCachedPosition(PositionOptions*); |
| 231 | 185 |
| 232 // Runs the success callbacks for the set of notifiers awaiting a cached | 186 // Runs the success callbacks for the set of notifiers awaiting a cached |
| 233 // position, the set is then cleared. The oneshots are removed everywhere. | 187 // position, the set is then cleared. The oneshots are removed everywhere. |
| 234 void makeCachedPositionCallbacks(); | 188 void makeCachedPositionCallbacks(); |
| 235 | 189 |
| 236 GeoNotifierSet m_oneShots; | 190 GeoNotifierSet m_oneShots; |
| 237 Watchers m_watchers; | 191 Watchers m_watchers; |
| 238 GeoNotifierSet m_pendingForPermissionNotifiers; | 192 GeoNotifierSet m_pendingForPermissionNotifiers; |
| 239 Member<Geoposition> m_lastPosition; | 193 Member<Geoposition> m_lastPosition; |
| 240 | 194 |
| 241 // States of Geolocation permission as granted by the embedder. Unknown | 195 // States of Geolocation permission as granted by the embedder. Unknown |
| 242 // means that the embedder still has to be asked for the current permission | 196 // means that the embedder still has to be asked for the current permission |
| 243 // level; Requested means that the user has yet to make a decision. | 197 // level; Requested means that the user has yet to make a decision. |
| 244 enum Permission { | 198 enum Permission { |
| 245 PermissionUnknown, | 199 PermissionUnknown, |
| 246 PermissionRequested, | 200 PermissionRequested, |
| 247 PermissionAllowed, | 201 PermissionAllowed, |
| 248 PermissionDenied | 202 PermissionDenied |
| 249 }; | 203 }; |
| 250 | 204 |
| 251 Permission m_geolocationPermission; | 205 Permission m_geolocationPermission; |
| 252 | 206 |
| 253 GeoNotifierSet m_requestsAwaitingCachedPosition; | 207 GeoNotifierSet m_requestsAwaitingCachedPosition; |
| 254 }; | 208 }; |
| 255 | 209 |
| 256 } // namespace WebCore | 210 } // namespace WebCore |
| 257 | 211 |
| 258 #endif // Geolocation_h | 212 #endif // Geolocation_h |
| OLD | NEW |