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

Side by Side Diff: content/browser/devtools/protocol/emulation_handler.cc

Issue 1411063007: Add mojo::StrongBindingSet and use it in GeolocationServiceContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/emulation_handler.h" 5 #include "content/browser/devtools/protocol/emulation_handler.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "content/browser/frame_host/render_frame_host_impl.h" 8 #include "content/browser/frame_host/render_frame_host_impl.h"
9 #include "content/browser/geolocation/geolocation_service_context.h" 9 #include "content/browser/geolocation/geolocation_service_context.h"
10 #include "content/browser/renderer_host/render_widget_host_impl.h" 10 #include "content/browser/renderer_host/render_widget_host_impl.h"
11 #include "content/browser/web_contents/web_contents_impl.h" 11 #include "content/browser/web_contents/web_contents_impl.h"
12 #include "content/common/view_messages.h" 12 #include "content/common/view_messages.h"
13 #include "content/public/common/geoposition.h"
13 #include "content/public/common/url_constants.h" 14 #include "content/public/common/url_constants.h"
14 15
15 namespace content { 16 namespace content {
16 namespace devtools { 17 namespace devtools {
17 namespace emulation { 18 namespace emulation {
18 19
19 using Response = DevToolsProtocolClient::Response; 20 using Response = DevToolsProtocolClient::Response;
20 21
21 namespace { 22 namespace {
22 23
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 UpdateTouchEventEmulationState(); 69 UpdateTouchEventEmulationState();
69 UpdateDeviceEmulationState(); 70 UpdateDeviceEmulationState();
70 } 71 }
71 72
72 Response EmulationHandler::SetGeolocationOverride( 73 Response EmulationHandler::SetGeolocationOverride(
73 double* latitude, double* longitude, double* accuracy) { 74 double* latitude, double* longitude, double* accuracy) {
74 if (!GetWebContents()) 75 if (!GetWebContents())
75 return Response::InternalError("Could not connect to view"); 76 return Response::InternalError("Could not connect to view");
76 77
77 GeolocationServiceContext* geolocation_context = 78 GeolocationServiceContext* geolocation_context =
78 GetWebContents()->GetGeolocationServiceContext(); 79 GeolocationServiceContext::GetOrCreateForWebContents(GetWebContents());
79 scoped_ptr<Geoposition> geoposition(new Geoposition()); 80 scoped_ptr<Geoposition> geoposition(new Geoposition());
80 if (latitude && longitude && accuracy) { 81 if (latitude && longitude && accuracy) {
81 geoposition->latitude = *latitude; 82 geoposition->latitude = *latitude;
82 geoposition->longitude = *longitude; 83 geoposition->longitude = *longitude;
83 geoposition->accuracy = *accuracy; 84 geoposition->accuracy = *accuracy;
84 geoposition->timestamp = base::Time::Now(); 85 geoposition->timestamp = base::Time::Now();
85 if (!geoposition->Validate()) { 86 if (!geoposition->Validate()) {
86 return Response::InternalError("Invalid geolocation"); 87 return Response::InternalError("Invalid geolocation");
87 } 88 }
88 } else { 89 } else {
89 geoposition->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; 90 geoposition->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE;
90 } 91 }
91 geolocation_context->SetOverride(geoposition.Pass()); 92 geolocation_context->SetOverride(geoposition.Pass());
92 return Response::OK(); 93 return Response::OK();
93 } 94 }
94 95
95 Response EmulationHandler::ClearGeolocationOverride() { 96 Response EmulationHandler::ClearGeolocationOverride() {
96 if (!GetWebContents()) 97 if (!GetWebContents())
97 return Response::InternalError("Could not connect to view"); 98 return Response::InternalError("Could not connect to view");
98 99
99 GeolocationServiceContext* geolocation_context = 100 GeolocationServiceContext* geolocation_context =
100 GetWebContents()->GetGeolocationServiceContext(); 101 GeolocationServiceContext::FromWebContents(GetWebContents());
101 geolocation_context->ClearOverride(); 102 if (geolocation_context)
103 geolocation_context->ClearOverride();
102 return Response::OK(); 104 return Response::OK();
Michael van Ouwerkerk 2015/11/11 11:20:56 Should this return OK if !geolocation_context ?
Sam McNally 2015/11/13 00:49:59 Yes. If an EmulationHandler tries to clear the ove
103 } 105 }
104 106
105 Response EmulationHandler::SetTouchEmulationEnabled( 107 Response EmulationHandler::SetTouchEmulationEnabled(
106 bool enabled, const std::string* configuration) { 108 bool enabled, const std::string* configuration) {
107 touch_emulation_enabled_ = enabled; 109 touch_emulation_enabled_ = enabled;
108 touch_emulation_configuration_ = 110 touch_emulation_configuration_ =
109 configuration ? *configuration : std::string(); 111 configuration ? *configuration : std::string();
110 UpdateTouchEventEmulationState(); 112 UpdateTouchEventEmulationState();
111 return Response::FallThrough(); 113 return Response::FallThrough();
112 } 114 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 widget_host->GetRoutingID(), device_emulation_params_)); 237 widget_host->GetRoutingID(), device_emulation_params_));
236 } else { 238 } else {
237 widget_host->Send(new ViewMsg_DisableDeviceEmulation( 239 widget_host->Send(new ViewMsg_DisableDeviceEmulation(
238 widget_host->GetRoutingID())); 240 widget_host->GetRoutingID()));
239 } 241 }
240 } 242 }
241 243
242 } // namespace emulation 244 } // namespace emulation
243 } // namespace devtools 245 } // namespace devtools
244 } // namespace content 246 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698