WebGeolocationManagerProxy.cpp [plain text]
#include "config.h"
#include "WebGeolocationManagerProxy.h"
#include "WebContext.h"
#include "WebGeolocationManagerMessages.h"
#include "WebGeolocationManagerProxyMessages.h"
namespace WebKit {
const char* WebGeolocationManagerProxy::supplementName()
{
return "WebGeolocationManagerProxy";
}
PassRefPtr<WebGeolocationManagerProxy> WebGeolocationManagerProxy::create(WebContext* context)
{
return adoptRef(new WebGeolocationManagerProxy(context));
}
WebGeolocationManagerProxy::WebGeolocationManagerProxy(WebContext* context)
: WebContextSupplement(context)
{
WebContextSupplement::context()->addMessageReceiver(Messages::WebGeolocationManagerProxy::messageReceiverName(), *this);
}
void WebGeolocationManagerProxy::initializeProvider(const WKGeolocationProviderBase* provider)
{
m_provider.initialize(provider);
}
void WebGeolocationManagerProxy::contextDestroyed()
{
m_updateRequesters.clear();
m_provider.stopUpdating(this);
}
void WebGeolocationManagerProxy::processDidClose(WebProcessProxy* webProcessProxy)
{
removeRequester(webProcessProxy);
}
void WebGeolocationManagerProxy::refWebContextSupplement()
{
API::Object::ref();
}
void WebGeolocationManagerProxy::derefWebContextSupplement()
{
API::Object::deref();
}
void WebGeolocationManagerProxy::providerDidChangePosition(WebGeolocationPosition* position)
{
if (!context())
return;
context()->sendToAllProcesses(Messages::WebGeolocationManager::DidChangePosition(position->data()));
}
void WebGeolocationManagerProxy::providerDidFailToDeterminePosition(const String& errorMessage)
{
if (!context())
return;
context()->sendToAllProcesses(Messages::WebGeolocationManager::DidFailToDeterminePosition(errorMessage));
}
#if PLATFORM(IOS)
void WebGeolocationManagerProxy::resetPermissions()
{
context()->sendToAllProcesses(Messages::WebGeolocationManager::ResetPermissions());
}
#endif
void WebGeolocationManagerProxy::startUpdating(IPC::Connection* connection)
{
bool wasUpdating = isUpdating();
m_updateRequesters.add(connection->client());
if (!wasUpdating) {
m_provider.setEnableHighAccuracy(this, isHighAccuracyEnabled());
m_provider.startUpdating(this);
}
}
void WebGeolocationManagerProxy::stopUpdating(IPC::Connection* connection)
{
removeRequester(connection->client());
}
void WebGeolocationManagerProxy::removeRequester(const IPC::Connection::Client* client)
{
bool wasUpdating = isUpdating();
bool highAccuracyWasEnabled = isHighAccuracyEnabled();
m_highAccuracyRequesters.remove(client);
m_updateRequesters.remove(client);
if (wasUpdating && !isUpdating())
m_provider.stopUpdating(this);
else {
bool highAccuracyShouldBeEnabled = isHighAccuracyEnabled();
if (highAccuracyShouldBeEnabled != highAccuracyWasEnabled)
m_provider.setEnableHighAccuracy(this, highAccuracyShouldBeEnabled);
}
}
void WebGeolocationManagerProxy::setEnableHighAccuracy(IPC::Connection* connection, bool enabled)
{
bool highAccuracyWasEnabled = isHighAccuracyEnabled();
if (enabled)
m_highAccuracyRequesters.add(connection->client());
else
m_highAccuracyRequesters.remove(connection->client());
bool highAccuracyShouldBeEnabled = isHighAccuracyEnabled();
if (isUpdating() && highAccuracyWasEnabled != highAccuracyShouldBeEnabled)
m_provider.setEnableHighAccuracy(this, highAccuracyShouldBeEnabled);
}
}