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

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

Issue 2762593002: Add --headless flag to Windows (Closed)
Patch Set: Fix Mac build Created 3 years, 9 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 <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"
20 #include "headless/app/headless_shell.h" 21 #include "headless/app/headless_shell.h"
21 #include "headless/app/headless_shell_switches.h" 22 #include "headless/app/headless_shell_switches.h"
22 #include "headless/public/headless_devtools_target.h" 23 #include "headless/public/headless_devtools_target.h"
23 #include "headless/public/util/deterministic_http_protocol_handler.h" 24 #include "headless/public/util/deterministic_http_protocol_handler.h"
24 #include "net/base/io_buffer.h" 25 #include "net/base/io_buffer.h"
25 #include "net/base/ip_address.h" 26 #include "net/base/ip_address.h"
26 #include "net/base/net_errors.h" 27 #include "net/base/net_errors.h"
27 #include "ui/gfx/geometry/size.h" 28 #include "ui/gfx/geometry/size.h"
28 29
30 #if defined(OS_WIN)
31 #include "sandbox/win/src/sandbox_types.h"
32 #endif
33
29 namespace headless { 34 namespace headless {
30 namespace { 35 namespace {
31 // Address where to listen to incoming DevTools connections. 36 // Address where to listen to incoming DevTools connections.
32 const char kDevToolsHttpServerAddress[] = "127.0.0.1"; 37 const char kDevToolsHttpServerAddress[] = "127.0.0.1";
33 // Default file name for screenshot. Can be overriden by "--screenshot" switch. 38 // Default file name for screenshot. Can be overriden by "--screenshot" switch.
34 const char kDefaultScreenshotFileName[] = "screenshot.png"; 39 const char kDefaultScreenshotFileName[] = "screenshot.png";
35 40
36 bool ParseWindowSize(std::string window_size, gfx::Size* parsed_window_size) { 41 bool ParseWindowSize(std::string window_size, gfx::Size* parsed_window_size) {
37 int width, height = 0; 42 int width, height = 0;
38 if (sscanf(window_size.c_str(), "%d%*[x,]%d", &width, &height) >= 2 && 43 if (sscanf(window_size.c_str(), "%d%*[x,]%d", &width, &height) >= 2 &&
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 return false; 428 return false;
424 } 429 }
425 if (command_line.HasSwitch(switches::kVirtualTimeBudget)) { 430 if (command_line.HasSwitch(switches::kVirtualTimeBudget)) {
426 LOG(ERROR) << "Virtual time budget is disabled " 431 LOG(ERROR) << "Virtual time budget is disabled "
427 << "when remote debugging is enabled."; 432 << "when remote debugging is enabled.";
428 return false; 433 return false;
429 } 434 }
430 return true; 435 return true;
431 } 436 }
432 437
438 #if defined(OS_WIN)
439 int HeadlessShellMain(HINSTANCE instance,
440 sandbox::SandboxInterfaceInfo* sandbox_info) {
441 base::CommandLine::Init(0, NULL);
442 HeadlessBrowser::Options::Builder builder(0, NULL);
443 builder.SetInstance(instance);
444 builder.SetSandboxInfo(std::move(sandbox_info));
445 #else
433 int HeadlessShellMain(int argc, const char** argv) { 446 int HeadlessShellMain(int argc, const char** argv) {
434 base::CommandLine::Init(argc, argv); 447 base::CommandLine::Init(argc, argv);
435 RunChildProcessIfNeeded(argc, argv); 448 RunChildProcessIfNeeded(argc, argv);
449 HeadlessBrowser::Options::Builder builder(argc, argv);
450 #endif // defined(OS_WIN)
436 HeadlessShell shell; 451 HeadlessShell shell;
437 HeadlessBrowser::Options::Builder builder(argc, argv);
438 452
439 // Enable devtools if requested. 453 // Enable devtools if requested.
440 const base::CommandLine& command_line( 454 const base::CommandLine& command_line(
441 *base::CommandLine::ForCurrentProcess()); 455 *base::CommandLine::ForCurrentProcess());
442 if (!ValidateCommandLine(command_line)) 456 if (!ValidateCommandLine(command_line))
443 return EXIT_FAILURE; 457 return EXIT_FAILURE;
444 458
445 if (command_line.HasSwitch(::switches::kEnableCrashReporter)) 459 if (command_line.HasSwitch(::switches::kEnableCrashReporter))
446 builder.SetCrashReporterEnabled(true); 460 builder.SetCrashReporterEnabled(true);
447 if (command_line.HasSwitch(switches::kCrashDumpsDir)) { 461 if (command_line.HasSwitch(switches::kCrashDumpsDir)) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 builder.SetOverrideWebPreferencesCallback(base::Bind([]( 532 builder.SetOverrideWebPreferencesCallback(base::Bind([](
519 WebPreferences* preferences) { preferences->hide_scrollbars = true; })); 533 WebPreferences* preferences) { preferences->hide_scrollbars = true; }));
520 } 534 }
521 535
522 return HeadlessBrowserMain( 536 return HeadlessBrowserMain(
523 builder.Build(), 537 builder.Build(),
524 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); 538 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell)));
525 } 539 }
526 540
527 } // namespace headless 541 } // namespace headless
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698