This source file includes following definitions.
- updating_
- OnMessageReceived
- geolocationDestroyed
- startUpdating
- stopUpdating
- setEnableHighAccuracy
- setController
- lastPosition
- requestPermission
- cancelPermissionRequest
- OnPermissionSet
- OnPositionUpdated
#include "content/renderer/geolocation_dispatcher.h"
#include "content/common/geolocation_messages.h"
#include "content/renderer/render_view_impl.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/web/WebGeolocationPermissionRequest.h"
#include "third_party/WebKit/public/web/WebGeolocationPermissionRequestManager.h"
#include "third_party/WebKit/public/web/WebGeolocationClient.h"
#include "third_party/WebKit/public/web/WebGeolocationPosition.h"
#include "third_party/WebKit/public/web/WebGeolocationError.h"
using blink::WebGeolocationController;
using blink::WebGeolocationError;
using blink::WebGeolocationPermissionRequest;
using blink::WebGeolocationPermissionRequestManager;
using blink::WebGeolocationPosition;
namespace content {
GeolocationDispatcher::GeolocationDispatcher(RenderViewImpl* render_view)
: RenderViewObserver(render_view),
pending_permissions_(new WebGeolocationPermissionRequestManager()),
enable_high_accuracy_(false),
updating_(false) {
}
GeolocationDispatcher::~GeolocationDispatcher() {}
bool GeolocationDispatcher::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(GeolocationDispatcher, message)
IPC_MESSAGE_HANDLER(GeolocationMsg_PermissionSet, OnPermissionSet)
IPC_MESSAGE_HANDLER(GeolocationMsg_PositionUpdated, OnPositionUpdated)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void GeolocationDispatcher::geolocationDestroyed() {
controller_.reset();
DCHECK(!updating_);
}
void GeolocationDispatcher::startUpdating() {
GURL url;
Send(new GeolocationHostMsg_StartUpdating(
routing_id(), url, enable_high_accuracy_));
updating_ = true;
}
void GeolocationDispatcher::stopUpdating() {
Send(new GeolocationHostMsg_StopUpdating(routing_id()));
updating_ = false;
}
void GeolocationDispatcher::setEnableHighAccuracy(bool enable_high_accuracy) {
bool has_changed = enable_high_accuracy_ != enable_high_accuracy;
enable_high_accuracy_ = enable_high_accuracy;
if (updating_ && has_changed)
startUpdating();
}
void GeolocationDispatcher::setController(
WebGeolocationController* controller) {
controller_.reset(controller);
}
bool GeolocationDispatcher::lastPosition(WebGeolocationPosition&) {
return false;
}
void GeolocationDispatcher::requestPermission(
const WebGeolocationPermissionRequest& permissionRequest) {
int bridge_id = pending_permissions_->add(permissionRequest);
base::string16 origin = permissionRequest.securityOrigin().toString();
Send(new GeolocationHostMsg_RequestPermission(
routing_id(), bridge_id, GURL(origin)));
}
void GeolocationDispatcher::cancelPermissionRequest(
const WebGeolocationPermissionRequest& permissionRequest) {
int bridge_id;
if (!pending_permissions_->remove(permissionRequest, bridge_id))
return;
base::string16 origin = permissionRequest.securityOrigin().toString();
Send(new GeolocationHostMsg_CancelPermissionRequest(
routing_id(), bridge_id, GURL(origin)));
}
void GeolocationDispatcher::OnPermissionSet(int bridge_id, bool is_allowed) {
WebGeolocationPermissionRequest permissionRequest;
if (!pending_permissions_->remove(bridge_id, permissionRequest))
return;
permissionRequest.setIsAllowed(is_allowed);
}
void GeolocationDispatcher::OnPositionUpdated(
const Geoposition& geoposition) {
if (!updating_)
return;
if (geoposition.Validate()) {
controller_->positionChanged(
WebGeolocationPosition(
geoposition.timestamp.ToDoubleT(),
geoposition.latitude, geoposition.longitude,
geoposition.accuracy,
geoposition.altitude > -10000.,
geoposition.altitude,
geoposition.altitude_accuracy >= 0.,
geoposition.altitude_accuracy,
geoposition.heading >= 0. && geoposition.heading <= 360.,
geoposition.heading,
geoposition.speed >= 0.,
geoposition.speed));
} else {
WebGeolocationError::Error code;
switch (geoposition.error_code) {
case Geoposition::ERROR_CODE_PERMISSION_DENIED:
code = WebGeolocationError::ErrorPermissionDenied;
break;
case Geoposition::ERROR_CODE_POSITION_UNAVAILABLE:
code = WebGeolocationError::ErrorPositionUnavailable;
break;
default:
NOTREACHED() << geoposition.error_code;
return;
}
controller_->errorOccurred(
WebGeolocationError(
code, blink::WebString::fromUTF8(geoposition.error_message)));
}
}
}