Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/debugger/devtools_http_handler_impl.h" | 5 #include "content/browser/debugger/devtools_http_handler_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 BrowserThread::PostTask( | 301 BrowserThread::PostTask( |
| 302 BrowserThread::UI, | 302 BrowserThread::UI, |
| 303 FROM_HERE, | 303 FROM_HERE, |
| 304 base::Bind(&DevToolsHttpHandlerImpl::OnThumbnailRequestUI, | 304 base::Bind(&DevToolsHttpHandlerImpl::OnThumbnailRequestUI, |
| 305 this, | 305 this, |
| 306 connection_id, | 306 connection_id, |
| 307 info)); | 307 info)); |
| 308 return; | 308 return; |
| 309 } | 309 } |
| 310 | 310 |
| 311 if (info.path.find("/trace/") == 0) { | |
| 312 // Trace request. | |
| 313 BrowserThread::PostTask( | |
| 314 BrowserThread::UI, | |
| 315 FROM_HERE, | |
| 316 base::Bind(&DevToolsHttpHandlerImpl::OnTraceRequestUI, | |
| 317 this, | |
| 318 connection_id, | |
| 319 info)); | |
| 320 return; | |
| 321 } | |
| 322 | |
| 311 if (info.path == "" || info.path == "/") { | 323 if (info.path == "" || info.path == "/") { |
| 312 // Discovery page request. | 324 // Discovery page request. |
| 313 BrowserThread::PostTask( | 325 BrowserThread::PostTask( |
| 314 BrowserThread::UI, | 326 BrowserThread::UI, |
| 315 FROM_HERE, | 327 FROM_HERE, |
| 316 base::Bind(&DevToolsHttpHandlerImpl::OnDiscoveryPageRequestUI, | 328 base::Bind(&DevToolsHttpHandlerImpl::OnDiscoveryPageRequestUI, |
| 317 this, | 329 this, |
| 318 connection_id)); | 330 connection_id)); |
| 319 return; | 331 return; |
| 320 } | 332 } |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 } | 583 } |
| 572 | 584 |
| 573 std::string page_url = info.path.substr(prefix.length()); | 585 std::string page_url = info.path.substr(prefix.length()); |
| 574 std::string data = delegate_->GetPageThumbnailData(GURL(page_url)); | 586 std::string data = delegate_->GetPageThumbnailData(GURL(page_url)); |
| 575 if (!data.empty()) | 587 if (!data.empty()) |
| 576 Send200(connection_id, data, "image/png"); | 588 Send200(connection_id, data, "image/png"); |
| 577 else | 589 else |
| 578 Send404(connection_id); | 590 Send404(connection_id); |
| 579 } | 591 } |
| 580 | 592 |
| 593 void DevToolsHttpHandlerImpl::OnTraceRequestUI( | |
| 594 int connection_id, | |
| 595 const net::HttpServerRequestInfo& info) { | |
| 596 std::string prefix = "/trace/"; | |
| 597 size_t pos = info.path.find(prefix); | |
|
pfeldman
2012/12/12 17:45:22
This discovery handler is supposed to be used with
| |
| 598 if (pos != 0) { | |
| 599 Send404(connection_id); | |
| 600 return; | |
| 601 } | |
| 602 | |
| 603 std::string command = info.path.substr(prefix.length()); | |
| 604 | |
| 605 std::string response("ok"); | |
| 606 if (command == "start") { | |
| 607 // TODO(bulach): capture categories somehow. | |
| 608 std::string categories; | |
| 609 devtools_trace_handler_.BeginTracing(categories); | |
| 610 } else if (command == "stop") | |
| 611 devtools_trace_handler_.EndTracingAsync(); | |
| 612 else if (command == "has_completed") { | |
| 613 response = devtools_trace_handler_.has_completed() ? | |
| 614 "ok" : "pending"; | |
| 615 } else if (command == "get") { | |
| 616 if (devtools_trace_handler_.has_completed()) { | |
| 617 Send200( | |
| 618 connection_id, devtools_trace_handler_.GetAndResetTrace(), | |
| 619 "binary/octet-stream"); | |
| 620 return; | |
| 621 } | |
| 622 Send404(connection_id); | |
| 623 return; | |
| 624 } | |
| 625 Send200(connection_id, response, "text/html; charset=UTF-8"); | |
| 626 } | |
| 627 | |
| 581 void DevToolsHttpHandlerImpl::OnDiscoveryPageRequestUI(int connection_id) { | 628 void DevToolsHttpHandlerImpl::OnDiscoveryPageRequestUI(int connection_id) { |
| 582 std::string response = delegate_->GetDiscoveryPageHTML(); | 629 std::string response = delegate_->GetDiscoveryPageHTML(); |
| 583 Send200(connection_id, response, "text/html; charset=UTF-8"); | 630 Send200(connection_id, response, "text/html; charset=UTF-8"); |
| 584 } | 631 } |
| 585 | 632 |
| 586 void DevToolsHttpHandlerImpl::OnWebSocketRequestUI( | 633 void DevToolsHttpHandlerImpl::OnWebSocketRequestUI( |
| 587 int connection_id, | 634 int connection_id, |
| 588 const net::HttpServerRequestInfo& request) { | 635 const net::HttpServerRequestInfo& request) { |
| 589 if (!thread_.get()) | 636 if (!thread_.get()) |
| 590 return; | 637 return; |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 825 page_info.id.c_str())); | 872 page_info.id.c_str())); |
| 826 std::string devtools_frontend_url = GetFrontendURLInternal( | 873 std::string devtools_frontend_url = GetFrontendURLInternal( |
| 827 page_info.id.c_str(), | 874 page_info.id.c_str(), |
| 828 host); | 875 host); |
| 829 dictionary->SetString("devtoolsFrontendUrl", devtools_frontend_url); | 876 dictionary->SetString("devtoolsFrontendUrl", devtools_frontend_url); |
| 830 } | 877 } |
| 831 return dictionary; | 878 return dictionary; |
| 832 } | 879 } |
| 833 | 880 |
| 834 } // namespace content | 881 } // namespace content |
| OLD | NEW |