Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(609)

Side by Side Diff: content/browser/devtools/devtools_http_handler.cc

Issue 2833213002: DevTools: retain DTAH in all the targets to match their life time. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 version.SetString("V8-Version", V8_VERSION_STRING); 528 version.SetString("V8-Version", V8_VERSION_STRING);
529 #if defined(OS_ANDROID) 529 #if defined(OS_ANDROID)
530 version.SetString("Android-Package", 530 version.SetString("Android-Package",
531 base::android::BuildInfo::GetInstance()->package_name()); 531 base::android::BuildInfo::GetInstance()->package_name());
532 #endif 532 #endif
533 SendJson(connection_id, net::HTTP_OK, &version, std::string()); 533 SendJson(connection_id, net::HTTP_OK, &version, std::string());
534 return; 534 return;
535 } 535 }
536 536
537 if (command == "list") { 537 if (command == "list") {
538 DevToolsAgentHost::DiscoverAllHosts( 538 RespondToJsonList(connection_id, info.headers["host"],
539 base::Bind(&DevToolsHttpHandler::RespondToJsonList, 539 DevToolsAgentHost::DiscoverAllHosts());
540 weak_factory_.GetWeakPtr(), connection_id,
541 info.headers["host"]));
542 return; 540 return;
543 } 541 }
544 542
545 if (command == "new") { 543 if (command == "new") {
546 GURL url(net::UnescapeURLComponent( 544 GURL url(net::UnescapeURLComponent(
547 query, net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS | 545 query, net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS |
548 net::UnescapeRule::PATH_SEPARATORS)); 546 net::UnescapeRule::PATH_SEPARATORS));
549 if (!url.is_valid()) 547 if (!url.is_valid())
550 url = GURL(url::kAboutBlankURL); 548 url = GURL(url::kAboutBlankURL);
551 scoped_refptr<DevToolsAgentHost> agent_host = nullptr; 549 scoped_refptr<DevToolsAgentHost> agent_host = nullptr;
552 agent_host = delegate_->CreateNewTarget(url); 550 agent_host = delegate_->CreateNewTarget(url);
553 if (!agent_host) { 551 if (!agent_host) {
554 SendJson(connection_id, 552 SendJson(connection_id,
555 net::HTTP_INTERNAL_SERVER_ERROR, 553 net::HTTP_INTERNAL_SERVER_ERROR,
556 NULL, 554 NULL,
557 "Could not create new page"); 555 "Could not create new page");
558 return; 556 return;
559 } 557 }
560 std::string host = info.headers["host"]; 558 std::string host = info.headers["host"];
561 std::unique_ptr<base::DictionaryValue> dictionary( 559 std::unique_ptr<base::DictionaryValue> dictionary(
562 SerializeDescriptor(agent_host, host)); 560 SerializeDescriptor(agent_host, host));
563 SendJson(connection_id, net::HTTP_OK, dictionary.get(), std::string()); 561 SendJson(connection_id, net::HTTP_OK, dictionary.get(), std::string());
564 const std::string target_id = agent_host->GetId();
565 agent_host_map_[target_id] = agent_host;
566 return; 562 return;
567 } 563 }
568 564
569 if (command == "activate" || command == "close") { 565 if (command == "activate" || command == "close") {
570 scoped_refptr<DevToolsAgentHost> agent_host = GetAgentHost(target_id); 566 scoped_refptr<DevToolsAgentHost> agent_host =
567 DevToolsAgentHost::GetForId(target_id);
571 if (!agent_host) { 568 if (!agent_host) {
572 SendJson(connection_id, 569 SendJson(connection_id,
573 net::HTTP_NOT_FOUND, 570 net::HTTP_NOT_FOUND,
574 NULL, 571 NULL,
575 "No such target id: " + target_id); 572 "No such target id: " + target_id);
576 return; 573 return;
577 } 574 }
578 575
579 if (command == "activate") { 576 if (command == "activate") {
580 if (agent_host->Activate()) { 577 if (agent_host->Activate()) {
(...skipping 25 matching lines...) Expand all
606 "Unknown command: " + command); 603 "Unknown command: " + command);
607 return; 604 return;
608 } 605 }
609 606
610 void DevToolsHttpHandler::RespondToJsonList( 607 void DevToolsHttpHandler::RespondToJsonList(
611 int connection_id, 608 int connection_id,
612 const std::string& host, 609 const std::string& host,
613 DevToolsAgentHost::List hosts) { 610 DevToolsAgentHost::List hosts) {
614 DevToolsAgentHost::List agent_hosts = std::move(hosts); 611 DevToolsAgentHost::List agent_hosts = std::move(hosts);
615 std::sort(agent_hosts.begin(), agent_hosts.end(), TimeComparator); 612 std::sort(agent_hosts.begin(), agent_hosts.end(), TimeComparator);
616 agent_host_map_.clear();
617 base::ListValue list_value; 613 base::ListValue list_value;
618 for (auto& agent_host : agent_hosts) { 614 for (auto& agent_host : agent_hosts)
619 agent_host_map_[agent_host->GetId()] = agent_host;
620 list_value.Append(SerializeDescriptor(agent_host, host)); 615 list_value.Append(SerializeDescriptor(agent_host, host));
621 }
622 SendJson(connection_id, net::HTTP_OK, &list_value, std::string()); 616 SendJson(connection_id, net::HTTP_OK, &list_value, std::string());
623 } 617 }
624 618
625 scoped_refptr<DevToolsAgentHost> DevToolsHttpHandler::GetAgentHost(
626 const std::string& target_id) {
627 DescriptorMap::const_iterator it = agent_host_map_.find(target_id);
628 return it != agent_host_map_.end() ? it->second : nullptr;
629 }
630
631 void DevToolsHttpHandler::OnDiscoveryPageRequest(int connection_id) { 619 void DevToolsHttpHandler::OnDiscoveryPageRequest(int connection_id) {
632 std::string response = delegate_->GetDiscoveryPageHTML(); 620 std::string response = delegate_->GetDiscoveryPageHTML();
633 Send200(connection_id, response, "text/html; charset=UTF-8"); 621 Send200(connection_id, response, "text/html; charset=UTF-8");
634 } 622 }
635 623
636 void DevToolsHttpHandler::OnFrontendResourceRequest( 624 void DevToolsHttpHandler::OnFrontendResourceRequest(
637 int connection_id, const std::string& path) { 625 int connection_id, const std::string& path) {
638 Send200(connection_id, 626 Send200(connection_id,
639 delegate_->GetFrontendResource(path), 627 delegate_->GetFrontendResource(path),
640 GetMimeType(path)); 628 GetMimeType(path));
(...skipping 20 matching lines...) Expand all
661 return; 649 return;
662 } 650 }
663 651
664 if (!base::StartsWith(request.path, kPageUrlPrefix, 652 if (!base::StartsWith(request.path, kPageUrlPrefix,
665 base::CompareCase::SENSITIVE)) { 653 base::CompareCase::SENSITIVE)) {
666 Send404(connection_id); 654 Send404(connection_id);
667 return; 655 return;
668 } 656 }
669 657
670 std::string target_id = request.path.substr(strlen(kPageUrlPrefix)); 658 std::string target_id = request.path.substr(strlen(kPageUrlPrefix));
671 scoped_refptr<DevToolsAgentHost> agent = GetAgentHost(target_id); 659 scoped_refptr<DevToolsAgentHost> agent =
660 DevToolsAgentHost::GetForId(target_id);
672 if (!agent) { 661 if (!agent) {
673 Send500(connection_id, "No such target id: " + target_id); 662 Send500(connection_id, "No such target id: " + target_id);
674 return; 663 return;
675 } 664 }
676 665
677 if (agent->IsAttached()) { 666 if (agent->IsAttached()) {
678 Send500(connection_id, 667 Send500(connection_id,
679 "Target with given id is being inspected: " + target_id); 668 "Target with given id is being inspected: " + target_id);
680 return; 669 return;
681 } 670 }
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 id.c_str())); 843 id.c_str()));
855 std::string devtools_frontend_url = GetFrontendURLInternal(id, host); 844 std::string devtools_frontend_url = GetFrontendURLInternal(id, host);
856 dictionary->SetString( 845 dictionary->SetString(
857 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); 846 kTargetDevtoolsFrontendUrlField, devtools_frontend_url);
858 } 847 }
859 848
860 return dictionary; 849 return dictionary;
861 } 850 }
862 851
863 } // namespace content 852 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698