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

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

Issue 2677033003: headless: Add a small C++ example application (Closed)
Patch Set: Rebased Created 3 years, 10 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
« no previous file with comments | « headless/app/headless_shell.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <memory> 5 #include <memory>
6 #include <sstream> 6 #include <sstream>
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } else if (base::CommandLine::ForCurrentProcess()->HasSwitch( 254 } else if (base::CommandLine::ForCurrentProcess()->HasSwitch(
255 switches::kScreenshot)) { 255 switches::kScreenshot)) {
256 CaptureScreenshot(); 256 CaptureScreenshot();
257 } else { 257 } else {
258 Shutdown(); 258 Shutdown();
259 } 259 }
260 } 260 }
261 261
262 void HeadlessShell::FetchDom() { 262 void HeadlessShell::FetchDom() {
263 devtools_client_->GetRuntime()->Evaluate( 263 devtools_client_->GetRuntime()->Evaluate(
264 "document.body.innerHTML", 264 "document.body.outerHTML",
265 base::Bind(&HeadlessShell::OnDomFetched, weak_factory_.GetWeakPtr())); 265 base::Bind(&HeadlessShell::OnDomFetched, weak_factory_.GetWeakPtr()));
266 } 266 }
267 267
268 void HeadlessShell::OnDomFetched( 268 void HeadlessShell::OnDomFetched(
269 std::unique_ptr<runtime::EvaluateResult> result) { 269 std::unique_ptr<runtime::EvaluateResult> result) {
270 if (result->HasExceptionDetails()) { 270 if (result->HasExceptionDetails()) {
271 LOG(ERROR) << "Failed to evaluate document.body.innerHTML: " 271 LOG(ERROR) << "Failed to evaluate document.body.outerHTML: "
272 << result->GetExceptionDetails()->GetText(); 272 << result->GetExceptionDetails()->GetText();
273 } else { 273 } else {
274 std::string dom; 274 std::string dom;
275 if (result->GetResult()->GetValue()->GetAsString(&dom)) { 275 if (result->GetResult()->GetValue()->GetAsString(&dom)) {
276 printf("%s\n", dom.c_str()); 276 printf("%s\n", dom.c_str());
277 } 277 }
278 } 278 }
279 Shutdown(); 279 Shutdown();
280 } 280 }
281 281
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 builder.SetOverrideWebPreferencesCallback(base::Bind([]( 510 builder.SetOverrideWebPreferencesCallback(base::Bind([](
511 WebPreferences* preferences) { preferences->hide_scrollbars = true; })); 511 WebPreferences* preferences) { preferences->hide_scrollbars = true; }));
512 } 512 }
513 513
514 return HeadlessBrowserMain( 514 return HeadlessBrowserMain(
515 builder.Build(), 515 builder.Build(),
516 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); 516 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell)));
517 } 517 }
518 518
519 } // namespace headless 519 } // namespace headless
OLDNEW
« no previous file with comments | « headless/app/headless_shell.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698