| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 int render_process_id, | 71 int render_process_id, |
| 72 int bridge_id) | 72 int bridge_id) |
| 73 : render_frame_id(render_frame_id), | 73 : render_frame_id(render_frame_id), |
| 74 render_process_id(render_process_id), | 74 render_process_id(render_process_id), |
| 75 bridge_id(bridge_id) { | 75 bridge_id(bridge_id) { |
| 76 } | 76 } |
| 77 | 77 |
| 78 GeolocationDispatcherHost::PendingPermission::~PendingPermission() { | 78 GeolocationDispatcherHost::PendingPermission::~PendingPermission() { |
| 79 } | 79 } |
| 80 | 80 |
| 81 GeolocationDispatcherHost::GeolocationDispatcherHost( | 81 GeolocationDispatcherHost::GeolocationDispatcherHost(WebContents* web_contents) |
| 82 WebContents* web_contents) | |
| 83 : WebContentsObserver(web_contents), | 82 : WebContentsObserver(web_contents), |
| 84 paused_(false), | 83 paused_(false), |
| 84 geolocationPrecision_(-1), |
| 85 weak_factory_(this) { | 85 weak_factory_(this) { |
| 86 // This is initialized by WebContentsImpl. Do not add any non-trivial | 86 // This is initialized by WebContentsImpl. Do not add any non-trivial |
| 87 // initialization here, defer to OnStartUpdating which is triggered whenever | 87 // initialization here, defer to OnStartUpdating which is triggered whenever |
| 88 // a javascript geolocation object is actually initialized. | 88 // a javascript geolocation object is actually initialized. |
| 89 } | 89 } |
| 90 | 90 |
| 91 GeolocationDispatcherHost::~GeolocationDispatcherHost() { | 91 GeolocationDispatcherHost::~GeolocationDispatcherHost() { |
| 92 } | 92 } |
| 93 | 93 |
| 94 void GeolocationDispatcherHost::RenderFrameDeleted( | 94 void GeolocationDispatcherHost::RenderFrameDeleted( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 RenderFrameHost* top_frame = i->first; | 133 RenderFrameHost* top_frame = i->first; |
| 134 while (top_frame->GetParent()) { | 134 while (top_frame->GetParent()) { |
| 135 top_frame = top_frame->GetParent(); | 135 top_frame = top_frame->GetParent(); |
| 136 } | 136 } |
| 137 GetContentClient()->browser()->DidUseGeolocationPermission( | 137 GetContentClient()->browser()->DidUseGeolocationPermission( |
| 138 web_contents(), | 138 web_contents(), |
| 139 i->first->GetLastCommittedURL().GetOrigin(), | 139 i->first->GetLastCommittedURL().GetOrigin(), |
| 140 top_frame->GetLastCommittedURL().GetOrigin()); | 140 top_frame->GetLastCommittedURL().GetOrigin()); |
| 141 | 141 |
| 142 i->first->Send(new GeolocationMsg_PositionUpdated( | 142 i->first->Send(new GeolocationMsg_PositionUpdated( |
| 143 i->first->GetRoutingID(), geoposition)); | 143 i->first->GetRoutingID(), |
| 144 Geoposition::ApplyPrecision(geoposition, geolocationPrecision_))); |
| 144 } | 145 } |
| 145 } | 146 } |
| 146 | 147 |
| 147 void GeolocationDispatcherHost::OnRequestPermission( | 148 void GeolocationDispatcherHost::OnRequestPermission( |
| 148 RenderFrameHost* render_frame_host, | 149 RenderFrameHost* render_frame_host, |
| 149 int bridge_id, | 150 int bridge_id, |
| 150 const GURL& requesting_frame, | 151 const GURL& requesting_frame, |
| 151 bool user_gesture) { | 152 bool user_gesture) { |
| 152 int render_process_id = render_frame_host->GetProcess()->GetID(); | 153 int render_process_id = render_frame_host->GetProcess()->GetID(); |
| 153 int render_frame_id = render_frame_host->GetRoutingID(); | 154 int render_frame_id = render_frame_host->GetRoutingID(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 AddLocationUpdateCallback( | 232 AddLocationUpdateCallback( |
| 232 base::Bind(&GeolocationDispatcherHost::OnLocationUpdate, | 233 base::Bind(&GeolocationDispatcherHost::OnLocationUpdate, |
| 233 base::Unretained(this)), | 234 base::Unretained(this)), |
| 234 high_accuracy); | 235 high_accuracy); |
| 235 } | 236 } |
| 236 | 237 |
| 237 void GeolocationDispatcherHost::SendGeolocationPermissionResponse( | 238 void GeolocationDispatcherHost::SendGeolocationPermissionResponse( |
| 238 int render_process_id, | 239 int render_process_id, |
| 239 int render_frame_id, | 240 int render_frame_id, |
| 240 int bridge_id, | 241 int bridge_id, |
| 242 int choice, |
| 241 bool allowed) { | 243 bool allowed) { |
| 242 for (size_t i = 0; i < pending_permissions_.size(); ++i) { | 244 for (size_t i = 0; i < pending_permissions_.size(); ++i) { |
| 243 if (pending_permissions_[i].render_process_id == render_process_id && | 245 if (pending_permissions_[i].render_process_id == render_process_id && |
| 244 pending_permissions_[i].render_frame_id == render_frame_id && | 246 pending_permissions_[i].render_frame_id == render_frame_id && |
| 245 pending_permissions_[i].bridge_id == bridge_id) { | 247 pending_permissions_[i].bridge_id == bridge_id) { |
| 246 RenderFrameHost* render_frame_host = | 248 RenderFrameHost* render_frame_host = |
| 247 RenderFrameHost::FromID(render_process_id, render_frame_id); | 249 RenderFrameHost::FromID(render_process_id, render_frame_id); |
| 248 if (render_frame_host) { | 250 if (render_frame_host) { |
| 249 render_frame_host->Send(new GeolocationMsg_PermissionSet( | 251 render_frame_host->Send(new GeolocationMsg_PermissionSet( |
| 250 render_frame_id, bridge_id, allowed)); | 252 render_frame_id, bridge_id, allowed)); |
| 251 } | 253 } |
| 252 | 254 |
| 253 if (allowed) { | 255 if (allowed) { |
| 256 geolocationPrecision_ = choice; |
| 254 GeolocationProviderImpl::GetInstance()-> | 257 GeolocationProviderImpl::GetInstance()-> |
| 255 UserDidOptIntoLocationServices(); | 258 UserDidOptIntoLocationServices(); |
| 256 } | 259 } |
| 257 | 260 |
| 258 pending_permissions_.erase(pending_permissions_.begin() + i); | 261 pending_permissions_.erase(pending_permissions_.begin() + i); |
| 259 return; | 262 return; |
| 260 } | 263 } |
| 261 } | 264 } |
| 262 | 265 |
| 263 NOTREACHED(); | 266 NOTREACHED(); |
| 264 } | 267 } |
| 265 | 268 |
| 266 } // namespace content | 269 } // namespace content |
| OLD | NEW |