| 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 10 matching lines...) Expand all Loading... |
| 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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/ScriptWrappable.h" | 30 #include "bindings/core/v8/ScriptWrappable.h" |
| 31 #include "core/dom/ActiveDOMObject.h" | 31 #include "core/dom/ContextLifecycleObserver.h" |
| 32 #include "core/page/PageLifecycleObserver.h" |
| 32 #include "modules/ModulesExport.h" | 33 #include "modules/ModulesExport.h" |
| 33 #include "modules/geolocation/GeoNotifier.h" | 34 #include "modules/geolocation/GeoNotifier.h" |
| 34 #include "modules/geolocation/GeolocationWatchers.h" | 35 #include "modules/geolocation/GeolocationWatchers.h" |
| 35 #include "modules/geolocation/Geoposition.h" | 36 #include "modules/geolocation/Geoposition.h" |
| 36 #include "modules/geolocation/PositionCallback.h" | 37 #include "modules/geolocation/PositionCallback.h" |
| 37 #include "modules/geolocation/PositionError.h" | 38 #include "modules/geolocation/PositionError.h" |
| 38 #include "modules/geolocation/PositionErrorCallback.h" | 39 #include "modules/geolocation/PositionErrorCallback.h" |
| 39 #include "modules/geolocation/PositionOptions.h" | 40 #include "modules/geolocation/PositionOptions.h" |
| 40 #include "platform/Timer.h" | 41 #include "platform/Timer.h" |
| 41 #include "platform/heap/Handle.h" | 42 #include "platform/heap/Handle.h" |
| 43 #include "third_party/WebKit/public/platform/modules/geolocation/geolocation.moj
om-blink.h" |
| 44 #include "third_party/WebKit/public/platform/modules/permissions/permission.mojo
m-blink.h" |
| 45 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom-blink.h" |
| 42 | 46 |
| 43 namespace blink { | 47 namespace blink { |
| 44 | 48 |
| 45 class Document; | 49 class Document; |
| 46 class LocalFrame; | 50 class LocalFrame; |
| 47 class GeolocationError; | 51 class GeolocationError; |
| 48 class ExecutionContext; | 52 class ExecutionContext; |
| 49 | 53 |
| 50 class MODULES_EXPORT Geolocation final | 54 class MODULES_EXPORT Geolocation final |
| 51 : public GarbageCollectedFinalized<Geolocation> | 55 : public GarbageCollectedFinalized<Geolocation> |
| 52 , public ScriptWrappable | 56 , public ScriptWrappable |
| 53 , public ActiveDOMObject { | 57 , public ContextLifecycleObserver |
| 58 , public PageLifecycleObserver { |
| 54 DEFINE_WRAPPERTYPEINFO(); | 59 DEFINE_WRAPPERTYPEINFO(); |
| 55 USING_GARBAGE_COLLECTED_MIXIN(Geolocation); | 60 USING_GARBAGE_COLLECTED_MIXIN(Geolocation); |
| 56 public: | 61 public: |
| 57 static Geolocation* create(ExecutionContext*); | 62 static Geolocation* create(ExecutionContext*); |
| 58 ~Geolocation() override; | 63 ~Geolocation(); |
| 59 DECLARE_VIRTUAL_TRACE(); | 64 DECLARE_VIRTUAL_TRACE(); |
| 60 | 65 |
| 61 void stop() override; | 66 // Inherited from ContextLifecycleObserver AND PageLifecycleObserver. |
| 67 void contextDestroyed() override; |
| 68 |
| 62 Document* document() const; | 69 Document* document() const; |
| 63 LocalFrame* frame() const; | 70 LocalFrame* frame() const; |
| 64 | 71 |
| 65 // Creates a oneshot and attempts to obtain a position that meets the | 72 // Creates a oneshot and attempts to obtain a position that meets the |
| 66 // constraints of the options. | 73 // constraints of the options. |
| 67 void getCurrentPosition(PositionCallback*, PositionErrorCallback*, const Pos
itionOptions&); | 74 void getCurrentPosition(PositionCallback*, PositionErrorCallback*, const Pos
itionOptions&); |
| 68 | 75 |
| 69 // Creates a watcher that will be notified whenever a new position is | 76 // Creates a watcher that will be notified whenever a new position is |
| 70 // available that meets the constraints of the options. | 77 // available that meets the constraints of the options. |
| 71 int watchPosition(PositionCallback*, PositionErrorCallback*, const PositionO
ptions&); | 78 int watchPosition(PositionCallback*, PositionErrorCallback*, const PositionO
ptions&); |
| 72 | 79 |
| 73 // Removes all references to the watcher, it will not be updated again. | 80 // Removes all references to the watcher, it will not be updated again. |
| 74 void clearWatch(int watchID); | 81 void clearWatch(int watchID); |
| 75 | 82 |
| 76 void setIsAllowed(bool); | |
| 77 | |
| 78 bool isAllowed() const { return m_geolocationPermission == PermissionAllowed
; } | 83 bool isAllowed() const { return m_geolocationPermission == PermissionAllowed
; } |
| 79 | 84 |
| 80 // Notifies this that a new position is available. Must never be called | 85 // Notifies this that a new position is available. Must never be called |
| 81 // before permission is granted by the user. | 86 // before permission is granted by the user. |
| 82 void positionChanged(); | 87 void positionChanged(); |
| 83 | 88 |
| 84 // Notifies this that an error has occurred, it must be handled immediately. | |
| 85 void setError(GeolocationError*); | |
| 86 | |
| 87 // Discards the notifier because a fatal error occurred for it. | 89 // Discards the notifier because a fatal error occurred for it. |
| 88 void fatalErrorOccurred(GeoNotifier*); | 90 void fatalErrorOccurred(GeoNotifier*); |
| 89 | 91 |
| 90 // Adds the notifier to the set awaiting a cached position. Runs the success | 92 // Adds the notifier to the set awaiting a cached position. Runs the success |
| 91 // callbacks for them if permission has been granted. Requests permission if | 93 // callbacks for them if permission has been granted. Requests permission if |
| 92 // it is unknown. | 94 // it is unknown. |
| 93 void requestUsesCachedPosition(GeoNotifier*); | 95 void requestUsesCachedPosition(GeoNotifier*); |
| 94 | 96 |
| 95 // Discards the notifier if it is a oneshot because it timed it. | 97 // Discards the notifier if it is a oneshot because it timed it. |
| 96 void requestTimedOut(GeoNotifier*); | 98 void requestTimedOut(GeoNotifier*); |
| 97 | 99 |
| 100 // Inherited from PageLifecycleObserver. |
| 101 void pageVisibilityChanged() override; |
| 102 |
| 98 private: | 103 private: |
| 99 // Returns the last known position, if any. May return null. | |
| 100 Geoposition* lastPosition(); | |
| 101 | |
| 102 bool isDenied() const { return m_geolocationPermission == PermissionDenied;
} | 104 bool isDenied() const { return m_geolocationPermission == PermissionDenied;
} |
| 103 | 105 |
| 104 explicit Geolocation(ExecutionContext*); | 106 explicit Geolocation(ExecutionContext*); |
| 105 | 107 |
| 106 typedef HeapVector<Member<GeoNotifier>> GeoNotifierVector; | 108 typedef HeapVector<Member<GeoNotifier>> GeoNotifierVector; |
| 107 typedef HeapHashSet<Member<GeoNotifier>> GeoNotifierSet; | 109 typedef HeapHashSet<Member<GeoNotifier>> GeoNotifierSet; |
| 108 | 110 |
| 109 bool hasListeners() const { return !m_oneShots.isEmpty() || !m_watchers.isEm
pty(); } | 111 bool hasListeners() const { return !m_oneShots.isEmpty() || !m_watchers.isEm
pty(); } |
| 110 | 112 |
| 111 void sendError(GeoNotifierVector&, PositionError*); | 113 void sendError(GeoNotifierVector&, PositionError*); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 134 void makeSuccessCallbacks(); | 136 void makeSuccessCallbacks(); |
| 135 | 137 |
| 136 // Sends the given error to all notifiers, unless the error is not fatal and | 138 // Sends the given error to all notifiers, unless the error is not fatal and |
| 137 // the notifier is due to receive a cached position. Clears the oneshots, | 139 // the notifier is due to receive a cached position. Clears the oneshots, |
| 138 // and also clears the watchers if the error is fatal. | 140 // and also clears the watchers if the error is fatal. |
| 139 void handleError(PositionError*); | 141 void handleError(PositionError*); |
| 140 | 142 |
| 141 // Requests permission to share positions with the page. | 143 // Requests permission to share positions with the page. |
| 142 void requestPermission(); | 144 void requestPermission(); |
| 143 | 145 |
| 144 // Attempts to register this with the controller for receiving updates. | 146 // Connects to the Geolocation mojo service and starts polling for updates. |
| 145 // Returns false if there is no controller to register with. | 147 void startUpdating(GeoNotifier*); |
| 146 bool startUpdating(GeoNotifier*); | |
| 147 | 148 |
| 148 void stopUpdating(); | 149 void stopUpdating(); |
| 149 | 150 |
| 150 // Processes the notifiers that were waiting for a permission decision. If | 151 void updateGeolocationServiceConnection(); |
| 151 // granted and this can be registered with the controller then the | 152 void queryNextPosition(); |
| 152 // notifier's timers are started. Otherwise, a fatal error is set on them. | |
| 153 void handlePendingPermissionNotifiers(); | |
| 154 | 153 |
| 155 // Attempts to obtain a position for the given notifier, either by using | 154 // Attempts to obtain a position for the given notifier, either by using |
| 156 // the cached position or by requesting one from the controller. Sets a | 155 // the cached position or by requesting one from the GeolocationService. |
| 157 // fatal error if permission is denied or no position can be obtained. | 156 // Sets a fatal error if permission is denied or no position can be |
| 157 // obtained. |
| 158 void startRequest(GeoNotifier*); | 158 void startRequest(GeoNotifier*); |
| 159 | 159 |
| 160 bool haveSuitableCachedPosition(const PositionOptions&); | 160 bool haveSuitableCachedPosition(const PositionOptions&); |
| 161 | 161 |
| 162 // Runs the success callbacks for the set of notifiers awaiting a cached | |
| 163 // position, the set is then cleared. The oneshots are removed everywhere. | |
| 164 void makeCachedPositionCallbacks(); | |
| 165 | |
| 166 // Record whether the origin trying to access Geolocation would be allowed | 162 // Record whether the origin trying to access Geolocation would be allowed |
| 167 // to access a feature that can only be accessed by secure origins. | 163 // to access a feature that can only be accessed by secure origins. |
| 168 // See https://goo.gl/Y0ZkNV | 164 // See https://goo.gl/Y0ZkNV |
| 169 void recordOriginTypeAccess() const; | 165 void recordOriginTypeAccess() const; |
| 170 | 166 |
| 167 void onPositionUpdated(mojom::blink::GeopositionPtr); |
| 168 |
| 169 // Processes the notifiers that were waiting for a permission decision. If |
| 170 // granted then the notifier's timers are started. Otherwise, a fatal error |
| 171 // is set on them. |
| 172 void onGeolocationPermissionUpdated(mojom::blink::PermissionStatus); |
| 173 |
| 174 void onGeolocationConnectionError(); |
| 175 void onPermissionConnectionError(); |
| 176 |
| 171 GeoNotifierSet m_oneShots; | 177 GeoNotifierSet m_oneShots; |
| 172 GeolocationWatchers m_watchers; | 178 GeolocationWatchers m_watchers; |
| 173 GeoNotifierSet m_pendingForPermissionNotifiers; | 179 GeoNotifierSet m_pendingForPermissionNotifiers; |
| 174 Member<Geoposition> m_lastPosition; | 180 Member<Geoposition> m_lastPosition; |
| 175 | 181 |
| 176 // States of Geolocation permission as granted by the embedder. Unknown | 182 // States of Geolocation permission as granted by the embedder. Unknown |
| 177 // means that the embedder still has to be asked for the current permission | 183 // means that the embedder still has to be asked for the current permission |
| 178 // level; Requested means that the user has yet to make a decision. | 184 // level; Requested means that the user has yet to make a decision. |
| 179 enum Permission { | 185 enum Permission { |
| 180 PermissionUnknown, | 186 PermissionUnknown, |
| 181 PermissionRequested, | 187 PermissionRequested, |
| 182 PermissionAllowed, | 188 PermissionAllowed, |
| 183 PermissionDenied | 189 PermissionDenied |
| 184 }; | 190 }; |
| 185 | 191 |
| 186 Permission m_geolocationPermission; | 192 Permission m_geolocationPermission; |
| 193 mojom::blink::GeolocationServicePtr m_geolocationService; |
| 194 bool m_enableHighAccuracy = false; |
| 195 mojom::blink::PermissionServicePtr m_permissionService; |
| 187 | 196 |
| 188 GeoNotifierSet m_requestsAwaitingCachedPosition; | 197 // Whether a GeoNotifier is waiting for a position update. |
| 198 bool m_updating = false; |
| 199 |
| 200 // Set to true when m_geolocationService is disconnected. This is used to |
| 201 // detect when m_geolocationService is disconnected and reconnected while |
| 202 // running callbacks in response to a call to onPositionUpdated(). |
| 203 bool m_disconnectedGeolocationService = false; |
| 189 }; | 204 }; |
| 190 | 205 |
| 191 } // namespace blink | 206 } // namespace blink |
| 192 | 207 |
| 193 #endif // Geolocation_h | 208 #endif // Geolocation_h |
| OLD | NEW |