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

Side by Side Diff: headless/app/headless_shell.cc

Issue 2035733002: headless: Implement screenshot capturing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <iostream> 5 #include <iostream>
6 #include <memory> 6 #include <memory>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 128
129 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 129 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
130 headless::switches::kDumpDom)) { 130 headless::switches::kDumpDom)) {
131 FetchDom(); 131 FetchDom();
132 } else if (base::CommandLine::ForCurrentProcess()->HasSwitch( 132 } else if (base::CommandLine::ForCurrentProcess()->HasSwitch(
133 headless::switches::kRepl)) { 133 headless::switches::kRepl)) {
134 std::cout 134 std::cout
135 << "Type a Javascript expression to evaluate or \"quit\" to exit." 135 << "Type a Javascript expression to evaluate or \"quit\" to exit."
136 << std::endl; 136 << std::endl;
137 InputExpression(); 137 InputExpression();
138 } else if (base::CommandLine::ForCurrentProcess()->HasSwitch(
139 headless::switches::kScreenshot)) {
140 CaptureScreenshot();
138 } else { 141 } else {
139 Shutdown(); 142 Shutdown();
140 } 143 }
141 } 144 }
142 145
143 void FetchDom() { 146 void FetchDom() {
144 devtools_client_->GetRuntime()->Evaluate( 147 devtools_client_->GetRuntime()->Evaluate(
145 "document.body.innerHTML", 148 "document.body.innerHTML",
146 base::Bind(&HeadlessShell::OnDomFetched, base::Unretained(this))); 149 base::Bind(&HeadlessShell::OnDomFetched, base::Unretained(this)));
147 } 150 }
(...skipping 26 matching lines...) Expand all
174 } 177 }
175 178
176 void OnExpressionResult(std::unique_ptr<runtime::EvaluateResult> result) { 179 void OnExpressionResult(std::unique_ptr<runtime::EvaluateResult> result) {
177 std::unique_ptr<base::Value> value = result->Serialize(); 180 std::unique_ptr<base::Value> value = result->Serialize();
178 std::string result_json; 181 std::string result_json;
179 base::JSONWriter::Write(*value, &result_json); 182 base::JSONWriter::Write(*value, &result_json);
180 std::cout << result_json << std::endl; 183 std::cout << result_json << std::endl;
181 InputExpression(); 184 InputExpression();
182 } 185 }
183 186
187 void CaptureScreenshot() {
188 devtools_client_->GetPage()->GetExperimental()->CaptureScreenshot(
189 page::CaptureScreenshotParams::Builder().Build(),
190 base::Bind(&HeadlessShell::OnScreenshotCaptured,
191 base::Unretained(this)));
192 }
193
194 void OnScreenshotCaptured(
195 std::unique_ptr<page::CaptureScreenshotResult> result) {
196 std::unique_ptr<base::Value> value = result->Serialize();
197 std::string result_json;
198 base::JSONWriter::Write(*value, &result_json);
199 std::cout << result_json << std::endl;
Sami 2016/06/02 14:22:19 Could you make this actually write out the png ins
Eric Seckler 2016/06/03 11:30:40 Done.
200 Shutdown();
201 }
202
184 bool RemoteDebuggingEnabled() const { 203 bool RemoteDebuggingEnabled() const {
185 const base::CommandLine& command_line = 204 const base::CommandLine& command_line =
186 *base::CommandLine::ForCurrentProcess(); 205 *base::CommandLine::ForCurrentProcess();
187 return command_line.HasSwitch(switches::kRemoteDebuggingPort); 206 return command_line.HasSwitch(switches::kRemoteDebuggingPort);
188 } 207 }
189 208
190 private: 209 private:
191 GURL url_; 210 GURL url_;
192 HeadlessBrowser* browser_; // Not owned. 211 HeadlessBrowser* browser_; // Not owned.
193 std::unique_ptr<HeadlessDevToolsClient> devtools_client_; 212 std::unique_ptr<HeadlessDevToolsClient> devtools_client_;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 262
244 if (command_line.HasSwitch(switches::kHostResolverRules)) { 263 if (command_line.HasSwitch(switches::kHostResolverRules)) {
245 builder.SetHostResolverRules( 264 builder.SetHostResolverRules(
246 command_line.GetSwitchValueASCII(switches::kHostResolverRules)); 265 command_line.GetSwitchValueASCII(switches::kHostResolverRules));
247 } 266 }
248 267
249 return HeadlessBrowserMain( 268 return HeadlessBrowserMain(
250 builder.Build(), 269 builder.Build(),
251 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); 270 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell)));
252 } 271 }
OLDNEW
« no previous file with comments | « no previous file | headless/app/headless_shell_switches.h » ('j') | headless/lib/browser/headless_browser_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698