Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/geolocation_dispatcher.h" | 5 #include "content/renderer/geolocation_dispatcher.h" |
| 6 | 6 |
| 7 #include "content/common/geolocation_messages.h" | 7 #include "content/common/geolocation_messages.h" |
| 8 #include "content/renderer/render_view_impl.h" | 8 #include "content/renderer/render_view_impl.h" |
| 9 #include "third_party/WebKit/public/platform/WebString.h" | 9 #include "third_party/WebKit/public/platform/WebString.h" |
| 10 #include "third_party/WebKit/public/web/WebGeolocationPermissionRequest.h" | 10 #include "third_party/WebKit/public/web/WebGeolocationPermissionRequest.h" |
| 11 #include "third_party/WebKit/public/web/WebGeolocationPermissionRequestManager.h " | 11 #include "third_party/WebKit/public/web/WebGeolocationPermissionRequestManager.h " |
| 12 #include "third_party/WebKit/public/web/WebGeolocationClient.h" | 12 #include "third_party/WebKit/public/web/WebGeolocationClient.h" |
| 13 #include "third_party/WebKit/public/web/WebGeolocationPosition.h" | 13 #include "third_party/WebKit/public/web/WebGeolocationPosition.h" |
| 14 #include "third_party/WebKit/public/web/WebGeolocationError.h" | 14 #include "third_party/WebKit/public/web/WebGeolocationError.h" |
| 15 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 15 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 16 | 16 |
| 17 using blink::WebGeolocationController; | 17 using blink::WebGeolocationController; |
| 18 using blink::WebGeolocationError; | 18 using blink::WebGeolocationError; |
| 19 using blink::WebGeolocationPermissionRequest; | 19 using blink::WebGeolocationPermissionRequest; |
| 20 using blink::WebGeolocationPermissionRequestManager; | 20 using blink::WebGeolocationPermissionRequestManager; |
| 21 using blink::WebGeolocationPosition; | 21 using blink::WebGeolocationPosition; |
| 22 | 22 |
| 23 namespace content { | 23 namespace content { |
| 24 | 24 |
| 25 GeolocationDispatcher::GeolocationDispatcher(RenderFrame* render_frame) | 25 GeolocationDispatcher::GeolocationDispatcher(RenderFrame* render_frame) |
| 26 : RenderFrameObserver(render_frame), | 26 : RenderFrameObserver(render_frame), |
| 27 pending_permissions_(new WebGeolocationPermissionRequestManager()), | 27 pending_permissions_(new WebGeolocationPermissionRequestManager()), |
| 28 enable_high_accuracy_(false), | 28 enable_high_accuracy_(false) { |
| 29 updating_(false) { | |
| 30 } | 29 } |
| 31 | 30 |
| 32 GeolocationDispatcher::~GeolocationDispatcher() {} | 31 GeolocationDispatcher::~GeolocationDispatcher() {} |
| 33 | 32 |
| 34 bool GeolocationDispatcher::OnMessageReceived(const IPC::Message& message) { | 33 bool GeolocationDispatcher::OnMessageReceived(const IPC::Message& message) { |
| 35 bool handled = true; | 34 bool handled = true; |
| 36 IPC_BEGIN_MESSAGE_MAP(GeolocationDispatcher, message) | 35 IPC_BEGIN_MESSAGE_MAP(GeolocationDispatcher, message) |
| 37 IPC_MESSAGE_HANDLER(GeolocationMsg_PermissionSet, OnPermissionSet) | 36 IPC_MESSAGE_HANDLER(GeolocationMsg_PermissionSet, OnPermissionSet) |
| 38 IPC_MESSAGE_HANDLER(GeolocationMsg_PositionUpdated, OnPositionUpdated) | |
| 39 IPC_MESSAGE_UNHANDLED(handled = false) | 37 IPC_MESSAGE_UNHANDLED(handled = false) |
| 40 IPC_END_MESSAGE_MAP() | 38 IPC_END_MESSAGE_MAP() |
| 41 return handled; | 39 return handled; |
| 42 } | 40 } |
| 43 | 41 |
| 44 void GeolocationDispatcher::startUpdating() { | 42 void GeolocationDispatcher::startUpdating() { |
| 45 GURL url; | 43 if (!geolocation_service_.get()) { |
| 46 Send(new GeolocationHostMsg_StartUpdating( | 44 render_frame()->GetServiceRegistry()->ConnectToRemoteService( |
| 47 routing_id(), url, enable_high_accuracy_)); | 45 &geolocation_service_); |
| 48 updating_ = true; | 46 geolocation_service_.set_client(this); |
| 47 } | |
| 48 geolocation_service_->StartUpdating(enable_high_accuracy_); | |
| 49 } | 49 } |
| 50 | 50 |
| 51 void GeolocationDispatcher::stopUpdating() { | 51 void GeolocationDispatcher::stopUpdating() { |
| 52 Send(new GeolocationHostMsg_StopUpdating(routing_id())); | 52 geolocation_service_.reset(); |
| 53 updating_ = false; | |
| 54 } | 53 } |
| 55 | 54 |
| 56 void GeolocationDispatcher::setEnableHighAccuracy(bool enable_high_accuracy) { | 55 void GeolocationDispatcher::setEnableHighAccuracy(bool enable_high_accuracy) { |
| 57 // GeolocationController calls setEnableHighAccuracy(true) before | 56 // GeolocationController calls setEnableHighAccuracy(true) before |
| 58 // startUpdating in response to the first high-accuracy Geolocation | 57 // startUpdating in response to the first high-accuracy Geolocation |
| 59 // subscription. When the last high-accuracy Geolocation unsubscribes | 58 // subscription. When the last high-accuracy Geolocation unsubscribes |
| 60 // it calls setEnableHighAccuracy(false) after stopUpdating. | 59 // it calls setEnableHighAccuracy(false) after stopUpdating. |
| 61 bool has_changed = enable_high_accuracy_ != enable_high_accuracy; | 60 bool has_changed = enable_high_accuracy_ != enable_high_accuracy; |
| 62 enable_high_accuracy_ = enable_high_accuracy; | 61 enable_high_accuracy_ = enable_high_accuracy; |
| 63 // We have a different accuracy requirement. Request browser to update. | 62 // We have a different accuracy requirement. Request browser to update. |
| 64 if (updating_ && has_changed) | 63 if (geolocation_service_.get() && has_changed) |
| 65 startUpdating(); | 64 startUpdating(); |
| 66 } | 65 } |
| 67 | 66 |
| 68 void GeolocationDispatcher::setController( | 67 void GeolocationDispatcher::setController( |
| 69 WebGeolocationController* controller) { | 68 WebGeolocationController* controller) { |
| 70 controller_.reset(controller); | 69 controller_.reset(controller); |
| 71 } | 70 } |
| 72 | 71 |
| 73 bool GeolocationDispatcher::lastPosition(WebGeolocationPosition&) { | 72 bool GeolocationDispatcher::lastPosition(WebGeolocationPosition&) { |
| 74 // The latest position is stored in the browser, not the renderer, so we | 73 // The latest position is stored in the browser, not the renderer, so we |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 102 } | 101 } |
| 103 | 102 |
| 104 // Permission for using geolocation has been set. | 103 // Permission for using geolocation has been set. |
| 105 void GeolocationDispatcher::OnPermissionSet(int bridge_id, bool is_allowed) { | 104 void GeolocationDispatcher::OnPermissionSet(int bridge_id, bool is_allowed) { |
| 106 WebGeolocationPermissionRequest permissionRequest; | 105 WebGeolocationPermissionRequest permissionRequest; |
| 107 if (!pending_permissions_->remove(bridge_id, permissionRequest)) | 106 if (!pending_permissions_->remove(bridge_id, permissionRequest)) |
| 108 return; | 107 return; |
| 109 permissionRequest.setIsAllowed(is_allowed); | 108 permissionRequest.setIsAllowed(is_allowed); |
| 110 } | 109 } |
| 111 | 110 |
| 112 // We have an updated geolocation position or error code. | 111 void GeolocationDispatcher::OnLocationUpdate(MojoGeopositionPtr geoposition) { |
|
Michael van Ouwerkerk
2014/10/08 14:13:08
Can we not accept references from mojo services? W
blundell
2014/10/09 08:32:52
Not as far as I'm aware.
| |
| 113 void GeolocationDispatcher::OnPositionUpdated( | 112 DCHECK(geolocation_service_.get()); |
| 114 const Geoposition& geoposition) { | |
| 115 // It is possible for the browser process to have queued an update message | |
| 116 // before receiving the stop updating message. | |
| 117 if (!updating_) | |
| 118 return; | |
| 119 | 113 |
| 120 if (geoposition.Validate()) { | 114 if (geoposition->valid) { |
| 121 controller_->positionChanged( | 115 controller_->positionChanged(WebGeolocationPosition( |
| 122 WebGeolocationPosition( | 116 geoposition->timestamp, |
| 123 geoposition.timestamp.ToDoubleT(), | 117 geoposition->latitude, |
| 124 geoposition.latitude, geoposition.longitude, | 118 geoposition->longitude, |
| 125 geoposition.accuracy, | 119 geoposition->accuracy, |
| 126 // Lowest point on land is at approximately -400 meters. | 120 // Lowest point on land is at approximately -400 meters. |
| 127 geoposition.altitude > -10000., | 121 geoposition->altitude > -10000., |
| 128 geoposition.altitude, | 122 geoposition->altitude, |
| 129 geoposition.altitude_accuracy >= 0., | 123 geoposition->altitude_accuracy >= 0., |
| 130 geoposition.altitude_accuracy, | 124 geoposition->altitude_accuracy, |
| 131 geoposition.heading >= 0. && geoposition.heading <= 360., | 125 geoposition->heading >= 0. && geoposition->heading <= 360., |
| 132 geoposition.heading, | 126 geoposition->heading, |
| 133 geoposition.speed >= 0., | 127 geoposition->speed >= 0., |
| 134 geoposition.speed)); | 128 geoposition->speed)); |
| 135 } else { | 129 } else { |
| 136 WebGeolocationError::Error code; | 130 WebGeolocationError::Error code; |
| 137 switch (geoposition.error_code) { | 131 switch (geoposition->error_code) { |
| 138 case Geoposition::ERROR_CODE_PERMISSION_DENIED: | 132 case Geoposition::ERROR_CODE_PERMISSION_DENIED: |
| 139 code = WebGeolocationError::ErrorPermissionDenied; | 133 code = WebGeolocationError::ErrorPermissionDenied; |
| 140 break; | 134 break; |
| 141 case Geoposition::ERROR_CODE_POSITION_UNAVAILABLE: | 135 case Geoposition::ERROR_CODE_POSITION_UNAVAILABLE: |
| 142 code = WebGeolocationError::ErrorPositionUnavailable; | 136 code = WebGeolocationError::ErrorPositionUnavailable; |
| 143 break; | 137 break; |
| 144 default: | 138 default: |
| 145 NOTREACHED() << geoposition.error_code; | 139 NOTREACHED() << geoposition->error_code; |
| 146 return; | 140 return; |
| 147 } | 141 } |
| 148 controller_->errorOccurred( | 142 controller_->errorOccurred(WebGeolocationError( |
| 149 WebGeolocationError( | 143 code, blink::WebString::fromUTF8(geoposition->error_message))); |
| 150 code, blink::WebString::fromUTF8(geoposition.error_message))); | |
| 151 } | 144 } |
| 152 } | 145 } |
| 153 | 146 |
| 154 } // namespace content | 147 } // namespace content |
| OLD | NEW |