Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #if defined(ENABLE_CLIENT_BASED_GEOLOCATION) | |
| 6 | |
| 7 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationPermissionRequ est.h" | |
| 8 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationPermissionRequ estContainer.h" | |
| 9 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationClient.h" | |
| 10 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationPosition.h" | |
| 11 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationError.h" | |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" | |
| 13 #include "chrome/renderer/geolocation_dispatcher.h" | |
|
joth
2010/12/07 10:24:51
alpha order
| |
| 14 #include "chrome/renderer/render_view.h" | |
| 15 #include "ipc/ipc_message.h" | |
| 16 | |
| 17 using namespace WebKit; | |
| 18 | |
| 19 GeolocationDispatcher::GeolocationDispatcher(RenderView* render_view) | |
| 20 : render_view_(render_view), | |
| 21 pending_permissions_(new WebGeolocationPermissionRequestContainer), | |
|
bulach
2010/12/07 11:18:42
we normally add "()", as new Foo()
| |
| 22 enable_high_accuracy_(false), | |
| 23 updating_(false) | |
| 24 { | |
|
joth
2010/12/07 10:24:51
move { to previous line
| |
| 25 } | |
| 26 | |
| 27 GeolocationDispatcher::~GeolocationDispatcher() | |
| 28 { | |
| 29 } | |
|
joth
2010/12/07 10:24:51
you are allowed to do this all on one line:
Foo::~
| |
| 30 | |
| 31 bool GeolocationDispatcher::OnMessageReceived(const IPC::Message& message) { | |
| 32 bool handled = true; | |
| 33 IPC_BEGIN_MESSAGE_MAP(GeolocationDispatcher, message) | |
| 34 IPC_MESSAGE_HANDLER(ViewMsg_Geolocation_PermissionSet, | |
| 35 OnGeolocationPermissionSet) | |
| 36 IPC_MESSAGE_HANDLER(ViewMsg_Geolocation_PositionUpdated, | |
| 37 OnGeolocationPositionUpdated) | |
| 38 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 39 IPC_END_MESSAGE_MAP() | |
| 40 return handled; | |
| 41 } | |
| 42 | |
| 43 void GeolocationDispatcher::geolocationDestroyed() { | |
| 44 controller_.reset(); | |
| 45 DCHECK(!updating_); | |
| 46 } | |
| 47 | |
| 48 void GeolocationDispatcher::startUpdating() { | |
| 49 // TODO(jknotten): Remove url and bridge_id from StartUpdating message | |
| 50 GURL url; | |
| 51 render_view_->Send(new ViewHostMsg_Geolocation_StartUpdating( | |
| 52 render_view_->routing_id(), -1, url, enable_high_accuracy_)); | |
| 53 updating_ = true; | |
| 54 } | |
| 55 | |
| 56 void GeolocationDispatcher::stopUpdating() { | |
| 57 // TODO(jknotten): Remove url and bridge_id from StartUpdating message | |
|
bulach
2010/12/07 11:18:42
nit: StopUpdating message
| |
| 58 render_view_->Send(new ViewHostMsg_Geolocation_StopUpdating( | |
| 59 render_view_->routing_id(), -1)); | |
| 60 updating_ = false; | |
| 61 } | |
| 62 | |
| 63 void GeolocationDispatcher::setEnableHighAccuracy(bool enable_high_accuracy) { | |
| 64 enable_high_accuracy_ = enable_high_accuracy; | |
|
joth
2010/12/07 10:24:51
do we not need to send IPC to the GeolocationDispa
joth
2010/12/08 10:47:40
ping
John Knottenbelt
2010/12/08 12:28:34
Sorry, missed this one. We don't need to send an I
joth
2010/12/08 12:54:29
what if there are still low-accuracy subscriber wh
| |
| 65 } | |
| 66 | |
| 67 void GeolocationDispatcher::setController( | |
| 68 const WebGeolocationController& controller) { | |
| 69 controller_ = controller; | |
|
joth
2010/12/07 10:24:51
this does a deep copy which feels a bit funky as n
| |
| 70 } | |
| 71 | |
| 72 bool GeolocationDispatcher::lastPosition(WebGeolocationPosition&) { | |
| 73 return false; | |
|
joth
2010/12/07 10:24:51
maybe comment why? (we don't want to fetch it sync
| |
| 74 } | |
| 75 | |
| 76 // TODO(jknotten): Change the messages to use a security origin, so no | |
| 77 // conversion is necessary. | |
| 78 void GeolocationDispatcher::requestPermission( | |
| 79 const WebGeolocationPermissionRequest& permissionRequest) { | |
| 80 int bridge_id = pending_permissions_->add(permissionRequest); | |
| 81 GURL url(static_cast<string16>( | |
| 82 permissionRequest.securityOrigin().toString())); | |
|
joth
2010/12/07 10:24:51
this cast looks suspect. ah I see you're forcing i
John Knottenbelt
2010/12/07 12:30:04
Done.
| |
| 83 render_view_->Send(new ViewHostMsg_Geolocation_RequestPermission( | |
| 84 render_view_->routing_id(), bridge_id, GURL(url))); | |
|
joth
2010/12/07 10:24:51
nit: no need for the GURL() around url (modulo my
John Knottenbelt
2010/12/07 12:30:04
Done.
| |
| 85 } | |
| 86 | |
| 87 // TODO(jknotten): Change the messages to use a security origin, so no | |
| 88 // conversion is necessary. | |
| 89 void GeolocationDispatcher::cancelPermissionRequest( | |
| 90 const WebGeolocationPermissionRequest& permissionRequest) { | |
| 91 int bridge_id; | |
| 92 if (!pending_permissions_->remove(permissionRequest, bridge_id)) | |
| 93 return; | |
| 94 GURL url(static_cast<string16>( | |
| 95 permissionRequest.securityOrigin().toString())); | |
| 96 render_view_->Send(new ViewHostMsg_Geolocation_CancelPermissionRequest( | |
| 97 render_view_->routing_id(), bridge_id, GURL(url))); | |
|
joth
2010/12/07 10:24:51
dittos
John Knottenbelt
2010/12/07 12:30:04
Done.
| |
| 98 } | |
| 99 | |
| 100 // Permission for using geolocation has been set. | |
| 101 void GeolocationDispatcher::OnGeolocationPermissionSet( | |
| 102 int bridge_id, bool is_allowed) { | |
| 103 WebGeolocationPermissionRequest permissionRequest; | |
| 104 if (!pending_permissions_->remove(bridge_id, permissionRequest)) | |
| 105 return; | |
| 106 permissionRequest.setIsAllowed(is_allowed); | |
| 107 } | |
| 108 | |
| 109 // We have an updated geolocation position or error code. | |
| 110 void GeolocationDispatcher::OnGeolocationPositionUpdated( | |
| 111 const Geoposition& geoposition) { | |
| 112 DCHECK(updating_); | |
|
joth
2010/12/07 10:24:51
suggest adding
DCHECK(geoposition.IsInitialized())
John Knottenbelt
2010/12/07 12:30:04
Done.
| |
| 113 if (geoposition.IsValidFix()) { | |
| 114 controller_.positionChanged( | |
| 115 WebGeolocationPosition( | |
| 116 static_cast<int64>(geoposition.timestamp.ToDoubleT() * 1000), | |
| 117 geoposition.latitude, geoposition.longitude, | |
| 118 geoposition.accuracy, | |
| 119 geoposition.is_valid_altitude(), geoposition.altitude, | |
| 120 geoposition.is_valid_altitude_accuracy(), | |
| 121 geoposition.altitude_accuracy, | |
| 122 geoposition.is_valid_heading(), geoposition.heading, | |
| 123 geoposition.is_valid_speed(), geoposition.speed)); | |
| 124 } else { | |
| 125 WebGeolocationError::Error code; | |
| 126 switch (geoposition.error_code) { | |
| 127 case Geoposition::ERROR_CODE_PERMISSION_DENIED: | |
| 128 code = WebGeolocationError::ErrorPermissionDenied; | |
| 129 break; | |
| 130 case Geoposition::ERROR_CODE_POSITION_UNAVAILABLE: | |
| 131 code = WebGeolocationError::ErrorPositionUnavailable; | |
| 132 break; | |
| 133 default: | |
| 134 DCHECK(false); | |
|
joth
2010/12/07 10:24:51
NOTREACHED() << geoposition.error_code;
joth
2010/12/08 10:47:40
ping
John Knottenbelt
2010/12/08 12:28:34
Done.
| |
| 135 } | |
| 136 controller_.errorOccurred( | |
| 137 WebGeolocationError( | |
| 138 code, WebKit::WebString::fromUTF8(geoposition.error_message))); | |
| 139 } | |
| 140 } | |
| 141 | |
| 142 #endif // CLIENT_BASED_GEOLOCATION | |
| OLD | NEW |