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); |
61 USING_PRE_FINALIZER(Geolocation, contextDestroyed); | |
56 public: | 62 public: |
57 static Geolocation* create(ExecutionContext*); | 63 static Geolocation* create(ExecutionContext*); |
58 ~Geolocation() override; | 64 ~Geolocation(); |
59 DECLARE_VIRTUAL_TRACE(); | 65 DECLARE_VIRTUAL_TRACE(); |
60 | 66 |
61 void stop() override; | 67 // Inherited from ContextLifecycleObserver AND used as a pre-finalizer. |
Michael van Ouwerkerk
2016/05/11 12:38:30
Thinking about it some more, I think we can rely o
Sam McNally
2016/05/12 07:17:20
Done.
| |
68 void contextDestroyed() override; | |
69 | |
62 Document* document() const; | 70 Document* document() const; |
63 LocalFrame* frame() const; | 71 LocalFrame* frame() const; |
64 | 72 |
65 // Creates a oneshot and attempts to obtain a position that meets the | 73 // Creates a oneshot and attempts to obtain a position that meets the |
66 // constraints of the options. | 74 // constraints of the options. |
67 void getCurrentPosition(PositionCallback*, PositionErrorCallback*, const Pos itionOptions&); | 75 void getCurrentPosition(PositionCallback*, PositionErrorCallback*, const Pos itionOptions&); |
68 | 76 |
69 // Creates a watcher that will be notified whenever a new position is | 77 // Creates a watcher that will be notified whenever a new position is |
70 // available that meets the constraints of the options. | 78 // available that meets the constraints of the options. |
71 int watchPosition(PositionCallback*, PositionErrorCallback*, const PositionO ptions&); | 79 int watchPosition(PositionCallback*, PositionErrorCallback*, const PositionO ptions&); |
72 | 80 |
73 // Removes all references to the watcher, it will not be updated again. | 81 // Removes all references to the watcher, it will not be updated again. |
74 void clearWatch(int watchID); | 82 void clearWatch(int watchID); |
75 | 83 |
76 void setIsAllowed(bool); | |
77 | |
78 bool isAllowed() const { return m_geolocationPermission == PermissionAllowed ; } | 84 bool isAllowed() const { return m_geolocationPermission == PermissionAllowed ; } |
79 | 85 |
80 // Notifies this that a new position is available. Must never be called | 86 // Notifies this that a new position is available. Must never be called |
81 // before permission is granted by the user. | 87 // before permission is granted by the user. |
82 void positionChanged(); | 88 void positionChanged(); |
83 | 89 |
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. | 90 // Discards the notifier because a fatal error occurred for it. |
88 void fatalErrorOccurred(GeoNotifier*); | 91 void fatalErrorOccurred(GeoNotifier*); |
89 | 92 |
90 // Adds the notifier to the set awaiting a cached position. Runs the success | 93 // 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 | 94 // callbacks for them if permission has been granted. Requests permission if |
92 // it is unknown. | 95 // it is unknown. |
93 void requestUsesCachedPosition(GeoNotifier*); | 96 void requestUsesCachedPosition(GeoNotifier*); |
94 | 97 |
95 // Discards the notifier if it is a oneshot because it timed it. | 98 // Discards the notifier if it is a oneshot because it timed it. |
96 void requestTimedOut(GeoNotifier*); | 99 void requestTimedOut(GeoNotifier*); |
97 | 100 |
101 // Inherited from PageLifecycleObserver. | |
102 void pageVisibilityChanged() override; | |
103 | |
98 private: | 104 private: |
99 // Returns the last known position, if any. May return null. | |
100 Geoposition* lastPosition(); | |
101 | |
102 bool isDenied() const { return m_geolocationPermission == PermissionDenied; } | 105 bool isDenied() const { return m_geolocationPermission == PermissionDenied; } |
103 | 106 |
104 explicit Geolocation(ExecutionContext*); | 107 explicit Geolocation(ExecutionContext*); |
105 | 108 |
106 typedef HeapVector<Member<GeoNotifier>> GeoNotifierVector; | 109 typedef HeapVector<Member<GeoNotifier>> GeoNotifierVector; |
107 typedef HeapHashSet<Member<GeoNotifier>> GeoNotifierSet; | 110 typedef HeapHashSet<Member<GeoNotifier>> GeoNotifierSet; |
108 | 111 |
109 bool hasListeners() const { return !m_oneShots.isEmpty() || !m_watchers.isEm pty(); } | 112 bool hasListeners() const { return !m_oneShots.isEmpty() || !m_watchers.isEm pty(); } |
110 | 113 |
111 void sendError(GeoNotifierVector&, PositionError*); | 114 void sendError(GeoNotifierVector&, PositionError*); |
(...skipping 22 matching lines...) Expand all Loading... | |
134 void makeSuccessCallbacks(); | 137 void makeSuccessCallbacks(); |
135 | 138 |
136 // Sends the given error to all notifiers, unless the error is not fatal and | 139 // 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, | 140 // the notifier is due to receive a cached position. Clears the oneshots, |
138 // and also clears the watchers if the error is fatal. | 141 // and also clears the watchers if the error is fatal. |
139 void handleError(PositionError*); | 142 void handleError(PositionError*); |
140 | 143 |
141 // Requests permission to share positions with the page. | 144 // Requests permission to share positions with the page. |
142 void requestPermission(); | 145 void requestPermission(); |
143 | 146 |
144 // Attempts to register this with the controller for receiving updates. | 147 // Connects to the Geolocation mojo service and starts polling for updates. |
145 // Returns false if there is no controller to register with. | 148 void startUpdating(GeoNotifier*); |
146 bool startUpdating(GeoNotifier*); | |
147 | 149 |
148 void stopUpdating(); | 150 void stopUpdating(); |
149 | 151 |
150 // Processes the notifiers that were waiting for a permission decision. If | 152 void updateGeolocationServiceConnection(); |
151 // granted and this can be registered with the controller then the | 153 void queryNextPosition(); |
152 // notifier's timers are started. Otherwise, a fatal error is set on them. | |
153 void handlePendingPermissionNotifiers(); | |
154 | 154 |
155 // Attempts to obtain a position for the given notifier, either by using | 155 // 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 | 156 // the cached position or by requesting one from the GeolocationService. |
157 // fatal error if permission is denied or no position can be obtained. | 157 // Sets a fatal error if permission is denied or no position can be |
158 // obtained. | |
158 void startRequest(GeoNotifier*); | 159 void startRequest(GeoNotifier*); |
159 | 160 |
160 bool haveSuitableCachedPosition(const PositionOptions&); | 161 bool haveSuitableCachedPosition(const PositionOptions&); |
161 | 162 |
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 | 163 // Record whether the origin trying to access Geolocation would be allowed |
167 // to access a feature that can only be accessed by secure origins. | 164 // to access a feature that can only be accessed by secure origins. |
168 // See https://goo.gl/Y0ZkNV | 165 // See https://goo.gl/Y0ZkNV |
169 void recordOriginTypeAccess() const; | 166 void recordOriginTypeAccess() const; |
170 | 167 |
168 void onPositionUpdated(mojom::blink::GeopositionPtr); | |
169 | |
170 // Processes the notifiers that were waiting for a permission decision. If | |
171 // granted then the notifier's timers are started. Otherwise, a fatal error | |
172 // is set on them. | |
173 void onGeolocationPermissionUpdated(mojom::blink::PermissionStatus); | |
174 | |
175 void onGeolocationConnectionError(); | |
176 void onPermissionConnectionError(); | |
177 | |
171 GeoNotifierSet m_oneShots; | 178 GeoNotifierSet m_oneShots; |
172 GeolocationWatchers m_watchers; | 179 GeolocationWatchers m_watchers; |
173 GeoNotifierSet m_pendingForPermissionNotifiers; | 180 GeoNotifierSet m_pendingForPermissionNotifiers; |
174 Member<Geoposition> m_lastPosition; | 181 Member<Geoposition> m_lastPosition; |
175 | 182 |
176 // States of Geolocation permission as granted by the embedder. Unknown | 183 // States of Geolocation permission as granted by the embedder. Unknown |
177 // means that the embedder still has to be asked for the current permission | 184 // 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. | 185 // level; Requested means that the user has yet to make a decision. |
179 enum Permission { | 186 enum Permission { |
180 PermissionUnknown, | 187 PermissionUnknown, |
181 PermissionRequested, | 188 PermissionRequested, |
182 PermissionAllowed, | 189 PermissionAllowed, |
183 PermissionDenied | 190 PermissionDenied |
184 }; | 191 }; |
185 | 192 |
186 Permission m_geolocationPermission; | 193 Permission m_geolocationPermission; |
194 mojom::blink::GeolocationServicePtr m_geolocationService; | |
195 bool m_enableHighAccuracy = false; | |
196 mojom::blink::PermissionServicePtr m_permissionService; | |
187 | 197 |
188 GeoNotifierSet m_requestsAwaitingCachedPosition; | 198 // Whether a GeoNotifier is waiting for a position update. |
199 bool m_updating = false; | |
200 | |
201 // Set to true when m_geolocationService is disconnected. This is used to | |
202 // detect when m_geolocationService is disconnected and reconnected while | |
203 // running callbacks in response to a call to onPositionUpdated(). | |
204 bool m_disconnectedGeolocationService = false; | |
189 }; | 205 }; |
190 | 206 |
191 } // namespace blink | 207 } // namespace blink |
192 | 208 |
193 #endif // Geolocation_h | 209 #endif // Geolocation_h |
OLD | NEW |