| OLD | NEW |
| 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 | 9 |
| 9 #include "base/base64.h" | 10 #include "base/base64.h" |
| 10 #include "base/base_switches.h" | 11 #include "base/base_switches.h" |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/callback.h" | 13 #include "base/callback.h" |
| 13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 15 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
| 16 #include "base/location.h" | 17 #include "base/location.h" |
| 17 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 18 #include "base/numerics/safe_conversions.h" | 19 #include "base/numerics/safe_conversions.h" |
| 19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 21 #include "content/public/app/content_main.h" |
| 20 #include "headless/app/headless_shell.h" | 22 #include "headless/app/headless_shell.h" |
| 21 #include "headless/app/headless_shell_switches.h" | 23 #include "headless/app/headless_shell_switches.h" |
| 22 #include "headless/public/headless_devtools_target.h" | 24 #include "headless/public/headless_devtools_target.h" |
| 23 #include "headless/public/util/deterministic_http_protocol_handler.h" | 25 #include "headless/public/util/deterministic_http_protocol_handler.h" |
| 24 #include "net/base/io_buffer.h" | 26 #include "net/base/io_buffer.h" |
| 25 #include "net/base/ip_address.h" | 27 #include "net/base/ip_address.h" |
| 26 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
| 27 #include "ui/gfx/geometry/size.h" | 29 #include "ui/gfx/geometry/size.h" |
| 28 | 30 |
| 31 #if defined(OS_WIN) |
| 32 #include "sandbox/win/src/sandbox_types.h" |
| 33 #endif |
| 34 |
| 29 namespace headless { | 35 namespace headless { |
| 30 namespace { | 36 namespace { |
| 31 // Address where to listen to incoming DevTools connections. | 37 // Address where to listen to incoming DevTools connections. |
| 32 const char kDevToolsHttpServerAddress[] = "127.0.0.1"; | 38 const char kDevToolsHttpServerAddress[] = "127.0.0.1"; |
| 33 // Default file name for screenshot. Can be overriden by "--screenshot" switch. | 39 // Default file name for screenshot. Can be overriden by "--screenshot" switch. |
| 34 const char kDefaultScreenshotFileName[] = "screenshot.png"; | 40 const char kDefaultScreenshotFileName[] = "screenshot.png"; |
| 35 | 41 |
| 36 bool ParseWindowSize(std::string window_size, gfx::Size* parsed_window_size) { | 42 bool ParseWindowSize(std::string window_size, gfx::Size* parsed_window_size) { |
| 37 int width, height = 0; | 43 int width, height = 0; |
| 38 if (sscanf(window_size.c_str(), "%d%*[x,]%d", &width, &height) >= 2 && | 44 if (sscanf(window_size.c_str(), "%d%*[x,]%d", &width, &height) >= 2 && |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 return false; | 429 return false; |
| 424 } | 430 } |
| 425 if (command_line.HasSwitch(switches::kVirtualTimeBudget)) { | 431 if (command_line.HasSwitch(switches::kVirtualTimeBudget)) { |
| 426 LOG(ERROR) << "Virtual time budget is disabled " | 432 LOG(ERROR) << "Virtual time budget is disabled " |
| 427 << "when remote debugging is enabled."; | 433 << "when remote debugging is enabled."; |
| 428 return false; | 434 return false; |
| 429 } | 435 } |
| 430 return true; | 436 return true; |
| 431 } | 437 } |
| 432 | 438 |
| 439 #if defined(OS_WIN) |
| 440 int HeadlessShellMain(HINSTANCE instance, |
| 441 sandbox::SandboxInterfaceInfo* sandbox_info) { |
| 442 base::CommandLine::Init(0, nullptr); |
| 443 HeadlessBrowser::Options::Builder builder(0, nullptr); |
| 444 builder.SetInstance(instance); |
| 445 builder.SetSandboxInfo(std::move(sandbox_info)); |
| 446 #else |
| 433 int HeadlessShellMain(int argc, const char** argv) { | 447 int HeadlessShellMain(int argc, const char** argv) { |
| 434 base::CommandLine::Init(argc, argv); | 448 base::CommandLine::Init(argc, argv); |
| 435 RunChildProcessIfNeeded(argc, argv); | 449 RunChildProcessIfNeeded(argc, argv); |
| 450 HeadlessBrowser::Options::Builder builder(argc, argv); |
| 451 #endif // defined(OS_WIN) |
| 436 HeadlessShell shell; | 452 HeadlessShell shell; |
| 437 HeadlessBrowser::Options::Builder builder(argc, argv); | |
| 438 | 453 |
| 439 // Enable devtools if requested. | 454 // Enable devtools if requested. |
| 440 const base::CommandLine& command_line( | 455 const base::CommandLine& command_line( |
| 441 *base::CommandLine::ForCurrentProcess()); | 456 *base::CommandLine::ForCurrentProcess()); |
| 442 if (!ValidateCommandLine(command_line)) | 457 if (!ValidateCommandLine(command_line)) |
| 443 return EXIT_FAILURE; | 458 return EXIT_FAILURE; |
| 444 | 459 |
| 445 if (command_line.HasSwitch(::switches::kEnableCrashReporter)) | 460 if (command_line.HasSwitch(switches::kEnableCrashReporter)) |
| 446 builder.SetCrashReporterEnabled(true); | 461 builder.SetCrashReporterEnabled(true); |
| 447 if (command_line.HasSwitch(switches::kCrashDumpsDir)) { | 462 if (command_line.HasSwitch(switches::kCrashDumpsDir)) { |
| 448 builder.SetCrashDumpsDir( | 463 builder.SetCrashDumpsDir( |
| 449 command_line.GetSwitchValuePath(switches::kCrashDumpsDir)); | 464 command_line.GetSwitchValuePath(switches::kCrashDumpsDir)); |
| 450 } | 465 } |
| 451 | 466 |
| 452 if (command_line.HasSwitch(::switches::kRemoteDebuggingPort)) { | 467 if (command_line.HasSwitch(::switches::kRemoteDebuggingPort)) { |
| 453 std::string address = kDevToolsHttpServerAddress; | 468 std::string address = kDevToolsHttpServerAddress; |
| 454 if (command_line.HasSwitch(switches::kRemoteDebuggingAddress)) { | 469 if (command_line.HasSwitch(switches::kRemoteDebuggingAddress)) { |
| 455 address = | 470 address = |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 if (command_line.HasSwitch(switches::kHideScrollbars)) { | 532 if (command_line.HasSwitch(switches::kHideScrollbars)) { |
| 518 builder.SetOverrideWebPreferencesCallback(base::Bind([]( | 533 builder.SetOverrideWebPreferencesCallback(base::Bind([]( |
| 519 WebPreferences* preferences) { preferences->hide_scrollbars = true; })); | 534 WebPreferences* preferences) { preferences->hide_scrollbars = true; })); |
| 520 } | 535 } |
| 521 | 536 |
| 522 return HeadlessBrowserMain( | 537 return HeadlessBrowserMain( |
| 523 builder.Build(), | 538 builder.Build(), |
| 524 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); | 539 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); |
| 525 } | 540 } |
| 526 | 541 |
| 542 int HeadlessShellMain(const content::ContentMainParams& params) { |
| 543 #if defined(OS_WIN) |
| 544 return HeadlessShellMain(params.instance, params.sandbox_info); |
| 545 #else |
| 546 return HeadlessShellMain(params.argc, params.argv); |
| 547 #endif |
| 548 } |
| 549 |
| 527 } // namespace headless | 550 } // namespace headless |
| OLD | NEW |