| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 UpdateTouchEventEmulationState(); | 62 UpdateTouchEventEmulationState(); |
| 62 UpdateDeviceEmulationState(); | 63 UpdateDeviceEmulationState(); |
| 63 } | 64 } |
| 64 | 65 |
| 65 Response EmulationHandler::SetGeolocationOverride( | 66 Response EmulationHandler::SetGeolocationOverride( |
| 66 double* latitude, double* longitude, double* accuracy) { | 67 double* latitude, double* longitude, double* accuracy) { |
| 67 if (!GetWebContents()) | 68 if (!GetWebContents()) |
| 68 return Response::InternalError("Could not connect to view"); | 69 return Response::InternalError("Could not connect to view"); |
| 69 | 70 |
| 70 GeolocationServiceContext* geolocation_context = | 71 GeolocationServiceContext* geolocation_context = |
| 71 GetWebContents()->GetGeolocationServiceContext(); | 72 GeolocationServiceContext::GetOrCreateForWebContents(GetWebContents()); |
| 72 scoped_ptr<Geoposition> geoposition(new Geoposition()); | 73 scoped_ptr<Geoposition> geoposition(new Geoposition()); |
| 73 if (latitude && longitude && accuracy) { | 74 if (latitude && longitude && accuracy) { |
| 74 geoposition->latitude = *latitude; | 75 geoposition->latitude = *latitude; |
| 75 geoposition->longitude = *longitude; | 76 geoposition->longitude = *longitude; |
| 76 geoposition->accuracy = *accuracy; | 77 geoposition->accuracy = *accuracy; |
| 77 geoposition->timestamp = base::Time::Now(); | 78 geoposition->timestamp = base::Time::Now(); |
| 78 if (!geoposition->Validate()) { | 79 if (!geoposition->Validate()) { |
| 79 return Response::InternalError("Invalid geolocation"); | 80 return Response::InternalError("Invalid geolocation"); |
| 80 } | 81 } |
| 81 } else { | 82 } else { |
| 82 geoposition->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; | 83 geoposition->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; |
| 83 } | 84 } |
| 84 geolocation_context->SetOverride(geoposition.Pass()); | 85 geolocation_context->SetOverride(geoposition.Pass()); |
| 85 return Response::OK(); | 86 return Response::OK(); |
| 86 } | 87 } |
| 87 | 88 |
| 88 Response EmulationHandler::ClearGeolocationOverride() { | 89 Response EmulationHandler::ClearGeolocationOverride() { |
| 89 if (!GetWebContents()) | 90 if (!GetWebContents()) |
| 90 return Response::InternalError("Could not connect to view"); | 91 return Response::InternalError("Could not connect to view"); |
| 91 | 92 |
| 92 GeolocationServiceContext* geolocation_context = | 93 GeolocationServiceContext* geolocation_context = |
| 93 GetWebContents()->GetGeolocationServiceContext(); | 94 GeolocationServiceContext::FromWebContents(GetWebContents()); |
| 94 geolocation_context->ClearOverride(); | 95 if (geolocation_context) |
| 96 geolocation_context->ClearOverride(); |
| 95 return Response::OK(); | 97 return Response::OK(); |
| 96 } | 98 } |
| 97 | 99 |
| 98 Response EmulationHandler::SetTouchEmulationEnabled( | 100 Response EmulationHandler::SetTouchEmulationEnabled( |
| 99 bool enabled, const std::string* configuration) { | 101 bool enabled, const std::string* configuration) { |
| 100 touch_emulation_enabled_ = enabled; | 102 touch_emulation_enabled_ = enabled; |
| 101 touch_emulation_configuration_ = | 103 touch_emulation_configuration_ = |
| 102 configuration ? *configuration : std::string(); | 104 configuration ? *configuration : std::string(); |
| 103 UpdateTouchEventEmulationState(); | 105 UpdateTouchEventEmulationState(); |
| 104 return Response::FallThrough(); | 106 return Response::FallThrough(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 widget_host->GetRoutingID(), device_emulation_params_)); | 229 widget_host->GetRoutingID(), device_emulation_params_)); |
| 228 } else { | 230 } else { |
| 229 widget_host->Send(new ViewMsg_DisableDeviceEmulation( | 231 widget_host->Send(new ViewMsg_DisableDeviceEmulation( |
| 230 widget_host->GetRoutingID())); | 232 widget_host->GetRoutingID())); |
| 231 } | 233 } |
| 232 } | 234 } |
| 233 | 235 |
| 234 } // namespace emulation | 236 } // namespace emulation |
| 235 } // namespace devtools | 237 } // namespace devtools |
| 236 } // namespace content | 238 } // namespace content |
| OLD | NEW |