| OLD | NEW |
| 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 Loading... |
| 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(); |
| 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(); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| OLD | NEW |