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/child/child_thread.h" | 7 #include "content/child/child_thread.h" |
8 #include "content/public/common/geoposition.h" | 8 #include "content/public/common/geoposition.h" |
9 #include "content/renderer/render_view_impl.h" | 9 #include "content/renderer/render_view_impl.h" |
10 #include "third_party/WebKit/public/platform/WebString.h" | 10 #include "third_party/WebKit/public/platform/WebString.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 | 25 |
26 GeolocationDispatcher::GeolocationDispatcher(RenderFrame* render_frame) | 26 GeolocationDispatcher::GeolocationDispatcher(RenderFrame* render_frame) |
27 : RenderFrameObserver(render_frame), | 27 : RenderFrameObserver(render_frame), |
28 pending_permissions_(new WebGeolocationPermissionRequestManager()), | 28 pending_permissions_(new WebGeolocationPermissionRequestManager()), |
29 enable_high_accuracy_(false) { | 29 enable_high_accuracy_(false) { |
30 } | 30 } |
31 | 31 |
32 GeolocationDispatcher::~GeolocationDispatcher() {} | 32 GeolocationDispatcher::~GeolocationDispatcher() {} |
33 | 33 |
34 void GeolocationDispatcher::startUpdating() { | 34 void GeolocationDispatcher::startUpdating() { |
35 if (!geolocation_service_.get()) { | 35 if (!geolocation_service_) { |
36 render_frame()->GetServiceRegistry()->ConnectToRemoteService( | 36 render_frame()->GetServiceRegistry()->ConnectToRemoteService( |
37 &geolocation_service_); | 37 &geolocation_service_); |
38 geolocation_service_.set_client(this); | |
39 } | 38 } |
40 if (enable_high_accuracy_) | 39 if (enable_high_accuracy_) |
41 geolocation_service_->SetHighAccuracy(true); | 40 geolocation_service_->SetHighAccuracy(true); |
41 QueryNextPosition(); | |
42 } | 42 } |
43 | 43 |
44 void GeolocationDispatcher::stopUpdating() { | 44 void GeolocationDispatcher::stopUpdating() { |
45 geolocation_service_.reset(); | 45 geolocation_service_.reset(); |
46 } | 46 } |
47 | 47 |
48 void GeolocationDispatcher::setEnableHighAccuracy(bool enable_high_accuracy) { | 48 void GeolocationDispatcher::setEnableHighAccuracy(bool enable_high_accuracy) { |
49 // GeolocationController calls setEnableHighAccuracy(true) before | 49 // GeolocationController calls setEnableHighAccuracy(true) before |
50 // startUpdating in response to the first high-accuracy Geolocation | 50 // startUpdating in response to the first high-accuracy Geolocation |
51 // subscription. When the last high-accuracy Geolocation unsubscribes | 51 // subscription. When the last high-accuracy Geolocation unsubscribes |
52 // it calls setEnableHighAccuracy(false) after stopUpdating. | 52 // it calls setEnableHighAccuracy(false) after stopUpdating. |
53 bool has_changed = enable_high_accuracy_ != enable_high_accuracy; | 53 bool has_changed = enable_high_accuracy_ != enable_high_accuracy; |
54 enable_high_accuracy_ = enable_high_accuracy; | 54 enable_high_accuracy_ = enable_high_accuracy; |
55 // We have a different accuracy requirement. Request browser to update. | 55 // We have a different accuracy requirement. Request browser to update. |
56 if (geolocation_service_.get() && has_changed) | 56 if (geolocation_service_ && has_changed) |
57 geolocation_service_->SetHighAccuracy(enable_high_accuracy_); | 57 geolocation_service_->SetHighAccuracy(enable_high_accuracy_); |
58 } | 58 } |
59 | 59 |
60 void GeolocationDispatcher::setController( | 60 void GeolocationDispatcher::setController( |
61 WebGeolocationController* controller) { | 61 WebGeolocationController* controller) { |
62 controller_.reset(controller); | 62 controller_.reset(controller); |
63 } | 63 } |
64 | 64 |
65 bool GeolocationDispatcher::lastPosition(WebGeolocationPosition&) { | 65 bool GeolocationDispatcher::lastPosition(WebGeolocationPosition&) { |
66 // The latest position is stored in the browser, not the renderer, so we | 66 // The latest position is stored in the browser, not the renderer, so we |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 void GeolocationDispatcher::OnPermissionSet( | 100 void GeolocationDispatcher::OnPermissionSet( |
101 int permission_request_id, | 101 int permission_request_id, |
102 PermissionStatus status) { | 102 PermissionStatus status) { |
103 WebGeolocationPermissionRequest permissionRequest; | 103 WebGeolocationPermissionRequest permissionRequest; |
104 if (!pending_permissions_->remove(permission_request_id, permissionRequest)) | 104 if (!pending_permissions_->remove(permission_request_id, permissionRequest)) |
105 return; | 105 return; |
106 | 106 |
107 permissionRequest.setIsAllowed(status == PERMISSION_STATUS_GRANTED); | 107 permissionRequest.setIsAllowed(status == PERMISSION_STATUS_GRANTED); |
108 } | 108 } |
109 | 109 |
110 void GeolocationDispatcher::OnLocationUpdate(MojoGeopositionPtr geoposition) { | 110 void GeolocationDispatcher::QueryNextPosition() { |
111 DCHECK(geolocation_service_.get()); | 111 DCHECK(geolocation_service_); |
112 geolocation_service_->QueryNextPosition( | |
113 base::Bind(&GeolocationDispatcher::OnPositionUpdate, | |
114 base::Unretained(this))); | |
115 } | |
116 | |
117 void GeolocationDispatcher::OnPositionUpdate(MojoGeopositionPtr geoposition) { | |
118 QueryNextPosition(); | |
blundell
2015/01/09 07:37:26
Nit: I think the code would be more clear by putti
| |
112 | 119 |
113 if (geoposition->valid) { | 120 if (geoposition->valid) { |
114 controller_->positionChanged(WebGeolocationPosition( | 121 controller_->positionChanged(WebGeolocationPosition( |
115 geoposition->timestamp, | 122 geoposition->timestamp, |
116 geoposition->latitude, | 123 geoposition->latitude, |
117 geoposition->longitude, | 124 geoposition->longitude, |
118 geoposition->accuracy, | 125 geoposition->accuracy, |
119 // Lowest point on land is at approximately -400 meters. | 126 // Lowest point on land is at approximately -400 meters. |
120 geoposition->altitude > -10000., | 127 geoposition->altitude > -10000., |
121 geoposition->altitude, | 128 geoposition->altitude, |
(...skipping 15 matching lines...) Expand all Loading... | |
137 default: | 144 default: |
138 NOTREACHED() << geoposition->error_code; | 145 NOTREACHED() << geoposition->error_code; |
139 return; | 146 return; |
140 } | 147 } |
141 controller_->errorOccurred(WebGeolocationError( | 148 controller_->errorOccurred(WebGeolocationError( |
142 code, blink::WebString::fromUTF8(geoposition->error_message))); | 149 code, blink::WebString::fromUTF8(geoposition->error_message))); |
143 } | 150 } |
144 } | 151 } |
145 | 152 |
146 } // namespace content | 153 } // namespace content |
OLD | NEW |