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/Source/WebKit/chromium/public/WebGeolocationPermiss
ionRequest.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebGeolocationPermiss
ionRequest.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebGeolocationPermiss
ionRequestManager.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebGeolocationPermiss
ionRequestManager.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebGeolocationClient.
h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebGeolocationClient.
h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebGeolocationPositio
n.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebGeolocationPositio
n.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebGeolocationError.h
" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebGeolocationError.h
" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
16 | 16 |
17 using WebKit::WebGeolocationController; | 17 using WebKit::WebGeolocationController; |
18 using WebKit::WebGeolocationError; | 18 using WebKit::WebGeolocationError; |
19 using WebKit::WebGeolocationPermissionRequest; | 19 using WebKit::WebGeolocationPermissionRequest; |
20 using WebKit::WebGeolocationPermissionRequestManager; | 20 using WebKit::WebGeolocationPermissionRequestManager; |
21 using WebKit::WebGeolocationPosition; | 21 using WebKit::WebGeolocationPosition; |
22 | 22 |
| 23 namespace content { |
| 24 |
23 GeolocationDispatcher::GeolocationDispatcher(RenderViewImpl* render_view) | 25 GeolocationDispatcher::GeolocationDispatcher(RenderViewImpl* render_view) |
24 : content::RenderViewObserver(render_view), | 26 : RenderViewObserver(render_view), |
25 pending_permissions_(new WebGeolocationPermissionRequestManager()), | 27 pending_permissions_(new WebGeolocationPermissionRequestManager()), |
26 enable_high_accuracy_(false), | 28 enable_high_accuracy_(false), |
27 updating_(false) { | 29 updating_(false) { |
28 } | 30 } |
29 | 31 |
30 GeolocationDispatcher::~GeolocationDispatcher() {} | 32 GeolocationDispatcher::~GeolocationDispatcher() {} |
31 | 33 |
32 bool GeolocationDispatcher::OnMessageReceived(const IPC::Message& message) { | 34 bool GeolocationDispatcher::OnMessageReceived(const IPC::Message& message) { |
33 bool handled = true; | 35 bool handled = true; |
34 IPC_BEGIN_MESSAGE_MAP(GeolocationDispatcher, message) | 36 IPC_BEGIN_MESSAGE_MAP(GeolocationDispatcher, message) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 // Permission for using geolocation has been set. | 108 // Permission for using geolocation has been set. |
107 void GeolocationDispatcher::OnPermissionSet(int bridge_id, bool is_allowed) { | 109 void GeolocationDispatcher::OnPermissionSet(int bridge_id, bool is_allowed) { |
108 WebGeolocationPermissionRequest permissionRequest; | 110 WebGeolocationPermissionRequest permissionRequest; |
109 if (!pending_permissions_->remove(bridge_id, permissionRequest)) | 111 if (!pending_permissions_->remove(bridge_id, permissionRequest)) |
110 return; | 112 return; |
111 permissionRequest.setIsAllowed(is_allowed); | 113 permissionRequest.setIsAllowed(is_allowed); |
112 } | 114 } |
113 | 115 |
114 // We have an updated geolocation position or error code. | 116 // We have an updated geolocation position or error code. |
115 void GeolocationDispatcher::OnPositionUpdated( | 117 void GeolocationDispatcher::OnPositionUpdated( |
116 const content::Geoposition& geoposition) { | 118 const Geoposition& geoposition) { |
117 // It is possible for the browser process to have queued an update message | 119 // It is possible for the browser process to have queued an update message |
118 // before receiving the stop updating message. | 120 // before receiving the stop updating message. |
119 if (!updating_) | 121 if (!updating_) |
120 return; | 122 return; |
121 | 123 |
122 if (geoposition.Validate()) { | 124 if (geoposition.Validate()) { |
123 controller_->positionChanged( | 125 controller_->positionChanged( |
124 WebGeolocationPosition( | 126 WebGeolocationPosition( |
125 geoposition.timestamp.ToDoubleT(), | 127 geoposition.timestamp.ToDoubleT(), |
126 geoposition.latitude, geoposition.longitude, | 128 geoposition.latitude, geoposition.longitude, |
127 geoposition.accuracy, | 129 geoposition.accuracy, |
128 // Lowest point on land is at approximately -400 meters. | 130 // Lowest point on land is at approximately -400 meters. |
129 geoposition.altitude > -10000., | 131 geoposition.altitude > -10000., |
130 geoposition.altitude, | 132 geoposition.altitude, |
131 geoposition.altitude_accuracy >= 0., | 133 geoposition.altitude_accuracy >= 0., |
132 geoposition.altitude_accuracy, | 134 geoposition.altitude_accuracy, |
133 geoposition.heading >= 0. && geoposition.heading <= 360., | 135 geoposition.heading >= 0. && geoposition.heading <= 360., |
134 geoposition.heading, | 136 geoposition.heading, |
135 geoposition.speed >= 0., | 137 geoposition.speed >= 0., |
136 geoposition.speed)); | 138 geoposition.speed)); |
137 } else { | 139 } else { |
138 WebGeolocationError::Error code; | 140 WebGeolocationError::Error code; |
139 switch (geoposition.error_code) { | 141 switch (geoposition.error_code) { |
140 case content::Geoposition::ERROR_CODE_PERMISSION_DENIED: | 142 case Geoposition::ERROR_CODE_PERMISSION_DENIED: |
141 code = WebGeolocationError::ErrorPermissionDenied; | 143 code = WebGeolocationError::ErrorPermissionDenied; |
142 break; | 144 break; |
143 case content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE: | 145 case Geoposition::ERROR_CODE_POSITION_UNAVAILABLE: |
144 code = WebGeolocationError::ErrorPositionUnavailable; | 146 code = WebGeolocationError::ErrorPositionUnavailable; |
145 break; | 147 break; |
146 default: | 148 default: |
147 NOTREACHED() << geoposition.error_code; | 149 NOTREACHED() << geoposition.error_code; |
148 return; | 150 return; |
149 } | 151 } |
150 controller_->errorOccurred( | 152 controller_->errorOccurred( |
151 WebGeolocationError( | 153 WebGeolocationError( |
152 code, WebKit::WebString::fromUTF8(geoposition.error_message))); | 154 code, WebKit::WebString::fromUTF8(geoposition.error_message))); |
153 } | 155 } |
154 } | 156 } |
| 157 |
| 158 } // namespace content |
OLD | NEW |