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

Side by Side Diff: chrome/browser/devtools/devtools_window.cc

Issue 2752423002: DevTools: [regression] remote debugging to a tcp port does not work via chrome:inspect (Closed)
Patch Set: review comment addressed. Created 3 years, 9 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
« no previous file with comments | « chrome/browser/devtools/devtools_window.h ('k') | chrome/browser/ui/webui/devtools_ui.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/devtools/devtools_window.h" 5 #include "chrome/browser/devtools/devtools_window.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 return; 460 return;
461 window->bindings_->AttachTo(worker_agent); 461 window->bindings_->AttachTo(worker_agent);
462 } 462 }
463 window->ScheduleShow(DevToolsToggleAction::Show()); 463 window->ScheduleShow(DevToolsToggleAction::Show());
464 } 464 }
465 465
466 // static 466 // static
467 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( 467 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker(
468 Profile* profile) { 468 Profile* profile) {
469 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); 469 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker"));
470 return Create(profile, NULL, true, false, false, std::string(), false, "", 470 return Create(profile, nullptr, kFrontendWorker, std::string(), false, "",
471 ""); 471 "");
472 } 472 }
473 473
474 // static 474 // static
475 void DevToolsWindow::OpenDevToolsWindow( 475 void DevToolsWindow::OpenDevToolsWindow(
476 content::WebContents* inspected_web_contents) { 476 content::WebContents* inspected_web_contents) {
477 ToggleDevToolsWindow( 477 ToggleDevToolsWindow(
478 inspected_web_contents, true, DevToolsToggleAction::Show(), ""); 478 inspected_web_contents, true, DevToolsToggleAction::Show(), "");
479 } 479 }
480 480
481 // static 481 // static
482 void DevToolsWindow::OpenDevToolsWindow( 482 void DevToolsWindow::OpenDevToolsWindow(
483 scoped_refptr<content::DevToolsAgentHost> agent_host, 483 scoped_refptr<content::DevToolsAgentHost> agent_host,
484 Profile* profile) { 484 Profile* profile) {
485 if (!profile) 485 if (!profile)
486 profile = Profile::FromBrowserContext(agent_host->GetBrowserContext()); 486 profile = Profile::FromBrowserContext(agent_host->GetBrowserContext());
487 487
488 if (!profile) 488 if (!profile)
489 return; 489 return;
490 490
491 std::string type = agent_host->GetType(); 491 std::string type = agent_host->GetType();
492
492 bool is_worker = type == DevToolsAgentHost::kTypeServiceWorker || 493 bool is_worker = type == DevToolsAgentHost::kTypeServiceWorker ||
493 type == DevToolsAgentHost::kTypeSharedWorker; 494 type == DevToolsAgentHost::kTypeSharedWorker;
494 495
495 if (!agent_host->GetFrontendURL().empty()) { 496 if (!agent_host->GetFrontendURL().empty()) {
496 bool is_v8_only = type == "node"; 497 FrontendType frontend_type = kFrontendRemote;
498 if (is_worker) {
499 frontend_type = kFrontendWorker;
500 } else if (type == "node") {
501 frontend_type = kFrontendV8;
502 }
497 DevToolsWindow::OpenExternalFrontend(profile, agent_host->GetFrontendURL(), 503 DevToolsWindow::OpenExternalFrontend(profile, agent_host->GetFrontendURL(),
498 agent_host, is_worker, is_v8_only); 504 agent_host, frontend_type);
499 return; 505 return;
500 } 506 }
501 507
502 if (is_worker) { 508 if (is_worker) {
503 DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); 509 DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host);
504 return; 510 return;
505 } 511 }
506 512
507 if (type == content::DevToolsAgentHost::kTypeFrame) { 513 if (type == content::DevToolsAgentHost::kTypeFrame) {
508 DevToolsWindow::OpenDevToolsWindowForFrame(profile, agent_host); 514 DevToolsWindow::OpenDevToolsWindowForFrame(profile, agent_host);
(...skipping 11 matching lines...) Expand all
520 const DevToolsToggleAction& action) { 526 const DevToolsToggleAction& action) {
521 ToggleDevToolsWindow(inspected_web_contents, true, action, ""); 527 ToggleDevToolsWindow(inspected_web_contents, true, action, "");
522 } 528 }
523 529
524 // static 530 // static
525 void DevToolsWindow::OpenDevToolsWindowForFrame( 531 void DevToolsWindow::OpenDevToolsWindowForFrame(
526 Profile* profile, 532 Profile* profile,
527 const scoped_refptr<content::DevToolsAgentHost>& agent_host) { 533 const scoped_refptr<content::DevToolsAgentHost>& agent_host) {
528 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); 534 DevToolsWindow* window = FindDevToolsWindow(agent_host.get());
529 if (!window) { 535 if (!window) {
530 window = DevToolsWindow::Create(profile, nullptr, false, false, false, 536 window = DevToolsWindow::Create(profile, nullptr, kFrontendDefault,
531 std::string(), false, std::string(), 537 std::string(), false, std::string(),
532 std::string()); 538 std::string());
533 if (!window) 539 if (!window)
534 return; 540 return;
535 window->bindings_->AttachTo(agent_host); 541 window->bindings_->AttachTo(agent_host);
536 } 542 }
537 window->ScheduleShow(DevToolsToggleAction::Show()); 543 window->ScheduleShow(DevToolsToggleAction::Show());
538 } 544 }
539 545
540 // static 546 // static
(...skipping 10 matching lines...) Expand all
551 browser->tab_strip_model()->GetActiveWebContents(), 557 browser->tab_strip_model()->GetActiveWebContents(),
552 action.type() == DevToolsToggleAction::kInspect, 558 action.type() == DevToolsToggleAction::kInspect,
553 action, ""); 559 action, "");
554 } 560 }
555 561
556 // static 562 // static
557 void DevToolsWindow::OpenExternalFrontend( 563 void DevToolsWindow::OpenExternalFrontend(
558 Profile* profile, 564 Profile* profile,
559 const std::string& frontend_url, 565 const std::string& frontend_url,
560 const scoped_refptr<content::DevToolsAgentHost>& agent_host, 566 const scoped_refptr<content::DevToolsAgentHost>& agent_host,
561 bool is_worker, 567 FrontendType frontend_type) {
562 bool is_v8_only) {
563 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); 568 DevToolsWindow* window = FindDevToolsWindow(agent_host.get());
564 if (!window) { 569 if (!window) {
565 window = Create(profile, nullptr, is_worker, is_v8_only, false, 570 window = Create(profile, nullptr, frontend_type,
566 DevToolsUI::GetProxyURL(frontend_url).spec(), false, 571 DevToolsUI::GetProxyURL(frontend_url).spec(), false,
567 std::string(), std::string()); 572 std::string(), std::string());
568 if (!window) 573 if (!window)
569 return; 574 return;
570 window->bindings_->AttachTo(agent_host); 575 window->bindings_->AttachTo(agent_host);
571 window->close_on_detach_ = false; 576 window->close_on_detach_ = false;
572 } 577 }
573 578
574 window->ScheduleShow(DevToolsToggleAction::Show()); 579 window->ScheduleShow(DevToolsToggleAction::Show());
575 } 580 }
576 581
577 // static 582 // static
578 void DevToolsWindow::OpenNodeFrontendWindow(Profile* profile) { 583 void DevToolsWindow::OpenNodeFrontendWindow(Profile* profile) {
579 DevToolsWindow* window = 584 DevToolsWindow* window =
580 Create(profile, nullptr, false, true, true, std::string(), false, 585 Create(profile, nullptr, kFrontendNode, std::string(), false,
581 std::string(), std::string()); 586 std::string(), std::string());
582 if (!window) 587 if (!window)
583 return; 588 return;
584 window->bindings_->AttachTo(DevToolsAgentHost::CreateForDiscovery()); 589 window->bindings_->AttachTo(DevToolsAgentHost::CreateForDiscovery());
585 window->ScheduleShow(DevToolsToggleAction::Show()); 590 window->ScheduleShow(DevToolsToggleAction::Show());
586 } 591 }
587 592
588 // static 593 // static
589 void DevToolsWindow::ToggleDevToolsWindow( 594 void DevToolsWindow::ToggleDevToolsWindow(
590 content::WebContents* inspected_web_contents, 595 content::WebContents* inspected_web_contents,
(...skipping 17 matching lines...) Expand all
608 break; 613 break;
609 case DevToolsToggleAction::kShowConsolePanel: 614 case DevToolsToggleAction::kShowConsolePanel:
610 panel = "console"; 615 panel = "console";
611 break; 616 break;
612 case DevToolsToggleAction::kShow: 617 case DevToolsToggleAction::kShow:
613 case DevToolsToggleAction::kToggle: 618 case DevToolsToggleAction::kToggle:
614 case DevToolsToggleAction::kReveal: 619 case DevToolsToggleAction::kReveal:
615 case DevToolsToggleAction::kNoOp: 620 case DevToolsToggleAction::kNoOp:
616 break; 621 break;
617 } 622 }
618 window = Create(profile, inspected_web_contents, false, false, false, 623 window = Create(profile, inspected_web_contents, kFrontendDefault,
619 std::string(), true, settings, panel); 624 std::string(), true, settings, panel);
620 if (!window) 625 if (!window)
621 return; 626 return;
622 window->bindings_->AttachTo(agent.get()); 627 window->bindings_->AttachTo(agent.get());
623 do_open = true; 628 do_open = true;
624 } 629 }
625 630
626 // Update toolbar to reflect DevTools changes. 631 // Update toolbar to reflect DevTools changes.
627 window->UpdateBrowserToolbar(); 632 window->UpdateBrowserToolbar();
628 633
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 std::vector<base::Callback<void(DevToolsWindow*)>> copy( 866 std::vector<base::Callback<void(DevToolsWindow*)>> copy(
862 g_creation_callbacks.Get()); 867 g_creation_callbacks.Get());
863 for (const auto& callback : copy) 868 for (const auto& callback : copy)
864 callback.Run(this); 869 callback.Run(this);
865 } 870 }
866 871
867 // static 872 // static
868 DevToolsWindow* DevToolsWindow::Create( 873 DevToolsWindow* DevToolsWindow::Create(
869 Profile* profile, 874 Profile* profile,
870 content::WebContents* inspected_web_contents, 875 content::WebContents* inspected_web_contents,
871 bool shared_worker_frontend, 876 FrontendType frontend_type,
872 bool v8_only_frontend, 877 const std::string& frontend_url,
873 bool node_frontend,
874 const std::string& remote_frontend,
875 bool can_dock, 878 bool can_dock,
876 const std::string& settings, 879 const std::string& settings,
877 const std::string& panel) { 880 const std::string& panel) {
878 if (profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled) || 881 if (profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled) ||
879 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) 882 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
880 return nullptr; 883 return nullptr;
881 884
882 if (inspected_web_contents) { 885 if (inspected_web_contents) {
883 // Check for a place to dock. 886 // Check for a place to dock.
884 Browser* browser = NULL; 887 Browser* browser = nullptr;
885 int tab; 888 int tab;
886 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents, 889 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents,
887 &browser, &tab) || 890 &browser, &tab) ||
888 browser->is_type_popup()) { 891 browser->is_type_popup()) {
889 can_dock = false; 892 can_dock = false;
890 } 893 }
891 } 894 }
892 895
893 // Create WebContents with devtools. 896 // Create WebContents with devtools.
894 GURL url(GetDevToolsURL(profile, shared_worker_frontend, v8_only_frontend, 897 GURL url(
895 node_frontend, remote_frontend, can_dock, panel)); 898 GetDevToolsURL(profile, frontend_type, frontend_url, can_dock, panel));
896 std::unique_ptr<WebContents> main_web_contents( 899 std::unique_ptr<WebContents> main_web_contents(
897 WebContents::Create(WebContents::CreateParams(profile))); 900 WebContents::Create(WebContents::CreateParams(profile)));
898 main_web_contents->GetController().LoadURL( 901 main_web_contents->GetController().LoadURL(
899 DecorateFrontendURL(url), content::Referrer(), 902 DecorateFrontendURL(url), content::Referrer(),
900 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); 903 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string());
901 DevToolsUIBindings* bindings = 904 DevToolsUIBindings* bindings =
902 DevToolsUIBindings::ForWebContents(main_web_contents.get()); 905 DevToolsUIBindings::ForWebContents(main_web_contents.get());
903 if (!bindings) 906 if (!bindings)
904 return nullptr; 907 return nullptr;
905 if (!settings.empty()) 908 if (!settings.empty())
906 SetPreferencesFromJson(profile, settings); 909 SetPreferencesFromJson(profile, settings);
907 return new DevToolsWindow(profile, main_web_contents.release(), bindings, 910 return new DevToolsWindow(profile, main_web_contents.release(), bindings,
908 inspected_web_contents, can_dock); 911 inspected_web_contents, can_dock);
909 } 912 }
910 913
911 // static 914 // static
912 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, 915 GURL DevToolsWindow::GetDevToolsURL(Profile* profile,
913 bool shared_worker_frontend, 916 FrontendType frontend_type,
914 bool v8_only_frontend, 917 const std::string& frontend_url,
915 bool node_frontend,
916 const std::string& remote_frontend,
917 bool can_dock, 918 bool can_dock,
918 const std::string& panel) { 919 const std::string& panel) {
919 std::string frontend_url(!remote_frontend.empty() 920 std::string url(!frontend_url.empty() ? frontend_url
920 ? remote_frontend 921 : chrome::kChromeUIDevToolsURL);
921 : chrome::kChromeUIDevToolsURL); 922 std::string url_string(url +
922 std::string url_string( 923 ((url.find("?") == std::string::npos) ? "?" : "&"));
923 frontend_url + 924 switch (frontend_type) {
924 ((frontend_url.find("?") == std::string::npos) ? "?" : "&")); 925 case kFrontendRemote:
925 if (shared_worker_frontend) 926 url_string += "&remoteFrontend=true";
926 url_string += "&isSharedWorker=true"; 927 break;
927 if (v8_only_frontend) 928 case kFrontendWorker:
928 url_string += "&v8only=true"; 929 url_string += "&isSharedWorker=true";
929 if (node_frontend) 930 break;
930 url_string += "&nodeFrontend=true"; 931 case kFrontendNode:
931 if (remote_frontend.size()) { 932 url_string += "&nodeFrontend=true";
932 url_string += "&remoteFrontend=true"; 933 // Fall through
933 } else { 934 case kFrontendV8:
935 url_string += "&v8only=true";
936 break;
937 case kFrontendDefault:
938 default:
939 break;
940 }
941
942 if (frontend_url.empty())
934 url_string += "&remoteBase=" + DevToolsUI::GetRemoteBaseURL().spec(); 943 url_string += "&remoteBase=" + DevToolsUI::GetRemoteBaseURL().spec();
935 }
936 if (can_dock) 944 if (can_dock)
937 url_string += "&can_dock=true"; 945 url_string += "&can_dock=true";
938 if (panel.size()) 946 if (panel.size())
939 url_string += "&panel=" + panel; 947 url_string += "&panel=" + panel;
940 return DevToolsUIBindings::SanitizeFrontendURL(GURL(url_string)); 948 return DevToolsUIBindings::SanitizeFrontendURL(GURL(url_string));
941 } 949 }
942 950
943 // static 951 // static
944 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( 952 DevToolsWindow* DevToolsWindow::FindDevToolsWindow(
945 DevToolsAgentHost* agent_host) { 953 DevToolsAgentHost* agent_host) {
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 bool DevToolsWindow::ReloadInspectedWebContents(bool bypass_cache) { 1409 bool DevToolsWindow::ReloadInspectedWebContents(bool bypass_cache) {
1402 // Only route reload via front-end if the agent is attached. 1410 // Only route reload via front-end if the agent is attached.
1403 WebContents* wc = GetInspectedWebContents(); 1411 WebContents* wc = GetInspectedWebContents();
1404 if (!wc || wc->GetCrashedStatus() != base::TERMINATION_STATUS_STILL_RUNNING) 1412 if (!wc || wc->GetCrashedStatus() != base::TERMINATION_STATUS_STILL_RUNNING)
1405 return false; 1413 return false;
1406 base::Value bypass_cache_value(bypass_cache); 1414 base::Value bypass_cache_value(bypass_cache);
1407 bindings_->CallClientFunction("DevToolsAPI.reloadInspectedPage", 1415 bindings_->CallClientFunction("DevToolsAPI.reloadInspectedPage",
1408 &bypass_cache_value, nullptr, nullptr); 1416 &bypass_cache_value, nullptr, nullptr);
1409 return true; 1417 return true;
1410 } 1418 }
OLDNEW
« no previous file with comments | « chrome/browser/devtools/devtools_window.h ('k') | chrome/browser/ui/webui/devtools_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698