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

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

Issue 2625223002: [DevTools] Dedicated frontend for debugging Node. (Closed)
Patch Set: test fix Created 3 years, 11 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/resources/inspect/inspect.css » ('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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 int modifiers) { 312 int modifiers) {
313 return key_code | (modifiers << 16); 313 return key_code | (modifiers << 16);
314 } 314 }
315 315
316 bool DevToolsEventForwarder::KeyWhitelistingAllowed(int key_code, 316 bool DevToolsEventForwarder::KeyWhitelistingAllowed(int key_code,
317 int modifiers) { 317 int modifiers) {
318 return (ui::VKEY_F1 <= key_code && key_code <= ui::VKEY_F12) || 318 return (ui::VKEY_F1 <= key_code && key_code <= ui::VKEY_F12) ||
319 modifiers != 0; 319 modifiers != 0;
320 } 320 }
321 321
322 void DevToolsWindow::OpenNodeFrontend() {
323 DevToolsWindow::OpenNodeFrontendWindow(profile_);
324 }
325
322 // DevToolsWindow::ObserverWithAccessor ------------------------------- 326 // DevToolsWindow::ObserverWithAccessor -------------------------------
323 327
324 DevToolsWindow::ObserverWithAccessor::ObserverWithAccessor( 328 DevToolsWindow::ObserverWithAccessor::ObserverWithAccessor(
325 WebContents* web_contents) 329 WebContents* web_contents)
326 : WebContentsObserver(web_contents) { 330 : WebContentsObserver(web_contents) {
327 } 331 }
328 332
329 DevToolsWindow::ObserverWithAccessor::~ObserverWithAccessor() { 333 DevToolsWindow::ObserverWithAccessor::~ObserverWithAccessor() {
330 } 334 }
331 335
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 return; 460 return;
457 window->bindings_->AttachTo(worker_agent); 461 window->bindings_->AttachTo(worker_agent);
458 } 462 }
459 window->ScheduleShow(DevToolsToggleAction::Show()); 463 window->ScheduleShow(DevToolsToggleAction::Show());
460 } 464 }
461 465
462 // static 466 // static
463 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( 467 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker(
464 Profile* profile) { 468 Profile* profile) {
465 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); 469 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker"));
466 return Create(profile, GURL(), NULL, true, false, std::string(), false, "", 470 return Create(profile, GURL(), NULL, true, false, false, std::string(),
467 ""); 471 false, "", "");
468 } 472 }
469 473
470 // static 474 // static
471 void DevToolsWindow::OpenDevToolsWindow( 475 void DevToolsWindow::OpenDevToolsWindow(
472 content::WebContents* inspected_web_contents) { 476 content::WebContents* inspected_web_contents) {
473 ToggleDevToolsWindow( 477 ToggleDevToolsWindow(
474 inspected_web_contents, true, DevToolsToggleAction::Show(), ""); 478 inspected_web_contents, true, DevToolsToggleAction::Show(), "");
475 } 479 }
476 480
477 // static 481 // static
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 ToggleDevToolsWindow(inspected_web_contents, true, action, ""); 521 ToggleDevToolsWindow(inspected_web_contents, true, action, "");
518 } 522 }
519 523
520 // static 524 // static
521 void DevToolsWindow::OpenDevToolsWindowForFrame( 525 void DevToolsWindow::OpenDevToolsWindowForFrame(
522 Profile* profile, 526 Profile* profile,
523 const scoped_refptr<content::DevToolsAgentHost>& agent_host) { 527 const scoped_refptr<content::DevToolsAgentHost>& agent_host) {
524 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); 528 DevToolsWindow* window = FindDevToolsWindow(agent_host.get());
525 if (!window) { 529 if (!window) {
526 window = DevToolsWindow::Create(profile, GURL(), nullptr, false, false, 530 window = DevToolsWindow::Create(profile, GURL(), nullptr, false, false,
527 std::string(), false, std::string(), 531 false, std::string(), false, std::string(),
528 std::string()); 532 std::string());
529 if (!window) 533 if (!window)
530 return; 534 return;
531 window->bindings_->AttachTo(agent_host); 535 window->bindings_->AttachTo(agent_host);
532 } 536 }
533 window->ScheduleShow(DevToolsToggleAction::Show()); 537 window->ScheduleShow(DevToolsToggleAction::Show());
534 } 538 }
535 539
536 // static 540 // static
537 void DevToolsWindow::ToggleDevToolsWindow( 541 void DevToolsWindow::ToggleDevToolsWindow(
(...skipping 13 matching lines...) Expand all
551 555
552 // static 556 // static
553 void DevToolsWindow::OpenExternalFrontend( 557 void DevToolsWindow::OpenExternalFrontend(
554 Profile* profile, 558 Profile* profile,
555 const std::string& frontend_url, 559 const std::string& frontend_url,
556 const scoped_refptr<content::DevToolsAgentHost>& agent_host, 560 const scoped_refptr<content::DevToolsAgentHost>& agent_host,
557 bool is_worker, 561 bool is_worker,
558 bool is_v8_only) { 562 bool is_v8_only) {
559 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); 563 DevToolsWindow* window = FindDevToolsWindow(agent_host.get());
560 if (!window) { 564 if (!window) {
561 window = Create(profile, GURL(), nullptr, is_worker, is_v8_only, 565 window = Create(profile, GURL(), nullptr, is_worker, is_v8_only, false,
562 DevToolsUI::GetProxyURL(frontend_url).spec(), false, 566 DevToolsUI::GetProxyURL(frontend_url).spec(), false,
563 std::string(), std::string()); 567 std::string(), std::string());
564 if (!window) 568 if (!window)
565 return; 569 return;
566 window->bindings_->AttachTo(agent_host); 570 window->bindings_->AttachTo(agent_host);
567 window->close_on_detach_ = false; 571 window->close_on_detach_ = false;
568 } 572 }
569 573
570 window->ScheduleShow(DevToolsToggleAction::Show()); 574 window->ScheduleShow(DevToolsToggleAction::Show());
571 } 575 }
572 576
573 // static 577 // static
578 void DevToolsWindow::OpenNodeFrontendWindow(Profile* profile) {
579 DevToolsWindow* window = Create(profile, GURL(), nullptr, false, true, true,
580 std::string(), false, std::string(),
581 std::string());
582 if (!window)
583 return;
584 window->bindings_->AttachTo(DevToolsAgentHost::CreateForDiscovery());
585 window->ScheduleShow(DevToolsToggleAction::Show());
586 }
587
588 // static
574 void DevToolsWindow::ToggleDevToolsWindow( 589 void DevToolsWindow::ToggleDevToolsWindow(
575 content::WebContents* inspected_web_contents, 590 content::WebContents* inspected_web_contents,
576 bool force_open, 591 bool force_open,
577 const DevToolsToggleAction& action, 592 const DevToolsToggleAction& action,
578 const std::string& settings) { 593 const std::string& settings) {
579 scoped_refptr<DevToolsAgentHost> agent( 594 scoped_refptr<DevToolsAgentHost> agent(
580 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); 595 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents));
581 DevToolsWindow* window = FindDevToolsWindow(agent.get()); 596 DevToolsWindow* window = FindDevToolsWindow(agent.get());
582 bool do_open = force_open; 597 bool do_open = force_open;
583 if (!window) { 598 if (!window) {
(...skipping 10 matching lines...) Expand all
594 case DevToolsToggleAction::kShowConsolePanel: 609 case DevToolsToggleAction::kShowConsolePanel:
595 panel = "console"; 610 panel = "console";
596 break; 611 break;
597 case DevToolsToggleAction::kShow: 612 case DevToolsToggleAction::kShow:
598 case DevToolsToggleAction::kToggle: 613 case DevToolsToggleAction::kToggle:
599 case DevToolsToggleAction::kReveal: 614 case DevToolsToggleAction::kReveal:
600 case DevToolsToggleAction::kNoOp: 615 case DevToolsToggleAction::kNoOp:
601 break; 616 break;
602 } 617 }
603 window = Create(profile, GURL(), inspected_web_contents, false, false, 618 window = Create(profile, GURL(), inspected_web_contents, false, false,
604 std::string(), true, settings, panel); 619 false, std::string(), true, settings, panel);
605 if (!window) 620 if (!window)
606 return; 621 return;
607 window->bindings_->AttachTo(agent.get()); 622 window->bindings_->AttachTo(agent.get());
608 do_open = true; 623 do_open = true;
609 } 624 }
610 625
611 // Update toolbar to reflect DevTools changes. 626 // Update toolbar to reflect DevTools changes.
612 window->UpdateBrowserToolbar(); 627 window->UpdateBrowserToolbar();
613 628
614 // If window is docked and visible, we hide it on toggle. If window is 629 // If window is docked and visible, we hide it on toggle. If window is
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 callback.Run(this); 863 callback.Run(this);
849 } 864 }
850 865
851 // static 866 // static
852 DevToolsWindow* DevToolsWindow::Create( 867 DevToolsWindow* DevToolsWindow::Create(
853 Profile* profile, 868 Profile* profile,
854 const GURL& frontend_url, 869 const GURL& frontend_url,
855 content::WebContents* inspected_web_contents, 870 content::WebContents* inspected_web_contents,
856 bool shared_worker_frontend, 871 bool shared_worker_frontend,
857 bool v8_only_frontend, 872 bool v8_only_frontend,
873 bool node_frontend,
858 const std::string& remote_frontend, 874 const std::string& remote_frontend,
859 bool can_dock, 875 bool can_dock,
860 const std::string& settings, 876 const std::string& settings,
861 const std::string& panel) { 877 const std::string& panel) {
862 if (profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled) || 878 if (profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled) ||
863 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) 879 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
864 return nullptr; 880 return nullptr;
865 881
866 if (inspected_web_contents) { 882 if (inspected_web_contents) {
867 // Check for a place to dock. 883 // Check for a place to dock.
868 Browser* browser = NULL; 884 Browser* browser = NULL;
869 int tab; 885 int tab;
870 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents, 886 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents,
871 &browser, &tab) || 887 &browser, &tab) ||
872 browser->is_type_popup()) { 888 browser->is_type_popup()) {
873 can_dock = false; 889 can_dock = false;
874 } 890 }
875 } 891 }
876 892
877 // Create WebContents with devtools. 893 // Create WebContents with devtools.
878 GURL url(GetDevToolsURL(profile, frontend_url, shared_worker_frontend, 894 GURL url(GetDevToolsURL(profile, frontend_url, shared_worker_frontend,
879 v8_only_frontend, remote_frontend, can_dock, panel)); 895 v8_only_frontend, node_frontend, remote_frontend, can_dock, panel));
880 std::unique_ptr<WebContents> main_web_contents( 896 std::unique_ptr<WebContents> main_web_contents(
881 WebContents::Create(WebContents::CreateParams(profile))); 897 WebContents::Create(WebContents::CreateParams(profile)));
882 main_web_contents->GetController().LoadURL( 898 main_web_contents->GetController().LoadURL(
883 DecorateFrontendURL(url), content::Referrer(), 899 DecorateFrontendURL(url), content::Referrer(),
884 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); 900 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string());
885 DevToolsUIBindings* bindings = 901 DevToolsUIBindings* bindings =
886 DevToolsUIBindings::ForWebContents(main_web_contents.get()); 902 DevToolsUIBindings::ForWebContents(main_web_contents.get());
887 if (!bindings) 903 if (!bindings)
888 return nullptr; 904 return nullptr;
889 if (!settings.empty()) 905 if (!settings.empty())
890 SetPreferencesFromJson(profile, settings); 906 SetPreferencesFromJson(profile, settings);
891 return new DevToolsWindow(profile, main_web_contents.release(), bindings, 907 return new DevToolsWindow(profile, main_web_contents.release(), bindings,
892 inspected_web_contents, can_dock); 908 inspected_web_contents, can_dock);
893 } 909 }
894 910
895 // static 911 // static
896 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, 912 GURL DevToolsWindow::GetDevToolsURL(Profile* profile,
897 const GURL& base_url, 913 const GURL& base_url,
898 bool shared_worker_frontend, 914 bool shared_worker_frontend,
899 bool v8_only_frontend, 915 bool v8_only_frontend,
916 bool node_frontend,
900 const std::string& remote_frontend, 917 const std::string& remote_frontend,
901 bool can_dock, 918 bool can_dock,
902 const std::string& panel) { 919 const std::string& panel) {
903 // Compatibility errors are encoded with data urls, pass them 920 // Compatibility errors are encoded with data urls, pass them
904 // through with no decoration. 921 // through with no decoration.
905 if (base_url.SchemeIs("data")) 922 if (base_url.SchemeIs("data"))
906 return base_url; 923 return base_url;
907 924
908 std::string frontend_url( 925 std::string frontend_url(
909 !remote_frontend.empty() ? 926 !remote_frontend.empty() ?
910 remote_frontend : 927 remote_frontend :
911 base_url.is_empty() ? chrome::kChromeUIDevToolsURL : base_url.spec()); 928 base_url.is_empty() ? chrome::kChromeUIDevToolsURL : base_url.spec());
912 std::string url_string( 929 std::string url_string(
913 frontend_url + 930 frontend_url +
914 ((frontend_url.find("?") == std::string::npos) ? "?" : "&")); 931 ((frontend_url.find("?") == std::string::npos) ? "?" : "&"));
915 if (shared_worker_frontend) 932 if (shared_worker_frontend)
916 url_string += "&isSharedWorker=true"; 933 url_string += "&isSharedWorker=true";
917 if (v8_only_frontend) 934 if (v8_only_frontend)
918 url_string += "&v8only=true"; 935 url_string += "&v8only=true";
936 if (node_frontend)
937 url_string += "&nodeFrontend=true";
919 if (remote_frontend.size()) { 938 if (remote_frontend.size()) {
920 url_string += "&remoteFrontend=true"; 939 url_string += "&remoteFrontend=true";
921 } else { 940 } else {
922 url_string += "&remoteBase=" + DevToolsUI::GetRemoteBaseURL().spec(); 941 url_string += "&remoteBase=" + DevToolsUI::GetRemoteBaseURL().spec();
923 } 942 }
924 if (can_dock) 943 if (can_dock)
925 url_string += "&can_dock=true"; 944 url_string += "&can_dock=true";
926 if (panel.size()) 945 if (panel.size())
927 url_string += "&panel=" + panel; 946 url_string += "&panel=" + panel;
928 return DevToolsUIBindings::SanitizeFrontendURL(GURL(url_string)); 947 return DevToolsUIBindings::SanitizeFrontendURL(GURL(url_string));
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 bool DevToolsWindow::ReloadInspectedWebContents(bool bypass_cache) { 1409 bool DevToolsWindow::ReloadInspectedWebContents(bool bypass_cache) {
1391 // Only route reload via front-end if the agent is attached. 1410 // Only route reload via front-end if the agent is attached.
1392 WebContents* wc = GetInspectedWebContents(); 1411 WebContents* wc = GetInspectedWebContents();
1393 if (!wc || wc->GetCrashedStatus() != base::TERMINATION_STATUS_STILL_RUNNING) 1412 if (!wc || wc->GetCrashedStatus() != base::TERMINATION_STATUS_STILL_RUNNING)
1394 return false; 1413 return false;
1395 base::FundamentalValue bypass_cache_value(bypass_cache); 1414 base::FundamentalValue bypass_cache_value(bypass_cache);
1396 bindings_->CallClientFunction("DevToolsAPI.reloadInspectedPage", 1415 bindings_->CallClientFunction("DevToolsAPI.reloadInspectedPage",
1397 &bypass_cache_value, nullptr, nullptr); 1416 &bypass_cache_value, nullptr, nullptr);
1398 return true; 1417 return true;
1399 } 1418 }
OLDNEW
« no previous file with comments | « chrome/browser/devtools/devtools_window.h ('k') | chrome/browser/resources/inspect/inspect.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698