| 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 #include "chrome/renderer/geolocation_dispatcher_old.h" | |
| 7 #include "base/command_line.h" | |
| 8 #include "chrome/common/chrome_switches.h" | |
| 9 #include "chrome/renderer/render_view.h" | |
| 10 #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" | |
| 11 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationServiceBridge.
h" | |
| 13 | |
| 14 using WebKit::WebFrame; | |
| 15 | |
| 16 GeolocationDispatcherOld::GeolocationDispatcherOld(RenderView* render_view) | |
| 17 : render_view_(render_view) { | |
| 18 render_view_->Send(new ViewHostMsg_Geolocation_RegisterDispatcher( | |
| 19 render_view_->routing_id())); | |
| 20 } | |
| 21 | |
| 22 GeolocationDispatcherOld::~GeolocationDispatcherOld() { | |
| 23 for (IDMap<WebKit::WebGeolocationServiceBridge>::iterator it(&bridges_map_); | |
| 24 !it.IsAtEnd(); it.Advance()) { | |
| 25 it.GetCurrentValue()->onWebGeolocationServiceDestroyed(); | |
| 26 } | |
| 27 render_view_->Send(new ViewHostMsg_Geolocation_UnregisterDispatcher( | |
| 28 render_view_->routing_id())); | |
| 29 } | |
| 30 | |
| 31 bool GeolocationDispatcherOld::OnMessageReceived(const IPC::Message& message) { | |
| 32 bool handled = true; | |
| 33 IPC_BEGIN_MESSAGE_MAP(GeolocationDispatcherOld, 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 GeolocationDispatcherOld::requestPermissionForFrame( | |
| 44 int bridge_id, const WebKit::WebURL& url) { | |
| 45 render_view_->Send(new ViewHostMsg_Geolocation_RequestPermission( | |
| 46 render_view_->routing_id(), bridge_id, GURL(url))); | |
| 47 } | |
| 48 | |
| 49 void GeolocationDispatcherOld::cancelPermissionRequestForFrame( | |
| 50 int bridge_id, const WebKit::WebURL& url) { | |
| 51 render_view_->Send(new ViewHostMsg_Geolocation_CancelPermissionRequest( | |
| 52 render_view_->routing_id(), bridge_id, GURL(url))); | |
| 53 } | |
| 54 | |
| 55 void GeolocationDispatcherOld::startUpdating( | |
| 56 int bridge_id, const WebKit::WebURL& url, bool enableHighAccuracy) { | |
| 57 render_view_->Send(new ViewHostMsg_Geolocation_StartUpdating( | |
| 58 render_view_->routing_id(), bridge_id, GURL(url), | |
| 59 enableHighAccuracy)); | |
| 60 } | |
| 61 | |
| 62 void GeolocationDispatcherOld::stopUpdating(int bridge_id) { | |
| 63 render_view_->Send(new ViewHostMsg_Geolocation_StopUpdating( | |
| 64 render_view_->routing_id(), bridge_id)); | |
| 65 } | |
| 66 | |
| 67 void GeolocationDispatcherOld::suspend(int bridge_id) { | |
| 68 render_view_->Send(new ViewHostMsg_Geolocation_Suspend( | |
| 69 render_view_->routing_id(), bridge_id)); | |
| 70 } | |
| 71 | |
| 72 void GeolocationDispatcherOld::resume(int bridge_id) { | |
| 73 render_view_->Send(new ViewHostMsg_Geolocation_Resume( | |
| 74 render_view_->routing_id(), bridge_id)); | |
| 75 } | |
| 76 | |
| 77 int GeolocationDispatcherOld::attachBridge( | |
| 78 WebKit::WebGeolocationServiceBridge* bridge) { | |
| 79 return bridges_map_.Add(bridge); | |
| 80 } | |
| 81 | |
| 82 void GeolocationDispatcherOld::detachBridge(int bridge_id) { | |
| 83 bridges_map_.Remove(bridge_id); | |
| 84 } | |
| 85 | |
| 86 void GeolocationDispatcherOld::OnGeolocationPermissionSet(int bridge_id, | |
| 87 bool allowed) { | |
| 88 WebKit::WebGeolocationServiceBridge* bridge = bridges_map_.Lookup(bridge_id); | |
| 89 if (bridge) { | |
| 90 bridge->setIsAllowed(allowed); | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 void GeolocationDispatcherOld::OnGeolocationPositionUpdated( | |
| 95 const Geoposition& geoposition) { | |
| 96 DCHECK(geoposition.IsInitialized()); | |
| 97 for (IDMap<WebKit::WebGeolocationServiceBridge>::iterator it(&bridges_map_); | |
| 98 !it.IsAtEnd(); it.Advance()) { | |
| 99 if (geoposition.IsValidFix()) { | |
| 100 it.GetCurrentValue()->setLastPosition( | |
| 101 geoposition.latitude, geoposition.longitude, | |
| 102 geoposition.is_valid_altitude(), geoposition.altitude, | |
| 103 geoposition.accuracy, | |
| 104 geoposition.is_valid_altitude_accuracy(), | |
| 105 geoposition.altitude_accuracy, | |
| 106 geoposition.is_valid_heading(), geoposition.heading, | |
| 107 geoposition.is_valid_speed(), geoposition.speed, | |
| 108 static_cast<int64>(geoposition.timestamp.ToDoubleT() * 1000)); | |
| 109 } else { | |
| 110 it.GetCurrentValue()->setLastError( | |
| 111 geoposition.error_code, | |
| 112 WebKit::WebString::fromUTF8(geoposition.error_message)); | |
| 113 } | |
| 114 } | |
| 115 } | |
| 116 #endif // !ENABLE_CLIENT_BASED_GEOLOCATION | |
| OLD | NEW |