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

Side by Side Diff: content/browser/devtools/protocol/page_handler.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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/devtools/protocol/page_handler.h" 5 #include "content/browser/devtools/protocol/page_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "content/browser/devtools/protocol/color_picker.h" 13 #include "content/browser/devtools/protocol/color_picker.h"
14 #include "content/browser/geolocation/geolocation_dispatcher_host.h"
14 #include "content/browser/renderer_host/render_view_host_impl.h" 15 #include "content/browser/renderer_host/render_view_host_impl.h"
15 #include "content/browser/renderer_host/render_widget_host_view_base.h" 16 #include "content/browser/renderer_host/render_widget_host_view_base.h"
16 #include "content/browser/web_contents/web_contents_impl.h" 17 #include "content/browser/web_contents/web_contents_impl.h"
17 #include "content/common/view_messages.h" 18 #include "content/common/view_messages.h"
18 #include "content/public/browser/javascript_dialog_manager.h" 19 #include "content/public/browser/javascript_dialog_manager.h"
19 #include "content/public/browser/navigation_controller.h" 20 #include "content/public/browser/navigation_controller.h"
20 #include "content/public/browser/navigation_entry.h" 21 #include "content/public/browser/navigation_entry.h"
21 #include "content/public/browser/web_contents_delegate.h" 22 #include "content/public/browser/web_contents_delegate.h"
22 #include "content/public/common/referrer.h" 23 #include "content/public/common/referrer.h"
23 #include "content/public/common/url_constants.h" 24 #include "content/public/common/url_constants.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 for (int i = 0; i != controller.GetEntryCount(); ++i) { 197 for (int i = 0; i != controller.GetEntryCount(); ++i) {
197 if (controller.GetEntryAtIndex(i)->GetUniqueID() == entry_id) { 198 if (controller.GetEntryAtIndex(i)->GetUniqueID() == entry_id) {
198 controller.GoToIndex(i); 199 controller.GoToIndex(i);
199 return Response::OK(); 200 return Response::OK();
200 } 201 }
201 } 202 }
202 203
203 return Response::InvalidParams("No entry with passed id"); 204 return Response::InvalidParams("No entry with passed id");
204 } 205 }
205 206
207 Response PageHandler::SetGeolocationOverride(double* latitude,
208 double* longitude,
209 double* accuracy) {
210 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
211 WebContents::FromRenderViewHost(host_));
212 if (!web_contents)
213 return Response::InternalError("No WebContents to override");
214 GeolocationDispatcherHost* geolocation_host =
215 web_contents->geolocation_dispatcher_host();
216 scoped_ptr<Geoposition> geoposition(new Geoposition());
217 if (latitude && longitude && accuracy) {
218 geoposition->latitude = *latitude;
219 geoposition->longitude = *longitude;
220 geoposition->accuracy = *accuracy;
221 geoposition->timestamp = base::Time::Now();
222 } else {
223 geoposition->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE;
224 }
225 geolocation_host->SetOverride(geoposition.Pass());
226 return Response::OK();
227 }
228
229 Response PageHandler::ClearGeolocationOverride() {
230 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
231 WebContents::FromRenderViewHost(host_));
232 if (!web_contents)
233 return Response::InternalError("No WebContents to override");
234 GeolocationDispatcherHost* geolocation_host =
235 web_contents->geolocation_dispatcher_host();
236 geolocation_host->ClearOverride();
237 return Response::OK();
238 }
239
240
206 Response PageHandler::SetTouchEmulationEnabled(bool enabled) { 241 Response PageHandler::SetTouchEmulationEnabled(bool enabled) {
207 touch_emulation_enabled_ = enabled; 242 touch_emulation_enabled_ = enabled;
208 UpdateTouchEventEmulationState(); 243 UpdateTouchEventEmulationState();
209 return Response::FallThrough(); 244 return Response::FallThrough();
210 } 245 }
211 246
212 scoped_refptr<DevToolsProtocol::Response> PageHandler::CaptureScreenshot( 247 scoped_refptr<DevToolsProtocol::Response> PageHandler::CaptureScreenshot(
213 scoped_refptr<DevToolsProtocol::Command> command) { 248 scoped_refptr<DevToolsProtocol::Command> command) {
214 if (!host_ || !host_->GetView()) 249 if (!host_ || !host_->GetView())
215 return command->InternalErrorResponse("Could not connect to view"); 250 return command->InternalErrorResponse("Could not connect to view");
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 color.set_b(b); 538 color.set_b(b);
504 color.set_a(a); 539 color.set_a(a);
505 ColorPickedParams params; 540 ColorPickedParams params;
506 params.set_color(color); 541 params.set_color(color);
507 client_->ColorPicked(params); 542 client_->ColorPicked(params);
508 } 543 }
509 544
510 } // namespace page 545 } // namespace page
511 } // namespace devtools 546 } // namespace devtools
512 } // namespace content 547 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698