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

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

Issue 2832963002: Reland of Add --headless flag to Windows (Closed)
Patch Set: Created 3 years, 8 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') | headless/app/headless_shell_main.cc » ('j') | 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 #include <utility> 8 #include <utility>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
11 #include "base/base_switches.h" 11 #include "base/base_switches.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/json/json_writer.h" 16 #include "base/json/json_writer.h"
17 #include "base/location.h" 17 #include "base/location.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "base/numerics/safe_conversions.h" 19 #include "base/numerics/safe_conversions.h"
20 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
21 #include "content/public/app/content_main.h"
21 #include "headless/app/headless_shell.h" 22 #include "headless/app/headless_shell.h"
22 #include "headless/app/headless_shell_switches.h" 23 #include "headless/app/headless_shell_switches.h"
23 #include "headless/public/headless_devtools_target.h" 24 #include "headless/public/headless_devtools_target.h"
24 #include "headless/public/util/deterministic_http_protocol_handler.h" 25 #include "headless/public/util/deterministic_http_protocol_handler.h"
25 #include "net/base/io_buffer.h" 26 #include "net/base/io_buffer.h"
26 #include "net/base/ip_address.h" 27 #include "net/base/ip_address.h"
27 #include "net/base/net_errors.h" 28 #include "net/base/net_errors.h"
28 #include "net/http/http_util.h" 29 #include "net/http/http_util.h"
29 #include "ui/gfx/geometry/size.h" 30 #include "ui/gfx/geometry/size.h"
30 31
32 #if defined(OS_WIN)
33 #include "sandbox/win/src/sandbox_types.h"
34 #endif
35
31 namespace headless { 36 namespace headless {
32 namespace { 37 namespace {
33 // Address where to listen to incoming DevTools connections. 38 // Address where to listen to incoming DevTools connections.
34 const char kDevToolsHttpServerAddress[] = "127.0.0.1"; 39 const char kDevToolsHttpServerAddress[] = "127.0.0.1";
35 // Default file name for screenshot. Can be overriden by "--screenshot" switch. 40 // Default file name for screenshot. Can be overriden by "--screenshot" switch.
36 const char kDefaultScreenshotFileName[] = "screenshot.png"; 41 const char kDefaultScreenshotFileName[] = "screenshot.png";
37 // Default file name for pdf. Can be overriden by "--print-to-pdf" switch. 42 // Default file name for pdf. Can be overriden by "--print-to-pdf" switch.
38 const char kDefaultPDFFileName[] = "output.pdf"; 43 const char kDefaultPDFFileName[] = "output.pdf";
39 44
40 bool ParseWindowSize(std::string window_size, gfx::Size* parsed_window_size) { 45 bool ParseWindowSize(std::string window_size, gfx::Size* parsed_window_size) {
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 if (!file_proxy_->Write( 422 if (!file_proxy_->Write(
418 0, buf->data(), buf->size(), 423 0, buf->data(), buf->size(),
419 base::Bind(&HeadlessShell::OnFileWritten, weak_factory_.GetWeakPtr(), 424 base::Bind(&HeadlessShell::OnFileWritten, weak_factory_.GetWeakPtr(),
420 file_name, buf->size()))) { 425 file_name, buf->size()))) {
421 // Operation may have completed successfully or failed. 426 // Operation may have completed successfully or failed.
422 OnFileWritten(file_name, buf->size(), base::File::FILE_ERROR_FAILED, 0); 427 OnFileWritten(file_name, buf->size(), base::File::FILE_ERROR_FAILED, 0);
423 } 428 }
424 } 429 }
425 430
426 void HeadlessShell::OnFileWritten(const base::FilePath file_name, 431 void HeadlessShell::OnFileWritten(const base::FilePath file_name,
427 const int length, 432 const size_t length,
428 base::File::Error error_code, 433 base::File::Error error_code,
429 int write_result) { 434 int write_result) {
430 if (write_result < length) { 435 if (write_result < static_cast<int>(length)) {
431 // TODO(eseckler): Support recovering from partial writes. 436 // TODO(eseckler): Support recovering from partial writes.
432 LOG(ERROR) << "Writing to file " << file_name.value() 437 LOG(ERROR) << "Writing to file " << file_name.value()
433 << " was unsuccessful: " 438 << " was unsuccessful: "
434 << base::File::ErrorToString(error_code); 439 << base::File::ErrorToString(error_code);
435 } else { 440 } else {
436 LOG(INFO) << "Written to file " << file_name.value() << "."; 441 LOG(INFO) << "Written to file " << file_name.value() << ".";
437 } 442 }
438 if (!file_proxy_->Close(base::Bind(&HeadlessShell::OnFileClosed, 443 if (!file_proxy_->Close(base::Bind(&HeadlessShell::OnFileClosed,
439 weak_factory_.GetWeakPtr()))) { 444 weak_factory_.GetWeakPtr()))) {
440 // Operation could not be started. 445 // Operation could not be started.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 return false; 495 return false;
491 } 496 }
492 if (command_line.HasSwitch(switches::kVirtualTimeBudget)) { 497 if (command_line.HasSwitch(switches::kVirtualTimeBudget)) {
493 LOG(ERROR) << "Virtual time budget is disabled " 498 LOG(ERROR) << "Virtual time budget is disabled "
494 << "when remote debugging is enabled."; 499 << "when remote debugging is enabled.";
495 return false; 500 return false;
496 } 501 }
497 return true; 502 return true;
498 } 503 }
499 504
505 #if defined(OS_WIN)
506 int HeadlessShellMain(HINSTANCE instance,
507 sandbox::SandboxInterfaceInfo* sandbox_info) {
508 base::CommandLine::Init(0, nullptr);
509 HeadlessBrowser::Options::Builder builder(0, nullptr);
510 builder.SetInstance(instance);
511 builder.SetSandboxInfo(std::move(sandbox_info));
512 #else
500 int HeadlessShellMain(int argc, const char** argv) { 513 int HeadlessShellMain(int argc, const char** argv) {
501 base::CommandLine::Init(argc, argv); 514 base::CommandLine::Init(argc, argv);
502 RunChildProcessIfNeeded(argc, argv); 515 RunChildProcessIfNeeded(argc, argv);
516 HeadlessBrowser::Options::Builder builder(argc, argv);
517 #endif // defined(OS_WIN)
503 HeadlessShell shell; 518 HeadlessShell shell;
504 HeadlessBrowser::Options::Builder builder(argc, argv);
505 519
506 // Enable devtools if requested. 520 // Enable devtools if requested.
507 const base::CommandLine& command_line( 521 const base::CommandLine& command_line(
508 *base::CommandLine::ForCurrentProcess()); 522 *base::CommandLine::ForCurrentProcess());
509 if (!ValidateCommandLine(command_line)) 523 if (!ValidateCommandLine(command_line))
510 return EXIT_FAILURE; 524 return EXIT_FAILURE;
511 525
512 if (command_line.HasSwitch(::switches::kEnableCrashReporter)) 526 if (command_line.HasSwitch(switches::kEnableCrashReporter))
513 builder.SetCrashReporterEnabled(true); 527 builder.SetCrashReporterEnabled(true);
514 if (command_line.HasSwitch(switches::kCrashDumpsDir)) { 528 if (command_line.HasSwitch(switches::kCrashDumpsDir)) {
515 builder.SetCrashDumpsDir( 529 builder.SetCrashDumpsDir(
516 command_line.GetSwitchValuePath(switches::kCrashDumpsDir)); 530 command_line.GetSwitchValuePath(switches::kCrashDumpsDir));
517 } 531 }
518 532
519 if (command_line.HasSwitch(::switches::kRemoteDebuggingPort)) { 533 if (command_line.HasSwitch(::switches::kRemoteDebuggingPort)) {
520 std::string address = kDevToolsHttpServerAddress; 534 std::string address = kDevToolsHttpServerAddress;
521 if (command_line.HasSwitch(switches::kRemoteDebuggingAddress)) { 535 if (command_line.HasSwitch(switches::kRemoteDebuggingAddress)) {
522 address = 536 address =
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 std::string ua = command_line.GetSwitchValueASCII(switches::kUserAgent); 604 std::string ua = command_line.GetSwitchValueASCII(switches::kUserAgent);
591 if (net::HttpUtil::IsValidHeaderValue(ua)) 605 if (net::HttpUtil::IsValidHeaderValue(ua))
592 builder.SetUserAgent(ua); 606 builder.SetUserAgent(ua);
593 } 607 }
594 608
595 return HeadlessBrowserMain( 609 return HeadlessBrowserMain(
596 builder.Build(), 610 builder.Build(),
597 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); 611 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell)));
598 } 612 }
599 613
614 int HeadlessShellMain(const content::ContentMainParams& params) {
615 #if defined(OS_WIN)
616 return HeadlessShellMain(params.instance, params.sandbox_info);
617 #else
618 return HeadlessShellMain(params.argc, params.argv);
619 #endif
620 }
621
600 } // namespace headless 622 } // namespace headless
OLDNEW
« no previous file with comments | « headless/app/headless_shell.h ('k') | headless/app/headless_shell_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698