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/devtools/devtools_http_handler_impl.h" | 5 #include "content/browser/devtools/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 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 page_list.push_back(PageInfo(*it, GetLastSelectedTime(*it))); | 519 page_list.push_back(PageInfo(*it, GetLastSelectedTime(*it))); |
520 | 520 |
521 std::sort(page_list.begin(), page_list.end(), TimeComparator); | 521 std::sort(page_list.begin(), page_list.end(), TimeComparator); |
522 | 522 |
523 base::ListValue* target_list = new base::ListValue(); | 523 base::ListValue* target_list = new base::ListValue(); |
524 std::string host = info.headers["host"]; | 524 std::string host = info.headers["host"]; |
525 for (PageList::iterator i = page_list.begin(); i != page_list.end(); ++i) | 525 for (PageList::iterator i = page_list.begin(); i != page_list.end(); ++i) |
526 target_list->Append(SerializePageInfo(i->first, host)); | 526 target_list->Append(SerializePageInfo(i->first, host)); |
527 | 527 |
528 AddRef(); // Balanced in SendTargetList. | 528 AddRef(); // Balanced in SendTargetList. |
529 BrowserThread::PostTaskAndReply( | 529 BrowserThread::PostTaskAndReplyWithResult( |
530 BrowserThread::IO, | 530 BrowserThread::IO, |
531 FROM_HERE, | 531 FROM_HERE, |
532 base::Bind(&DevToolsHttpHandlerImpl::CollectWorkerInfo, | 532 base::Bind(&DevToolsHttpHandlerImpl::CollectWorkerInfo, |
533 base::Unretained(this), | 533 base::Unretained(this)), |
534 target_list, | |
535 host), | |
536 base::Bind(&DevToolsHttpHandlerImpl::SendTargetList, | 534 base::Bind(&DevToolsHttpHandlerImpl::SendTargetList, |
537 base::Unretained(this), | 535 base::Unretained(this), |
538 connection_id, | 536 connection_id, |
| 537 host, |
539 target_list)); | 538 target_list)); |
540 return; | 539 return; |
541 } | 540 } |
542 | 541 |
543 if (command == "new") { | 542 if (command == "new") { |
544 RenderViewHost* rvh = delegate_->CreateNewTarget(); | 543 RenderViewHost* rvh = delegate_->CreateNewTarget(); |
545 if (!rvh) { | 544 if (!rvh) { |
546 SendJson(connection_id, | 545 SendJson(connection_id, |
547 net::HTTP_INTERNAL_SERVER_ERROR, | 546 net::HTTP_INTERNAL_SERVER_ERROR, |
548 NULL, | 547 NULL, |
(...skipping 29 matching lines...) Expand all Loading... |
578 return; | 577 return; |
579 } | 578 } |
580 } | 579 } |
581 SendJson(connection_id, | 580 SendJson(connection_id, |
582 net::HTTP_NOT_FOUND, | 581 net::HTTP_NOT_FOUND, |
583 NULL, | 582 NULL, |
584 "Unknown command: " + command); | 583 "Unknown command: " + command); |
585 return; | 584 return; |
586 } | 585 } |
587 | 586 |
588 void DevToolsHttpHandlerImpl::CollectWorkerInfo(base::ListValue* target_list, | 587 DevToolsHttpHandlerImpl::WorkerInfoList |
589 std::string host) { | 588 DevToolsHttpHandlerImpl::CollectWorkerInfo() { |
| 589 return WorkerService::GetInstance()->GetWorkers(); |
| 590 } |
590 | 591 |
591 std::vector<WorkerService::WorkerInfo> worker_info = | 592 void DevToolsHttpHandlerImpl::SendTargetList( |
592 WorkerService::GetInstance()->GetWorkers(); | 593 int connection_id, |
593 | 594 const std::string& host, |
| 595 base::ListValue* target_list, |
| 596 const WorkerInfoList& worker_info) { |
594 for (size_t i = 0; i < worker_info.size(); ++i) | 597 for (size_t i = 0; i < worker_info.size(); ++i) |
595 target_list->Append(SerializeWorkerInfo(worker_info[i], host)); | 598 target_list->Append(SerializeWorkerInfo(worker_info[i], host)); |
596 } | |
597 | |
598 void DevToolsHttpHandlerImpl::SendTargetList(int connection_id, | |
599 base::ListValue* target_list) { | |
600 SendJson(connection_id, net::HTTP_OK, target_list, std::string()); | 599 SendJson(connection_id, net::HTTP_OK, target_list, std::string()); |
601 delete target_list; | 600 delete target_list; |
602 Release(); // Balanced OnJsonRequestUI. | 601 Release(); // Balanced OnJsonRequestUI. |
603 } | 602 } |
604 | 603 |
605 void DevToolsHttpHandlerImpl::OnThumbnailRequestUI( | 604 void DevToolsHttpHandlerImpl::OnThumbnailRequestUI( |
606 int connection_id, const GURL& page_url) { | 605 int connection_id, const GURL& page_url) { |
607 std::string data = delegate_->GetPageThumbnailData(page_url); | 606 std::string data = delegate_->GetPageThumbnailData(page_url); |
608 if (!data.empty()) | 607 if (!data.empty()) |
609 Send200(connection_id, data, "image/png"); | 608 Send200(connection_id, data, "image/png"); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 host.c_str(), | 859 host.c_str(), |
861 kPageUrlPrefix, | 860 kPageUrlPrefix, |
862 id.c_str())); | 861 id.c_str())); |
863 std::string devtools_frontend_url = GetFrontendURLInternal( | 862 std::string devtools_frontend_url = GetFrontendURLInternal( |
864 id.c_str(), | 863 id.c_str(), |
865 host); | 864 host); |
866 dictionary->SetString(kTargetDevtoolsFrontendUrlField, devtools_frontend_url); | 865 dictionary->SetString(kTargetDevtoolsFrontendUrlField, devtools_frontend_url); |
867 } | 866 } |
868 | 867 |
869 } // namespace content | 868 } // namespace content |
OLD | NEW |