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

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: cast test Created 3 years, 7 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 DevToolsManager* manager = DevToolsManager::GetInstance();
539 base::Bind(&DevToolsHttpHandler::RespondToJsonList, 539 DevToolsAgentHost::List list =
540 weak_factory_.GetWeakPtr(), connection_id, 540 manager->delegate() ? manager->delegate()->RemoteDebuggingTargets()
541 info.headers["host"])); 541 : DevToolsAgentHost::GetOrCreateAll();
542 RespondToJsonList(connection_id, info.headers["host"], std::move(list));
542 return; 543 return;
543 } 544 }
544 545
545 if (command == "new") { 546 if (command == "new") {
546 GURL url(net::UnescapeURLComponent( 547 GURL url(net::UnescapeURLComponent(
547 query, net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS | 548 query, net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS |
548 net::UnescapeRule::PATH_SEPARATORS)); 549 net::UnescapeRule::PATH_SEPARATORS));
549 if (!url.is_valid()) 550 if (!url.is_valid())
550 url = GURL(url::kAboutBlankURL); 551 url = GURL(url::kAboutBlankURL);
551 scoped_refptr<DevToolsAgentHost> agent_host = nullptr; 552 scoped_refptr<DevToolsAgentHost> agent_host = nullptr;
552 agent_host = delegate_->CreateNewTarget(url); 553 agent_host = delegate_->CreateNewTarget(url);
553 if (!agent_host) { 554 if (!agent_host) {
554 SendJson(connection_id, 555 SendJson(connection_id,
555 net::HTTP_INTERNAL_SERVER_ERROR, 556 net::HTTP_INTERNAL_SERVER_ERROR,
556 NULL, 557 NULL,
557 "Could not create new page"); 558 "Could not create new page");
558 return; 559 return;
559 } 560 }
560 std::string host = info.headers["host"]; 561 std::string host = info.headers["host"];
561 std::unique_ptr<base::DictionaryValue> dictionary( 562 std::unique_ptr<base::DictionaryValue> dictionary(
562 SerializeDescriptor(agent_host, host)); 563 SerializeDescriptor(agent_host, host));
563 SendJson(connection_id, net::HTTP_OK, dictionary.get(), std::string()); 564 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; 565 return;
567 } 566 }
568 567
569 if (command == "activate" || command == "close") { 568 if (command == "activate" || command == "close") {
570 scoped_refptr<DevToolsAgentHost> agent_host = GetAgentHost(target_id); 569 scoped_refptr<DevToolsAgentHost> agent_host =
570 DevToolsAgentHost::GetForId(target_id);
571 if (!agent_host) { 571 if (!agent_host) {
572 SendJson(connection_id, 572 SendJson(connection_id,
573 net::HTTP_NOT_FOUND, 573 net::HTTP_NOT_FOUND,
574 NULL, 574 NULL,
575 "No such target id: " + target_id); 575 "No such target id: " + target_id);
576 return; 576 return;
577 } 577 }
578 578
579 if (command == "activate") { 579 if (command == "activate") {
580 if (agent_host->Activate()) { 580 if (agent_host->Activate()) {
(...skipping 25 matching lines...) Expand all
606 "Unknown command: " + command); 606 "Unknown command: " + command);
607 return; 607 return;
608 } 608 }
609 609
610 void DevToolsHttpHandler::RespondToJsonList( 610 void DevToolsHttpHandler::RespondToJsonList(
611 int connection_id, 611 int connection_id,
612 const std::string& host, 612 const std::string& host,
613 DevToolsAgentHost::List hosts) { 613 DevToolsAgentHost::List hosts) {
614 DevToolsAgentHost::List agent_hosts = std::move(hosts); 614 DevToolsAgentHost::List agent_hosts = std::move(hosts);
615 std::sort(agent_hosts.begin(), agent_hosts.end(), TimeComparator); 615 std::sort(agent_hosts.begin(), agent_hosts.end(), TimeComparator);
616 agent_host_map_.clear();
617 base::ListValue list_value; 616 base::ListValue list_value;
618 for (auto& agent_host : agent_hosts) { 617 for (auto& agent_host : agent_hosts)
619 agent_host_map_[agent_host->GetId()] = agent_host;
620 list_value.Append(SerializeDescriptor(agent_host, host)); 618 list_value.Append(SerializeDescriptor(agent_host, host));
621 }
622 SendJson(connection_id, net::HTTP_OK, &list_value, std::string()); 619 SendJson(connection_id, net::HTTP_OK, &list_value, std::string());
623 } 620 }
624 621
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) { 622 void DevToolsHttpHandler::OnDiscoveryPageRequest(int connection_id) {
632 std::string response = delegate_->GetDiscoveryPageHTML(); 623 std::string response = delegate_->GetDiscoveryPageHTML();
633 Send200(connection_id, response, "text/html; charset=UTF-8"); 624 Send200(connection_id, response, "text/html; charset=UTF-8");
634 } 625 }
635 626
636 void DevToolsHttpHandler::OnFrontendResourceRequest( 627 void DevToolsHttpHandler::OnFrontendResourceRequest(
637 int connection_id, const std::string& path) { 628 int connection_id, const std::string& path) {
638 Send200(connection_id, 629 Send200(connection_id,
639 delegate_->GetFrontendResource(path), 630 delegate_->GetFrontendResource(path),
640 GetMimeType(path)); 631 GetMimeType(path));
(...skipping 20 matching lines...) Expand all
661 return; 652 return;
662 } 653 }
663 654
664 if (!base::StartsWith(request.path, kPageUrlPrefix, 655 if (!base::StartsWith(request.path, kPageUrlPrefix,
665 base::CompareCase::SENSITIVE)) { 656 base::CompareCase::SENSITIVE)) {
666 Send404(connection_id); 657 Send404(connection_id);
667 return; 658 return;
668 } 659 }
669 660
670 std::string target_id = request.path.substr(strlen(kPageUrlPrefix)); 661 std::string target_id = request.path.substr(strlen(kPageUrlPrefix));
671 scoped_refptr<DevToolsAgentHost> agent = GetAgentHost(target_id); 662 scoped_refptr<DevToolsAgentHost> agent =
663 DevToolsAgentHost::GetForId(target_id);
672 if (!agent) { 664 if (!agent) {
673 Send500(connection_id, "No such target id: " + target_id); 665 Send500(connection_id, "No such target id: " + target_id);
674 return; 666 return;
675 } 667 }
676 668
677 if (agent->IsAttached()) { 669 if (agent->IsAttached()) {
678 Send500(connection_id, 670 Send500(connection_id,
679 "Target with given id is being inspected: " + target_id); 671 "Target with given id is being inspected: " + target_id);
680 return; 672 return;
681 } 673 }
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 id.c_str())); 846 id.c_str()));
855 std::string devtools_frontend_url = GetFrontendURLInternal(id, host); 847 std::string devtools_frontend_url = GetFrontendURLInternal(id, host);
856 dictionary->SetString( 848 dictionary->SetString(
857 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); 849 kTargetDevtoolsFrontendUrlField, devtools_frontend_url);
858 } 850 }
859 851
860 return dictionary; 852 return dictionary;
861 } 853 }
862 854
863 } // namespace content 855 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/devtools_http_handler.h ('k') | content/public/browser/devtools_agent_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698