OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 virtual int getBridgeId() const; | 75 virtual int getBridgeId() const; |
76 virtual void attachBridgeIfNeeded(); | 76 virtual void attachBridgeIfNeeded(); |
77 | 77 |
78 // WebGeolocationServiceBridge | 78 // WebGeolocationServiceBridge |
79 virtual void setIsAllowed(bool allowed); | 79 virtual void setIsAllowed(bool allowed); |
80 virtual void setLastPosition(double latitude, double longitude, bool provide
sAltitude, double altitude, double accuracy, bool providesAltitudeAccuracy, doub
le altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, d
ouble speed, long long timestamp); | 80 virtual void setLastPosition(double latitude, double longitude, bool provide
sAltitude, double altitude, double accuracy, bool providesAltitudeAccuracy, doub
le altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, d
ouble speed, long long timestamp); |
81 virtual void setLastError(int errorCode, const WebString& message); | 81 virtual void setLastError(int errorCode, const WebString& message); |
82 virtual void onWebGeolocationServiceDestroyed(); | 82 virtual void onWebGeolocationServiceDestroyed(); |
83 | 83 |
84 private: | 84 private: |
85 WebViewClient* getWebViewClient(); | 85 bool isAttached() const; |
86 | 86 // Pointer back to the WebKit geolocation client. We obtain this via the fra
me's page, but need to cache it |
| 87 // as it may still be alive after the page has detached from the frame. |
| 88 WebGeolocationService* m_webGeolocationService; |
87 // GeolocationServiceChromium owns us, we only have a pointer back to it. | 89 // GeolocationServiceChromium owns us, we only have a pointer back to it. |
88 GeolocationServiceChromium* m_GeolocationServiceChromium; | 90 GeolocationServiceChromium* m_geolocationServiceChromium; |
89 int m_bridgeId; | 91 int m_bridgeId; |
90 }; | 92 }; |
91 | 93 |
92 GeolocationServiceBridge* createGeolocationServiceBridgeImpl(GeolocationServiceC
hromium* geolocationServiceChromium) | 94 GeolocationServiceBridge* createGeolocationServiceBridgeImpl(GeolocationServiceC
hromium* geolocationServiceChromium) |
93 { | 95 { |
94 return new WebGeolocationServiceBridgeImpl(geolocationServiceChromium); | 96 return new WebGeolocationServiceBridgeImpl(geolocationServiceChromium); |
95 } | 97 } |
96 | 98 |
97 WebGeolocationServiceBridgeImpl::WebGeolocationServiceBridgeImpl(GeolocationServ
iceChromium* geolocationServiceChromium) | 99 WebGeolocationServiceBridgeImpl::WebGeolocationServiceBridgeImpl(GeolocationServ
iceChromium* geolocationServiceChromium) |
98 : m_GeolocationServiceChromium(geolocationServiceChromium) | 100 : m_webGeolocationService(0) |
| 101 , m_geolocationServiceChromium(geolocationServiceChromium) |
99 , m_bridgeId(0) | 102 , m_bridgeId(0) |
100 { | 103 { |
101 } | 104 } |
102 | 105 |
103 WebGeolocationServiceBridgeImpl::~WebGeolocationServiceBridgeImpl() | 106 WebGeolocationServiceBridgeImpl::~WebGeolocationServiceBridgeImpl() |
104 { | 107 { |
105 WebKit::WebViewClient* webViewClient = getWebViewClient(); | 108 if (isAttached()) |
106 // Geolocation has an OwnPtr to us, and it's destroyed after the frame has | 109 m_webGeolocationService->detachBridge(m_bridgeId); |
107 // been potentially disconnected. In this case, it calls stopUpdating() | |
108 // has been called and we have already detached ourselves. | |
109 if (!webViewClient) | |
110 ASSERT(!m_bridgeId); | |
111 else if (m_bridgeId) | |
112 webViewClient->geolocationService()->detachBridge(m_bridgeId); | |
113 } | 110 } |
114 | 111 |
115 bool WebGeolocationServiceBridgeImpl::startUpdating(PositionOptions* positionOpt
ions) | 112 bool WebGeolocationServiceBridgeImpl::startUpdating(PositionOptions* positionOpt
ions) |
116 { | 113 { |
117 attachBridgeIfNeeded(); | 114 attachBridgeIfNeeded(); |
118 getWebViewClient()->geolocationService()->startUpdating(m_bridgeId, m_Geoloc
ationServiceChromium->frame()->document()->url(), positionOptions->enableHighAcc
uracy()); | 115 if (!isAttached()) |
| 116 return false; |
| 117 m_webGeolocationService->startUpdating(m_bridgeId, m_geolocationServiceChrom
ium->frame()->document()->url(), positionOptions->enableHighAccuracy()); |
119 return true; | 118 return true; |
120 } | 119 } |
121 | 120 |
122 void WebGeolocationServiceBridgeImpl::stopUpdating() | 121 void WebGeolocationServiceBridgeImpl::stopUpdating() |
123 { | 122 { |
124 WebViewClient* webViewClient = getWebViewClient(); | 123 if (isAttached()) { |
125 if (m_bridgeId && webViewClient) { | 124 m_webGeolocationService->stopUpdating(m_bridgeId); |
126 WebGeolocationService* geolocationService = webViewClient->geolocationSe
rvice(); | 125 m_webGeolocationService->detachBridge(m_bridgeId); |
127 geolocationService->stopUpdating(m_bridgeId); | 126 m_bridgeId = 0; |
128 geolocationService->detachBridge(m_bridgeId); | 127 m_webGeolocationService = 0; |
129 } | 128 } |
130 m_bridgeId = 0; | |
131 } | 129 } |
132 | 130 |
133 void WebGeolocationServiceBridgeImpl::suspend() | 131 void WebGeolocationServiceBridgeImpl::suspend() |
134 { | 132 { |
135 getWebViewClient()->geolocationService()->suspend(m_bridgeId); | 133 if (isAttached()) |
| 134 m_webGeolocationService->suspend(m_bridgeId); |
136 } | 135 } |
137 | 136 |
138 void WebGeolocationServiceBridgeImpl::resume() | 137 void WebGeolocationServiceBridgeImpl::resume() |
139 { | 138 { |
140 getWebViewClient()->geolocationService()->resume(m_bridgeId); | 139 if (isAttached()) |
| 140 m_webGeolocationService->resume(m_bridgeId); |
141 } | 141 } |
142 | 142 |
143 int WebGeolocationServiceBridgeImpl::getBridgeId() const | 143 int WebGeolocationServiceBridgeImpl::getBridgeId() const |
144 { | 144 { |
145 return m_bridgeId; | 145 return m_bridgeId; |
146 } | 146 } |
147 | 147 |
148 void WebGeolocationServiceBridgeImpl::attachBridgeIfNeeded() | 148 void WebGeolocationServiceBridgeImpl::attachBridgeIfNeeded() |
149 { | 149 { |
150 if (!m_bridgeId) | 150 if (isAttached()) |
151 m_bridgeId = getWebViewClient()->geolocationService()->attachBridge(this
); | 151 return; |
| 152 // Lazy attach to the geolocation service of the associated page if there is
one. |
| 153 Frame* frame = m_geolocationServiceChromium->frame(); |
| 154 if (!frame || !frame->page()) |
| 155 return; |
| 156 WebKit::ChromeClientImpl* chromeClientImpl = static_cast<WebKit::ChromeClien
tImpl*>(frame->page()->chrome()->client()); |
| 157 WebKit::WebViewClient* webViewClient = chromeClientImpl->webView()->client()
; |
| 158 m_webGeolocationService = webViewClient->geolocationService(); |
| 159 ASSERT(m_webGeolocationService); |
| 160 m_bridgeId = m_webGeolocationService->attachBridge(this); |
| 161 if (!m_bridgeId) { |
| 162 // Attach failed. Release association with this service. |
| 163 m_webGeolocationService = 0; |
| 164 } |
152 } | 165 } |
153 | 166 |
154 void WebGeolocationServiceBridgeImpl::setIsAllowed(bool allowed) | 167 void WebGeolocationServiceBridgeImpl::setIsAllowed(bool allowed) |
155 { | 168 { |
156 m_GeolocationServiceChromium->setIsAllowed(allowed); | 169 m_geolocationServiceChromium->setIsAllowed(allowed); |
157 } | 170 } |
158 | 171 |
159 void WebGeolocationServiceBridgeImpl::setLastPosition(double latitude, double lo
ngitude, bool providesAltitude, double altitude, double accuracy, bool providesA
ltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading,
bool providesSpeed, double speed, long long timestamp) | 172 void WebGeolocationServiceBridgeImpl::setLastPosition(double latitude, double lo
ngitude, bool providesAltitude, double altitude, double accuracy, bool providesA
ltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading,
bool providesSpeed, double speed, long long timestamp) |
160 { | 173 { |
161 RefPtr<Geoposition> geoposition = Geoposition::create(Coordinates::create(la
titude, longitude, providesAltitude, altitude, accuracy, providesAltitudeAccurac
y, altitudeAccuracy, providesHeading, heading, providesSpeed, speed), timestamp)
; | 174 RefPtr<Geoposition> geoposition = Geoposition::create(Coordinates::create(la
titude, longitude, providesAltitude, altitude, accuracy, providesAltitudeAccurac
y, altitudeAccuracy, providesHeading, heading, providesSpeed, speed), timestamp)
; |
162 m_GeolocationServiceChromium->setLastPosition(geoposition); | 175 m_geolocationServiceChromium->setLastPosition(geoposition); |
163 } | 176 } |
164 | 177 |
165 void WebGeolocationServiceBridgeImpl::setLastError(int errorCode, const WebStrin
g& message) | 178 void WebGeolocationServiceBridgeImpl::setLastError(int errorCode, const WebStrin
g& message) |
166 { | 179 { |
167 m_GeolocationServiceChromium->setLastError(errorCode, message); | 180 m_geolocationServiceChromium->setLastError(errorCode, message); |
168 } | |
169 | |
170 WebViewClient* WebGeolocationServiceBridgeImpl::getWebViewClient() | |
171 { | |
172 Frame* frame = m_GeolocationServiceChromium->frame(); | |
173 if (!frame || !frame->page()) | |
174 return 0; | |
175 WebKit::ChromeClientImpl* chromeClientImpl = static_cast<WebKit::ChromeClien
tImpl*>(frame->page()->chrome()->client()); | |
176 WebKit::WebViewClient* webViewClient = chromeClientImpl->webView()->client()
; | |
177 return webViewClient; | |
178 } | 181 } |
179 | 182 |
180 void WebGeolocationServiceBridgeImpl::onWebGeolocationServiceDestroyed() | 183 void WebGeolocationServiceBridgeImpl::onWebGeolocationServiceDestroyed() |
181 { | 184 { |
| 185 m_bridgeId = 0; |
| 186 m_webGeolocationService = 0; |
| 187 } |
| 188 |
| 189 bool WebGeolocationServiceBridgeImpl::isAttached() const |
| 190 { |
| 191 // Test the class invariant. |
| 192 if (m_webGeolocationService) |
| 193 ASSERT(m_bridgeId); |
| 194 else |
| 195 ASSERT(!m_bridgeId); |
| 196 |
| 197 return m_webGeolocationService; |
182 } | 198 } |
183 | 199 |
184 } // namespace WebKit | 200 } // namespace WebKit |
185 | 201 |
186 #endif // ENABLE(GEOLOCATION) | 202 #endif // ENABLE(GEOLOCATION) |
OLD | NEW |