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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "content/public/common/content_switches.h" | 12 #include "content/public/common/content_switches.h" |
| 13 #include "headless/app/headless_shell_switches.h" |
13 #include "headless/public/headless_browser.h" | 14 #include "headless/public/headless_browser.h" |
14 #include "headless/public/headless_web_contents.h" | 15 #include "headless/public/headless_web_contents.h" |
15 #include "net/base/ip_address.h" | 16 #include "net/base/ip_address.h" |
16 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
17 | 18 |
18 using headless::HeadlessBrowser; | 19 using headless::HeadlessBrowser; |
19 using headless::HeadlessWebContents; | 20 using headless::HeadlessWebContents; |
20 | 21 |
21 namespace { | 22 namespace { |
22 // Address where to listen to incoming DevTools connections. | 23 // Address where to listen to incoming DevTools connections. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 web_contents_ = nullptr; | 62 web_contents_ = nullptr; |
62 browser_->Shutdown(); | 63 browser_->Shutdown(); |
63 } | 64 } |
64 } | 65 } |
65 | 66 |
66 // HeadlessWebContents::Observer implementation: | 67 // HeadlessWebContents::Observer implementation: |
67 void DocumentOnLoadCompletedInMainFrame() override { | 68 void DocumentOnLoadCompletedInMainFrame() override { |
68 ShutdownIfNeeded(); | 69 ShutdownIfNeeded(); |
69 } | 70 } |
70 | 71 |
| 72 void DidFinishNavigation(bool success) override {} |
| 73 |
71 private: | 74 private: |
72 HeadlessBrowser* browser_; // Not owned. | 75 HeadlessBrowser* browser_; // Not owned. |
73 scoped_ptr<HeadlessWebContents> web_contents_; | 76 scoped_ptr<HeadlessWebContents> web_contents_; |
74 | 77 |
75 DISALLOW_COPY_AND_ASSIGN(HeadlessShell); | 78 DISALLOW_COPY_AND_ASSIGN(HeadlessShell); |
76 }; | 79 }; |
77 | 80 |
78 int main(int argc, const char** argv) { | 81 int main(int argc, const char** argv) { |
79 HeadlessShell shell; | 82 HeadlessShell shell; |
80 HeadlessBrowser::Options::Builder builder(argc, argv); | 83 HeadlessBrowser::Options::Builder builder(argc, argv); |
81 | 84 |
82 // Enable devtools if requested. | 85 // Enable devtools if requested. |
83 base::CommandLine command_line(argc, argv); | 86 base::CommandLine command_line(argc, argv); |
84 if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) { | 87 if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) { |
85 int parsed_port; | 88 int parsed_port; |
86 std::string port_str = | 89 std::string port_str = |
87 command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort); | 90 command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort); |
88 if (base::StringToInt(port_str, &parsed_port) && | 91 if (base::StringToInt(port_str, &parsed_port) && |
89 base::IsValueInRangeForNumericType<uint16_t>(parsed_port)) { | 92 base::IsValueInRangeForNumericType<uint16_t>(parsed_port)) { |
90 net::IPAddress devtools_address; | 93 net::IPAddress devtools_address; |
91 bool result = | 94 bool result = |
92 devtools_address.AssignFromIPLiteral(kDevToolsHttpServerAddress); | 95 devtools_address.AssignFromIPLiteral(kDevToolsHttpServerAddress); |
93 DCHECK(result); | 96 DCHECK(result); |
94 builder.EnableDevToolsServer(net::IPEndPoint( | 97 builder.EnableDevToolsServer(net::IPEndPoint( |
95 devtools_address, base::checked_cast<uint16_t>(parsed_port))); | 98 devtools_address, base::checked_cast<uint16_t>(parsed_port))); |
96 } | 99 } |
97 } | 100 } |
98 | 101 |
| 102 if (command_line.HasSwitch(headless::switches::kProxyServer)) { |
| 103 std::string proxy_server = |
| 104 command_line.GetSwitchValueASCII(headless::switches::kProxyServer); |
| 105 net::HostPortPair parsed_proxy_server = |
| 106 net::HostPortPair::FromString(proxy_server); |
| 107 if (parsed_proxy_server.host().empty() || !parsed_proxy_server.port()) { |
| 108 LOG(ERROR) << "Malformed proxy server url"; |
| 109 return EXIT_FAILURE; |
| 110 } |
| 111 builder.SetProxyServer(parsed_proxy_server); |
| 112 } |
| 113 |
99 return HeadlessBrowserMain( | 114 return HeadlessBrowserMain( |
100 builder.Build(), | 115 builder.Build(), |
101 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); | 116 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); |
102 } | 117 } |
OLD | NEW |