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