| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 | 317 |
| 318 private: | 318 private: |
| 319 base::MessageLoop* const message_loop_; | 319 base::MessageLoop* const message_loop_; |
| 320 ServerWrapper* const server_wrapper_; | 320 ServerWrapper* const server_wrapper_; |
| 321 const int connection_id_; | 321 const int connection_id_; |
| 322 scoped_refptr<DevToolsAgentHost> agent_host_; | 322 scoped_refptr<DevToolsAgentHost> agent_host_; |
| 323 }; | 323 }; |
| 324 | 324 |
| 325 static bool TimeComparator(const DevToolsTargetDescriptor* desc1, | 325 static bool TimeComparator(const DevToolsTargetDescriptor* desc1, |
| 326 const DevToolsTargetDescriptor* desc2) { | 326 const DevToolsTargetDescriptor* desc2) { |
| 327 return desc1->GetAgentHost()->GetLastActivityTime() > | 327 return desc1->GetLastActivityTime() > desc2->GetLastActivityTime(); |
| 328 desc2->GetAgentHost()->GetLastActivityTime(); | |
| 329 } | 328 } |
| 330 | 329 |
| 331 // DevToolsHttpHandler::ServerSocketFactory ---------------------------------- | 330 // DevToolsHttpHandler::ServerSocketFactory ---------------------------------- |
| 332 | 331 |
| 333 std::unique_ptr<net::ServerSocket> | 332 std::unique_ptr<net::ServerSocket> |
| 334 DevToolsHttpHandler::ServerSocketFactory::CreateForHttpServer() { | 333 DevToolsHttpHandler::ServerSocketFactory::CreateForHttpServer() { |
| 335 return nullptr; | 334 return nullptr; |
| 336 } | 335 } |
| 337 | 336 |
| 338 std::unique_ptr<net::ServerSocket> | 337 std::unique_ptr<net::ServerSocket> |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 | 578 |
| 580 if (command == "list") { | 579 if (command == "list") { |
| 581 std::string host = info.headers["host"]; | 580 std::string host = info.headers["host"]; |
| 582 DevToolsTargetDescriptor::List descriptors = | 581 DevToolsTargetDescriptor::List descriptors = |
| 583 devtools_discovery::DevToolsDiscoveryManager::GetInstance()-> | 582 devtools_discovery::DevToolsDiscoveryManager::GetInstance()-> |
| 584 GetDescriptors(); | 583 GetDescriptors(); |
| 585 std::sort(descriptors.begin(), descriptors.end(), TimeComparator); | 584 std::sort(descriptors.begin(), descriptors.end(), TimeComparator); |
| 586 base::STLDeleteValues(&descriptor_map_); | 585 base::STLDeleteValues(&descriptor_map_); |
| 587 base::ListValue list_value; | 586 base::ListValue list_value; |
| 588 for (DevToolsTargetDescriptor* descriptor : descriptors) { | 587 for (DevToolsTargetDescriptor* descriptor : descriptors) { |
| 589 descriptor_map_[descriptor->GetAgentHost()->GetId()] = descriptor; | 588 descriptor_map_[descriptor->GetId()] = descriptor; |
| 590 list_value.Append(SerializeDescriptor(*descriptor, host)); | 589 list_value.Append(SerializeDescriptor(*descriptor, host)); |
| 591 } | 590 } |
| 592 SendJson(connection_id, net::HTTP_OK, &list_value, std::string()); | 591 SendJson(connection_id, net::HTTP_OK, &list_value, std::string()); |
| 593 return; | 592 return; |
| 594 } | 593 } |
| 595 | 594 |
| 596 if (command == "new") { | 595 if (command == "new") { |
| 597 GURL url(net::UnescapeURLComponent( | 596 GURL url(net::UnescapeURLComponent( |
| 598 query, net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS | | 597 query, net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS | |
| 599 net::UnescapeRule::PATH_SEPARATORS)); | 598 net::UnescapeRule::PATH_SEPARATORS)); |
| 600 if (!url.is_valid()) | 599 if (!url.is_valid()) |
| 601 url = GURL(url::kAboutBlankURL); | 600 url = GURL(url::kAboutBlankURL); |
| 602 std::unique_ptr<DevToolsTargetDescriptor> descriptor = | 601 std::unique_ptr<DevToolsTargetDescriptor> descriptor = |
| 603 devtools_discovery::DevToolsDiscoveryManager::GetInstance()->CreateNew( | 602 devtools_discovery::DevToolsDiscoveryManager::GetInstance()->CreateNew( |
| 604 url); | 603 url); |
| 605 if (!descriptor) { | 604 if (!descriptor) { |
| 606 SendJson(connection_id, | 605 SendJson(connection_id, |
| 607 net::HTTP_INTERNAL_SERVER_ERROR, | 606 net::HTTP_INTERNAL_SERVER_ERROR, |
| 608 NULL, | 607 NULL, |
| 609 "Could not create new page"); | 608 "Could not create new page"); |
| 610 return; | 609 return; |
| 611 } | 610 } |
| 612 std::string host = info.headers["host"]; | 611 std::string host = info.headers["host"]; |
| 613 std::unique_ptr<base::DictionaryValue> dictionary( | 612 std::unique_ptr<base::DictionaryValue> dictionary( |
| 614 SerializeDescriptor(*descriptor.get(), host)); | 613 SerializeDescriptor(*descriptor.get(), host)); |
| 615 SendJson(connection_id, net::HTTP_OK, dictionary.get(), std::string()); | 614 SendJson(connection_id, net::HTTP_OK, dictionary.get(), std::string()); |
| 616 const std::string target_id = descriptor->GetAgentHost()->GetId(); | 615 const std::string target_id = descriptor->GetId(); |
| 617 descriptor_map_[target_id] = descriptor.release(); | 616 descriptor_map_[target_id] = descriptor.release(); |
| 618 return; | 617 return; |
| 619 } | 618 } |
| 620 | 619 |
| 621 if (command == "activate" || command == "close") { | 620 if (command == "activate" || command == "close") { |
| 622 DevToolsTargetDescriptor* descriptor = GetDescriptor(target_id); | 621 DevToolsTargetDescriptor* descriptor = GetDescriptor(target_id); |
| 623 if (!descriptor) { | 622 if (!descriptor) { |
| 624 SendJson(connection_id, | 623 SendJson(connection_id, |
| 625 net::HTTP_NOT_FOUND, | 624 net::HTTP_NOT_FOUND, |
| 626 NULL, | 625 NULL, |
| 627 "No such target id: " + target_id); | 626 "No such target id: " + target_id); |
| 628 return; | 627 return; |
| 629 } | 628 } |
| 630 | 629 |
| 631 if (command == "activate") { | 630 if (command == "activate") { |
| 632 if (descriptor->GetAgentHost()->Activate()) { | 631 if (descriptor->Activate()) { |
| 633 SendJson(connection_id, net::HTTP_OK, NULL, "Target activated"); | 632 SendJson(connection_id, net::HTTP_OK, NULL, "Target activated"); |
| 634 } else { | 633 } else { |
| 635 SendJson(connection_id, | 634 SendJson(connection_id, |
| 636 net::HTTP_INTERNAL_SERVER_ERROR, | 635 net::HTTP_INTERNAL_SERVER_ERROR, |
| 637 NULL, | 636 NULL, |
| 638 "Could not activate target id: " + target_id); | 637 "Could not activate target id: " + target_id); |
| 639 } | 638 } |
| 640 return; | 639 return; |
| 641 } | 640 } |
| 642 | 641 |
| 643 if (command == "close") { | 642 if (command == "close") { |
| 644 if (descriptor->GetAgentHost()->Close()) { | 643 if (descriptor->Close()) { |
| 645 SendJson(connection_id, net::HTTP_OK, NULL, "Target is closing"); | 644 SendJson(connection_id, net::HTTP_OK, NULL, "Target is closing"); |
| 646 } else { | 645 } else { |
| 647 SendJson(connection_id, | 646 SendJson(connection_id, |
| 648 net::HTTP_INTERNAL_SERVER_ERROR, | 647 net::HTTP_INTERNAL_SERVER_ERROR, |
| 649 NULL, | 648 NULL, |
| 650 "Could not close target id: " + target_id); | 649 "Could not close target id: " + target_id); |
| 651 } | 650 } |
| 652 return; | 651 return; |
| 653 } | 652 } |
| 654 } | 653 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 665 if (it == descriptor_map_.end()) | 664 if (it == descriptor_map_.end()) |
| 666 return nullptr; | 665 return nullptr; |
| 667 return it->second; | 666 return it->second; |
| 668 } | 667 } |
| 669 | 668 |
| 670 void DevToolsHttpHandler::OnThumbnailRequest( | 669 void DevToolsHttpHandler::OnThumbnailRequest( |
| 671 int connection_id, const std::string& target_id) { | 670 int connection_id, const std::string& target_id) { |
| 672 DevToolsTargetDescriptor* descriptor = GetDescriptor(target_id); | 671 DevToolsTargetDescriptor* descriptor = GetDescriptor(target_id); |
| 673 GURL page_url; | 672 GURL page_url; |
| 674 if (descriptor) | 673 if (descriptor) |
| 675 page_url = descriptor->GetAgentHost()->GetURL(); | 674 page_url = descriptor->GetURL(); |
| 676 std::string data = delegate_->GetPageThumbnailData(page_url); | 675 std::string data = delegate_->GetPageThumbnailData(page_url); |
| 677 if (!data.empty()) | 676 if (!data.empty()) |
| 678 Send200(connection_id, data, "image/png"); | 677 Send200(connection_id, data, "image/png"); |
| 679 else | 678 else |
| 680 Send404(connection_id); | 679 Send404(connection_id); |
| 681 } | 680 } |
| 682 | 681 |
| 683 void DevToolsHttpHandler::OnDiscoveryPageRequest(int connection_id) { | 682 void DevToolsHttpHandler::OnDiscoveryPageRequest(int connection_id) { |
| 684 std::string response = delegate_->GetDiscoveryPageHTML(); | 683 std::string response = delegate_->GetDiscoveryPageHTML(); |
| 685 Send200(connection_id, response, "text/html; charset=UTF-8"); | 684 Send200(connection_id, response, "text/html; charset=UTF-8"); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 thread_->task_runner()->PostTask( | 892 thread_->task_runner()->PostTask( |
| 894 FROM_HERE, | 893 FROM_HERE, |
| 895 base::Bind(&ServerWrapper::AcceptWebSocket, | 894 base::Bind(&ServerWrapper::AcceptWebSocket, |
| 896 base::Unretained(server_wrapper_), connection_id, request)); | 895 base::Unretained(server_wrapper_), connection_id, request)); |
| 897 } | 896 } |
| 898 | 897 |
| 899 base::DictionaryValue* DevToolsHttpHandler::SerializeDescriptor( | 898 base::DictionaryValue* DevToolsHttpHandler::SerializeDescriptor( |
| 900 const DevToolsTargetDescriptor& descriptor, | 899 const DevToolsTargetDescriptor& descriptor, |
| 901 const std::string& host) { | 900 const std::string& host) { |
| 902 base::DictionaryValue* dictionary = new base::DictionaryValue; | 901 base::DictionaryValue* dictionary = new base::DictionaryValue; |
| 903 scoped_refptr<content::DevToolsAgentHost> agent_host = | 902 |
| 904 descriptor.GetAgentHost(); | 903 std::string id = descriptor.GetId(); |
| 905 std::string id = agent_host->GetId(); | |
| 906 dictionary->SetString(kTargetIdField, id); | 904 dictionary->SetString(kTargetIdField, id); |
| 907 std::string parent_id = agent_host->GetParentId(); | 905 std::string parent_id = descriptor.GetParentId(); |
| 908 if (!parent_id.empty()) | 906 if (!parent_id.empty()) |
| 909 dictionary->SetString(kTargetParentIdField, parent_id); | 907 dictionary->SetString(kTargetParentIdField, parent_id); |
| 910 dictionary->SetString(kTargetTypeField, agent_host->GetType()); | 908 dictionary->SetString(kTargetTypeField, descriptor.GetType()); |
| 911 dictionary->SetString(kTargetTitleField, | 909 dictionary->SetString(kTargetTitleField, |
| 912 net::EscapeForHTML(agent_host->GetTitle())); | 910 net::EscapeForHTML(descriptor.GetTitle())); |
| 913 dictionary->SetString(kTargetDescriptionField, agent_host->GetDescription()); | 911 dictionary->SetString(kTargetDescriptionField, descriptor.GetDescription()); |
| 914 | 912 |
| 915 GURL url = agent_host->GetURL(); | 913 GURL url = descriptor.GetURL(); |
| 916 dictionary->SetString(kTargetUrlField, url.spec()); | 914 dictionary->SetString(kTargetUrlField, url.spec()); |
| 917 | 915 |
| 918 GURL favicon_url = agent_host->GetFaviconURL(); | 916 GURL favicon_url = descriptor.GetFaviconURL(); |
| 919 if (favicon_url.is_valid()) | 917 if (favicon_url.is_valid()) |
| 920 dictionary->SetString(kTargetFaviconUrlField, favicon_url.spec()); | 918 dictionary->SetString(kTargetFaviconUrlField, favicon_url.spec()); |
| 921 | 919 |
| 922 if (!delegate_->GetPageThumbnailData(url).empty()) { | 920 if (!delegate_->GetPageThumbnailData(url).empty()) { |
| 923 dictionary->SetString(kTargetThumbnailUrlField, | 921 dictionary->SetString(kTargetThumbnailUrlField, |
| 924 std::string(kThumbUrlPrefix) + id); | 922 std::string(kThumbUrlPrefix) + id); |
| 925 } | 923 } |
| 926 | 924 |
| 927 if (!agent_host->IsAttached()) { | 925 if (!descriptor.IsAttached()) { |
| 928 dictionary->SetString(kTargetWebSocketDebuggerUrlField, | 926 dictionary->SetString(kTargetWebSocketDebuggerUrlField, |
| 929 base::StringPrintf("ws://%s%s%s", | 927 base::StringPrintf("ws://%s%s%s", |
| 930 host.c_str(), | 928 host.c_str(), |
| 931 kPageUrlPrefix, | 929 kPageUrlPrefix, |
| 932 id.c_str())); | 930 id.c_str())); |
| 933 std::string devtools_frontend_url = GetFrontendURLInternal( | 931 std::string devtools_frontend_url = GetFrontendURLInternal( |
| 934 id.c_str(), | 932 id.c_str(), |
| 935 host); | 933 host); |
| 936 dictionary->SetString( | 934 dictionary->SetString( |
| 937 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); | 935 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); |
| 938 } | 936 } |
| 939 | 937 |
| 940 return dictionary; | 938 return dictionary; |
| 941 } | 939 } |
| 942 | 940 |
| 943 } // namespace devtools_http_handler | 941 } // namespace devtools_http_handler |
| OLD | NEW |