Index: content/renderer/geolocation_dispatcher.cc |
diff --git a/content/renderer/geolocation_dispatcher.cc b/content/renderer/geolocation_dispatcher.cc |
index fde4fc98cba9217f6adfb0c669ed1ecf23f69a5e..a099a3d96d5741dea16c27ff41ec233d0fb55df2 100644 |
--- a/content/renderer/geolocation_dispatcher.cc |
+++ b/content/renderer/geolocation_dispatcher.cc |
@@ -25,7 +25,8 @@ |
GeolocationDispatcher::GeolocationDispatcher(RenderFrame* render_frame) |
: RenderFrameObserver(render_frame), |
pending_permissions_(new WebGeolocationPermissionRequestManager()), |
- enable_high_accuracy_(false) { |
+ enable_high_accuracy_(false), |
+ updating_(false) { |
} |
GeolocationDispatcher::~GeolocationDispatcher() {} |
@@ -34,23 +35,22 @@ |
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::startUpdating() { |
- if (!geolocation_service_.get()) { |
- render_frame()->GetServiceRegistry()->ConnectToRemoteService( |
- &geolocation_service_); |
- geolocation_service_.set_client(this); |
- } |
- if (enable_high_accuracy_) |
- geolocation_service_->SetHighAccuracy(true); |
+ GURL url; |
+ Send(new GeolocationHostMsg_StartUpdating( |
+ routing_id(), url, enable_high_accuracy_)); |
+ updating_ = true; |
} |
void GeolocationDispatcher::stopUpdating() { |
- geolocation_service_.reset(); |
+ Send(new GeolocationHostMsg_StopUpdating(routing_id())); |
+ updating_ = false; |
} |
void GeolocationDispatcher::setEnableHighAccuracy(bool enable_high_accuracy) { |
@@ -61,8 +61,8 @@ |
bool has_changed = enable_high_accuracy_ != enable_high_accuracy; |
enable_high_accuracy_ = enable_high_accuracy; |
// We have a different accuracy requirement. Request browser to update. |
- if (geolocation_service_.get() && has_changed) |
- geolocation_service_->SetHighAccuracy(enable_high_accuracy_); |
+ if (updating_ && has_changed) |
+ startUpdating(); |
} |
void GeolocationDispatcher::setController( |
@@ -103,27 +103,32 @@ |
permissionRequest.setIsAllowed(is_allowed); |
} |
-void GeolocationDispatcher::OnLocationUpdate(MojoGeopositionPtr geoposition) { |
- DCHECK(geolocation_service_.get()); |
+// We have an updated geolocation position or error code. |
+void GeolocationDispatcher::OnPositionUpdated( |
+ const Geoposition& geoposition) { |
+ // It is possible for the browser process to have queued an update message |
+ // before receiving the stop updating message. |
+ if (!updating_) |
+ return; |
- if (geoposition->valid) { |
- controller_->positionChanged(WebGeolocationPosition( |
- geoposition->timestamp, |
- geoposition->latitude, |
- geoposition->longitude, |
- geoposition->accuracy, |
- // Lowest point on land is at approximately -400 meters. |
- 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)); |
+ if (geoposition.Validate()) { |
+ controller_->positionChanged( |
+ WebGeolocationPosition( |
+ geoposition.timestamp.ToDoubleT(), |
+ geoposition.latitude, geoposition.longitude, |
+ geoposition.accuracy, |
+ // Lowest point on land is at approximately -400 meters. |
+ 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) { |
+ switch (geoposition.error_code) { |
case Geoposition::ERROR_CODE_PERMISSION_DENIED: |
code = WebGeolocationError::ErrorPermissionDenied; |
break; |
@@ -131,11 +136,12 @@ |
code = WebGeolocationError::ErrorPositionUnavailable; |
break; |
default: |
- NOTREACHED() << geoposition->error_code; |
+ NOTREACHED() << geoposition.error_code; |
return; |
} |
- controller_->errorOccurred(WebGeolocationError( |
- code, blink::WebString::fromUTF8(geoposition->error_message))); |
+ controller_->errorOccurred( |
+ WebGeolocationError( |
+ code, blink::WebString::fromUTF8(geoposition.error_message))); |
} |
} |