Index: headless/app/headless_shell.cc |
diff --git a/headless/app/headless_shell.cc b/headless/app/headless_shell.cc |
index 530a7c5dc3498e2d3b19d99b12c8ce6da043d47a..feafedf98f634113a3588456659f5c324d4aafb9 100644 |
--- a/headless/app/headless_shell.cc |
+++ b/headless/app/headless_shell.cc |
@@ -106,16 +106,24 @@ class HeadlessShell : public HeadlessWebContents::Observer, |
// TODO(alexclarke): Should we navigate to about:blank first if using |
// virtual time? |
- if (!args.empty() && !args[0].empty()) |
- builder.SetInitialURL(GURL(args[0])); |
- |
- web_contents_ = builder.Build(); |
- if (!web_contents_) { |
- LOG(ERROR) << "Navigation failed"; |
- browser_->Shutdown(); |
- return; |
+ if (args.empty()) { |
Eric Seckler
2017/01/11 13:39:20
nit: get rid of brackets, i.e.
if (args.empty())
jzfeng
2017/01/11 13:56:13
Thanks for the tip! Done.
|
+ args.push_back("about:blank"); |
+ } |
+ for (auto it = args.rbegin(); it != args.rend(); ++it) { |
+ GURL url(*it); |
+ HeadlessWebContents* web_contents = builder.SetInitialURL(url).Build(); |
+ if (!web_contents) { |
+ LOG(ERROR) << "Navigation to " << url << " failed"; |
+ browser_->Shutdown(); |
+ return; |
+ } |
+ if (!web_contents_ && !RemoteDebuggingEnabled()) { |
+ // TODO(jzfeng): Support observing multiple targets. |
+ url_ = url; |
+ web_contents_ = web_contents; |
+ web_contents_->AddObserver(this); |
+ } |
} |
- web_contents_->AddObserver(this); |
} |
void Shutdown() { |
@@ -138,8 +146,6 @@ class HeadlessShell : public HeadlessWebContents::Observer, |
// HeadlessWebContents::Observer implementation: |
void DevToolsTargetReady() override { |
- if (RemoteDebuggingEnabled()) |
- return; |
web_contents_->GetDevToolsTarget()->AttachClient(devtools_client_.get()); |
devtools_client_->GetInspector()->GetExperimental()->AddObserver(this); |
devtools_client_->GetPage()->AddObserver(this); |
@@ -400,6 +406,41 @@ class HeadlessShell : public HeadlessWebContents::Observer, |
DISALLOW_COPY_AND_ASSIGN(HeadlessShell); |
}; |
+bool ValidateCommandLine(const base::CommandLine& command_line) { |
+ if (!command_line.HasSwitch(::switches::kRemoteDebuggingPort)) { |
+ if (command_line.GetArgs().size() <= 1) |
Sami
2017/01/11 13:14:28
Looks like this should be before the previous if s
Sami
2017/01/11 13:33:32
Oops, I misread, ignore me :)
|
+ return true; |
+ LOG(ERROR) << "Open multiple tabs is only supported when the " |
+ << "remote debug port is set."; |
+ return false; |
+ } |
+ if (command_line.HasSwitch(switches::kDumpDom)) { |
+ LOG(ERROR) << "Dump DOM is disabled when remote debugging is enabled."; |
+ return false; |
+ } |
+ if (command_line.HasSwitch(switches::kRepl)) { |
+ LOG(ERROR) << "Evaluate Javascript is disabled " |
+ << "when remote debugging is enabled."; |
+ return false; |
+ } |
+ if (command_line.HasSwitch(switches::kScreenshot)) { |
+ LOG(ERROR) << "Capture screenshot is disabled " |
+ << "when remote debugging is enabled."; |
+ return false; |
+ } |
+ if (command_line.HasSwitch(switches::kTimeout)) { |
+ LOG(ERROR) << "Navigation timeout is disabled " |
+ << "when remote debugging is enabled."; |
+ return false; |
+ } |
+ if (command_line.HasSwitch(switches::kVirtualTimeBudget)) { |
+ LOG(ERROR) << "Virtual time budget is disabled " |
+ << "when remote debugging is enabled."; |
+ return false; |
+ } |
+ return true; |
+} |
+ |
int HeadlessShellMain(int argc, const char** argv) { |
RunChildProcessIfNeeded(argc, argv); |
HeadlessShell shell; |
@@ -407,6 +448,10 @@ int HeadlessShellMain(int argc, const char** argv) { |
// Enable devtools if requested. |
base::CommandLine command_line(argc, argv); |
+ if (!ValidateCommandLine(command_line)) { |
Eric Seckler
2017/01/11 13:39:20
nit: same here (no brackets).
jzfeng
2017/01/11 13:56:13
Done.
|
+ return EXIT_FAILURE; |
+ } |
+ |
if (command_line.HasSwitch(::switches::kRemoteDebuggingPort)) { |
std::string address = kDevToolsHttpServerAddress; |
if (command_line.HasSwitch(switches::kRemoteDebuggingAddress)) { |