OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/devtools/protocol/page_handler.h" | |
6 | |
7 #include "base/base64.h" | |
8 #include "content/browser/renderer_host/render_view_host_impl.h" | |
9 | |
10 namespace content { | |
11 namespace devtools { | |
12 namespace page { | |
13 | |
14 typedef DevToolsProtocolClient::Response Response; | |
15 | |
16 PageHandler::PageHandler() | |
17 : weak_factory_(this) { | |
18 } | |
19 | |
20 PageHandler::~PageHandler() { | |
21 } | |
22 | |
23 void PageHandler::SetRenderViewHost(RenderViewHostImpl* host) { | |
24 host_ = host; | |
25 } | |
26 | |
27 void PageHandler::SetClient(scoped_ptr<Client> client) { | |
28 client_.swap(client); | |
29 } | |
30 | |
31 Response PageHandler::Enable() { | |
32 return Response::FallThrough(); | |
33 } | |
34 | |
35 Response PageHandler::Disable() { | |
36 return Response::FallThrough(); | |
37 } | |
38 | |
39 Response PageHandler::Reload(const bool* ignoreCache, | |
40 const std::string* script_to_evaluate_on_load, | |
41 const std::string* script_preprocessor) { | |
42 return Response::FallThrough(); | |
43 } | |
44 | |
45 Response PageHandler::Navigate(const std::string& url, | |
46 FrameId* frame_id) { | |
47 return Response::FallThrough(); | |
48 } | |
49 | |
50 Response PageHandler::GetNavigationHistory( | |
51 int* current_index, | |
52 std::vector<NavigationEntry>* entries) { | |
53 return Response::FallThrough(); | |
54 } | |
55 | |
56 Response PageHandler::NavigateToHistoryEntry(int entry_id) { | |
57 return Response::FallThrough(); | |
58 } | |
59 | |
60 Response PageHandler::SetTouchEmulationEnabled(bool enabled) { | |
61 return Response::FallThrough(); | |
62 } | |
63 | |
64 scoped_refptr<DevToolsProtocol::Response> PageHandler::CaptureScreenshot( | |
65 scoped_refptr<DevToolsProtocol::Command> command) { | |
66 if (!host_ || !host_->GetView()) | |
67 return command->InternalErrorResponse("Could not connect to view"); | |
68 | |
69 host_->GetSnapshotFromBrowser( | |
70 base::Bind(&PageHandler::ScreenshotCaptured, | |
71 weak_factory_.GetWeakPtr(), command)); | |
72 return command->AsyncResponsePromise(); | |
73 } | |
74 | |
75 Response PageHandler::CanScreencast(bool* result) { | |
76 return Response::FallThrough(); | |
77 } | |
78 | |
79 Response PageHandler::CanEmulate(bool* result) { | |
80 return Response::FallThrough(); | |
81 } | |
82 | |
83 Response PageHandler::StartScreencast(const std::string* format, | |
84 const int* quality, | |
85 const int* max_width, | |
86 const int* max_height) { | |
87 return Response::FallThrough(); | |
88 } | |
89 | |
90 Response PageHandler::StopScreencast() { | |
91 return Response::FallThrough(); | |
92 } | |
93 | |
94 Response PageHandler::HandleJavaScriptDialog(bool accept, | |
95 const std::string* prompt_text) { | |
96 return Response::FallThrough(); | |
97 } | |
98 | |
99 scoped_refptr<DevToolsProtocol::Response> PageHandler::QueryUsageAndQuota( | |
100 const std::string& security_origin, | |
101 scoped_refptr<DevToolsProtocol::Command> command) { | |
102 return NULL; | |
103 } | |
104 | |
105 Response PageHandler::SetColorPickerEnabled(bool enabled) { | |
106 return Response::FallThrough(); | |
107 } | |
108 | |
109 void PageHandler::ScreenshotCaptured( | |
110 scoped_refptr<DevToolsProtocol::Command> command, | |
111 const unsigned char* png_data, | |
112 size_t png_size) { | |
113 if (!png_data || !png_size) { | |
114 client_->SendInternalErrorResponse(command, | |
115 "Unable to capture screenshot"); | |
dgozman
2014/09/22 12:46:06
nit: indentation
vkuzkokov
2014/09/22 12:57:28
Done.
| |
116 return; | |
117 } | |
118 | |
119 std::string base_64_data; | |
120 base::Base64Encode( | |
121 base::StringPiece(reinterpret_cast<const char*>(png_data), png_size), | |
122 &base_64_data); | |
123 | |
124 CaptureScreenshotResponse response; | |
125 response.set_data(base_64_data); | |
126 client_->SendCaptureScreenshotResponse(command, response); | |
127 } | |
128 | |
129 } // namespace page | |
130 } // namespace devtools | |
131 } // namespace content | |
OLD | NEW |