WebGeolocationClient.cpp [plain text]
#include "WebKitDLL.h"
#include "WebGeolocationClient.h"
#include "WebFrame.h"
#include "WebGeolocationPolicyListener.h"
#include "WebGeolocationPosition.h"
#include "WebSecurityOrigin.h"
#include "WebView.h"
#include <WebCore/Document.h>
#include <WebCore/Frame.h>
#include <WebCore/Geolocation.h>
#include <WebCore/SecurityOrigin.h>
using namespace WebCore;
WebGeolocationClient::WebGeolocationClient(WebView* webView)
: m_webView(webView)
{
}
void WebGeolocationClient::geolocationDestroyed()
{
delete this;
}
void WebGeolocationClient::startUpdating()
{
COMPtr<IWebGeolocationProvider> provider;
if (FAILED(m_webView->geolocationProvider(&provider)))
return;
provider->registerWebView(m_webView.get());
}
void WebGeolocationClient::stopUpdating()
{
COMPtr<IWebGeolocationProvider> provider;
if (FAILED(m_webView->geolocationProvider(&provider)))
return;
provider->unregisterWebView(m_webView.get());
}
GeolocationPosition* WebGeolocationClient::lastPosition()
{
COMPtr<IWebGeolocationProvider> provider;
if (FAILED(m_webView->geolocationProvider(&provider)))
return 0;
COMPtr<IWebGeolocationPosition> position;
if (FAILED(provider->lastPosition(&position)))
return 0;
return core(position.get());
}
void WebGeolocationClient::requestPermission(Geolocation* geolocation)
{
COMPtr<IWebUIDelegate> uiDelegate;
if (FAILED(m_webView->uiDelegate(&uiDelegate))) {
geolocation->setIsAllowed(false);
return;
}
COMPtr<IWebUIDelegatePrivate2> uiDelegatePrivate2(Query, uiDelegate);
if (!uiDelegatePrivate2) {
geolocation->setIsAllowed(false);
return;
}
Frame* frame = geolocation->frame();
COMPtr<WebSecurityOrigin> origin(AdoptCOM, WebSecurityOrigin::createInstance(frame->document()->securityOrigin()));
COMPtr<WebGeolocationPolicyListener> listener = WebGeolocationPolicyListener::createInstance(geolocation);
HRESULT hr = uiDelegatePrivate2->decidePolicyForGeolocationRequest(m_webView.get(), kit(frame), origin.get(), listener.get());
if (hr != E_NOTIMPL)
return;
geolocation->setIsAllowed(false);
}