| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "content/shell/browser/shell_devtools_bindings.h" | 5 #include "content/shell/browser/shell_devtools_bindings.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 11 #include "base/json/string_escape.h" | 11 #include "base/json/string_escape.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/navigation_handle.h" |
| 18 #include "content/public/browser/render_frame_host.h" | 19 #include "content/public/browser/render_frame_host.h" |
| 19 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| 20 #include "content/public/browser/storage_partition.h" | 21 #include "content/public/browser/storage_partition.h" |
| 21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/common/content_client.h" | 23 #include "content/public/common/content_client.h" |
| 23 #include "content/shell/browser/shell.h" | 24 #include "content/shell/browser/shell.h" |
| 24 #include "content/shell/browser/shell_browser_context.h" | 25 #include "content/shell/browser/shell_browser_context.h" |
| 25 #include "content/shell/browser/shell_browser_main_parts.h" | 26 #include "content/shell/browser/shell_browser_main_parts.h" |
| 26 #include "content/shell/browser/shell_content_browser_client.h" | 27 #include "content/shell/browser/shell_content_browser_client.h" |
| 27 #include "content/shell/browser/shell_devtools_manager_delegate.h" | 28 #include "content/shell/browser/shell_devtools_manager_delegate.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 inspect_element_at_y_(-1), | 122 inspect_element_at_y_(-1), |
| 122 weak_factory_(this) {} | 123 weak_factory_(this) {} |
| 123 | 124 |
| 124 ShellDevToolsBindings::~ShellDevToolsBindings() { | 125 ShellDevToolsBindings::~ShellDevToolsBindings() { |
| 125 for (const auto& pair : pending_requests_) | 126 for (const auto& pair : pending_requests_) |
| 126 delete pair.first; | 127 delete pair.first; |
| 127 if (agent_host_) | 128 if (agent_host_) |
| 128 agent_host_->DetachClient(this); | 129 agent_host_->DetachClient(this); |
| 129 } | 130 } |
| 130 | 131 |
| 131 void ShellDevToolsBindings::RenderViewCreated( | 132 void ShellDevToolsBindings::ReadyToCommitNavigation( |
| 132 RenderViewHost* render_view_host) { | 133 content::NavigationHandle* navigation_handle) { |
| 133 CreateFrontendHost(); | 134 if (navigation_handle->IsInMainFrame()) { |
| 135 CreateFrontendHost(navigation_handle->GetRenderFrameHost()); |
| 136 } |
| 134 } | 137 } |
| 135 | 138 |
| 136 #if !defined(OS_ANDROID) | 139 #if !defined(OS_ANDROID) |
| 137 void ShellDevToolsBindings::CreateFrontendHost() { | 140 void ShellDevToolsBindings::CreateFrontendHost( |
| 138 if (!frontend_host_) { | 141 RenderFrameHost* render_frame_host) { |
| 139 frontend_host_.reset(DevToolsFrontendHost::Create( | 142 frontend_host_.reset(DevToolsFrontendHost::Create( |
| 140 web_contents()->GetMainFrame(), | 143 render_frame_host, |
| 141 base::Bind(&ShellDevToolsBindings::HandleMessageFromDevToolsFrontend, | 144 base::Bind(&ShellDevToolsBindings::HandleMessageFromDevToolsFrontend, |
| 142 base::Unretained(this)))); | 145 base::Unretained(this)))); |
| 143 } | |
| 144 } | 146 } |
| 145 #endif | 147 #endif |
| 146 | 148 |
| 147 #if defined(OS_ANDROID) | 149 #if defined(OS_ANDROID) |
| 148 void ShellDevToolsBindings::CreateFrontendHost() {} | 150 void ShellDevToolsBindings::CreateFrontendHost() {} |
| 149 #endif | 151 #endif |
| 150 | 152 |
| 151 void ShellDevToolsBindings::DocumentAvailableInMainFrame() { | 153 void ShellDevToolsBindings::DocumentAvailableInMainFrame() { |
| 152 agent_host_ = DevToolsAgentHost::GetOrCreateFor(inspected_contents_); | 154 agent_host_ = DevToolsAgentHost::GetOrCreateFor(inspected_contents_); |
| 153 agent_host_->AttachClient(this); | 155 agent_host_->AttachClient(this); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 } | 371 } |
| 370 | 372 |
| 371 void ShellDevToolsBindings::AgentHostClosed(DevToolsAgentHost* agent_host, | 373 void ShellDevToolsBindings::AgentHostClosed(DevToolsAgentHost* agent_host, |
| 372 bool replaced) { | 374 bool replaced) { |
| 373 agent_host_ = nullptr; | 375 agent_host_ = nullptr; |
| 374 if (delegate_) | 376 if (delegate_) |
| 375 delegate_->Close(); | 377 delegate_->Close(); |
| 376 } | 378 } |
| 377 | 379 |
| 378 } // namespace content | 380 } // namespace content |
| OLD | NEW |