Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: headless/lib/browser/headless_web_contents_impl.cc

Issue 2843773002: HeadlessWebContents Observers for devtools clients attaching/detatching (Closed)
Patch Set: Added a test Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 agent_host_->RemoveObserver(this);
198 if (render_process_host_) 200 if (render_process_host_)
199 render_process_host_->RemoveObserver(this); 201 render_process_host_->RemoveObserver(this);
200 } 202 }
201 203
202 void HeadlessWebContentsImpl::RenderFrameCreated( 204 void HeadlessWebContentsImpl::RenderFrameCreated(
203 content::RenderFrameHost* render_frame_host) { 205 content::RenderFrameHost* render_frame_host) {
204 if (!mojo_services_.empty()) { 206 if (!mojo_services_.empty()) {
205 render_frame_host->AllowBindings(content::BINDINGS_POLICY_HEADLESS); 207 render_frame_host->AllowBindings(content::BINDINGS_POLICY_HEADLESS);
206 } 208 }
207 209
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 observer_map_[observer] = base::MakeUnique<WebContentsObserverAdapter>( 272 observer_map_[observer] = base::MakeUnique<WebContentsObserverAdapter>(
271 web_contents_.get(), observer); 273 web_contents_.get(), observer);
272 } 274 }
273 275
274 void HeadlessWebContentsImpl::RemoveObserver(Observer* observer) { 276 void HeadlessWebContentsImpl::RemoveObserver(Observer* observer) {
275 ObserverMap::iterator it = observer_map_.find(observer); 277 ObserverMap::iterator it = observer_map_.find(observer);
276 DCHECK(it != observer_map_.end()); 278 DCHECK(it != observer_map_.end());
277 observer_map_.erase(it); 279 observer_map_.erase(it);
278 } 280 }
279 281
282 void HeadlessWebContentsImpl::DevToolsAgentHostAttached(
283 content::DevToolsAgentHost* agent_host) {
284 for (const auto& pair : observer_map_) {
285 pair.second->observer()->DevToolsClientAttached();
286 }
287 }
288
289 void HeadlessWebContentsImpl::DevToolsAgentHostDetached(
290 content::DevToolsAgentHost* agent_host) {
291 for (const auto& pair : observer_map_) {
292 pair.second->observer()->DevToolsClientDetached();
293 }
294 }
295
280 void HeadlessWebContentsImpl::RenderProcessExited( 296 void HeadlessWebContentsImpl::RenderProcessExited(
281 content::RenderProcessHost* host, 297 content::RenderProcessHost* host,
282 base::TerminationStatus status, 298 base::TerminationStatus status,
283 int exit_code) { 299 int exit_code) {
284 DCHECK_EQ(render_process_host_, host); 300 DCHECK_EQ(render_process_host_, host);
285 for (const auto& pair : observer_map_) { 301 for (const auto& pair : observer_map_) {
286 pair.second->observer()->RenderProcessExited(status, exit_code); 302 pair.second->observer()->RenderProcessExited(status, exit_code);
287 } 303 }
288 } 304 }
289 305
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 HeadlessWebContents::Builder::MojoService::MojoService() {} 392 HeadlessWebContents::Builder::MojoService::MojoService() {}
377 393
378 HeadlessWebContents::Builder::MojoService::MojoService( 394 HeadlessWebContents::Builder::MojoService::MojoService(
379 const std::string& service_name, 395 const std::string& service_name,
380 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& service_factory) 396 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& service_factory)
381 : service_name(service_name), service_factory(service_factory) {} 397 : service_name(service_name), service_factory(service_factory) {}
382 398
383 HeadlessWebContents::Builder::MojoService::~MojoService() {} 399 HeadlessWebContents::Builder::MojoService::~MojoService() {}
384 400
385 } // namespace headless 401 } // namespace headless
OLDNEW
« no previous file with comments | « headless/lib/browser/headless_web_contents_impl.h ('k') | headless/lib/headless_devtools_client_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698