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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 agent_host_->InspectElement(x, y); | 136 agent_host_->InspectElement(x, y); |
137 } | 137 } |
138 | 138 |
139 void ShellDevToolsFrontend::Close() { | 139 void ShellDevToolsFrontend::Close() { |
140 frontend_shell_->Close(); | 140 frontend_shell_->Close(); |
141 } | 141 } |
142 | 142 |
143 void ShellDevToolsFrontend::DisconnectFromTarget() { | 143 void ShellDevToolsFrontend::DisconnectFromTarget() { |
144 if (!agent_host_) | 144 if (!agent_host_) |
145 return; | 145 return; |
146 agent_host_->DetachClient(); | 146 agent_host_->DetachClient(this); |
147 agent_host_ = NULL; | 147 agent_host_ = NULL; |
148 } | 148 } |
149 | 149 |
150 ShellDevToolsFrontend::ShellDevToolsFrontend(Shell* frontend_shell, | 150 ShellDevToolsFrontend::ShellDevToolsFrontend(Shell* frontend_shell, |
151 WebContents* inspected_contents) | 151 WebContents* inspected_contents) |
152 : WebContentsObserver(frontend_shell->web_contents()), | 152 : WebContentsObserver(frontend_shell->web_contents()), |
153 frontend_shell_(frontend_shell), | 153 frontend_shell_(frontend_shell), |
154 inspected_contents_(inspected_contents), | 154 inspected_contents_(inspected_contents), |
155 weak_factory_(this) { | 155 weak_factory_(this) { |
156 } | 156 } |
(...skipping 13 matching lines...) Expand all Loading... |
170 } | 170 } |
171 } | 171 } |
172 | 172 |
173 void ShellDevToolsFrontend::DocumentAvailableInMainFrame() { | 173 void ShellDevToolsFrontend::DocumentAvailableInMainFrame() { |
174 agent_host_ = DevToolsAgentHost::GetOrCreateFor(inspected_contents_); | 174 agent_host_ = DevToolsAgentHost::GetOrCreateFor(inspected_contents_); |
175 agent_host_->AttachClient(this); | 175 agent_host_->AttachClient(this); |
176 } | 176 } |
177 | 177 |
178 void ShellDevToolsFrontend::WebContentsDestroyed() { | 178 void ShellDevToolsFrontend::WebContentsDestroyed() { |
179 if (agent_host_) | 179 if (agent_host_) |
180 agent_host_->DetachClient(); | 180 agent_host_->DetachClient(this); |
181 delete this; | 181 delete this; |
182 } | 182 } |
183 | 183 |
184 void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend( | 184 void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend( |
185 const std::string& message) { | 185 const std::string& message) { |
186 if (!agent_host_) | 186 if (!agent_host_) |
187 return; | 187 return; |
188 std::string method; | 188 std::string method; |
189 base::ListValue* params = NULL; | 189 base::ListValue* params = NULL; |
190 base::DictionaryValue* dict = NULL; | 190 base::DictionaryValue* dict = NULL; |
191 std::unique_ptr<base::Value> parsed_message = base::JSONReader::Read(message); | 191 std::unique_ptr<base::Value> parsed_message = base::JSONReader::Read(message); |
192 if (!parsed_message || | 192 if (!parsed_message || |
193 !parsed_message->GetAsDictionary(&dict) || | 193 !parsed_message->GetAsDictionary(&dict) || |
194 !dict->GetString("method", &method)) { | 194 !dict->GetString("method", &method)) { |
195 return; | 195 return; |
196 } | 196 } |
197 int request_id = 0; | 197 int request_id = 0; |
198 dict->GetInteger("id", &request_id); | 198 dict->GetInteger("id", &request_id); |
199 dict->GetList("params", ¶ms); | 199 dict->GetList("params", ¶ms); |
200 | 200 |
201 if (method == "dispatchProtocolMessage" && params && params->GetSize() == 1) { | 201 if (method == "dispatchProtocolMessage" && params && params->GetSize() == 1) { |
202 if (!agent_host_ || !agent_host_->IsAttached()) | 202 if (!agent_host_ || !agent_host_->IsAttached()) |
203 return; | 203 return; |
204 std::string protocol_message; | 204 std::string protocol_message; |
205 if (!params->GetString(0, &protocol_message)) | 205 if (!params->GetString(0, &protocol_message)) |
206 return; | 206 return; |
207 agent_host_->DispatchProtocolMessage(protocol_message); | 207 agent_host_->DispatchProtocolMessage(this, protocol_message); |
208 } else if (method == "loadCompleted") { | 208 } else if (method == "loadCompleted") { |
209 web_contents()->GetMainFrame()->ExecuteJavaScriptForTests( | 209 web_contents()->GetMainFrame()->ExecuteJavaScriptForTests( |
210 base::ASCIIToUTF16("DevToolsAPI.setUseSoftMenu(true);")); | 210 base::ASCIIToUTF16("DevToolsAPI.setUseSoftMenu(true);")); |
211 } else if (method == "loadNetworkResource" && params->GetSize() == 3) { | 211 } else if (method == "loadNetworkResource" && params->GetSize() == 3) { |
212 // TODO(pfeldman): handle some of the embedder messages in content. | 212 // TODO(pfeldman): handle some of the embedder messages in content. |
213 std::string url; | 213 std::string url; |
214 std::string headers; | 214 std::string headers; |
215 int stream_id; | 215 int stream_id; |
216 if (!params->GetString(0, &url) || | 216 if (!params->GetString(0, &url) || |
217 !params->GetString(1, &headers) || | 217 !params->GetString(1, &headers) || |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 CallClientFunction("DevToolsAPI.embedderMessageAck", | 345 CallClientFunction("DevToolsAPI.embedderMessageAck", |
346 &id_value, arg, nullptr); | 346 &id_value, arg, nullptr); |
347 } | 347 } |
348 | 348 |
349 void ShellDevToolsFrontend::AgentHostClosed( | 349 void ShellDevToolsFrontend::AgentHostClosed( |
350 DevToolsAgentHost* agent_host, bool replaced) { | 350 DevToolsAgentHost* agent_host, bool replaced) { |
351 frontend_shell_->Close(); | 351 frontend_shell_->Close(); |
352 } | 352 } |
353 | 353 |
354 } // namespace content | 354 } // namespace content |
OLD | NEW |