| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_frontend.h" | 5 #include "content/shell/browser/shell_devtools_frontend.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "content/public/browser/devtools_http_handler.h" | 13 #include "content/public/browser/devtools_http_handler.h" |
| 14 #include "content/public/browser/devtools_manager.h" | |
| 15 #include "content/public/browser/render_frame_host.h" | 14 #include "content/public/browser/render_frame_host.h" |
| 16 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
| 17 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/common/content_client.h" | 17 #include "content/public/common/content_client.h" |
| 19 #include "content/shell/browser/shell.h" | 18 #include "content/shell/browser/shell.h" |
| 20 #include "content/shell/browser/shell_browser_context.h" | 19 #include "content/shell/browser/shell_browser_context.h" |
| 21 #include "content/shell/browser/shell_browser_main_parts.h" | 20 #include "content/shell/browser/shell_browser_main_parts.h" |
| 22 #include "content/shell/browser/shell_content_browser_client.h" | 21 #include "content/shell/browser/shell_content_browser_client.h" |
| 23 #include "content/shell/browser/shell_devtools_delegate.h" | 22 #include "content/shell/browser/shell_devtools_delegate.h" |
| 24 #include "content/shell/browser/webkit_test_controller.h" | 23 #include "content/shell/browser/webkit_test_controller.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 agent_host_(agent_host) { | 109 agent_host_(agent_host) { |
| 111 } | 110 } |
| 112 | 111 |
| 113 ShellDevToolsFrontend::~ShellDevToolsFrontend() { | 112 ShellDevToolsFrontend::~ShellDevToolsFrontend() { |
| 114 } | 113 } |
| 115 | 114 |
| 116 void ShellDevToolsFrontend::RenderViewCreated( | 115 void ShellDevToolsFrontend::RenderViewCreated( |
| 117 RenderViewHost* render_view_host) { | 116 RenderViewHost* render_view_host) { |
| 118 if (!frontend_host_) { | 117 if (!frontend_host_) { |
| 119 frontend_host_.reset(DevToolsFrontendHost::Create(render_view_host, this)); | 118 frontend_host_.reset(DevToolsFrontendHost::Create(render_view_host, this)); |
| 120 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( | 119 agent_host_->AttachClient(this); |
| 121 agent_host_.get(), this); | |
| 122 } | 120 } |
| 123 } | 121 } |
| 124 | 122 |
| 125 void ShellDevToolsFrontend::DocumentOnLoadCompletedInMainFrame() { | 123 void ShellDevToolsFrontend::DocumentOnLoadCompletedInMainFrame() { |
| 126 web_contents()->GetMainFrame()->ExecuteJavaScript( | 124 web_contents()->GetMainFrame()->ExecuteJavaScript( |
| 127 base::ASCIIToUTF16("InspectorFrontendAPI.setUseSoftMenu(true);")); | 125 base::ASCIIToUTF16("InspectorFrontendAPI.setUseSoftMenu(true);")); |
| 128 } | 126 } |
| 129 | 127 |
| 130 void ShellDevToolsFrontend::WebContentsDestroyed() { | 128 void ShellDevToolsFrontend::WebContentsDestroyed() { |
| 131 DevToolsManager::GetInstance()->ClientHostClosing(this); | 129 agent_host_->DetachClient(); |
| 132 delete this; | 130 delete this; |
| 133 } | 131 } |
| 134 | 132 |
| 135 void ShellDevToolsFrontend::RenderProcessGone(base::TerminationStatus status) { | 133 void ShellDevToolsFrontend::RenderProcessGone(base::TerminationStatus status) { |
| 136 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) | 134 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) |
| 137 WebKitTestController::Get()->DevToolsProcessCrashed(); | 135 WebKitTestController::Get()->DevToolsProcessCrashed(); |
| 138 } | 136 } |
| 139 | 137 |
| 140 void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend( | 138 void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend( |
| 141 const std::string& message) { | 139 const std::string& message) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 153 return; | 151 return; |
| 154 } | 152 } |
| 155 | 153 |
| 156 if (method != "sendMessageToBrowser" || | 154 if (method != "sendMessageToBrowser" || |
| 157 params->GetSize() != 1 || | 155 params->GetSize() != 1 || |
| 158 !params->GetString(0, &browser_message)) { | 156 !params->GetString(0, &browser_message)) { |
| 159 return; | 157 return; |
| 160 } | 158 } |
| 161 dict->GetInteger("id", &id); | 159 dict->GetInteger("id", &id); |
| 162 | 160 |
| 163 DevToolsManager::GetInstance()->DispatchOnInspectorBackend( | 161 agent_host_->DispatchOnInspectorBackend(browser_message); |
| 164 this, browser_message); | |
| 165 | 162 |
| 166 if (id) { | 163 if (id) { |
| 167 std::string code = "InspectorFrontendAPI.embedderMessageAck(" + | 164 std::string code = "InspectorFrontendAPI.embedderMessageAck(" + |
| 168 base::IntToString(id) + ",\"\");"; | 165 base::IntToString(id) + ",\"\");"; |
| 169 base::string16 javascript = base::UTF8ToUTF16(code); | 166 base::string16 javascript = base::UTF8ToUTF16(code); |
| 170 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); | 167 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); |
| 171 } | 168 } |
| 172 } | 169 } |
| 173 | 170 |
| 174 void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontendToBackend( | 171 void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontendToBackend( |
| 175 const std::string& message) { | 172 const std::string& message) { |
| 176 DevToolsManager::GetInstance()->DispatchOnInspectorBackend( | 173 agent_host_->DispatchOnInspectorBackend(message); |
| 177 this, message); | |
| 178 } | 174 } |
| 179 | 175 |
| 180 void ShellDevToolsFrontend::DispatchOnInspectorFrontend( | 176 void ShellDevToolsFrontend::DispatchProtocolMessage( |
| 181 const std::string& message) { | 177 DevToolsAgentHost* agent_host, const std::string& message) { |
| 182 std::string code = "InspectorFrontendAPI.dispatchMessage(" + message + ");"; | 178 std::string code = "InspectorFrontendAPI.dispatchMessage(" + message + ");"; |
| 183 base::string16 javascript = base::UTF8ToUTF16(code); | 179 base::string16 javascript = base::UTF8ToUTF16(code); |
| 184 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); | 180 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); |
| 185 } | 181 } |
| 186 | 182 |
| 187 void ShellDevToolsFrontend::InspectedContentsClosing() { | 183 void ShellDevToolsFrontend::AgentHostClosed( |
| 184 DevToolsAgentHost* agent_host, bool replaced) { |
| 188 frontend_shell_->Close(); | 185 frontend_shell_->Close(); |
| 189 } | 186 } |
| 190 | 187 |
| 191 } // namespace content | 188 } // namespace content |
| OLD | NEW |