| 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/browser/geolocation/geolocation_dispatcher_host.h" | 5 #include "content/browser/geolocation/geolocation_dispatcher_host.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 UMA_HISTOGRAM_ENUMERATION("Geolocation.LocationUpdate.ErrorCode", | 62 UMA_HISTOGRAM_ENUMERATION("Geolocation.LocationUpdate.ErrorCode", |
| 63 code, | 63 code, |
| 64 GEOPOSITION_ERROR_CODE_COUNT); | 64 GEOPOSITION_ERROR_CODE_COUNT); |
| 65 } | 65 } |
| 66 | 66 |
| 67 } // namespace | 67 } // namespace |
| 68 | 68 |
| 69 GeolocationDispatcherHost::PendingPermission::PendingPermission( | 69 GeolocationDispatcherHost::PendingPermission::PendingPermission( |
| 70 int render_frame_id, | 70 int render_frame_id, |
| 71 int render_process_id, | 71 int render_process_id, |
| 72 int bridge_id) | 72 int bridge_id, |
| 73 const GURL& origin) |
| 73 : render_frame_id(render_frame_id), | 74 : render_frame_id(render_frame_id), |
| 74 render_process_id(render_process_id), | 75 render_process_id(render_process_id), |
| 75 bridge_id(bridge_id) { | 76 bridge_id(bridge_id), |
| 77 origin(origin) { |
| 76 } | 78 } |
| 77 | 79 |
| 78 GeolocationDispatcherHost::PendingPermission::~PendingPermission() { | 80 GeolocationDispatcherHost::PendingPermission::~PendingPermission() { |
| 79 } | 81 } |
| 80 | 82 |
| 81 GeolocationDispatcherHost::GeolocationDispatcherHost( | 83 GeolocationDispatcherHost::GeolocationDispatcherHost( |
| 82 WebContents* web_contents) | 84 WebContents* web_contents) |
| 83 : WebContentsObserver(web_contents), | 85 : WebContentsObserver(web_contents), |
| 84 paused_(false), | 86 paused_(false), |
| 85 weak_factory_(this) { | 87 weak_factory_(this) { |
| 86 // This is initialized by WebContentsImpl. Do not add any non-trivial | 88 // This is initialized by WebContentsImpl. Do not add any non-trivial |
| 87 // initialization here, defer to OnStartUpdating which is triggered whenever | 89 // initialization here, defer to OnStartUpdating which is triggered whenever |
| 88 // a javascript geolocation object is actually initialized. | 90 // a javascript geolocation object is actually initialized. |
| 89 } | 91 } |
| 90 | 92 |
| 91 GeolocationDispatcherHost::~GeolocationDispatcherHost() { | 93 GeolocationDispatcherHost::~GeolocationDispatcherHost() { |
| 92 } | 94 } |
| 93 | 95 |
| 94 void GeolocationDispatcherHost::RenderFrameDeleted( | 96 void GeolocationDispatcherHost::RenderFrameDeleted( |
| 95 RenderFrameHost* render_frame_host) { | 97 RenderFrameHost* render_frame_host) { |
| 96 OnStopUpdating(render_frame_host); | 98 OnStopUpdating(render_frame_host); |
| 99 |
| 100 CancelPermissionRequestsForFrame(render_frame_host); |
| 97 } | 101 } |
| 98 | 102 |
| 99 void GeolocationDispatcherHost::RenderViewHostChanged( | 103 void GeolocationDispatcherHost::RenderViewHostChanged( |
| 100 RenderViewHost* old_host, | 104 RenderViewHost* old_host, |
| 101 RenderViewHost* new_host) { | 105 RenderViewHost* new_host) { |
| 102 updating_frames_.clear(); | 106 updating_frames_.clear(); |
| 103 paused_ = false; | 107 paused_ = false; |
| 104 geolocation_subscription_.reset(); | 108 geolocation_subscription_.reset(); |
| 105 } | 109 } |
| 106 | 110 |
| 111 void GeolocationDispatcherHost::DidNavigateAnyFrame( |
| 112 RenderFrameHost* render_frame_host, |
| 113 const LoadCommittedDetails& details, |
| 114 const FrameNavigateParams& params) { |
| 115 if (details.is_in_page) |
| 116 return; |
| 117 |
| 118 CancelPermissionRequestsForFrame(render_frame_host); |
| 119 } |
| 120 |
| 107 bool GeolocationDispatcherHost::OnMessageReceived( | 121 bool GeolocationDispatcherHost::OnMessageReceived( |
| 108 const IPC::Message& msg, RenderFrameHost* render_frame_host) { | 122 const IPC::Message& msg, RenderFrameHost* render_frame_host) { |
| 109 bool handled = true; | 123 bool handled = true; |
| 110 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(GeolocationDispatcherHost, msg, | 124 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(GeolocationDispatcherHost, msg, |
| 111 render_frame_host) | 125 render_frame_host) |
| 112 IPC_MESSAGE_HANDLER(GeolocationHostMsg_RequestPermission, | 126 IPC_MESSAGE_HANDLER(GeolocationHostMsg_RequestPermission, |
| 113 OnRequestPermission) | 127 OnRequestPermission) |
| 114 IPC_MESSAGE_HANDLER(GeolocationHostMsg_CancelPermissionRequest, | |
| 115 OnCancelPermissionRequest) | |
| 116 IPC_MESSAGE_HANDLER(GeolocationHostMsg_StartUpdating, OnStartUpdating) | 128 IPC_MESSAGE_HANDLER(GeolocationHostMsg_StartUpdating, OnStartUpdating) |
| 117 IPC_MESSAGE_HANDLER(GeolocationHostMsg_StopUpdating, OnStopUpdating) | 129 IPC_MESSAGE_HANDLER(GeolocationHostMsg_StopUpdating, OnStopUpdating) |
| 118 IPC_MESSAGE_UNHANDLED(handled = false) | 130 IPC_MESSAGE_UNHANDLED(handled = false) |
| 119 IPC_END_MESSAGE_MAP() | 131 IPC_END_MESSAGE_MAP() |
| 120 return handled; | 132 return handled; |
| 121 } | 133 } |
| 122 | 134 |
| 123 void GeolocationDispatcherHost::OnLocationUpdate( | 135 void GeolocationDispatcherHost::OnLocationUpdate( |
| 124 const Geoposition& geoposition) { | 136 const Geoposition& geoposition) { |
| 125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 140 top_frame->GetLastCommittedURL().GetOrigin()); | 152 top_frame->GetLastCommittedURL().GetOrigin()); |
| 141 | 153 |
| 142 i->first->Send(new GeolocationMsg_PositionUpdated( | 154 i->first->Send(new GeolocationMsg_PositionUpdated( |
| 143 i->first->GetRoutingID(), geoposition)); | 155 i->first->GetRoutingID(), geoposition)); |
| 144 } | 156 } |
| 145 } | 157 } |
| 146 | 158 |
| 147 void GeolocationDispatcherHost::OnRequestPermission( | 159 void GeolocationDispatcherHost::OnRequestPermission( |
| 148 RenderFrameHost* render_frame_host, | 160 RenderFrameHost* render_frame_host, |
| 149 int bridge_id, | 161 int bridge_id, |
| 150 const GURL& requesting_frame, | 162 const GURL& requesting_origin, |
| 151 bool user_gesture) { | 163 bool user_gesture) { |
| 152 int render_process_id = render_frame_host->GetProcess()->GetID(); | 164 int render_process_id = render_frame_host->GetProcess()->GetID(); |
| 153 int render_frame_id = render_frame_host->GetRoutingID(); | 165 int render_frame_id = render_frame_host->GetRoutingID(); |
| 154 | 166 |
| 155 PendingPermission pending_permission( | 167 PendingPermission pending_permission( |
| 156 render_frame_id, render_process_id, bridge_id); | 168 render_frame_id, render_process_id, bridge_id, requesting_origin); |
| 157 pending_permissions_.push_back(pending_permission); | 169 pending_permissions_.push_back(pending_permission); |
| 158 | 170 |
| 159 GetContentClient()->browser()->RequestGeolocationPermission( | 171 GetContentClient()->browser()->RequestGeolocationPermission( |
| 160 web_contents(), | 172 web_contents(), |
| 161 bridge_id, | 173 bridge_id, |
| 162 requesting_frame, | 174 requesting_origin, |
| 163 user_gesture, | 175 user_gesture, |
| 164 base::Bind(&GeolocationDispatcherHost::SendGeolocationPermissionResponse, | 176 base::Bind(&GeolocationDispatcherHost::SendGeolocationPermissionResponse, |
| 165 weak_factory_.GetWeakPtr(), | 177 weak_factory_.GetWeakPtr(), |
| 166 render_process_id, render_frame_id, bridge_id)); | 178 render_process_id, render_frame_id, bridge_id)); |
| 167 } | 179 } |
| 168 | 180 |
| 169 void GeolocationDispatcherHost::OnCancelPermissionRequest( | |
| 170 RenderFrameHost* render_frame_host, | |
| 171 int bridge_id, | |
| 172 const GURL& requesting_frame) { | |
| 173 int render_process_id = render_frame_host->GetProcess()->GetID(); | |
| 174 int render_frame_id = render_frame_host->GetRoutingID(); | |
| 175 for (size_t i = 0; i < pending_permissions_.size(); ++i) { | |
| 176 if (pending_permissions_[i].render_process_id == render_process_id && | |
| 177 pending_permissions_[i].render_frame_id == render_frame_id && | |
| 178 pending_permissions_[i].bridge_id == bridge_id) { | |
| 179 GetContentClient()->browser()->CancelGeolocationPermissionRequest( | |
| 180 web_contents(), bridge_id, requesting_frame); | |
| 181 | |
| 182 pending_permissions_.erase(pending_permissions_.begin() + i); | |
| 183 return; | |
| 184 } | |
| 185 } | |
| 186 } | |
| 187 | |
| 188 void GeolocationDispatcherHost::OnStartUpdating( | 181 void GeolocationDispatcherHost::OnStartUpdating( |
| 189 RenderFrameHost* render_frame_host, | 182 RenderFrameHost* render_frame_host, |
| 190 const GURL& requesting_frame, | 183 const GURL& requesting_origin, |
| 191 bool enable_high_accuracy) { | 184 bool enable_high_accuracy) { |
| 192 // StartUpdating() can be invoked as a result of high-accuracy mode | 185 // StartUpdating() can be invoked as a result of high-accuracy mode |
| 193 // being enabled / disabled. No need to record the dispatcher again. | 186 // being enabled / disabled. No need to record the dispatcher again. |
| 194 UMA_HISTOGRAM_BOOLEAN( | 187 UMA_HISTOGRAM_BOOLEAN( |
| 195 "Geolocation.GeolocationDispatcherHostImpl.EnableHighAccuracy", | 188 "Geolocation.GeolocationDispatcherHostImpl.EnableHighAccuracy", |
| 196 enable_high_accuracy); | 189 enable_high_accuracy); |
| 197 | 190 |
| 198 updating_frames_[render_frame_host] = enable_high_accuracy; | 191 updating_frames_[render_frame_host] = enable_high_accuracy; |
| 199 RefreshGeolocationOptions(); | 192 RefreshGeolocationOptions(); |
| 200 } | 193 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 } | 249 } |
| 257 | 250 |
| 258 pending_permissions_.erase(pending_permissions_.begin() + i); | 251 pending_permissions_.erase(pending_permissions_.begin() + i); |
| 259 return; | 252 return; |
| 260 } | 253 } |
| 261 } | 254 } |
| 262 | 255 |
| 263 NOTREACHED(); | 256 NOTREACHED(); |
| 264 } | 257 } |
| 265 | 258 |
| 259 void GeolocationDispatcherHost::CancelPermissionRequestsForFrame( |
| 260 RenderFrameHost* render_frame_host) { |
| 261 int render_process_id = render_frame_host->GetProcess()->GetID(); |
| 262 int render_frame_id = render_frame_host->GetRoutingID(); |
| 263 |
| 264 for (size_t i = 0; i < pending_permissions_.size(); ++i) { |
| 265 if (pending_permissions_[i].render_process_id == render_process_id && |
| 266 pending_permissions_[i].render_frame_id == render_frame_id) { |
| 267 GetContentClient()->browser()->CancelGeolocationPermissionRequest( |
| 268 web_contents(), |
| 269 pending_permissions_[i].bridge_id, |
| 270 pending_permissions_[i].origin); |
| 271 pending_permissions_.erase(pending_permissions_.begin() + i); |
| 272 } |
| 273 } |
| 274 } |
| 275 |
| 266 } // namespace content | 276 } // namespace content |
| OLD | NEW |