author | eckhart.koppen@nokia.com |
Wed, 31 Mar 2010 11:06:36 +0300 | |
changeset 7 | f7bc934e204c |
parent 3 | 41300fa6a67c |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved. |
|
3 |
* |
|
4 |
* Redistribution and use in source and binary forms, with or without |
|
5 |
* modification, are permitted provided that the following conditions |
|
6 |
* are met: |
|
7 |
* 1. Redistributions of source code must retain the above copyright |
|
8 |
* notice, this list of conditions and the following disclaimer. |
|
9 |
* 2. Redistributions in binary form must reproduce the above copyright |
|
10 |
* notice, this list of conditions and the following disclaimer in the |
|
11 |
* documentation and/or other materials provided with the distribution. |
|
12 |
* |
|
13 |
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
|
14 |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
15 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
16 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
|
17 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
18 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
19 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
20 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
21 |
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
22 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
23 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
24 |
*/ |
|
25 |
||
26 |
#ifndef Geolocation_h |
|
27 |
#define Geolocation_h |
|
28 |
||
29 |
#include "GeolocationService.h" |
|
30 |
#include "PositionCallback.h" |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
31 |
#include "PositionError.h" |
0 | 32 |
#include "PositionErrorCallback.h" |
33 |
#include "PositionOptions.h" |
|
34 |
#include "Timer.h" |
|
35 |
#include <wtf/Platform.h> |
|
36 |
#include <wtf/HashMap.h> |
|
37 |
#include <wtf/HashSet.h> |
|
38 |
#include <wtf/OwnPtr.h> |
|
39 |
#include <wtf/PassRefPtr.h> |
|
40 |
#include <wtf/RefCounted.h> |
|
41 |
#include <wtf/RefPtr.h> |
|
42 |
#include <wtf/Vector.h> |
|
43 |
||
44 |
namespace WebCore { |
|
45 |
||
46 |
class Frame; |
|
47 |
class Geoposition; |
|
48 |
||
49 |
class Geolocation : public RefCounted<Geolocation>, public GeolocationServiceClient { |
|
50 |
public: |
|
51 |
static PassRefPtr<Geolocation> create(Frame* frame) { return adoptRef(new Geolocation(frame)); } |
|
52 |
||
53 |
virtual ~Geolocation() {} |
|
54 |
||
55 |
void disconnectFrame(); |
|
56 |
||
57 |
Geoposition* lastPosition() const { return m_service->lastPosition(); } |
|
58 |
||
59 |
void getCurrentPosition(PassRefPtr<PositionCallback>, PassRefPtr<PositionErrorCallback>, PassRefPtr<PositionOptions>); |
|
60 |
int watchPosition(PassRefPtr<PositionCallback>, PassRefPtr<PositionErrorCallback>, PassRefPtr<PositionOptions>); |
|
61 |
void clearWatch(int watchId); |
|
62 |
||
63 |
void suspend(); |
|
64 |
void resume(); |
|
65 |
||
66 |
void setIsAllowed(bool); |
|
67 |
bool isAllowed() const { return m_allowGeolocation == Yes; } |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
68 |
bool isDenied() const { return m_allowGeolocation == No; } |
0 | 69 |
|
70 |
void setShouldClearCache(bool shouldClearCache) { m_shouldClearCache = shouldClearCache; } |
|
71 |
bool shouldClearCache() const { return m_shouldClearCache; } |
|
72 |
||
73 |
private: |
|
74 |
Geolocation(Frame*); |
|
75 |
||
76 |
class GeoNotifier : public RefCounted<GeoNotifier> { |
|
77 |
public: |
|
78 |
static PassRefPtr<GeoNotifier> create(Geolocation* geolocation, PassRefPtr<PositionCallback> positionCallback, PassRefPtr<PositionErrorCallback> positionErrorCallback, PassRefPtr<PositionOptions> options) { return adoptRef(new GeoNotifier(geolocation, positionCallback, positionErrorCallback, options)); } |
|
79 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
80 |
void setFatalError(PassRefPtr<PositionError>); |
0 | 81 |
bool hasZeroTimeout() const; |
82 |
void startTimerIfNeeded(); |
|
83 |
void timerFired(Timer<GeoNotifier>*); |
|
84 |
||
85 |
Geolocation* m_geolocation; |
|
86 |
RefPtr<PositionCallback> m_successCallback; |
|
87 |
RefPtr<PositionErrorCallback> m_errorCallback; |
|
88 |
RefPtr<PositionOptions> m_options; |
|
89 |
Timer<GeoNotifier> m_timer; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
RefPtr<PositionError> m_fatalError; |
0 | 91 |
|
92 |
private: |
|
93 |
GeoNotifier(Geolocation*, PassRefPtr<PositionCallback>, PassRefPtr<PositionErrorCallback>, PassRefPtr<PositionOptions>); |
|
94 |
}; |
|
95 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
96 |
class Watchers { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
97 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
98 |
void set(int id, PassRefPtr<GeoNotifier>); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
99 |
void remove(int id); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
100 |
void remove(GeoNotifier*); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
101 |
void clear(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
102 |
bool isEmpty() const; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
103 |
void getNotifiersVector(Vector<RefPtr<GeoNotifier> >&) const; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
104 |
private: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
105 |
typedef HashMap<int, RefPtr<GeoNotifier> > IdToNotifierMap; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
106 |
typedef HashMap<RefPtr<GeoNotifier>, int> NotifierToIdMap; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
107 |
IdToNotifierMap m_idToNotifierMap; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
108 |
NotifierToIdMap m_notifierToIdMap; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
109 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
110 |
|
0 | 111 |
bool hasListeners() const { return !m_oneShots.isEmpty() || !m_watchers.isEmpty(); } |
112 |
||
113 |
void sendError(Vector<RefPtr<GeoNotifier> >&, PositionError*); |
|
114 |
void sendPosition(Vector<RefPtr<GeoNotifier> >&, Geoposition*); |
|
115 |
||
116 |
static void stopTimer(Vector<RefPtr<GeoNotifier> >&); |
|
117 |
void stopTimersForOneShots(); |
|
118 |
void stopTimersForWatchers(); |
|
119 |
void stopTimers(); |
|
120 |
||
121 |
void makeSuccessCallbacks(); |
|
122 |
void handleError(PositionError*); |
|
123 |
||
124 |
void requestPermission(); |
|
125 |
||
126 |
// GeolocationServiceClient |
|
127 |
virtual void geolocationServicePositionChanged(GeolocationService*); |
|
128 |
virtual void geolocationServiceErrorOccurred(GeolocationService*); |
|
129 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
130 |
PassRefPtr<GeoNotifier> startRequest(PassRefPtr<PositionCallback>, PassRefPtr<PositionErrorCallback>, PassRefPtr<PositionOptions>); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
131 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
132 |
void fatalErrorOccurred(GeoNotifier*); |
0 | 133 |
void requestTimedOut(GeoNotifier*); |
134 |
||
135 |
typedef HashSet<RefPtr<GeoNotifier> > GeoNotifierSet; |
|
136 |
||
137 |
GeoNotifierSet m_oneShots; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
138 |
Watchers m_watchers; |
0 | 139 |
Frame* m_frame; |
140 |
OwnPtr<GeolocationService> m_service; |
|
141 |
||
142 |
enum { |
|
143 |
Unknown, |
|
144 |
InProgress, |
|
145 |
Yes, |
|
146 |
No |
|
147 |
} m_allowGeolocation; |
|
148 |
bool m_shouldClearCache; |
|
149 |
}; |
|
150 |
||
151 |
} // namespace WebCore |
|
152 |
||
153 |
#endif // Geolocation_h |