Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(878)

Side by Side Diff: content/browser/geolocation/geolocation_dispatcher_host.cc

Issue 603323004: DevTools: Add geolocation override in browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Expanded SetOverride description. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/geolocation/geolocation_dispatcher_host.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 paused_(false), 84 paused_(false),
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::SetOverride(
95 scoped_ptr<Geoposition> geoposition) {
96 geoposition_override_.swap(geoposition);
97 RefreshGeolocationOptions();
98 OnLocationUpdate(*geoposition_override_);
99 }
100
101 void GeolocationDispatcherHost::ClearOverride() {
102 geoposition_override_.reset();
103 RefreshGeolocationOptions();
104 }
105
94 void GeolocationDispatcherHost::RenderFrameDeleted( 106 void GeolocationDispatcherHost::RenderFrameDeleted(
95 RenderFrameHost* render_frame_host) { 107 RenderFrameHost* render_frame_host) {
96 OnStopUpdating(render_frame_host); 108 OnStopUpdating(render_frame_host);
97 } 109 }
98 110
99 void GeolocationDispatcherHost::RenderViewHostChanged( 111 void GeolocationDispatcherHost::RenderViewHostChanged(
100 RenderViewHost* old_host, 112 RenderViewHost* old_host,
101 RenderViewHost* new_host) { 113 RenderViewHost* new_host) {
102 updating_frames_.clear(); 114 updating_frames_.clear();
103 paused_ = false; 115 paused_ = false;
(...skipping 19 matching lines...) Expand all
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));
126 138
127 RecordGeopositionErrorCode(geoposition.error_code); 139 RecordGeopositionErrorCode(geoposition.error_code);
128 if (paused_) 140 if (paused_)
129 return; 141 return;
130 142
131 for (std::map<RenderFrameHost*, bool>::iterator i = updating_frames_.begin(); 143 for (std::map<RenderFrameHost*, bool>::iterator i = updating_frames_.begin();
132 i != updating_frames_.end(); ++i) { 144 i != updating_frames_.end(); ++i) {
133 RenderFrameHost* top_frame = i->first; 145 UpdateGeoposition(i->first, geoposition);
134 while (top_frame->GetParent()) {
135 top_frame = top_frame->GetParent();
136 }
137 GetContentClient()->browser()->DidUseGeolocationPermission(
138 web_contents(),
139 i->first->GetLastCommittedURL().GetOrigin(),
140 top_frame->GetLastCommittedURL().GetOrigin());
141
142 i->first->Send(new GeolocationMsg_PositionUpdated(
143 i->first->GetRoutingID(), geoposition));
144 } 146 }
145 } 147 }
146 148
149 void GeolocationDispatcherHost::UpdateGeoposition(
150 RenderFrameHost* frame,
151 const Geoposition& geoposition) {
152 RenderFrameHost* top_frame = frame;
153 while (top_frame->GetParent()) {
154 top_frame = top_frame->GetParent();
155 }
156 GetContentClient()->browser()->DidUseGeolocationPermission(
157 web_contents(),
158 frame->GetLastCommittedURL().GetOrigin(),
159 top_frame->GetLastCommittedURL().GetOrigin());
160
161 frame->Send(new GeolocationMsg_PositionUpdated(
162 frame->GetRoutingID(), geoposition));
163 }
164
147 void GeolocationDispatcherHost::OnRequestPermission( 165 void GeolocationDispatcherHost::OnRequestPermission(
148 RenderFrameHost* render_frame_host, 166 RenderFrameHost* render_frame_host,
149 int bridge_id, 167 int bridge_id,
150 const GURL& requesting_frame, 168 const GURL& requesting_frame,
151 bool user_gesture) { 169 bool user_gesture) {
152 int render_process_id = render_frame_host->GetProcess()->GetID(); 170 int render_process_id = render_frame_host->GetProcess()->GetID();
153 int render_frame_id = render_frame_host->GetRoutingID(); 171 int render_frame_id = render_frame_host->GetRoutingID();
154 172
155 PendingPermission pending_permission( 173 PendingPermission pending_permission(
156 render_frame_id, render_process_id, bridge_id); 174 render_frame_id, render_process_id, bridge_id);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 const GURL& requesting_frame, 208 const GURL& requesting_frame,
191 bool enable_high_accuracy) { 209 bool enable_high_accuracy) {
192 // StartUpdating() can be invoked as a result of high-accuracy mode 210 // StartUpdating() can be invoked as a result of high-accuracy mode
193 // being enabled / disabled. No need to record the dispatcher again. 211 // being enabled / disabled. No need to record the dispatcher again.
194 UMA_HISTOGRAM_BOOLEAN( 212 UMA_HISTOGRAM_BOOLEAN(
195 "Geolocation.GeolocationDispatcherHostImpl.EnableHighAccuracy", 213 "Geolocation.GeolocationDispatcherHostImpl.EnableHighAccuracy",
196 enable_high_accuracy); 214 enable_high_accuracy);
197 215
198 updating_frames_[render_frame_host] = enable_high_accuracy; 216 updating_frames_[render_frame_host] = enable_high_accuracy;
199 RefreshGeolocationOptions(); 217 RefreshGeolocationOptions();
218 if (geoposition_override_.get())
219 UpdateGeoposition(render_frame_host, *geoposition_override_);
200 } 220 }
201 221
202 void GeolocationDispatcherHost::OnStopUpdating( 222 void GeolocationDispatcherHost::OnStopUpdating(
203 RenderFrameHost* render_frame_host) { 223 RenderFrameHost* render_frame_host) {
204 updating_frames_.erase(render_frame_host); 224 updating_frames_.erase(render_frame_host);
205 RefreshGeolocationOptions(); 225 RefreshGeolocationOptions();
206 } 226 }
207 227
208 void GeolocationDispatcherHost::PauseOrResume(bool should_pause) { 228 void GeolocationDispatcherHost::PauseOrResume(bool should_pause) {
209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
210 paused_ = should_pause; 230 paused_ = should_pause;
211 RefreshGeolocationOptions(); 231 RefreshGeolocationOptions();
232 if (geoposition_override_.get())
blundell 2014/10/21 08:44:20 drive-by: Naively, it seems like the code at lines
vkuzkokov 2014/10/21 11:58:27 There is a check in OnLocationUpdate. This doesn't
blundell 2014/10/21 12:12:44 Ah right, I had forgotten about that. It matters f
233 OnLocationUpdate(*geoposition_override_);
212 } 234 }
213 235
214 void GeolocationDispatcherHost::RefreshGeolocationOptions() { 236 void GeolocationDispatcherHost::RefreshGeolocationOptions() {
215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
216 238
217 if (updating_frames_.empty() || paused_) { 239 if (updating_frames_.empty() || paused_ || geoposition_override_.get()) {
218 geolocation_subscription_.reset(); 240 geolocation_subscription_.reset();
219 return; 241 return;
220 } 242 }
221 243
222 bool high_accuracy = false; 244 bool high_accuracy = false;
223 for (std::map<RenderFrameHost*, bool>::iterator i = 245 for (std::map<RenderFrameHost*, bool>::iterator i =
224 updating_frames_.begin(); i != updating_frames_.end(); ++i) { 246 updating_frames_.begin(); i != updating_frames_.end(); ++i) {
225 if (i->second) { 247 if (i->second) {
226 high_accuracy = true; 248 high_accuracy = true;
227 break; 249 break;
(...skipping 29 matching lines...) Expand all
257 279
258 pending_permissions_.erase(pending_permissions_.begin() + i); 280 pending_permissions_.erase(pending_permissions_.begin() + i);
259 return; 281 return;
260 } 282 }
261 } 283 }
262 284
263 NOTREACHED(); 285 NOTREACHED();
264 } 286 }
265 287
266 } // namespace content 288 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/geolocation/geolocation_dispatcher_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698