| 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 <iostream> | 5 #include <iostream> |
| 6 #include <memory> | 6 #include <memory> |
| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 112 } |
| 113 web_contents_->AddObserver(this); | 113 web_contents_->AddObserver(this); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void Shutdown() { | 116 void Shutdown() { |
| 117 if (!web_contents_) | 117 if (!web_contents_) |
| 118 return; | 118 return; |
| 119 if (!RemoteDebuggingEnabled()) { | 119 if (!RemoteDebuggingEnabled()) { |
| 120 devtools_client_->GetEmulation()->GetExperimental()->RemoveObserver(this); | 120 devtools_client_->GetEmulation()->GetExperimental()->RemoveObserver(this); |
| 121 devtools_client_->GetPage()->RemoveObserver(this); | 121 devtools_client_->GetPage()->RemoveObserver(this); |
| 122 web_contents_->GetDevToolsTarget()->DetachClient(devtools_client_.get()); | 122 if (web_contents_->GetDevToolsTarget()) { |
| 123 web_contents_->GetDevToolsTarget()->DetachClient( |
| 124 devtools_client_.get()); |
| 125 } |
| 123 } | 126 } |
| 124 web_contents_->RemoveObserver(this); | 127 web_contents_->RemoveObserver(this); |
| 125 web_contents_ = nullptr; | 128 web_contents_ = nullptr; |
| 126 browser_context_->Close(); | 129 browser_context_->Close(); |
| 127 browser_->Shutdown(); | 130 browser_->Shutdown(); |
| 128 } | 131 } |
| 129 | 132 |
| 130 // HeadlessWebContents::Observer implementation: | 133 // HeadlessWebContents::Observer implementation: |
| 131 void DevToolsTargetReady() override { | 134 void DevToolsTargetReady() override { |
| 132 if (RemoteDebuggingEnabled()) | 135 if (RemoteDebuggingEnabled()) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 152 .SetPolicy(emulation::VirtualTimePolicy:: | 155 .SetPolicy(emulation::VirtualTimePolicy:: |
| 153 PAUSE_IF_NETWORK_FETCHES_PENDING) | 156 PAUSE_IF_NETWORK_FETCHES_PENDING) |
| 154 .SetBudget(budget_ms) | 157 .SetBudget(budget_ms) |
| 155 .Build()); | 158 .Build()); |
| 156 } else { | 159 } else { |
| 157 PollReadyState(); | 160 PollReadyState(); |
| 158 } | 161 } |
| 159 // TODO(skyostil): Implement more features to demonstrate the devtools API. | 162 // TODO(skyostil): Implement more features to demonstrate the devtools API. |
| 160 } | 163 } |
| 161 | 164 |
| 165 void RenderProcessExited(base::TerminationStatus status, |
| 166 int exit_code) override { |
| 167 if (status == base::TERMINATION_STATUS_NORMAL_TERMINATION) |
| 168 return; |
| 169 |
| 170 LOG(ERROR) << "Abnormal renderer termination."; |
| 171 Shutdown(); |
| 172 } |
| 173 |
| 162 void PollReadyState() { | 174 void PollReadyState() { |
| 163 // We need to check the current location in addition to the ready state to | 175 // We need to check the current location in addition to the ready state to |
| 164 // be sure the expected page is ready. | 176 // be sure the expected page is ready. |
| 165 devtools_client_->GetRuntime()->Evaluate( | 177 devtools_client_->GetRuntime()->Evaluate( |
| 166 "document.readyState + ' ' + document.location.href", | 178 "document.readyState + ' ' + document.location.href", |
| 167 base::Bind(&HeadlessShell::OnReadyState, base::Unretained(this))); | 179 base::Bind(&HeadlessShell::OnReadyState, base::Unretained(this))); |
| 168 } | 180 } |
| 169 | 181 |
| 170 void OnReadyState(std::unique_ptr<runtime::EvaluateResult> result) { | 182 void OnReadyState(std::unique_ptr<runtime::EvaluateResult> result) { |
| 171 std::string ready_state_and_url; | 183 std::string ready_state_and_url; |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 } | 441 } |
| 430 builder.SetWindowSize(parsed_window_size); | 442 builder.SetWindowSize(parsed_window_size); |
| 431 } | 443 } |
| 432 | 444 |
| 433 return HeadlessBrowserMain( | 445 return HeadlessBrowserMain( |
| 434 builder.Build(), | 446 builder.Build(), |
| 435 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); | 447 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); |
| 436 } | 448 } |
| 437 | 449 |
| 438 } // namespace headless | 450 } // namespace headless |
| OLD | NEW |