| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/message_loop/message_loop_proxy.h" | 13 #include "base/message_loop/message_loop_proxy.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "components/devtools_discovery/devtools_discovery_manager.h" |
| 20 #include "components/devtools_http_handler/devtools_http_handler.h" | 21 #include "components/devtools_http_handler/devtools_http_handler.h" |
| 21 #include "components/devtools_http_handler/devtools_http_handler_delegate.h" | 22 #include "components/devtools_http_handler/devtools_http_handler_delegate.h" |
| 22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/devtools_agent_host.h" | 24 #include "content/public/browser/devtools_agent_host.h" |
| 24 #include "content/public/browser/devtools_target.h" | |
| 25 #include "content/public/common/url_constants.h" | 25 #include "content/public/common/url_constants.h" |
| 26 #include "content/public/common/user_agent.h" | 26 #include "content/public/common/user_agent.h" |
| 27 #include "net/base/escape.h" | 27 #include "net/base/escape.h" |
| 28 #include "net/base/io_buffer.h" | 28 #include "net/base/io_buffer.h" |
| 29 #include "net/base/ip_endpoint.h" | 29 #include "net/base/ip_endpoint.h" |
| 30 #include "net/base/net_errors.h" | 30 #include "net/base/net_errors.h" |
| 31 #include "net/server/http_server.h" | 31 #include "net/server/http_server.h" |
| 32 #include "net/server/http_server_request_info.h" | 32 #include "net/server/http_server_request_info.h" |
| 33 #include "net/server/http_server_response_info.h" | 33 #include "net/server/http_server_response_info.h" |
| 34 #include "net/socket/server_socket.h" | 34 #include "net/socket/server_socket.h" |
| 35 | 35 |
| 36 #if defined(OS_ANDROID) | 36 #if defined(OS_ANDROID) |
| 37 #include "base/android/build_info.h" | 37 #include "base/android/build_info.h" |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 using content::BrowserThread; | 40 using content::BrowserThread; |
| 41 using content::DevToolsAgentHost; | 41 using content::DevToolsAgentHost; |
| 42 using content::DevToolsAgentHostClient; | 42 using content::DevToolsAgentHostClient; |
| 43 using content::DevToolsManagerDelegate; | 43 using devtools_discovery::DevToolsTargetDescriptor; |
| 44 using content::DevToolsTarget; | |
| 45 | 44 |
| 46 namespace devtools_http_handler { | 45 namespace devtools_http_handler { |
| 47 | 46 |
| 48 namespace { | 47 namespace { |
| 49 | 48 |
| 50 const base::FilePath::CharType kDevToolsActivePortFileName[] = | 49 const base::FilePath::CharType kDevToolsActivePortFileName[] = |
| 51 FILE_PATH_LITERAL("DevToolsActivePort"); | 50 FILE_PATH_LITERAL("DevToolsActivePort"); |
| 52 | 51 |
| 53 const char kDevToolsHandlerThreadName[] = "Chrome_DevToolsHandlerThread"; | 52 const char kDevToolsHandlerThreadName[] = "Chrome_DevToolsHandlerThread"; |
| 54 | 53 |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 agent_host_->DispatchProtocolMessage(message); | 311 agent_host_->DispatchProtocolMessage(message); |
| 313 } | 312 } |
| 314 | 313 |
| 315 private: | 314 private: |
| 316 base::MessageLoop* const message_loop_; | 315 base::MessageLoop* const message_loop_; |
| 317 ServerWrapper* const server_wrapper_; | 316 ServerWrapper* const server_wrapper_; |
| 318 const int connection_id_; | 317 const int connection_id_; |
| 319 scoped_refptr<DevToolsAgentHost> agent_host_; | 318 scoped_refptr<DevToolsAgentHost> agent_host_; |
| 320 }; | 319 }; |
| 321 | 320 |
| 322 static bool TimeComparator(const DevToolsTarget* target1, | 321 static bool TimeComparator(const DevToolsTargetDescriptor* desc1, |
| 323 const DevToolsTarget* target2) { | 322 const DevToolsTargetDescriptor* desc2) { |
| 324 return target1->GetLastActivityTime() > target2->GetLastActivityTime(); | 323 return desc1->GetLastActivityTime() > desc2->GetLastActivityTime(); |
| 325 } | 324 } |
| 326 | 325 |
| 327 // DevToolsHttpHandler::ServerSocketFactory ---------------------------------- | 326 // DevToolsHttpHandler::ServerSocketFactory ---------------------------------- |
| 328 | 327 |
| 329 scoped_ptr<net::ServerSocket> | 328 scoped_ptr<net::ServerSocket> |
| 330 DevToolsHttpHandler::ServerSocketFactory::CreateForHttpServer() { | 329 DevToolsHttpHandler::ServerSocketFactory::CreateForHttpServer() { |
| 331 return scoped_ptr<net::ServerSocket>(); | 330 return scoped_ptr<net::ServerSocket>(); |
| 332 } | 331 } |
| 333 | 332 |
| 334 scoped_ptr<net::ServerSocket> | 333 scoped_ptr<net::ServerSocket> |
| 335 DevToolsHttpHandler::ServerSocketFactory::CreateForTethering( | 334 DevToolsHttpHandler::ServerSocketFactory::CreateForTethering( |
| 336 std::string* name) { | 335 std::string* name) { |
| 337 return scoped_ptr<net::ServerSocket>(); | 336 return scoped_ptr<net::ServerSocket>(); |
| 338 } | 337 } |
| 339 | 338 |
| 340 // DevToolsHttpHandler ------------------------------------------------------- | 339 // DevToolsHttpHandler ------------------------------------------------------- |
| 341 | 340 |
| 342 DevToolsHttpHandler::~DevToolsHttpHandler() { | 341 DevToolsHttpHandler::~DevToolsHttpHandler() { |
| 343 TerminateOnUI(thread_, server_wrapper_, socket_factory_); | 342 TerminateOnUI(thread_, server_wrapper_, socket_factory_); |
| 344 STLDeleteValues(&target_map_); | 343 STLDeleteValues(&descriptor_map_); |
| 345 STLDeleteValues(&connection_to_client_); | 344 STLDeleteValues(&connection_to_client_); |
| 346 } | 345 } |
| 347 | 346 |
| 348 GURL DevToolsHttpHandler::GetFrontendURL(const std::string& path) { | 347 GURL DevToolsHttpHandler::GetFrontendURL(const std::string& path) { |
| 349 if (!server_ip_address_) | 348 if (!server_ip_address_) |
| 350 return GURL(); | 349 return GURL(); |
| 351 return GURL(std::string("http://") + server_ip_address_->ToString() + | 350 return GURL(std::string("http://") + server_ip_address_->ToString() + |
| 352 (path.empty() ? frontend_url_ : path)); | 351 (path.empty() ? frontend_url_ : path)); |
| 353 } | 352 } |
| 354 | 353 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 #if defined(OS_ANDROID) | 557 #if defined(OS_ANDROID) |
| 559 version.SetString("Android-Package", | 558 version.SetString("Android-Package", |
| 560 base::android::BuildInfo::GetInstance()->package_name()); | 559 base::android::BuildInfo::GetInstance()->package_name()); |
| 561 #endif | 560 #endif |
| 562 SendJson(connection_id, net::HTTP_OK, &version, std::string()); | 561 SendJson(connection_id, net::HTTP_OK, &version, std::string()); |
| 563 return; | 562 return; |
| 564 } | 563 } |
| 565 | 564 |
| 566 if (command == "list") { | 565 if (command == "list") { |
| 567 std::string host = info.headers["host"]; | 566 std::string host = info.headers["host"]; |
| 568 if (manager_delegate_) { | 567 DevToolsTargetDescriptor::List descriptors = |
| 569 manager_delegate_->EnumerateTargets( | 568 devtools_discovery::DevToolsDiscoveryManager::GetInstance()-> |
| 570 base::Bind(&DevToolsHttpHandler::OnTargetListReceivedWeak, | 569 GetDescriptors(); |
| 571 weak_factory_.GetWeakPtr(), connection_id, host)); | 570 std::sort(descriptors.begin(), descriptors.end(), TimeComparator); |
| 572 } else { | 571 STLDeleteValues(&descriptor_map_); |
| 573 DevToolsManagerDelegate::TargetList empty_list; | 572 base::ListValue list_value; |
| 574 OnTargetListReceived(connection_id, host, empty_list); | 573 for (DevToolsTargetDescriptor* descriptor : descriptors) { |
| 574 descriptor_map_[descriptor->GetId()] = descriptor; |
| 575 list_value.Append(SerializeDescriptor(*descriptor, host)); |
| 575 } | 576 } |
| 577 SendJson(connection_id, net::HTTP_OK, &list_value, std::string()); |
| 576 return; | 578 return; |
| 577 } | 579 } |
| 578 | 580 |
| 579 if (command == "new") { | 581 if (command == "new") { |
| 580 GURL url(net::UnescapeURLComponent( | 582 GURL url(net::UnescapeURLComponent( |
| 581 query, net::UnescapeRule::URL_SPECIAL_CHARS)); | 583 query, net::UnescapeRule::URL_SPECIAL_CHARS)); |
| 582 if (!url.is_valid()) | 584 if (!url.is_valid()) |
| 583 url = GURL(url::kAboutBlankURL); | 585 url = GURL(url::kAboutBlankURL); |
| 584 scoped_ptr<DevToolsTarget> target; | 586 scoped_ptr<DevToolsTargetDescriptor> descriptor = |
| 585 if (manager_delegate_) | 587 devtools_discovery::DevToolsDiscoveryManager::GetInstance()-> |
| 586 target = manager_delegate_->CreateNewTarget(url); | 588 CreateNew(url); |
| 587 if (!target) { | 589 if (!descriptor) { |
| 588 SendJson(connection_id, | 590 SendJson(connection_id, |
| 589 net::HTTP_INTERNAL_SERVER_ERROR, | 591 net::HTTP_INTERNAL_SERVER_ERROR, |
| 590 NULL, | 592 NULL, |
| 591 "Could not create new page"); | 593 "Could not create new page"); |
| 592 return; | 594 return; |
| 593 } | 595 } |
| 594 std::string host = info.headers["host"]; | 596 std::string host = info.headers["host"]; |
| 595 scoped_ptr<base::DictionaryValue> dictionary( | 597 scoped_ptr<base::DictionaryValue> dictionary( |
| 596 SerializeTarget(*target.get(), host)); | 598 SerializeDescriptor(*descriptor.get(), host)); |
| 597 SendJson(connection_id, net::HTTP_OK, dictionary.get(), std::string()); | 599 SendJson(connection_id, net::HTTP_OK, dictionary.get(), std::string()); |
| 598 const std::string target_id = target->GetId(); | 600 const std::string target_id = descriptor->GetId(); |
| 599 target_map_[target_id] = target.release(); | 601 descriptor_map_[target_id] = descriptor.release(); |
| 600 return; | 602 return; |
| 601 } | 603 } |
| 602 | 604 |
| 603 if (command == "activate" || command == "close") { | 605 if (command == "activate" || command == "close") { |
| 604 DevToolsTarget* target = GetTarget(target_id); | 606 DevToolsTargetDescriptor* descriptor = GetDescriptor(target_id); |
| 605 if (!target) { | 607 if (!descriptor) { |
| 606 SendJson(connection_id, | 608 SendJson(connection_id, |
| 607 net::HTTP_NOT_FOUND, | 609 net::HTTP_NOT_FOUND, |
| 608 NULL, | 610 NULL, |
| 609 "No such target id: " + target_id); | 611 "No such target id: " + target_id); |
| 610 return; | 612 return; |
| 611 } | 613 } |
| 612 | 614 |
| 613 if (command == "activate") { | 615 if (command == "activate") { |
| 614 if (target->Activate()) { | 616 if (descriptor->Activate()) { |
| 615 SendJson(connection_id, net::HTTP_OK, NULL, "Target activated"); | 617 SendJson(connection_id, net::HTTP_OK, NULL, "Target activated"); |
| 616 } else { | 618 } else { |
| 617 SendJson(connection_id, | 619 SendJson(connection_id, |
| 618 net::HTTP_INTERNAL_SERVER_ERROR, | 620 net::HTTP_INTERNAL_SERVER_ERROR, |
| 619 NULL, | 621 NULL, |
| 620 "Could not activate target id: " + target_id); | 622 "Could not activate target id: " + target_id); |
| 621 } | 623 } |
| 622 return; | 624 return; |
| 623 } | 625 } |
| 624 | 626 |
| 625 if (command == "close") { | 627 if (command == "close") { |
| 626 if (target->Close()) { | 628 if (descriptor->Close()) { |
| 627 SendJson(connection_id, net::HTTP_OK, NULL, "Target is closing"); | 629 SendJson(connection_id, net::HTTP_OK, NULL, "Target is closing"); |
| 628 } else { | 630 } else { |
| 629 SendJson(connection_id, | 631 SendJson(connection_id, |
| 630 net::HTTP_INTERNAL_SERVER_ERROR, | 632 net::HTTP_INTERNAL_SERVER_ERROR, |
| 631 NULL, | 633 NULL, |
| 632 "Could not close target id: " + target_id); | 634 "Could not close target id: " + target_id); |
| 633 } | 635 } |
| 634 return; | 636 return; |
| 635 } | 637 } |
| 636 } | 638 } |
| 637 SendJson(connection_id, | 639 SendJson(connection_id, |
| 638 net::HTTP_NOT_FOUND, | 640 net::HTTP_NOT_FOUND, |
| 639 NULL, | 641 NULL, |
| 640 "Unknown command: " + command); | 642 "Unknown command: " + command); |
| 641 return; | 643 return; |
| 642 } | 644 } |
| 643 | 645 |
| 644 // static | 646 DevToolsTargetDescriptor* DevToolsHttpHandler::GetDescriptor( |
| 645 void DevToolsHttpHandler::OnTargetListReceivedWeak( | 647 const std::string& target_id) { |
| 646 base::WeakPtr<DevToolsHttpHandler> handler, | 648 DescriptorMap::const_iterator it = descriptor_map_.find(target_id); |
| 647 int connection_id, | 649 if (it == descriptor_map_.end()) |
| 648 const std::string& host, | 650 return nullptr; |
| 649 const DevToolsManagerDelegate::TargetList& targets) { | |
| 650 if (handler) { | |
| 651 handler->OnTargetListReceived(connection_id, host, targets); | |
| 652 } else { | |
| 653 STLDeleteContainerPointers(targets.begin(), targets.end()); | |
| 654 } | |
| 655 } | |
| 656 | |
| 657 void DevToolsHttpHandler::OnTargetListReceived( | |
| 658 int connection_id, | |
| 659 const std::string& host, | |
| 660 const DevToolsManagerDelegate::TargetList& targets) { | |
| 661 DevToolsManagerDelegate::TargetList sorted_targets = targets; | |
| 662 std::sort(sorted_targets.begin(), sorted_targets.end(), TimeComparator); | |
| 663 | |
| 664 STLDeleteValues(&target_map_); | |
| 665 base::ListValue list_value; | |
| 666 for (DevToolsManagerDelegate::TargetList::const_iterator it = | |
| 667 sorted_targets.begin(); it != sorted_targets.end(); ++it) { | |
| 668 DevToolsTarget* target = *it; | |
| 669 target_map_[target->GetId()] = target; | |
| 670 list_value.Append(SerializeTarget(*target, host)); | |
| 671 } | |
| 672 SendJson(connection_id, net::HTTP_OK, &list_value, std::string()); | |
| 673 } | |
| 674 | |
| 675 DevToolsTarget* DevToolsHttpHandler::GetTarget(const std::string& id) { | |
| 676 TargetMap::const_iterator it = target_map_.find(id); | |
| 677 if (it == target_map_.end()) | |
| 678 return NULL; | |
| 679 return it->second; | 651 return it->second; |
| 680 } | 652 } |
| 681 | 653 |
| 682 void DevToolsHttpHandler::OnThumbnailRequest( | 654 void DevToolsHttpHandler::OnThumbnailRequest( |
| 683 int connection_id, const std::string& target_id) { | 655 int connection_id, const std::string& target_id) { |
| 684 DevToolsTarget* target = GetTarget(target_id); | 656 DevToolsTargetDescriptor* descriptor = GetDescriptor(target_id); |
| 685 GURL page_url; | 657 GURL page_url; |
| 686 if (target) | 658 if (descriptor) |
| 687 page_url = target->GetURL(); | 659 page_url = descriptor->GetURL(); |
| 688 std::string data = manager_delegate_ ? | 660 std::string data = delegate_->GetPageThumbnailData(page_url); |
| 689 manager_delegate_->GetPageThumbnailData(page_url) : ""; | |
| 690 if (!data.empty()) | 661 if (!data.empty()) |
| 691 Send200(connection_id, data, "image/png"); | 662 Send200(connection_id, data, "image/png"); |
| 692 else | 663 else |
| 693 Send404(connection_id); | 664 Send404(connection_id); |
| 694 } | 665 } |
| 695 | 666 |
| 696 void DevToolsHttpHandler::OnDiscoveryPageRequest(int connection_id) { | 667 void DevToolsHttpHandler::OnDiscoveryPageRequest(int connection_id) { |
| 697 std::string response = delegate_->GetDiscoveryPageHTML(); | 668 std::string response = delegate_->GetDiscoveryPageHTML(); |
| 698 Send200(connection_id, response, "text/html; charset=UTF-8"); | 669 Send200(connection_id, response, "text/html; charset=UTF-8"); |
| 699 } | 670 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 724 AcceptWebSocket(connection_id, request); | 695 AcceptWebSocket(connection_id, request); |
| 725 return; | 696 return; |
| 726 } | 697 } |
| 727 | 698 |
| 728 size_t pos = request.path.find(kPageUrlPrefix); | 699 size_t pos = request.path.find(kPageUrlPrefix); |
| 729 if (pos != 0) { | 700 if (pos != 0) { |
| 730 Send404(connection_id); | 701 Send404(connection_id); |
| 731 return; | 702 return; |
| 732 } | 703 } |
| 733 | 704 |
| 734 std::string page_id = request.path.substr(strlen(kPageUrlPrefix)); | 705 std::string target_id = request.path.substr(strlen(kPageUrlPrefix)); |
| 735 DevToolsTarget* target = GetTarget(page_id); | 706 DevToolsTargetDescriptor* descriptor = GetDescriptor(target_id); |
| 736 scoped_refptr<DevToolsAgentHost> agent = | 707 scoped_refptr<DevToolsAgentHost> agent = |
| 737 target ? target->GetAgentHost() : NULL; | 708 descriptor ? descriptor->GetAgentHost() : nullptr; |
| 738 if (!agent.get()) { | 709 if (!agent.get()) { |
| 739 Send500(connection_id, "No such target id: " + page_id); | 710 Send500(connection_id, "No such target id: " + target_id); |
| 740 return; | 711 return; |
| 741 } | 712 } |
| 742 | 713 |
| 743 if (agent->IsAttached()) { | 714 if (agent->IsAttached()) { |
| 744 Send500(connection_id, | 715 Send500(connection_id, |
| 745 "Target with given id is being inspected: " + page_id); | 716 "Target with given id is being inspected: " + target_id); |
| 746 return; | 717 return; |
| 747 } | 718 } |
| 748 | 719 |
| 749 DevToolsAgentHostClientImpl* client_host = new DevToolsAgentHostClientImpl( | 720 DevToolsAgentHostClientImpl* client_host = new DevToolsAgentHostClientImpl( |
| 750 thread_->message_loop(), server_wrapper_, connection_id, agent); | 721 thread_->message_loop(), server_wrapper_, connection_id, agent); |
| 751 connection_to_client_[connection_id] = client_host; | 722 connection_to_client_[connection_id] = client_host; |
| 752 | 723 |
| 753 AcceptWebSocket(connection_id, request); | 724 AcceptWebSocket(connection_id, request); |
| 754 } | 725 } |
| 755 | 726 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 768 if (it != connection_to_client_.end()) { | 739 if (it != connection_to_client_.end()) { |
| 769 delete it->second; | 740 delete it->second; |
| 770 connection_to_client_.erase(connection_id); | 741 connection_to_client_.erase(connection_id); |
| 771 } | 742 } |
| 772 } | 743 } |
| 773 | 744 |
| 774 DevToolsHttpHandler::DevToolsHttpHandler( | 745 DevToolsHttpHandler::DevToolsHttpHandler( |
| 775 scoped_ptr<ServerSocketFactory> server_socket_factory, | 746 scoped_ptr<ServerSocketFactory> server_socket_factory, |
| 776 const std::string& frontend_url, | 747 const std::string& frontend_url, |
| 777 DevToolsHttpHandlerDelegate* delegate, | 748 DevToolsHttpHandlerDelegate* delegate, |
| 778 DevToolsManagerDelegate* manager_delegate, | |
| 779 const base::FilePath& output_directory, | 749 const base::FilePath& output_directory, |
| 780 const base::FilePath& debug_frontend_dir, | 750 const base::FilePath& debug_frontend_dir, |
| 781 const std::string& product_name, | 751 const std::string& product_name, |
| 782 const std::string& user_agent) | 752 const std::string& user_agent) |
| 783 : thread_(nullptr), | 753 : thread_(nullptr), |
| 784 frontend_url_(frontend_url), | 754 frontend_url_(frontend_url), |
| 785 product_name_(product_name), | 755 product_name_(product_name), |
| 786 user_agent_(user_agent), | 756 user_agent_(user_agent), |
| 787 server_wrapper_(nullptr), | 757 server_wrapper_(nullptr), |
| 788 delegate_(delegate), | 758 delegate_(delegate), |
| 789 manager_delegate_(manager_delegate), | |
| 790 socket_factory_(nullptr), | 759 socket_factory_(nullptr), |
| 791 weak_factory_(this) { | 760 weak_factory_(this) { |
| 792 bool bundles_resources = frontend_url_.empty(); | 761 bool bundles_resources = frontend_url_.empty(); |
| 793 if (frontend_url_.empty()) | 762 if (frontend_url_.empty()) |
| 794 frontend_url_ = "/devtools/inspector.html"; | 763 frontend_url_ = "/devtools/inspector.html"; |
| 795 | 764 |
| 796 BrowserThread::PostTask( | 765 BrowserThread::PostTask( |
| 797 BrowserThread::FILE, FROM_HERE, | 766 BrowserThread::FILE, FROM_HERE, |
| 798 base::Bind(&StartServerOnFile, | 767 base::Bind(&StartServerOnFile, |
| 799 weak_factory_.GetWeakPtr(), | 768 weak_factory_.GetWeakPtr(), |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 if (!thread_) | 874 if (!thread_) |
| 906 return; | 875 return; |
| 907 thread_->message_loop()->PostTask( | 876 thread_->message_loop()->PostTask( |
| 908 FROM_HERE, | 877 FROM_HERE, |
| 909 base::Bind(&ServerWrapper::AcceptWebSocket, | 878 base::Bind(&ServerWrapper::AcceptWebSocket, |
| 910 base::Unretained(server_wrapper_), | 879 base::Unretained(server_wrapper_), |
| 911 connection_id, | 880 connection_id, |
| 912 request)); | 881 request)); |
| 913 } | 882 } |
| 914 | 883 |
| 915 base::DictionaryValue* DevToolsHttpHandler::SerializeTarget( | 884 base::DictionaryValue* DevToolsHttpHandler::SerializeDescriptor( |
| 916 const DevToolsTarget& target, | 885 const DevToolsTargetDescriptor& descriptor, |
| 917 const std::string& host) { | 886 const std::string& host) { |
| 918 base::DictionaryValue* dictionary = new base::DictionaryValue; | 887 base::DictionaryValue* dictionary = new base::DictionaryValue; |
| 919 | 888 |
| 920 std::string id = target.GetId(); | 889 std::string id = descriptor.GetId(); |
| 921 dictionary->SetString(kTargetIdField, id); | 890 dictionary->SetString(kTargetIdField, id); |
| 922 std::string parent_id = target.GetParentId(); | 891 std::string parent_id = descriptor.GetParentId(); |
| 923 if (!parent_id.empty()) | 892 if (!parent_id.empty()) |
| 924 dictionary->SetString(kTargetParentIdField, parent_id); | 893 dictionary->SetString(kTargetParentIdField, parent_id); |
| 925 dictionary->SetString(kTargetTypeField, target.GetType()); | 894 dictionary->SetString(kTargetTypeField, descriptor.GetType()); |
| 926 dictionary->SetString(kTargetTitleField, | 895 dictionary->SetString(kTargetTitleField, |
| 927 net::EscapeForHTML(target.GetTitle())); | 896 net::EscapeForHTML(descriptor.GetTitle())); |
| 928 dictionary->SetString(kTargetDescriptionField, target.GetDescription()); | 897 dictionary->SetString(kTargetDescriptionField, descriptor.GetDescription()); |
| 929 | 898 |
| 930 GURL url = target.GetURL(); | 899 GURL url = descriptor.GetURL(); |
| 931 dictionary->SetString(kTargetUrlField, url.spec()); | 900 dictionary->SetString(kTargetUrlField, url.spec()); |
| 932 | 901 |
| 933 GURL favicon_url = target.GetFaviconURL(); | 902 GURL favicon_url = descriptor.GetFaviconURL(); |
| 934 if (favicon_url.is_valid()) | 903 if (favicon_url.is_valid()) |
| 935 dictionary->SetString(kTargetFaviconUrlField, favicon_url.spec()); | 904 dictionary->SetString(kTargetFaviconUrlField, favicon_url.spec()); |
| 936 | 905 |
| 937 if (manager_delegate_ && | 906 if (!delegate_->GetPageThumbnailData(url).empty()) { |
| 938 !manager_delegate_->GetPageThumbnailData(url).empty()) { | |
| 939 dictionary->SetString(kTargetThumbnailUrlField, | 907 dictionary->SetString(kTargetThumbnailUrlField, |
| 940 std::string(kThumbUrlPrefix) + id); | 908 std::string(kThumbUrlPrefix) + id); |
| 941 } | 909 } |
| 942 | 910 |
| 943 if (!target.IsAttached()) { | 911 if (!descriptor.IsAttached()) { |
| 944 dictionary->SetString(kTargetWebSocketDebuggerUrlField, | 912 dictionary->SetString(kTargetWebSocketDebuggerUrlField, |
| 945 base::StringPrintf("ws://%s%s%s", | 913 base::StringPrintf("ws://%s%s%s", |
| 946 host.c_str(), | 914 host.c_str(), |
| 947 kPageUrlPrefix, | 915 kPageUrlPrefix, |
| 948 id.c_str())); | 916 id.c_str())); |
| 949 std::string devtools_frontend_url = GetFrontendURLInternal( | 917 std::string devtools_frontend_url = GetFrontendURLInternal( |
| 950 id.c_str(), | 918 id.c_str(), |
| 951 host); | 919 host); |
| 952 dictionary->SetString( | 920 dictionary->SetString( |
| 953 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); | 921 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); |
| 954 } | 922 } |
| 955 | 923 |
| 956 return dictionary; | 924 return dictionary; |
| 957 } | 925 } |
| 958 | 926 |
| 959 } // namespace devtools_http_handler | 927 } // namespace devtools_http_handler |
| OLD | NEW |