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

Unified Diff: WebKit/chromium/src/WebGeolocationServiceBridgeImpl.cpp

Issue 3316011: Merge 66886 - 2010-09-07 Jonathan Dixon <joth@chromium.org>... (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/517/
Patch Set: Created 10 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « WebKit/chromium/public/WebGeolocationService.h ('k') | WebKit/chromium/src/WebGeolocationServiceMock.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: WebKit/chromium/src/WebGeolocationServiceBridgeImpl.cpp
===================================================================
--- WebKit/chromium/src/WebGeolocationServiceBridgeImpl.cpp (revision 67096)
+++ WebKit/chromium/src/WebGeolocationServiceBridgeImpl.cpp (working copy)
@@ -82,10 +82,12 @@
virtual void onWebGeolocationServiceDestroyed();
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 @@
}
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 @@
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::onWebGeolocationServiceDestroyed()
{
- 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
« no previous file with comments | « WebKit/chromium/public/WebGeolocationService.h ('k') | WebKit/chromium/src/WebGeolocationServiceMock.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698