OLD | NEW |
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 "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "content/browser/geolocation/geolocation_dispatcher_host.h" |
8 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 10 #include "content/browser/web_contents/web_contents_impl.h" |
9 | 11 |
10 namespace content { | 12 namespace content { |
11 namespace devtools { | 13 namespace devtools { |
12 namespace page { | 14 namespace page { |
13 | 15 |
14 typedef DevToolsProtocolClient::Response Response; | 16 typedef DevToolsProtocolClient::Response Response; |
15 | 17 |
16 PageHandler::PageHandler() | 18 PageHandler::PageHandler() |
17 : weak_factory_(this) { | 19 : weak_factory_(this) { |
18 } | 20 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 Response PageHandler::GetNavigationHistory( | 52 Response PageHandler::GetNavigationHistory( |
51 int* current_index, | 53 int* current_index, |
52 std::vector<NavigationEntry>* entries) { | 54 std::vector<NavigationEntry>* entries) { |
53 return Response::FallThrough(); | 55 return Response::FallThrough(); |
54 } | 56 } |
55 | 57 |
56 Response PageHandler::NavigateToHistoryEntry(int entry_id) { | 58 Response PageHandler::NavigateToHistoryEntry(int entry_id) { |
57 return Response::FallThrough(); | 59 return Response::FallThrough(); |
58 } | 60 } |
59 | 61 |
| 62 Response PageHandler::SetGeolocationOverride(double* latitude, |
| 63 double* longitude, |
| 64 double* accuracy) { |
| 65 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
| 66 WebContents::FromRenderViewHost(host_)); |
| 67 if (!web_contents) |
| 68 return Response::InternalError("No WebContents to override"); |
| 69 GeolocationDispatcherHost* geolocation_host = |
| 70 web_contents->geolocation_dispatcher_host(); |
| 71 scoped_ptr<Geoposition> geoposition(new Geoposition()); |
| 72 if (latitude && longitude && accuracy) { |
| 73 geoposition->latitude = *latitude; |
| 74 geoposition->longitude = *longitude; |
| 75 geoposition->accuracy = *accuracy; |
| 76 geoposition->timestamp = base::Time::Now(); |
| 77 } else { |
| 78 geoposition->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; |
| 79 } |
| 80 geolocation_host->SetOverride(geoposition.Pass()); |
| 81 return Response::OK(); |
| 82 } |
| 83 |
| 84 Response PageHandler::ClearGeolocationOverride() { |
| 85 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
| 86 WebContents::FromRenderViewHost(host_)); |
| 87 if (!web_contents) |
| 88 return Response::InternalError("No WebContents to override"); |
| 89 GeolocationDispatcherHost* geolocation_host = |
| 90 web_contents->geolocation_dispatcher_host(); |
| 91 geolocation_host->ClearOverride(); |
| 92 return Response::OK(); |
| 93 } |
| 94 |
| 95 |
60 Response PageHandler::SetTouchEmulationEnabled(bool enabled) { | 96 Response PageHandler::SetTouchEmulationEnabled(bool enabled) { |
61 return Response::FallThrough(); | 97 return Response::FallThrough(); |
62 } | 98 } |
63 | 99 |
64 scoped_refptr<DevToolsProtocol::Response> PageHandler::CaptureScreenshot( | 100 scoped_refptr<DevToolsProtocol::Response> PageHandler::CaptureScreenshot( |
65 scoped_refptr<DevToolsProtocol::Command> command) { | 101 scoped_refptr<DevToolsProtocol::Command> command) { |
66 if (!host_ || !host_->GetView()) | 102 if (!host_ || !host_->GetView()) |
67 return command->InternalErrorResponse("Could not connect to view"); | 103 return command->InternalErrorResponse("Could not connect to view"); |
68 | 104 |
69 host_->GetSnapshotFromBrowser( | 105 host_->GetSnapshotFromBrowser( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 &base_64_data); | 158 &base_64_data); |
123 | 159 |
124 CaptureScreenshotResponse response; | 160 CaptureScreenshotResponse response; |
125 response.set_data(base_64_data); | 161 response.set_data(base_64_data); |
126 client_->SendCaptureScreenshotResponse(command, response); | 162 client_->SendCaptureScreenshotResponse(command, response); |
127 } | 163 } |
128 | 164 |
129 } // namespace page | 165 } // namespace page |
130 } // namespace devtools | 166 } // namespace devtools |
131 } // namespace content | 167 } // namespace content |
OLD | NEW |