Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "headless/lib/browser/headless_web_contents_impl.h" | 5 #include "headless/lib/browser/headless_web_contents_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 new HeadlessWebContentsImpl::Delegate(browser_context)), | 185 new HeadlessWebContentsImpl::Delegate(browser_context)), |
| 186 web_contents_(web_contents), | 186 web_contents_(web_contents), |
| 187 agent_host_(content::DevToolsAgentHost::GetOrCreateFor(web_contents)), | 187 agent_host_(content::DevToolsAgentHost::GetOrCreateFor(web_contents)), |
| 188 browser_context_(browser_context), | 188 browser_context_(browser_context), |
| 189 render_process_host_(web_contents->GetRenderProcessHost()) { | 189 render_process_host_(web_contents->GetRenderProcessHost()) { |
| 190 #if BUILDFLAG(ENABLE_BASIC_PRINTING) | 190 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 191 printing::HeadlessPrintManager::CreateForWebContents(web_contents); | 191 printing::HeadlessPrintManager::CreateForWebContents(web_contents); |
| 192 #endif | 192 #endif |
| 193 web_contents_->SetDelegate(web_contents_delegate_.get()); | 193 web_contents_->SetDelegate(web_contents_delegate_.get()); |
| 194 render_process_host_->AddObserver(this); | 194 render_process_host_->AddObserver(this); |
| 195 agent_host_->AddObserver(this); | |
| 195 } | 196 } |
| 196 | 197 |
| 197 HeadlessWebContentsImpl::~HeadlessWebContentsImpl() { | 198 HeadlessWebContentsImpl::~HeadlessWebContentsImpl() { |
| 199 if (agent_host_) | |
|
Sami
2017/04/25 18:31:12
agent_host_ should always be non-null, right?
alex clarke (OOO till 29th)
2017/04/26 08:11:07
Done.
| |
| 200 agent_host_->RemoveObserver(this); | |
| 198 if (render_process_host_) | 201 if (render_process_host_) |
| 199 render_process_host_->RemoveObserver(this); | 202 render_process_host_->RemoveObserver(this); |
| 200 } | 203 } |
| 201 | 204 |
| 202 void HeadlessWebContentsImpl::RenderFrameCreated( | 205 void HeadlessWebContentsImpl::RenderFrameCreated( |
| 203 content::RenderFrameHost* render_frame_host) { | 206 content::RenderFrameHost* render_frame_host) { |
| 204 if (!mojo_services_.empty()) { | 207 if (!mojo_services_.empty()) { |
| 205 render_frame_host->AllowBindings(content::BINDINGS_POLICY_HEADLESS); | 208 render_frame_host->AllowBindings(content::BINDINGS_POLICY_HEADLESS); |
| 206 } | 209 } |
| 207 | 210 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 observer_map_[observer] = base::MakeUnique<WebContentsObserverAdapter>( | 273 observer_map_[observer] = base::MakeUnique<WebContentsObserverAdapter>( |
| 271 web_contents_.get(), observer); | 274 web_contents_.get(), observer); |
| 272 } | 275 } |
| 273 | 276 |
| 274 void HeadlessWebContentsImpl::RemoveObserver(Observer* observer) { | 277 void HeadlessWebContentsImpl::RemoveObserver(Observer* observer) { |
| 275 ObserverMap::iterator it = observer_map_.find(observer); | 278 ObserverMap::iterator it = observer_map_.find(observer); |
| 276 DCHECK(it != observer_map_.end()); | 279 DCHECK(it != observer_map_.end()); |
| 277 observer_map_.erase(it); | 280 observer_map_.erase(it); |
| 278 } | 281 } |
| 279 | 282 |
| 283 void HeadlessWebContentsImpl::DevToolsAgentHostAttached( | |
| 284 content::DevToolsAgentHost* agent_host) { | |
| 285 for (const auto& pair : observer_map_) { | |
| 286 pair.second->observer()->DevToolsClientAttached(); | |
| 287 } | |
| 288 } | |
| 289 | |
| 290 void HeadlessWebContentsImpl::DevToolsAgentHostDetached( | |
| 291 content::DevToolsAgentHost* agent_host) { | |
| 292 for (const auto& pair : observer_map_) { | |
| 293 pair.second->observer()->DevToolsClientDettached(); | |
|
Sami
2017/04/25 18:31:12
typo: Detached
alex clarke (OOO till 29th)
2017/04/26 08:11:07
Done.
| |
| 294 } | |
| 295 } | |
| 296 | |
| 280 void HeadlessWebContentsImpl::RenderProcessExited( | 297 void HeadlessWebContentsImpl::RenderProcessExited( |
| 281 content::RenderProcessHost* host, | 298 content::RenderProcessHost* host, |
| 282 base::TerminationStatus status, | 299 base::TerminationStatus status, |
| 283 int exit_code) { | 300 int exit_code) { |
| 284 DCHECK_EQ(render_process_host_, host); | 301 DCHECK_EQ(render_process_host_, host); |
| 285 for (const auto& pair : observer_map_) { | 302 for (const auto& pair : observer_map_) { |
| 286 pair.second->observer()->RenderProcessExited(status, exit_code); | 303 pair.second->observer()->RenderProcessExited(status, exit_code); |
| 287 } | 304 } |
| 288 } | 305 } |
| 289 | 306 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 HeadlessWebContents::Builder::MojoService::MojoService() {} | 393 HeadlessWebContents::Builder::MojoService::MojoService() {} |
| 377 | 394 |
| 378 HeadlessWebContents::Builder::MojoService::MojoService( | 395 HeadlessWebContents::Builder::MojoService::MojoService( |
| 379 const std::string& service_name, | 396 const std::string& service_name, |
| 380 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& service_factory) | 397 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& service_factory) |
| 381 : service_name(service_name), service_factory(service_factory) {} | 398 : service_name(service_name), service_factory(service_factory) {} |
| 382 | 399 |
| 383 HeadlessWebContents::Builder::MojoService::~MojoService() {} | 400 HeadlessWebContents::Builder::MojoService::~MojoService() {} |
| 384 | 401 |
| 385 } // namespace headless | 402 } // namespace headless |
| OLD | NEW |