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 "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 Loading... |
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, GURL(), NULL, true, false, false, std::string(), | 470 return Create(profile, NULL, true, false, false, std::string(), false, "", |
471 false, "", ""); | 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 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 const DevToolsToggleAction& action) { | 520 const DevToolsToggleAction& action) { |
521 ToggleDevToolsWindow(inspected_web_contents, true, action, ""); | 521 ToggleDevToolsWindow(inspected_web_contents, true, action, ""); |
522 } | 522 } |
523 | 523 |
524 // static | 524 // static |
525 void DevToolsWindow::OpenDevToolsWindowForFrame( | 525 void DevToolsWindow::OpenDevToolsWindowForFrame( |
526 Profile* profile, | 526 Profile* profile, |
527 const scoped_refptr<content::DevToolsAgentHost>& agent_host) { | 527 const scoped_refptr<content::DevToolsAgentHost>& agent_host) { |
528 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); | 528 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); |
529 if (!window) { | 529 if (!window) { |
530 window = DevToolsWindow::Create(profile, GURL(), nullptr, false, false, | 530 window = DevToolsWindow::Create(profile, nullptr, false, false, false, |
531 false, std::string(), false, std::string(), | 531 std::string(), false, std::string(), |
532 std::string()); | 532 std::string()); |
533 if (!window) | 533 if (!window) |
534 return; | 534 return; |
535 window->bindings_->AttachTo(agent_host); | 535 window->bindings_->AttachTo(agent_host); |
536 } | 536 } |
537 window->ScheduleShow(DevToolsToggleAction::Show()); | 537 window->ScheduleShow(DevToolsToggleAction::Show()); |
538 } | 538 } |
539 | 539 |
540 // static | 540 // static |
541 void DevToolsWindow::ToggleDevToolsWindow( | 541 void DevToolsWindow::ToggleDevToolsWindow( |
(...skipping 13 matching lines...) Expand all Loading... |
555 | 555 |
556 // static | 556 // static |
557 void DevToolsWindow::OpenExternalFrontend( | 557 void DevToolsWindow::OpenExternalFrontend( |
558 Profile* profile, | 558 Profile* profile, |
559 const std::string& frontend_url, | 559 const std::string& frontend_url, |
560 const scoped_refptr<content::DevToolsAgentHost>& agent_host, | 560 const scoped_refptr<content::DevToolsAgentHost>& agent_host, |
561 bool is_worker, | 561 bool is_worker, |
562 bool is_v8_only) { | 562 bool is_v8_only) { |
563 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); | 563 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); |
564 if (!window) { | 564 if (!window) { |
565 window = Create(profile, GURL(), nullptr, is_worker, is_v8_only, false, | 565 window = Create(profile, nullptr, is_worker, is_v8_only, false, |
566 DevToolsUI::GetProxyURL(frontend_url).spec(), false, | 566 DevToolsUI::GetProxyURL(frontend_url).spec(), false, |
567 std::string(), std::string()); | 567 std::string(), std::string()); |
568 if (!window) | 568 if (!window) |
569 return; | 569 return; |
570 window->bindings_->AttachTo(agent_host); | 570 window->bindings_->AttachTo(agent_host); |
571 window->close_on_detach_ = false; | 571 window->close_on_detach_ = false; |
572 } | 572 } |
573 | 573 |
574 window->ScheduleShow(DevToolsToggleAction::Show()); | 574 window->ScheduleShow(DevToolsToggleAction::Show()); |
575 } | 575 } |
576 | 576 |
577 // static | 577 // static |
578 void DevToolsWindow::OpenNodeFrontendWindow(Profile* profile) { | 578 void DevToolsWindow::OpenNodeFrontendWindow(Profile* profile) { |
579 DevToolsWindow* window = Create(profile, GURL(), nullptr, false, true, true, | 579 DevToolsWindow* window = |
580 std::string(), false, std::string(), | 580 Create(profile, nullptr, false, true, true, std::string(), false, |
581 std::string()); | 581 std::string(), std::string()); |
582 if (!window) | 582 if (!window) |
583 return; | 583 return; |
584 window->bindings_->AttachTo(DevToolsAgentHost::CreateForDiscovery()); | 584 window->bindings_->AttachTo(DevToolsAgentHost::CreateForDiscovery()); |
585 window->ScheduleShow(DevToolsToggleAction::Show()); | 585 window->ScheduleShow(DevToolsToggleAction::Show()); |
586 } | 586 } |
587 | 587 |
588 // static | 588 // static |
589 void DevToolsWindow::ToggleDevToolsWindow( | 589 void DevToolsWindow::ToggleDevToolsWindow( |
590 content::WebContents* inspected_web_contents, | 590 content::WebContents* inspected_web_contents, |
591 bool force_open, | 591 bool force_open, |
(...skipping 16 matching lines...) Expand all Loading... |
608 break; | 608 break; |
609 case DevToolsToggleAction::kShowConsolePanel: | 609 case DevToolsToggleAction::kShowConsolePanel: |
610 panel = "console"; | 610 panel = "console"; |
611 break; | 611 break; |
612 case DevToolsToggleAction::kShow: | 612 case DevToolsToggleAction::kShow: |
613 case DevToolsToggleAction::kToggle: | 613 case DevToolsToggleAction::kToggle: |
614 case DevToolsToggleAction::kReveal: | 614 case DevToolsToggleAction::kReveal: |
615 case DevToolsToggleAction::kNoOp: | 615 case DevToolsToggleAction::kNoOp: |
616 break; | 616 break; |
617 } | 617 } |
618 window = Create(profile, GURL(), inspected_web_contents, false, false, | 618 window = Create(profile, inspected_web_contents, false, false, false, |
619 false, std::string(), true, settings, panel); | 619 std::string(), true, settings, panel); |
620 if (!window) | 620 if (!window) |
621 return; | 621 return; |
622 window->bindings_->AttachTo(agent.get()); | 622 window->bindings_->AttachTo(agent.get()); |
623 do_open = true; | 623 do_open = true; |
624 } | 624 } |
625 | 625 |
626 // Update toolbar to reflect DevTools changes. | 626 // Update toolbar to reflect DevTools changes. |
627 window->UpdateBrowserToolbar(); | 627 window->UpdateBrowserToolbar(); |
628 | 628 |
629 // 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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 | 860 |
861 std::vector<base::Callback<void(DevToolsWindow*)>> copy( | 861 std::vector<base::Callback<void(DevToolsWindow*)>> copy( |
862 g_creation_callbacks.Get()); | 862 g_creation_callbacks.Get()); |
863 for (const auto& callback : copy) | 863 for (const auto& callback : copy) |
864 callback.Run(this); | 864 callback.Run(this); |
865 } | 865 } |
866 | 866 |
867 // static | 867 // static |
868 DevToolsWindow* DevToolsWindow::Create( | 868 DevToolsWindow* DevToolsWindow::Create( |
869 Profile* profile, | 869 Profile* profile, |
870 const GURL& frontend_url, | |
871 content::WebContents* inspected_web_contents, | 870 content::WebContents* inspected_web_contents, |
872 bool shared_worker_frontend, | 871 bool shared_worker_frontend, |
873 bool v8_only_frontend, | 872 bool v8_only_frontend, |
874 bool node_frontend, | 873 bool node_frontend, |
875 const std::string& remote_frontend, | 874 const std::string& remote_frontend, |
876 bool can_dock, | 875 bool can_dock, |
877 const std::string& settings, | 876 const std::string& settings, |
878 const std::string& panel) { | 877 const std::string& panel) { |
879 if (profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled) || | 878 if (profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled) || |
880 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) | 879 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) |
881 return nullptr; | 880 return nullptr; |
882 | 881 |
883 if (inspected_web_contents) { | 882 if (inspected_web_contents) { |
884 // Check for a place to dock. | 883 // Check for a place to dock. |
885 Browser* browser = NULL; | 884 Browser* browser = NULL; |
886 int tab; | 885 int tab; |
887 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents, | 886 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents, |
888 &browser, &tab) || | 887 &browser, &tab) || |
889 browser->is_type_popup()) { | 888 browser->is_type_popup()) { |
890 can_dock = false; | 889 can_dock = false; |
891 } | 890 } |
892 } | 891 } |
893 | 892 |
894 // Create WebContents with devtools. | 893 // Create WebContents with devtools. |
895 GURL url(GetDevToolsURL(profile, frontend_url, shared_worker_frontend, | 894 GURL url(GetDevToolsURL(profile, shared_worker_frontend, v8_only_frontend, |
896 v8_only_frontend, node_frontend, remote_frontend, can_dock, panel)); | 895 node_frontend, remote_frontend, can_dock, panel)); |
897 std::unique_ptr<WebContents> main_web_contents( | 896 std::unique_ptr<WebContents> main_web_contents( |
898 WebContents::Create(WebContents::CreateParams(profile))); | 897 WebContents::Create(WebContents::CreateParams(profile))); |
899 main_web_contents->GetController().LoadURL( | 898 main_web_contents->GetController().LoadURL( |
900 DecorateFrontendURL(url), content::Referrer(), | 899 DecorateFrontendURL(url), content::Referrer(), |
901 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); | 900 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); |
902 DevToolsUIBindings* bindings = | 901 DevToolsUIBindings* bindings = |
903 DevToolsUIBindings::ForWebContents(main_web_contents.get()); | 902 DevToolsUIBindings::ForWebContents(main_web_contents.get()); |
904 if (!bindings) | 903 if (!bindings) |
905 return nullptr; | 904 return nullptr; |
906 if (!settings.empty()) | 905 if (!settings.empty()) |
907 SetPreferencesFromJson(profile, settings); | 906 SetPreferencesFromJson(profile, settings); |
908 return new DevToolsWindow(profile, main_web_contents.release(), bindings, | 907 return new DevToolsWindow(profile, main_web_contents.release(), bindings, |
909 inspected_web_contents, can_dock); | 908 inspected_web_contents, can_dock); |
910 } | 909 } |
911 | 910 |
912 // static | 911 // static |
913 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, | 912 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, |
914 const GURL& base_url, | |
915 bool shared_worker_frontend, | 913 bool shared_worker_frontend, |
916 bool v8_only_frontend, | 914 bool v8_only_frontend, |
917 bool node_frontend, | 915 bool node_frontend, |
918 const std::string& remote_frontend, | 916 const std::string& remote_frontend, |
919 bool can_dock, | 917 bool can_dock, |
920 const std::string& panel) { | 918 const std::string& panel) { |
921 // Compatibility errors are encoded with data urls, pass them | 919 std::string frontend_url(!remote_frontend.empty() |
922 // through with no decoration. | 920 ? remote_frontend |
923 if (base_url.SchemeIs("data")) | 921 : chrome::kChromeUIDevToolsURL); |
924 return base_url; | |
925 | |
926 std::string frontend_url( | |
927 !remote_frontend.empty() ? | |
928 remote_frontend : | |
929 base_url.is_empty() ? chrome::kChromeUIDevToolsURL : base_url.spec()); | |
930 std::string url_string( | 922 std::string url_string( |
931 frontend_url + | 923 frontend_url + |
932 ((frontend_url.find("?") == std::string::npos) ? "?" : "&")); | 924 ((frontend_url.find("?") == std::string::npos) ? "?" : "&")); |
933 if (shared_worker_frontend) | 925 if (shared_worker_frontend) |
934 url_string += "&isSharedWorker=true"; | 926 url_string += "&isSharedWorker=true"; |
935 if (v8_only_frontend) | 927 if (v8_only_frontend) |
936 url_string += "&v8only=true"; | 928 url_string += "&v8only=true"; |
937 if (node_frontend) | 929 if (node_frontend) |
938 url_string += "&nodeFrontend=true"; | 930 url_string += "&nodeFrontend=true"; |
939 if (remote_frontend.size()) { | 931 if (remote_frontend.size()) { |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1409 bool DevToolsWindow::ReloadInspectedWebContents(bool bypass_cache) { | 1401 bool DevToolsWindow::ReloadInspectedWebContents(bool bypass_cache) { |
1410 // Only route reload via front-end if the agent is attached. | 1402 // Only route reload via front-end if the agent is attached. |
1411 WebContents* wc = GetInspectedWebContents(); | 1403 WebContents* wc = GetInspectedWebContents(); |
1412 if (!wc || wc->GetCrashedStatus() != base::TERMINATION_STATUS_STILL_RUNNING) | 1404 if (!wc || wc->GetCrashedStatus() != base::TERMINATION_STATUS_STILL_RUNNING) |
1413 return false; | 1405 return false; |
1414 base::Value bypass_cache_value(bypass_cache); | 1406 base::Value bypass_cache_value(bypass_cache); |
1415 bindings_->CallClientFunction("DevToolsAPI.reloadInspectedPage", | 1407 bindings_->CallClientFunction("DevToolsAPI.reloadInspectedPage", |
1416 &bypass_cache_value, nullptr, nullptr); | 1408 &bypass_cache_value, nullptr, nullptr); |
1417 return true; | 1409 return true; |
1418 } | 1410 } |
OLD | NEW |