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