Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: third_party/WebKit/Source/modules/geolocation/Geolocation.h

Issue 1367853002: Move GeolocationDispatcher into blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 11 matching lines...) Expand all
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/ActiveDOMObject.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"
Michael van Ouwerkerk 2016/05/04 13:52:17 Can we omit "third_party/WebKit" here and below?
Sam McNally 2016/05/05 11:50:24 No, only the root of the generated files tree is a
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>
Michael van Ouwerkerk 2016/05/04 13:52:17 This class should probably use "USING_PRE_FINALIZE
Sam McNally 2016/05/05 11:50:24 Done.
52 , public ScriptWrappable 56 , public ScriptWrappable
53 , public ActiveDOMObject { 57 , public ActiveDOMObject
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() override;
59 DECLARE_VIRTUAL_TRACE(); 64 DECLARE_VIRTUAL_TRACE();
60 65
61 void stop() override; 66 void stop() override;
62 Document* document() const; 67 Document* document() const;
63 LocalFrame* frame() const; 68 LocalFrame* frame() const;
64 69
65 // Creates a oneshot and attempts to obtain a position that meets the 70 // Creates a oneshot and attempts to obtain a position that meets the
66 // constraints of the options. 71 // constraints of the options.
67 void getCurrentPosition(PositionCallback*, PositionErrorCallback*, const Pos itionOptions&); 72 void getCurrentPosition(PositionCallback*, PositionErrorCallback*, const Pos itionOptions&);
68 73
69 // Creates a watcher that will be notified whenever a new position is 74 // Creates a watcher that will be notified whenever a new position is
70 // available that meets the constraints of the options. 75 // available that meets the constraints of the options.
71 int watchPosition(PositionCallback*, PositionErrorCallback*, const PositionO ptions&); 76 int watchPosition(PositionCallback*, PositionErrorCallback*, const PositionO ptions&);
72 77
73 // Removes all references to the watcher, it will not be updated again. 78 // Removes all references to the watcher, it will not be updated again.
74 void clearWatch(int watchID); 79 void clearWatch(int watchID);
75 80
76 void setIsAllowed(bool);
77
78 bool isAllowed() const { return m_geolocationPermission == PermissionAllowed ; } 81 bool isAllowed() const { return m_geolocationPermission == PermissionAllowed ; }
79 82
80 // Notifies this that a new position is available. Must never be called 83 // Notifies this that a new position is available. Must never be called
81 // before permission is granted by the user. 84 // before permission is granted by the user.
82 void positionChanged(); 85 void positionChanged();
83 86
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. 87 // Discards the notifier because a fatal error occurred for it.
88 void fatalErrorOccurred(GeoNotifier*); 88 void fatalErrorOccurred(GeoNotifier*);
89 89
90 // Adds the notifier to the set awaiting a cached position. Runs the success 90 // 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 91 // callbacks for them if permission has been granted. Requests permission if
92 // it is unknown. 92 // it is unknown.
93 void requestUsesCachedPosition(GeoNotifier*); 93 void requestUsesCachedPosition(GeoNotifier*);
94 94
95 // Discards the notifier if it is a oneshot because it timed it. 95 // Discards the notifier if it is a oneshot because it timed it.
96 void requestTimedOut(GeoNotifier*); 96 void requestTimedOut(GeoNotifier*);
97 97
98 // Inherited from PageLifecycleObserver.
99 void pageVisibilityChanged() override;
100
98 private: 101 private:
99 // Returns the last known position, if any. May return null. 102 // Returns the last known position, if any. May return null.
100 Geoposition* lastPosition(); 103 Geoposition* lastPosition();
101 104
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;
(...skipping 26 matching lines...) Expand all
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;
Michael van Ouwerkerk 2016/05/04 13:52:17 When is this destroyed? The owner is GC'd at some
Sam McNally 2016/05/05 11:50:24 A mojo InterfacePtr isn't always connected to some
195 bool m_enableHighAccuracy = false;
196 mojom::blink::PermissionServicePtr m_permissionService;
187 197
188 GeoNotifierSet m_requestsAwaitingCachedPosition; 198 bool m_updating = false;
Michael van Ouwerkerk 2016/05/04 13:52:17 Please document the distinction between m_updating
Sam McNally 2016/05/05 11:50:24 Done.
199 bool m_queryInProgress = false;
189 }; 200 };
190 201
191 } // namespace blink 202 } // namespace blink
192 203
193 #endif // Geolocation_h 204 #endif // Geolocation_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698