| 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/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 } | 187 } |
| 188 int request_id = 0; | 188 int request_id = 0; |
| 189 dict->GetInteger("id", &request_id); | 189 dict->GetInteger("id", &request_id); |
| 190 dict->GetList("params", ¶ms); | 190 dict->GetList("params", ¶ms); |
| 191 | 191 |
| 192 std::string browser_message; | 192 std::string browser_message; |
| 193 if (method == "sendMessageToBrowser" && params && | 193 if (method == "sendMessageToBrowser" && params && |
| 194 params->GetSize() == 1 && params->GetString(0, &browser_message)) { | 194 params->GetSize() == 1 && params->GetString(0, &browser_message)) { |
| 195 agent_host_->DispatchProtocolMessage(browser_message); | 195 agent_host_->DispatchProtocolMessage(browser_message); |
| 196 } else if (method == "loadCompleted") { | 196 } else if (method == "loadCompleted") { |
| 197 web_contents()->GetMainFrame()->ExecuteJavaScript( | 197 web_contents()->GetMainFrame()->ExecuteJavaScriptForTests( |
| 198 base::ASCIIToUTF16("DevToolsAPI.setUseSoftMenu(true);")); | 198 base::ASCIIToUTF16("DevToolsAPI.setUseSoftMenu(true);")); |
| 199 } else if (method == "loadNetworkResource" && params->GetSize() == 3) { | 199 } else if (method == "loadNetworkResource" && params->GetSize() == 3) { |
| 200 // TODO(pfeldman): handle some of the embedder messages in content. | 200 // TODO(pfeldman): handle some of the embedder messages in content. |
| 201 std::string url; | 201 std::string url; |
| 202 std::string headers; | 202 std::string headers; |
| 203 int stream_id; | 203 int stream_id; |
| 204 if (!params->GetString(0, &url) || | 204 if (!params->GetString(0, &url) || |
| 205 !params->GetString(1, &headers) || | 205 !params->GetString(1, &headers) || |
| 206 !params->GetInteger(2, &stream_id)) { | 206 !params->GetInteger(2, &stream_id)) { |
| 207 return; | 207 return; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 if (agent_host_) | 254 if (agent_host_) |
| 255 agent_host_->DispatchProtocolMessage(message); | 255 agent_host_->DispatchProtocolMessage(message); |
| 256 } | 256 } |
| 257 | 257 |
| 258 void ShellDevToolsFrontend::DispatchProtocolMessage( | 258 void ShellDevToolsFrontend::DispatchProtocolMessage( |
| 259 DevToolsAgentHost* agent_host, const std::string& message) { | 259 DevToolsAgentHost* agent_host, const std::string& message) { |
| 260 | 260 |
| 261 if (message.length() < kMaxMessageChunkSize) { | 261 if (message.length() < kMaxMessageChunkSize) { |
| 262 base::string16 javascript = base::UTF8ToUTF16( | 262 base::string16 javascript = base::UTF8ToUTF16( |
| 263 "DevToolsAPI.dispatchMessage(" + message + ");"); | 263 "DevToolsAPI.dispatchMessage(" + message + ");"); |
| 264 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); | 264 web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(javascript); |
| 265 return; | 265 return; |
| 266 } | 266 } |
| 267 | 267 |
| 268 base::FundamentalValue total_size(static_cast<int>(message.length())); | 268 base::FundamentalValue total_size(static_cast<int>(message.length())); |
| 269 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { | 269 for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { |
| 270 std::string param; | 270 std::string param; |
| 271 base::JSONWriter::Write( | 271 base::JSONWriter::Write( |
| 272 base::StringValue(message.substr(pos, kMaxMessageChunkSize)), ¶m); | 272 base::StringValue(message.substr(pos, kMaxMessageChunkSize)), ¶m); |
| 273 std::string code = "DevToolsAPI.dispatchMessageChunk(" + param + ");"; | 273 std::string code = "DevToolsAPI.dispatchMessageChunk(" + param + ");"; |
| 274 base::string16 javascript = base::UTF8ToUTF16(code); | 274 base::string16 javascript = base::UTF8ToUTF16(code); |
| 275 web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); | 275 web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(javascript); |
| 276 } | 276 } |
| 277 } | 277 } |
| 278 | 278 |
| 279 void ShellDevToolsFrontend::OnURLFetchComplete(const net::URLFetcher* source) { | 279 void ShellDevToolsFrontend::OnURLFetchComplete(const net::URLFetcher* source) { |
| 280 // TODO(pfeldman): this is a copy of chrome's devtools_ui_bindings.cc. | 280 // TODO(pfeldman): this is a copy of chrome's devtools_ui_bindings.cc. |
| 281 // We should handle some of the commands including this one in content. | 281 // We should handle some of the commands including this one in content. |
| 282 DCHECK(source); | 282 DCHECK(source); |
| 283 PendingRequestsMap::iterator it = pending_requests_.find(source); | 283 PendingRequestsMap::iterator it = pending_requests_.find(source); |
| 284 DCHECK(it != pending_requests_.end()); | 284 DCHECK(it != pending_requests_.end()); |
| 285 | 285 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 313 if (arg2) { | 313 if (arg2) { |
| 314 base::JSONWriter::Write(*arg2, &json); | 314 base::JSONWriter::Write(*arg2, &json); |
| 315 javascript.append(", ").append(json); | 315 javascript.append(", ").append(json); |
| 316 if (arg3) { | 316 if (arg3) { |
| 317 base::JSONWriter::Write(*arg3, &json); | 317 base::JSONWriter::Write(*arg3, &json); |
| 318 javascript.append(", ").append(json); | 318 javascript.append(", ").append(json); |
| 319 } | 319 } |
| 320 } | 320 } |
| 321 } | 321 } |
| 322 javascript.append(");"); | 322 javascript.append(");"); |
| 323 web_contents()->GetMainFrame()->ExecuteJavaScript( | 323 web_contents()->GetMainFrame()->ExecuteJavaScriptForTests( |
| 324 base::UTF8ToUTF16(javascript)); | 324 base::UTF8ToUTF16(javascript)); |
| 325 } | 325 } |
| 326 | 326 |
| 327 void ShellDevToolsFrontend::SendMessageAck(int request_id, | 327 void ShellDevToolsFrontend::SendMessageAck(int request_id, |
| 328 const base::Value* arg) { | 328 const base::Value* arg) { |
| 329 base::FundamentalValue id_value(request_id); | 329 base::FundamentalValue id_value(request_id); |
| 330 CallClientFunction("DevToolsAPI.embedderMessageAck", | 330 CallClientFunction("DevToolsAPI.embedderMessageAck", |
| 331 &id_value, arg, nullptr); | 331 &id_value, arg, nullptr); |
| 332 } | 332 } |
| 333 | 333 |
| 334 void ShellDevToolsFrontend::AgentHostClosed( | 334 void ShellDevToolsFrontend::AgentHostClosed( |
| 335 DevToolsAgentHost* agent_host, bool replaced) { | 335 DevToolsAgentHost* agent_host, bool replaced) { |
| 336 frontend_shell_->Close(); | 336 frontend_shell_->Close(); |
| 337 } | 337 } |
| 338 | 338 |
| 339 } // namespace content | 339 } // namespace content |
| OLD | NEW |