Index: content/shell/browser/shell_devtools_frontend.cc |
diff --git a/content/shell/browser/shell_devtools_frontend.cc b/content/shell/browser/shell_devtools_frontend.cc |
index 42ffa70e0354b191cbc11bb62c2a5d5ba100f8a6..a6bead64ffbe3ae8ddf232723c8ef1e70c7e4117 100644 |
--- a/content/shell/browser/shell_devtools_frontend.cc |
+++ b/content/shell/browser/shell_devtools_frontend.cc |
@@ -60,13 +60,21 @@ void ShellDevToolsFrontend::Focus() { |
} |
void ShellDevToolsFrontend::InspectElementAt(int x, int y) { |
- agent_host_->InspectElement(x, y); |
+ if (agent_host_) |
+ agent_host_->InspectElement(x, y); |
} |
void ShellDevToolsFrontend::Close() { |
frontend_shell_->Close(); |
} |
+void ShellDevToolsFrontend::DisconnectFromTarget() { |
+ if (!agent_host_) |
+ return; |
+ agent_host_->DetachClient(); |
+ agent_host_ = NULL; |
+} |
+ |
ShellDevToolsFrontend::ShellDevToolsFrontend(Shell* frontend_shell, |
DevToolsAgentHost* agent_host) |
: WebContentsObserver(frontend_shell->web_contents()), |
@@ -82,17 +90,26 @@ void ShellDevToolsFrontend::RenderViewCreated( |
if (!frontend_host_) { |
frontend_host_.reset( |
DevToolsFrontendHost::Create(web_contents()->GetMainFrame(), this)); |
- agent_host_->AttachClient(this); |
} |
} |
+void ShellDevToolsFrontend::DidNavigateMainFrame( |
+ const LoadCommittedDetails& details, |
+ const FrameNavigateParams& params) { |
+ if (agent_host_) |
+ agent_host_->AttachClient(this); |
+} |
+ |
void ShellDevToolsFrontend::WebContentsDestroyed() { |
- agent_host_->DetachClient(); |
+ if (agent_host_) |
+ agent_host_->DetachClient(); |
delete this; |
} |
void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend( |
const std::string& message) { |
+ if (!agent_host_) |
+ return; |
std::string method; |
int id = 0; |
base::ListValue* params = NULL; |
@@ -127,7 +144,8 @@ void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend( |
void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontendToBackend( |
const std::string& message) { |
- agent_host_->DispatchProtocolMessage(message); |
+ if (agent_host_) |
+ agent_host_->DispatchProtocolMessage(message); |
} |
void ShellDevToolsFrontend::DispatchProtocolMessage( |
@@ -151,6 +169,11 @@ void ShellDevToolsFrontend::DispatchProtocolMessage( |
} |
} |
+void ShellDevToolsFrontend::AttachTo(WebContents* inspected_contents) { |
+ DisconnectFromTarget(); |
+ agent_host_ = DevToolsAgentHost::GetOrCreateFor(inspected_contents); |
+} |
+ |
void ShellDevToolsFrontend::AgentHostClosed( |
DevToolsAgentHost* agent_host, bool replaced) { |
frontend_shell_->Close(); |