Chromium Code Reviews| 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 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 preferences->hide_scrollbars = true; | 97 preferences->hide_scrollbars = true; |
| 98 })); | 98 })); |
| 99 } | 99 } |
| 100 browser_context_ = context_builder.Build(); | 100 browser_context_ = context_builder.Build(); |
| 101 | 101 |
| 102 HeadlessWebContents::Builder builder( | 102 HeadlessWebContents::Builder builder( |
| 103 browser_context_->CreateWebContentsBuilder()); | 103 browser_context_->CreateWebContentsBuilder()); |
| 104 base::CommandLine::StringVector args = | 104 base::CommandLine::StringVector args = |
| 105 base::CommandLine::ForCurrentProcess()->GetArgs(); | 105 base::CommandLine::ForCurrentProcess()->GetArgs(); |
| 106 | 106 |
| 107 if (!MultiTabsCheckPassed(args.size())) { | |
|
Eric Seckler
2017/01/10 17:42:30
nit: Can we move this to HeadlessShellMain() befor
jzfeng
2017/01/11 12:00:27
Good point. Done.
| |
| 108 browser_->Shutdown(); | |
| 109 return; | |
| 110 } | |
| 107 // TODO(alexclarke): Should we navigate to about:blank first if using | 111 // TODO(alexclarke): Should we navigate to about:blank first if using |
| 108 // virtual time? | 112 // virtual time? |
| 109 if (!args.empty() && !args[0].empty()) | 113 if (args.empty()) { |
| 110 builder.SetInitialURL(GURL(args[0])); | 114 args.push_back("about:blank"); |
| 111 | 115 } |
| 112 web_contents_ = builder.Build(); | 116 for (auto it = args.rbegin(); it != args.rend(); ++it) { |
| 113 if (!web_contents_) { | 117 url_ = GURL(*it); |
|
Eric Seckler
2017/01/10 17:42:30
Good spot, seems like we didn't set url_ correctly
jzfeng
2017/01/11 12:00:27
By experiment, I found the tab order on the Inspec
| |
| 114 LOG(ERROR) << "Navigation failed"; | 118 web_contents_ = builder.SetInitialURL(url_).Build(); |
| 115 browser_->Shutdown(); | 119 if (!web_contents_) { |
| 116 return; | 120 LOG(ERROR) << "Navigation to " << url_ << " failed"; |
| 121 browser_->Shutdown(); | |
| 122 return; | |
| 123 } | |
| 117 } | 124 } |
| 118 web_contents_->AddObserver(this); | 125 web_contents_->AddObserver(this); |
|
Eric Seckler
2017/01/10 17:42:30
I think this is a rather temporary solution, since
| |
| 119 } | 126 } |
| 120 | 127 |
| 121 void Shutdown() { | 128 void Shutdown() { |
| 122 if (!web_contents_) | 129 if (!web_contents_) |
| 123 return; | 130 return; |
| 124 if (!RemoteDebuggingEnabled()) { | 131 if (!RemoteDebuggingEnabled()) { |
| 125 devtools_client_->GetEmulation()->GetExperimental()->RemoveObserver(this); | 132 devtools_client_->GetEmulation()->GetExperimental()->RemoveObserver(this); |
| 126 devtools_client_->GetInspector()->GetExperimental()->RemoveObserver(this); | 133 devtools_client_->GetInspector()->GetExperimental()->RemoveObserver(this); |
| 127 devtools_client_->GetPage()->RemoveObserver(this); | 134 devtools_client_->GetPage()->RemoveObserver(this); |
| 128 if (web_contents_->GetDevToolsTarget()) { | 135 if (web_contents_->GetDevToolsTarget()) { |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 } | 386 } |
| 380 | 387 |
| 381 void OnScreenshotFileClosed(const int close_result) { Shutdown(); } | 388 void OnScreenshotFileClosed(const int close_result) { Shutdown(); } |
| 382 | 389 |
| 383 bool RemoteDebuggingEnabled() const { | 390 bool RemoteDebuggingEnabled() const { |
| 384 const base::CommandLine& command_line = | 391 const base::CommandLine& command_line = |
| 385 *base::CommandLine::ForCurrentProcess(); | 392 *base::CommandLine::ForCurrentProcess(); |
| 386 return command_line.HasSwitch(::switches::kRemoteDebuggingPort); | 393 return command_line.HasSwitch(::switches::kRemoteDebuggingPort); |
| 387 } | 394 } |
| 388 | 395 |
| 396 bool MultiTabsCheckPassed(const int tab_number) const { | |
|
Sami
2017/01/11 11:32:37
nit: I'm not sure what the method name is saying.
jzfeng
2017/01/11 12:00:27
I moved this function to HeadlessShellMain and cha
alex clarke (OOO till 29th)
2017/01/11 12:03:39
One rule of thumb, any type of integer or floating
| |
| 397 if (tab_number < 2 || RemoteDebuggingEnabled()) { | |
| 398 return true; | |
| 399 } | |
| 400 const base::CommandLine& command_line = | |
| 401 *base::CommandLine::ForCurrentProcess(); | |
| 402 if (command_line.HasSwitch(switches::kDumpDom)) { | |
|
Eric Seckler
2017/01/10 17:42:30
Actually, I think at the moment, we kinda require
jzfeng
2017/01/11 12:00:27
Done.
| |
| 403 LOG(ERROR) << "Dump dom is not supported for multiple tabs."; | |
|
Sami
2017/01/11 11:32:37
nit: s/dom/DOM/
jzfeng
2017/01/11 12:00:27
Done.
| |
| 404 return false; | |
| 405 } | |
| 406 if (command_line.HasSwitch(switches::kRepl)) { | |
| 407 LOG(ERROR) << "Evaluate Javascript is not supported for multiple tabs."; | |
| 408 return false; | |
| 409 } | |
| 410 if (command_line.HasSwitch(switches::kScreenshot)) { | |
| 411 // TODO(jzfeng): Add support for multiple tabs in the future. | |
| 412 LOG(ERROR) << "Capture screenshot is not supported for multiple tabs."; | |
| 413 return false; | |
| 414 } | |
| 415 return true; | |
| 416 } | |
| 417 | |
| 389 private: | 418 private: |
| 390 GURL url_; | 419 GURL url_; |
| 391 HeadlessBrowser* browser_; // Not owned. | 420 HeadlessBrowser* browser_; // Not owned. |
| 392 std::unique_ptr<HeadlessDevToolsClient> devtools_client_; | 421 std::unique_ptr<HeadlessDevToolsClient> devtools_client_; |
| 393 HeadlessWebContents* web_contents_; | 422 HeadlessWebContents* web_contents_; |
| 394 bool processed_page_ready_; | 423 bool processed_page_ready_; |
| 395 std::unique_ptr<net::FileStream> screenshot_file_stream_; | 424 std::unique_ptr<net::FileStream> screenshot_file_stream_; |
| 396 HeadlessBrowserContext* browser_context_; | 425 HeadlessBrowserContext* browser_context_; |
| 397 std::unique_ptr<DeterministicDispatcher> deterministic_dispatcher_; | 426 std::unique_ptr<DeterministicDispatcher> deterministic_dispatcher_; |
| 398 base::WeakPtrFactory<HeadlessShell> weak_factory_; | 427 base::WeakPtrFactory<HeadlessShell> weak_factory_; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 } | 500 } |
| 472 builder.SetWindowSize(parsed_window_size); | 501 builder.SetWindowSize(parsed_window_size); |
| 473 } | 502 } |
| 474 | 503 |
| 475 return HeadlessBrowserMain( | 504 return HeadlessBrowserMain( |
| 476 builder.Build(), | 505 builder.Build(), |
| 477 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); | 506 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); |
| 478 } | 507 } |
| 479 | 508 |
| 480 } // namespace headless | 509 } // namespace headless |
| OLD | NEW |