| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 #if !defined(CHROME_MULTIPLE_DLL_CHILD) | 64 #if !defined(CHROME_MULTIPLE_DLL_CHILD) |
| 65 web_contents_(nullptr), | 65 web_contents_(nullptr), |
| 66 browser_context_(nullptr), | 66 browser_context_(nullptr), |
| 67 #endif | 67 #endif |
| 68 processed_page_ready_(false), | 68 processed_page_ready_(false), |
| 69 weak_factory_(this) { | 69 weak_factory_(this) { |
| 70 } | 70 } |
| 71 | 71 |
| 72 HeadlessShell::~HeadlessShell() {} | 72 HeadlessShell::~HeadlessShell() {} |
| 73 | 73 |
| 74 #if !defined(CHROME_MULTIPLE_DLL_CHILD) |
| 74 void HeadlessShell::OnStart(HeadlessBrowser* browser) { | 75 void HeadlessShell::OnStart(HeadlessBrowser* browser) { |
| 75 // TODO(dvallet): Consider making a Windows specific class to make specific | |
| 76 // child builds clearer. | |
| 77 #if !defined(CHROME_MULTIPLE_DLL_CHILD) | |
| 78 browser_ = browser; | 76 browser_ = browser; |
| 79 | 77 |
| 80 HeadlessBrowserContext::Builder context_builder = | 78 HeadlessBrowserContext::Builder context_builder = |
| 81 browser_->CreateBrowserContextBuilder(); | 79 browser_->CreateBrowserContextBuilder(); |
| 82 // TODO(eseckler): These switches should also affect BrowserContexts that | 80 // TODO(eseckler): These switches should also affect BrowserContexts that |
| 83 // are created via DevTools later. | 81 // are created via DevTools later. |
| 84 DeterministicHttpProtocolHandler* http_handler = nullptr; | 82 DeterministicHttpProtocolHandler* http_handler = nullptr; |
| 85 DeterministicHttpProtocolHandler* https_handler = nullptr; | 83 DeterministicHttpProtocolHandler* https_handler = nullptr; |
| 86 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 84 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 87 switches::kDeterministicFetch)) { | 85 switches::kDeterministicFetch)) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 browser_->Shutdown(); | 129 browser_->Shutdown(); |
| 132 return; | 130 return; |
| 133 } | 131 } |
| 134 if (!web_contents_ && !RemoteDebuggingEnabled()) { | 132 if (!web_contents_ && !RemoteDebuggingEnabled()) { |
| 135 // TODO(jzfeng): Support observing multiple targets. | 133 // TODO(jzfeng): Support observing multiple targets. |
| 136 url_ = url; | 134 url_ = url; |
| 137 web_contents_ = web_contents; | 135 web_contents_ = web_contents; |
| 138 web_contents_->AddObserver(this); | 136 web_contents_->AddObserver(this); |
| 139 } | 137 } |
| 140 } | 138 } |
| 141 #endif // !defined(CHROME_MULTIPLE_DLL_CHILD) | |
| 142 } | 139 } |
| 143 | 140 |
| 144 void HeadlessShell::Shutdown() { | 141 void HeadlessShell::Shutdown() { |
| 145 #if !defined(CHROME_MULTIPLE_DLL_CHILD) | |
| 146 if (!web_contents_) | 142 if (!web_contents_) |
| 147 return; | 143 return; |
| 148 if (!RemoteDebuggingEnabled()) { | 144 if (!RemoteDebuggingEnabled()) { |
| 149 devtools_client_->GetEmulation()->GetExperimental()->RemoveObserver(this); | 145 devtools_client_->GetEmulation()->GetExperimental()->RemoveObserver(this); |
| 150 devtools_client_->GetInspector()->GetExperimental()->RemoveObserver(this); | 146 devtools_client_->GetInspector()->GetExperimental()->RemoveObserver(this); |
| 151 devtools_client_->GetPage()->GetExperimental()->RemoveObserver(this); | 147 devtools_client_->GetPage()->GetExperimental()->RemoveObserver(this); |
| 152 if (web_contents_->GetDevToolsTarget()) { | 148 if (web_contents_->GetDevToolsTarget()) { |
| 153 web_contents_->GetDevToolsTarget()->DetachClient(devtools_client_.get()); | 149 web_contents_->GetDevToolsTarget()->DetachClient(devtools_client_.get()); |
| 154 } | 150 } |
| 155 } | 151 } |
| 156 web_contents_->RemoveObserver(this); | 152 web_contents_->RemoveObserver(this); |
| 157 web_contents_ = nullptr; | 153 web_contents_ = nullptr; |
| 158 browser_context_->Close(); | 154 browser_context_->Close(); |
| 159 browser_->Shutdown(); | 155 browser_->Shutdown(); |
| 160 #endif // !defined(CHROME_MULTIPLE_DLL_CHILD) | |
| 161 } | 156 } |
| 162 | 157 |
| 163 void HeadlessShell::DevToolsTargetReady() { | 158 void HeadlessShell::DevToolsTargetReady() { |
| 164 #if !defined(CHROME_MULTIPLE_DLL_CHILD) | |
| 165 web_contents_->GetDevToolsTarget()->AttachClient(devtools_client_.get()); | 159 web_contents_->GetDevToolsTarget()->AttachClient(devtools_client_.get()); |
| 166 devtools_client_->GetInspector()->GetExperimental()->AddObserver(this); | 160 devtools_client_->GetInspector()->GetExperimental()->AddObserver(this); |
| 167 devtools_client_->GetPage()->GetExperimental()->AddObserver(this); | 161 devtools_client_->GetPage()->GetExperimental()->AddObserver(this); |
| 168 devtools_client_->GetPage()->Enable(); | 162 devtools_client_->GetPage()->Enable(); |
| 169 | 163 |
| 170 devtools_client_->GetEmulation()->GetExperimental()->AddObserver(this); | 164 devtools_client_->GetEmulation()->GetExperimental()->AddObserver(this); |
| 171 | 165 |
| 172 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 166 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 173 switches::kDeterministicFetch)) { | 167 switches::kDeterministicFetch)) { |
| 174 devtools_client_->GetPage()->GetExperimental()->SetControlNavigations( | 168 devtools_client_->GetPage()->GetExperimental()->SetControlNavigations( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 int timeout_ms; | 220 int timeout_ms; |
| 227 CHECK(base::StringToInt(timeout_ms_ascii, &timeout_ms)) | 221 CHECK(base::StringToInt(timeout_ms_ascii, &timeout_ms)) |
| 228 << "Expected an integer value for --timeout="; | 222 << "Expected an integer value for --timeout="; |
| 229 browser_->BrowserMainThread()->PostDelayedTask( | 223 browser_->BrowserMainThread()->PostDelayedTask( |
| 230 FROM_HERE, | 224 FROM_HERE, |
| 231 base::Bind(&HeadlessShell::FetchTimeout, weak_factory_.GetWeakPtr()), | 225 base::Bind(&HeadlessShell::FetchTimeout, weak_factory_.GetWeakPtr()), |
| 232 base::TimeDelta::FromMilliseconds(timeout_ms)); | 226 base::TimeDelta::FromMilliseconds(timeout_ms)); |
| 233 } | 227 } |
| 234 | 228 |
| 235 // TODO(skyostil): Implement more features to demonstrate the devtools API. | 229 // TODO(skyostil): Implement more features to demonstrate the devtools API. |
| 230 } |
| 236 #endif // !defined(CHROME_MULTIPLE_DLL_CHILD) | 231 #endif // !defined(CHROME_MULTIPLE_DLL_CHILD) |
| 237 } | |
| 238 | 232 |
| 239 void HeadlessShell::FetchTimeout() { | 233 void HeadlessShell::FetchTimeout() { |
| 240 LOG(INFO) << "Timeout."; | 234 LOG(INFO) << "Timeout."; |
| 241 devtools_client_->GetPage()->GetExperimental()->StopLoading( | 235 devtools_client_->GetPage()->GetExperimental()->StopLoading( |
| 242 page::StopLoadingParams::Builder().Build()); | 236 page::StopLoadingParams::Builder().Build()); |
| 243 } | 237 } |
| 244 | 238 |
| 245 void HeadlessShell::OnTargetCrashed( | 239 void HeadlessShell::OnTargetCrashed( |
| 246 const inspector::TargetCrashedParams& params) { | 240 const inspector::TargetCrashedParams& params) { |
| 247 LOG(ERROR) << "Abnormal renderer termination."; | 241 LOG(ERROR) << "Abnormal renderer termination."; |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 | 672 |
| 679 int HeadlessShellMain(const content::ContentMainParams& params) { | 673 int HeadlessShellMain(const content::ContentMainParams& params) { |
| 680 #if defined(OS_WIN) | 674 #if defined(OS_WIN) |
| 681 return HeadlessShellMain(params.instance, params.sandbox_info); | 675 return HeadlessShellMain(params.instance, params.sandbox_info); |
| 682 #else | 676 #else |
| 683 return HeadlessShellMain(params.argc, params.argv); | 677 return HeadlessShellMain(params.argc, params.argv); |
| 684 #endif | 678 #endif |
| 685 } | 679 } |
| 686 | 680 |
| 687 } // namespace headless | 681 } // namespace headless |
| OLD | NEW |