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 <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "content/browser/geolocation/geolocation_provider.h" | 12 #include "content/browser/geolocation/geolocation_provider.h" |
13 #include "content/browser/renderer_host/render_message_filter.h" | 13 #include "content/browser/renderer_host/render_message_filter.h" |
14 #include "content/browser/renderer_host/render_process_host_impl.h" | 14 #include "content/browser/renderer_host/render_process_host_impl.h" |
15 #include "content/browser/renderer_host/render_view_host_impl.h" | 15 #include "content/browser/renderer_host/render_view_host_impl.h" |
16 #include "content/public/browser/geolocation_permission_context.h" | 16 #include "content/public/browser/geolocation_permission_context.h" |
17 #include "content/public/common/geoposition.h" | 17 #include "content/public/common/geoposition.h" |
18 #include "content/common/geolocation_messages.h" | 18 #include "content/common/geolocation_messages.h" |
19 | 19 |
20 using content::BrowserThread; | 20 namespace content { |
21 using content::GeolocationPermissionContext; | |
22 using content::Geoposition; | |
23 using content::RenderViewHostImpl; | |
24 | 21 |
25 namespace { | 22 namespace { |
26 | 23 |
27 void NotifyArbitratorPermissionGranted() { | 24 void NotifyArbitratorPermissionGranted() { |
28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
29 GeolocationProvider::GetInstance()->OnPermissionGranted(); | 26 GeolocationProvider::GetInstance()->OnPermissionGranted(); |
30 } | 27 } |
31 | 28 |
32 void SendGeolocationPermissionResponse(int render_process_id, | 29 void SendGeolocationPermissionResponse(const GeolocationPermissionRequestID& id, |
33 int render_view_id, | |
34 int bridge_id, | |
35 bool allowed) { | 30 bool allowed) { |
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
37 RenderViewHostImpl* r = RenderViewHostImpl::FromID( | 32 RenderViewHostImpl* r = RenderViewHostImpl::FromID( |
38 render_process_id, render_view_id); | 33 id.render_process_id, id.render_view_id); |
39 if (!r) | 34 if (!r) |
40 return; | 35 return; |
41 r->Send(new GeolocationMsg_PermissionSet(render_view_id, bridge_id, allowed)); | 36 r->Send(new GeolocationMsg_PermissionSet(id.render_view_id, id.bridge_id, |
| 37 allowed)); |
42 | 38 |
43 if (allowed) { | 39 if (allowed) { |
44 BrowserThread::PostTask( | 40 BrowserThread::PostTask( |
45 BrowserThread::IO, FROM_HERE, | 41 BrowserThread::IO, FROM_HERE, |
46 base::Bind(&NotifyArbitratorPermissionGranted)); | 42 base::Bind(&NotifyArbitratorPermissionGranted)); |
47 } | 43 } |
48 } | 44 } |
49 | 45 |
50 class GeolocationDispatcherHostImpl : public GeolocationDispatcherHost, | 46 class GeolocationDispatcherHostImpl : public GeolocationDispatcherHost, |
51 public GeolocationObserver { | 47 public GeolocationObserver { |
52 public: | 48 public: |
53 GeolocationDispatcherHostImpl( | 49 GeolocationDispatcherHostImpl( |
54 int render_process_id, | 50 int render_process_id, |
55 GeolocationPermissionContext* geolocation_permission_context); | 51 GeolocationPermissionContext* geolocation_permission_context); |
56 | 52 |
57 // GeolocationDispatcherHost | 53 // GeolocationDispatcherHost |
58 virtual bool OnMessageReceived(const IPC::Message& msg, bool* msg_was_ok); | 54 virtual bool OnMessageReceived(const IPC::Message& msg, bool* msg_was_ok); |
59 | 55 |
60 // GeolocationObserver | 56 // GeolocationObserver |
61 virtual void OnLocationUpdate(const Geoposition& position); | 57 virtual void OnLocationUpdate(const Geoposition& position); |
62 | 58 |
63 private: | 59 private: |
64 virtual ~GeolocationDispatcherHostImpl(); | 60 virtual ~GeolocationDispatcherHostImpl(); |
65 | 61 |
66 void OnRequestPermission( | 62 void OnRequestPermission(int render_view_id, |
67 int render_view_id, int bridge_id, const GURL& requesting_frame); | 63 int bridge_id, |
68 void OnCancelPermissionRequest( | 64 const GURL& requesting_frame); |
69 int render_view_id, int bridge_id, const GURL& requesting_frame); | 65 void OnCancelPermissionRequest(int render_view_id, |
70 void OnStartUpdating( | 66 int bridge_id, |
71 int render_view_id, const GURL& requesting_frame, | 67 const GURL& requesting_frame); |
72 bool enable_high_accuracy); | 68 void OnStartUpdating(int render_view_id, |
| 69 const GURL& requesting_frame, |
| 70 bool enable_high_accuracy); |
73 void OnStopUpdating(int render_view_id); | 71 void OnStopUpdating(int render_view_id); |
74 | 72 |
75 // Updates the |location_arbitrator_| with the currently required update | 73 // Updates the |location_arbitrator_| with the currently required update |
76 // options, based on |renderer_update_options_|. | 74 // options, based on |renderer_update_options_|. |
77 void RefreshGeolocationObserverOptions(); | 75 void RefreshGeolocationObserverOptions(); |
78 | 76 |
79 int render_process_id_; | 77 int render_process_id_; |
80 scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; | 78 scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; |
81 | 79 |
82 // Iterated when sending location updates to renderer processes. The fan out | 80 // Iterated when sending location updates to renderer processes. The fan out |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 it != geolocation_renderer_ids_.end(); ++it) { | 131 it != geolocation_renderer_ids_.end(); ++it) { |
134 Send(new GeolocationMsg_PositionUpdated(*it, geoposition)); | 132 Send(new GeolocationMsg_PositionUpdated(*it, geoposition)); |
135 } | 133 } |
136 } | 134 } |
137 | 135 |
138 void GeolocationDispatcherHostImpl::OnRequestPermission( | 136 void GeolocationDispatcherHostImpl::OnRequestPermission( |
139 int render_view_id, | 137 int render_view_id, |
140 int bridge_id, | 138 int bridge_id, |
141 const GURL& requesting_frame) { | 139 const GURL& requesting_frame) { |
142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
143 DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":" | 141 const GeolocationPermissionRequestID id(render_process_id_, render_view_id, |
144 << render_view_id << ":" << bridge_id; | 142 bridge_id); |
| 143 DVLOG(1) << __FUNCTION__ << " " << id.ToString(); |
145 if (geolocation_permission_context_) { | 144 if (geolocation_permission_context_) { |
146 geolocation_permission_context_->RequestGeolocationPermission( | 145 geolocation_permission_context_->RequestGeolocationPermission( |
147 render_process_id_, render_view_id, bridge_id, | 146 id, requesting_frame, base::Bind(&SendGeolocationPermissionResponse, |
148 requesting_frame, | 147 id)); |
149 base::Bind( | |
150 &SendGeolocationPermissionResponse, | |
151 render_process_id_, render_view_id, bridge_id)); | |
152 } else { | 148 } else { |
153 BrowserThread::PostTask( | 149 BrowserThread::PostTask( |
154 BrowserThread::UI, FROM_HERE, | 150 BrowserThread::UI, FROM_HERE, |
155 base::Bind( | 151 base::Bind(&SendGeolocationPermissionResponse, id, true)); |
156 &SendGeolocationPermissionResponse, | |
157 render_process_id_, render_view_id, bridge_id, true)); | |
158 } | 152 } |
159 } | 153 } |
160 | 154 |
161 void GeolocationDispatcherHostImpl::OnCancelPermissionRequest( | 155 void GeolocationDispatcherHostImpl::OnCancelPermissionRequest( |
162 int render_view_id, | 156 int render_view_id, |
163 int bridge_id, | 157 int bridge_id, |
164 const GURL& requesting_frame) { | 158 const GURL& requesting_frame) { |
165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
166 DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":" | 160 const GeolocationPermissionRequestID id(render_process_id_, render_view_id, |
167 << render_view_id << ":" << bridge_id; | 161 bridge_id); |
168 if (!geolocation_permission_context_) | 162 DVLOG(1) << __FUNCTION__ << " " << id.ToString(); |
169 return; | 163 if (geolocation_permission_context_) { |
170 geolocation_permission_context_->CancelGeolocationPermissionRequest( | 164 geolocation_permission_context_->CancelGeolocationPermissionRequest( |
171 render_process_id_, render_view_id, bridge_id, | 165 id, requesting_frame); |
172 requesting_frame); | 166 } |
173 } | 167 } |
174 | 168 |
175 void GeolocationDispatcherHostImpl::OnStartUpdating( | 169 void GeolocationDispatcherHostImpl::OnStartUpdating( |
176 int render_view_id, | 170 int render_view_id, |
177 const GURL& requesting_frame, | 171 const GURL& requesting_frame, |
178 bool enable_high_accuracy) { | 172 bool enable_high_accuracy) { |
179 // StartUpdating() can be invoked as a result of high-accuracy mode | 173 // StartUpdating() can be invoked as a result of high-accuracy mode |
180 // being enabled / disabled. No need to record the dispatcher again. | 174 // being enabled / disabled. No need to record the dispatcher again. |
181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
182 DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":" | 176 DVLOG(1) << __FUNCTION__ << " " << render_process_id_ << ":" |
(...skipping 28 matching lines...) Expand all Loading... |
211 if (!location_provider_) | 205 if (!location_provider_) |
212 location_provider_ = GeolocationProvider::GetInstance(); | 206 location_provider_ = GeolocationProvider::GetInstance(); |
213 // Re-add to re-establish our options, in case they changed. | 207 // Re-add to re-establish our options, in case they changed. |
214 location_provider_->AddObserver( | 208 location_provider_->AddObserver( |
215 this, | 209 this, |
216 GeolocationObserverOptions::Collapse(renderer_update_options_)); | 210 GeolocationObserverOptions::Collapse(renderer_update_options_)); |
217 } | 211 } |
218 } | 212 } |
219 } // namespace | 213 } // namespace |
220 | 214 |
| 215 |
| 216 // GeolocationDispatcherHost -------------------------------------------------- |
| 217 |
| 218 // static |
221 GeolocationDispatcherHost* GeolocationDispatcherHost::New( | 219 GeolocationDispatcherHost* GeolocationDispatcherHost::New( |
222 int render_process_id, | 220 int render_process_id, |
223 GeolocationPermissionContext* geolocation_permission_context) { | 221 GeolocationPermissionContext* geolocation_permission_context) { |
224 return new GeolocationDispatcherHostImpl( | 222 return new GeolocationDispatcherHostImpl( |
225 render_process_id, | 223 render_process_id, |
226 geolocation_permission_context); | 224 geolocation_permission_context); |
227 } | 225 } |
| 226 |
| 227 GeolocationDispatcherHost::GeolocationDispatcherHost() { |
| 228 } |
| 229 |
| 230 GeolocationDispatcherHost::~GeolocationDispatcherHost() { |
| 231 } |
| 232 |
| 233 } // namespace content |
OLD | NEW |