Commit ec1e1427 authored by alexclarke's avatar alexclarke Committed by Commit bot

HeadlessWebContents Observers for devtools clients attaching/detatching

BUG=546953

Review-Url: https://codereview.chromium.org/2843773002
Cr-Commit-Position: refs/heads/master@{#467268}
parent fb4604d2
...@@ -192,9 +192,11 @@ HeadlessWebContentsImpl::HeadlessWebContentsImpl( ...@@ -192,9 +192,11 @@ HeadlessWebContentsImpl::HeadlessWebContentsImpl(
#endif #endif
web_contents_->SetDelegate(web_contents_delegate_.get()); web_contents_->SetDelegate(web_contents_delegate_.get());
render_process_host_->AddObserver(this); render_process_host_->AddObserver(this);
agent_host_->AddObserver(this);
} }
HeadlessWebContentsImpl::~HeadlessWebContentsImpl() { HeadlessWebContentsImpl::~HeadlessWebContentsImpl() {
agent_host_->RemoveObserver(this);
if (render_process_host_) if (render_process_host_)
render_process_host_->RemoveObserver(this); render_process_host_->RemoveObserver(this);
} }
...@@ -277,6 +279,20 @@ void HeadlessWebContentsImpl::RemoveObserver(Observer* observer) { ...@@ -277,6 +279,20 @@ void HeadlessWebContentsImpl::RemoveObserver(Observer* observer) {
observer_map_.erase(it); observer_map_.erase(it);
} }
void HeadlessWebContentsImpl::DevToolsAgentHostAttached(
content::DevToolsAgentHost* agent_host) {
for (const auto& pair : observer_map_) {
pair.second->observer()->DevToolsClientAttached();
}
}
void HeadlessWebContentsImpl::DevToolsAgentHostDetached(
content::DevToolsAgentHost* agent_host) {
for (const auto& pair : observer_map_) {
pair.second->observer()->DevToolsClientDetached();
}
}
void HeadlessWebContentsImpl::RenderProcessExited( void HeadlessWebContentsImpl::RenderProcessExited(
content::RenderProcessHost* host, content::RenderProcessHost* host,
base::TerminationStatus status, base::TerminationStatus status,
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include "content/public/browser/devtools_agent_host_observer.h"
#include "content/public/browser/render_process_host_observer.h" #include "content/public/browser/render_process_host_observer.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "headless/lib/browser/headless_window_tree_host.h" #include "headless/lib/browser/headless_window_tree_host.h"
...@@ -35,6 +36,7 @@ class WebContentsObserverAdapter; ...@@ -35,6 +36,7 @@ class WebContentsObserverAdapter;
class HEADLESS_EXPORT HeadlessWebContentsImpl class HEADLESS_EXPORT HeadlessWebContentsImpl
: public HeadlessWebContents, : public HeadlessWebContents,
public HeadlessDevToolsTarget, public HeadlessDevToolsTarget,
public content::DevToolsAgentHostObserver,
public content::RenderProcessHostObserver, public content::RenderProcessHostObserver,
public content::WebContentsObserver { public content::WebContentsObserver {
public: public:
...@@ -65,7 +67,13 @@ class HEADLESS_EXPORT HeadlessWebContentsImpl ...@@ -65,7 +67,13 @@ class HEADLESS_EXPORT HeadlessWebContentsImpl
void DetachClient(HeadlessDevToolsClient* client) override; void DetachClient(HeadlessDevToolsClient* client) override;
bool IsAttached() override; bool IsAttached() override;
// RenderProcessHostObserver implementation: // content::DevToolsAgentHostObserver implementation:
void DevToolsAgentHostAttached(
content::DevToolsAgentHost* agent_host) override;
void DevToolsAgentHostDetached(
content::DevToolsAgentHost* agent_host) override;
// content::RenderProcessHostObserver implementation:
void RenderProcessExited(content::RenderProcessHost* host, void RenderProcessExited(content::RenderProcessHost* host,
base::TerminationStatus status, base::TerminationStatus status,
int exit_code) override; int exit_code) override;
......
...@@ -1022,4 +1022,27 @@ class RawDevtoolsProtocolTest ...@@ -1022,4 +1022,27 @@ class RawDevtoolsProtocolTest
HEADLESS_ASYNC_DEVTOOLED_TEST_F(RawDevtoolsProtocolTest); HEADLESS_ASYNC_DEVTOOLED_TEST_F(RawDevtoolsProtocolTest);
class DevToolsAttachAndDetachNotifications
: public HeadlessAsyncDevTooledBrowserTest {
public:
void DevToolsClientAttached() override { dev_tools_client_attached_ = true; }
void RunDevTooledTest() override {
EXPECT_TRUE(dev_tools_client_attached_);
FinishAsynchronousTest();
}
void DevToolsClientDetached() override { dev_tools_client_detached_ = true; }
void TearDownOnMainThread() override {
EXPECT_TRUE(dev_tools_client_detached_);
}
private:
bool dev_tools_client_attached_ = false;
bool dev_tools_client_detached_ = false;
};
HEADLESS_ASYNC_DEVTOOLED_TEST_F(DevToolsAttachAndDetachNotifications);
} // namespace headless } // namespace headless
...@@ -41,6 +41,14 @@ class HEADLESS_EXPORT HeadlessWebContents { ...@@ -41,6 +41,14 @@ class HEADLESS_EXPORT HeadlessWebContents {
// TODO(altimin): Support this event for pages that aren't created by us. // TODO(altimin): Support this event for pages that aren't created by us.
virtual void DevToolsTargetReady() {} virtual void DevToolsTargetReady() {}
// Indicates that a DevTools client attached to this HeadlessWebContents
// instance.
virtual void DevToolsClientAttached() {}
// Indicates that a DevTools client detached from this HeadlessWebContents
// instance.
virtual void DevToolsClientDetached() {}
// This method is invoked when the process of the observed RenderProcessHost // This method is invoked when the process of the observed RenderProcessHost
// exits (either normally or with a crash). To determine if the process // exits (either normally or with a crash). To determine if the process
// closed normally or crashed, examine the |status| parameter. // closed normally or crashed, examine the |status| parameter.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment