summaryrefslogtreecommitdiffstats
path: root/WebKit/chromium/src/WebGeolocationServiceBridgeImpl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/chromium/src/WebGeolocationServiceBridgeImpl.cpp')
-rw-r--r--WebKit/chromium/src/WebGeolocationServiceBridgeImpl.cpp86
1 files changed, 51 insertions, 35 deletions
diff --git a/WebKit/chromium/src/WebGeolocationServiceBridgeImpl.cpp b/WebKit/chromium/src/WebGeolocationServiceBridgeImpl.cpp
index bbb7162..bbc852f 100644
--- a/WebKit/chromium/src/WebGeolocationServiceBridgeImpl.cpp
+++ b/WebKit/chromium/src/WebGeolocationServiceBridgeImpl.cpp
@@ -79,13 +79,15 @@ public:
virtual void setIsAllowed(bool allowed);
virtual void setLastPosition(double latitude, double longitude, bool providesAltitude, double altitude, double accuracy, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed, long long timestamp);
virtual void setLastError(int errorCode, const WebString& message);
- virtual void onWebGeolocationServiceDestroyed();
+ virtual void didDestroyGeolocationService();
private:
- WebViewClient* getWebViewClient();
-
+ bool isAttached() const;
+ // Pointer back to the WebKit geolocation client. We obtain this via the frame's page, but need to cache it
+ // as it may still be alive after the page has detached from the frame.
+ WebGeolocationService* m_webGeolocationService;
// GeolocationServiceChromium owns us, we only have a pointer back to it.
- GeolocationServiceChromium* m_GeolocationServiceChromium;
+ GeolocationServiceChromium* m_geolocationServiceChromium;
int m_bridgeId;
};
@@ -95,49 +97,47 @@ GeolocationServiceBridge* createGeolocationServiceBridgeImpl(GeolocationServiceC
}
WebGeolocationServiceBridgeImpl::WebGeolocationServiceBridgeImpl(GeolocationServiceChromium* geolocationServiceChromium)
- : m_GeolocationServiceChromium(geolocationServiceChromium)
+ : m_webGeolocationService(0)
+ , m_geolocationServiceChromium(geolocationServiceChromium)
, m_bridgeId(0)
{
}
WebGeolocationServiceBridgeImpl::~WebGeolocationServiceBridgeImpl()
{
- WebKit::WebViewClient* webViewClient = getWebViewClient();
- // Geolocation has an OwnPtr to us, and it's destroyed after the frame has
- // been potentially disconnected. In this case, it calls stopUpdating()
- // has been called and we have already detached ourselves.
- if (!webViewClient)
- ASSERT(!m_bridgeId);
- else if (m_bridgeId)
- webViewClient->geolocationService()->detachBridge(m_bridgeId);
+ if (isAttached())
+ m_webGeolocationService->detachBridge(m_bridgeId);
}
bool WebGeolocationServiceBridgeImpl::startUpdating(PositionOptions* positionOptions)
{
attachBridgeIfNeeded();
- getWebViewClient()->geolocationService()->startUpdating(m_bridgeId, m_GeolocationServiceChromium->frame()->document()->url(), positionOptions->enableHighAccuracy());
+ if (!isAttached())
+ return false;
+ m_webGeolocationService->startUpdating(m_bridgeId, m_geolocationServiceChromium->frame()->document()->url(), positionOptions->enableHighAccuracy());
return true;
}
void WebGeolocationServiceBridgeImpl::stopUpdating()
{
- WebViewClient* webViewClient = getWebViewClient();
- if (m_bridgeId && webViewClient) {
- WebGeolocationService* geolocationService = webViewClient->geolocationService();
- geolocationService->stopUpdating(m_bridgeId);
- geolocationService->detachBridge(m_bridgeId);
+ if (isAttached()) {
+ m_webGeolocationService->stopUpdating(m_bridgeId);
+ m_webGeolocationService->detachBridge(m_bridgeId);
+ m_bridgeId = 0;
+ m_webGeolocationService = 0;
}
- m_bridgeId = 0;
}
void WebGeolocationServiceBridgeImpl::suspend()
{
- getWebViewClient()->geolocationService()->suspend(m_bridgeId);
+ if (isAttached())
+ m_webGeolocationService->suspend(m_bridgeId);
}
void WebGeolocationServiceBridgeImpl::resume()
{
- getWebViewClient()->geolocationService()->resume(m_bridgeId);
+ if (isAttached())
+ m_webGeolocationService->resume(m_bridgeId);
}
int WebGeolocationServiceBridgeImpl::getBridgeId() const
@@ -147,38 +147,54 @@ int WebGeolocationServiceBridgeImpl::getBridgeId() const
void WebGeolocationServiceBridgeImpl::attachBridgeIfNeeded()
{
- if (!m_bridgeId)
- m_bridgeId = getWebViewClient()->geolocationService()->attachBridge(this);
+ if (isAttached())
+ return;
+ // Lazy attach to the geolocation service of the associated page if there is one.
+ Frame* frame = m_geolocationServiceChromium->frame();
+ if (!frame || !frame->page())
+ return;
+ WebKit::ChromeClientImpl* chromeClientImpl = static_cast<WebKit::ChromeClientImpl*>(frame->page()->chrome()->client());
+ WebKit::WebViewClient* webViewClient = chromeClientImpl->webView()->client();
+ m_webGeolocationService = webViewClient->geolocationService();
+ ASSERT(m_webGeolocationService);
+ m_bridgeId = m_webGeolocationService->attachBridge(this);
+ if (!m_bridgeId) {
+ // Attach failed. Release association with this service.
+ m_webGeolocationService = 0;
+ }
}
void WebGeolocationServiceBridgeImpl::setIsAllowed(bool allowed)
{
- m_GeolocationServiceChromium->setIsAllowed(allowed);
+ m_geolocationServiceChromium->setIsAllowed(allowed);
}
void WebGeolocationServiceBridgeImpl::setLastPosition(double latitude, double longitude, bool providesAltitude, double altitude, double accuracy, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed, long long timestamp)
{
RefPtr<Geoposition> geoposition = Geoposition::create(Coordinates::create(latitude, longitude, providesAltitude, altitude, accuracy, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed), timestamp);
- m_GeolocationServiceChromium->setLastPosition(geoposition);
+ m_geolocationServiceChromium->setLastPosition(geoposition);
}
void WebGeolocationServiceBridgeImpl::setLastError(int errorCode, const WebString& message)
{
- m_GeolocationServiceChromium->setLastError(errorCode, message);
+ m_geolocationServiceChromium->setLastError(errorCode, message);
}
-WebViewClient* WebGeolocationServiceBridgeImpl::getWebViewClient()
+void WebGeolocationServiceBridgeImpl::didDestroyGeolocationService()
{
- Frame* frame = m_GeolocationServiceChromium->frame();
- if (!frame || !frame->page())
- return 0;
- WebKit::ChromeClientImpl* chromeClientImpl = static_cast<WebKit::ChromeClientImpl*>(frame->page()->chrome()->client());
- WebKit::WebViewClient* webViewClient = chromeClientImpl->webView()->client();
- return webViewClient;
+ m_bridgeId = 0;
+ m_webGeolocationService = 0;
}
-void WebGeolocationServiceBridgeImpl::onWebGeolocationServiceDestroyed()
+bool WebGeolocationServiceBridgeImpl::isAttached() const
{
+ // Test the class invariant.
+ if (m_webGeolocationService)
+ ASSERT(m_bridgeId);
+ else
+ ASSERT(!m_bridgeId);
+
+ return m_webGeolocationService;
}
} // namespace WebKit