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 28 matching lines...) Expand all Loading... |
39 | 39 |
40 namespace WebCore { | 40 namespace WebCore { |
41 | 41 |
42 class Document; | 42 class Document; |
43 class LocalFrame; | 43 class LocalFrame; |
44 class GeolocationController; | 44 class GeolocationController; |
45 class GeolocationError; | 45 class GeolocationError; |
46 class GeolocationPosition; | 46 class GeolocationPosition; |
47 class ExecutionContext; | 47 class ExecutionContext; |
48 | 48 |
49 class Geolocation FINAL : public RefCountedWillBeGarbageCollectedFinalized<Geolo
cation>, public ScriptWrappable, public ActiveDOMObject | 49 class Geolocation FINAL |
50 { | 50 : public GarbageCollectedFinalized<Geolocation> |
| 51 , public ScriptWrappable |
| 52 , public ActiveDOMObject { |
51 public: | 53 public: |
52 static PassRefPtrWillBeRawPtr<Geolocation> create(ExecutionContext*); | 54 static Geolocation* create(ExecutionContext*); |
53 virtual ~Geolocation(); | 55 virtual ~Geolocation(); |
54 void trace(Visitor*); | 56 void trace(Visitor*); |
55 | 57 |
56 virtual void stop() OVERRIDE; | 58 virtual void stop() OVERRIDE; |
57 Document* document() const; | 59 Document* document() const; |
58 LocalFrame* frame() const; | 60 LocalFrame* frame() const; |
59 | 61 |
60 // Creates a oneshot and attempts to obtain a position that meets the | 62 // Creates a oneshot and attempts to obtain a position that meets the |
61 // constraints of the options. | 63 // constraints of the options. |
62 void getCurrentPosition(PassOwnPtr<PositionCallback>, PassOwnPtr<PositionErr
orCallback>, PassRefPtrWillBeRawPtr<PositionOptions>); | 64 void getCurrentPosition(PassOwnPtr<PositionCallback>, PassOwnPtr<PositionErr
orCallback>, PositionOptions*); |
63 | 65 |
64 // Creates a watcher that will be notified whenever a new position is | 66 // Creates a watcher that will be notified whenever a new position is |
65 // available that meets the constraints of the options. | 67 // available that meets the constraints of the options. |
66 int watchPosition(PassOwnPtr<PositionCallback>, PassOwnPtr<PositionErrorCall
back>, PassRefPtrWillBeRawPtr<PositionOptions>); | 68 int watchPosition(PassOwnPtr<PositionCallback>, PassOwnPtr<PositionErrorCall
back>, PositionOptions*); |
67 | 69 |
68 // Removes all references to the watcher, it will not be updated again. | 70 // Removes all references to the watcher, it will not be updated again. |
69 void clearWatch(int watchID); | 71 void clearWatch(int watchID); |
70 | 72 |
71 void setIsAllowed(bool); | 73 void setIsAllowed(bool); |
72 | 74 |
73 bool isAllowed() const { return m_allowGeolocation == Yes; } | 75 bool isAllowed() const { return m_allowGeolocation == Yes; } |
74 | 76 |
75 // Notifies this that a new position is available. Must never be called | 77 // Notifies this that a new position is available. Must never be called |
76 // before permission is granted by the user. | 78 // before permission is granted by the user. |
77 void positionChanged(); | 79 void positionChanged(); |
78 | 80 |
79 // Notifies this that an error has occurred, it must be handled immediately. | 81 // Notifies this that an error has occurred, it must be handled immediately. |
80 void setError(GeolocationError*); | 82 void setError(GeolocationError*); |
81 | 83 |
82 private: | 84 private: |
83 // Returns the last known position, if any. May return null. | 85 // Returns the last known position, if any. May return null. |
84 Geoposition* lastPosition(); | 86 Geoposition* lastPosition(); |
85 | 87 |
86 bool isDenied() const { return m_allowGeolocation == No; } | 88 bool isDenied() const { return m_allowGeolocation == No; } |
87 | 89 |
88 explicit Geolocation(ExecutionContext*); | 90 explicit Geolocation(ExecutionContext*); |
89 | 91 |
90 // Holds the success and error callbacks and the options that were provided | 92 // Holds the success and error callbacks and the options that were provided |
91 // when a oneshot or watcher were created. Also, if specified in the | 93 // when a oneshot or watcher were created. Also, if specified in the |
92 // options, manages a timer to limit the time to wait for the system to | 94 // options, manages a timer to limit the time to wait for the system to |
93 // obtain a position. | 95 // obtain a position. |
94 class GeoNotifier : public RefCountedWillBeGarbageCollectedFinalized<GeoNoti
fier> { | 96 class GeoNotifier : public GarbageCollectedFinalized<GeoNotifier> { |
95 public: | 97 public: |
96 static PassRefPtrWillBeRawPtr<GeoNotifier> create(Geolocation* geolocati
on, PassOwnPtr<PositionCallback> positionCallback, PassOwnPtr<PositionErrorCallb
ack> positionErrorCallback, PassRefPtrWillBeRawPtr<PositionOptions> options) | 98 static GeoNotifier* create(Geolocation* geolocation, PassOwnPtr<Position
Callback> positionCallback, PassOwnPtr<PositionErrorCallback> positionErrorCallb
ack, PositionOptions* options) |
97 { | 99 { |
98 return adoptRefWillBeNoop(new GeoNotifier(geolocation, positionCallb
ack, positionErrorCallback, options)); | 100 return new GeoNotifier(geolocation, positionCallback, positionErrorC
allback, options); |
99 } | 101 } |
100 void trace(Visitor*); | 102 void trace(Visitor*); |
101 | 103 |
102 PositionOptions* options() const { return m_options.get(); }; | 104 PositionOptions* options() const { return m_options.get(); }; |
103 | 105 |
104 // Sets the given error as the fatal error if there isn't one yet. | 106 // Sets the given error as the fatal error if there isn't one yet. |
105 // Starts the timer with an interval of 0. | 107 // Starts the timer with an interval of 0. |
106 void setFatalError(PassRefPtrWillBeRawPtr<PositionError>); | 108 void setFatalError(PositionError*); |
107 | 109 |
108 bool useCachedPosition() const { return m_useCachedPosition; } | 110 bool useCachedPosition() const { return m_useCachedPosition; } |
109 | 111 |
110 // Tells the notifier to use a cached position and starts its timer with | 112 // Tells the notifier to use a cached position and starts its timer with |
111 // an interval of 0. | 113 // an interval of 0. |
112 void setUseCachedPosition(); | 114 void setUseCachedPosition(); |
113 | 115 |
114 void runSuccessCallback(Geoposition*); | 116 void runSuccessCallback(Geoposition*); |
115 void runErrorCallback(PositionError*); | 117 void runErrorCallback(PositionError*); |
116 | 118 |
117 void startTimer(); | 119 void startTimer(); |
118 void stopTimer(); | 120 void stopTimer(); |
119 | 121 |
120 // Runs the error callback if there is a fatal error. Otherwise, if a | 122 // Runs the error callback if there is a fatal error. Otherwise, if a |
121 // cached position must be used, registers itself for receiving one. | 123 // cached position must be used, registers itself for receiving one. |
122 // Otherwise, the notifier has expired, and its error callback is run. | 124 // Otherwise, the notifier has expired, and its error callback is run. |
123 void timerFired(Timer<GeoNotifier>*); | 125 void timerFired(Timer<GeoNotifier>*); |
124 | 126 |
125 private: | 127 private: |
126 GeoNotifier(Geolocation*, PassOwnPtr<PositionCallback>, PassOwnPtr<Posit
ionErrorCallback>, PassRefPtrWillBeRawPtr<PositionOptions>); | 128 GeoNotifier(Geolocation*, PassOwnPtr<PositionCallback>, PassOwnPtr<Posit
ionErrorCallback>, PositionOptions*); |
127 | 129 |
128 RefPtrWillBeMember<Geolocation> m_geolocation; | 130 Member<Geolocation> m_geolocation; |
129 OwnPtr<PositionCallback> m_successCallback; | 131 OwnPtr<PositionCallback> m_successCallback; |
130 OwnPtr<PositionErrorCallback> m_errorCallback; | 132 OwnPtr<PositionErrorCallback> m_errorCallback; |
131 RefPtrWillBeMember<PositionOptions> m_options; | 133 Member<PositionOptions> m_options; |
132 Timer<GeoNotifier> m_timer; | 134 Timer<GeoNotifier> m_timer; |
133 RefPtrWillBeMember<PositionError> m_fatalError; | 135 Member<PositionError> m_fatalError; |
134 bool m_useCachedPosition; | 136 bool m_useCachedPosition; |
135 }; | 137 }; |
136 | 138 |
137 typedef WillBeHeapVector<RefPtrWillBeMember<GeoNotifier> > GeoNotifierVector
; | 139 typedef HeapVector<Member<GeoNotifier> > GeoNotifierVector; |
138 typedef WillBeHeapHashSet<RefPtrWillBeMember<GeoNotifier> > GeoNotifierSet; | 140 typedef HeapHashSet<Member<GeoNotifier> > GeoNotifierSet; |
139 | 141 |
140 class Watchers { | 142 class Watchers { |
141 DISALLOW_ALLOCATION(); | 143 DISALLOW_ALLOCATION(); |
142 public: | 144 public: |
143 void trace(Visitor*); | 145 void trace(Visitor*); |
144 bool add(int id, PassRefPtrWillBeRawPtr<GeoNotifier>); | 146 bool add(int id, GeoNotifier*); |
145 GeoNotifier* find(int id); | 147 GeoNotifier* find(int id); |
146 void remove(int id); | 148 void remove(int id); |
147 void remove(GeoNotifier*); | 149 void remove(GeoNotifier*); |
148 bool contains(GeoNotifier*) const; | 150 bool contains(GeoNotifier*) const; |
149 void clear(); | 151 void clear(); |
150 bool isEmpty() const; | 152 bool isEmpty() const; |
151 void getNotifiersVector(GeoNotifierVector&) const; | 153 void getNotifiersVector(GeoNotifierVector&) const; |
152 private: | 154 private: |
153 typedef WillBeHeapHashMap<int, RefPtrWillBeMember<GeoNotifier> > IdToNot
ifierMap; | 155 typedef HeapHashMap<int, Member<GeoNotifier> > IdToNotifierMap; |
154 typedef WillBeHeapHashMap<RefPtrWillBeMember<GeoNotifier>, int> Notifier
ToIdMap; | 156 typedef HeapHashMap<Member<GeoNotifier>, int> NotifierToIdMap; |
155 IdToNotifierMap m_idToNotifierMap; | 157 IdToNotifierMap m_idToNotifierMap; |
156 NotifierToIdMap m_notifierToIdMap; | 158 NotifierToIdMap m_notifierToIdMap; |
157 }; | 159 }; |
158 | 160 |
159 bool hasListeners() const { return !m_oneShots.isEmpty() || !m_watchers.isEm
pty(); } | 161 bool hasListeners() const { return !m_oneShots.isEmpty() || !m_watchers.isEm
pty(); } |
160 | 162 |
161 void sendError(GeoNotifierVector&, PositionError*); | 163 void sendError(GeoNotifierVector&, PositionError*); |
162 void sendPosition(GeoNotifierVector&, Geoposition*); | 164 void sendPosition(GeoNotifierVector&, Geoposition*); |
163 | 165 |
164 // Removes notifiers that use a cached position from |notifiers| and | 166 // Removes notifiers that use a cached position from |notifiers| and |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 | 222 |
221 bool haveSuitableCachedPosition(PositionOptions*); | 223 bool haveSuitableCachedPosition(PositionOptions*); |
222 | 224 |
223 // Runs the success callbacks for the set of notifiers awaiting a cached | 225 // Runs the success callbacks for the set of notifiers awaiting a cached |
224 // position, the set is then cleared. The oneshots are removed everywhere. | 226 // position, the set is then cleared. The oneshots are removed everywhere. |
225 void makeCachedPositionCallbacks(); | 227 void makeCachedPositionCallbacks(); |
226 | 228 |
227 GeoNotifierSet m_oneShots; | 229 GeoNotifierSet m_oneShots; |
228 Watchers m_watchers; | 230 Watchers m_watchers; |
229 GeoNotifierSet m_pendingForPermissionNotifiers; | 231 GeoNotifierSet m_pendingForPermissionNotifiers; |
230 RefPtrWillBeMember<Geoposition> m_lastPosition; | 232 Member<Geoposition> m_lastPosition; |
231 | 233 |
232 enum { | 234 enum { |
233 Unknown, | 235 Unknown, |
234 InProgress, | 236 InProgress, |
235 Yes, | 237 Yes, |
236 No | 238 No |
237 } m_allowGeolocation; | 239 } m_allowGeolocation; |
238 | 240 |
239 GeoNotifierSet m_requestsAwaitingCachedPosition; | 241 GeoNotifierSet m_requestsAwaitingCachedPosition; |
240 }; | 242 }; |
241 | 243 |
242 } // namespace WebCore | 244 } // namespace WebCore |
243 | 245 |
244 #endif // Geolocation_h | 246 #endif // Geolocation_h |
OLD | NEW |