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

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

Issue 2566573002: DevTools: Open Elements panel sooner on Inspect Element (Closed)
Patch Set: Missed one showConsolePanel Created 4 years 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 "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 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 return; 457 return;
458 window->bindings_->AttachTo(worker_agent); 458 window->bindings_->AttachTo(worker_agent);
459 } 459 }
460 window->ScheduleShow(DevToolsToggleAction::Show()); 460 window->ScheduleShow(DevToolsToggleAction::Show());
461 } 461 }
462 462
463 // static 463 // static
464 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( 464 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker(
465 Profile* profile) { 465 Profile* profile) {
466 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); 466 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker"));
467 return Create(profile, GURL(), NULL, true, false, std::string(), false, ""); 467 return Create(profile, GURL(), NULL, true, false, std::string(), false, "",
468 "");
468 } 469 }
469 470
470 // static 471 // static
471 void DevToolsWindow::OpenDevToolsWindow( 472 void DevToolsWindow::OpenDevToolsWindow(
472 content::WebContents* inspected_web_contents) { 473 content::WebContents* inspected_web_contents) {
473 ToggleDevToolsWindow( 474 ToggleDevToolsWindow(
474 inspected_web_contents, true, DevToolsToggleAction::Show(), ""); 475 inspected_web_contents, true, DevToolsToggleAction::Show(), "");
475 } 476 }
476 477
477 // static 478 // static
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 ToggleDevToolsWindow(inspected_web_contents, true, action, ""); 518 ToggleDevToolsWindow(inspected_web_contents, true, action, "");
518 } 519 }
519 520
520 // static 521 // static
521 void DevToolsWindow::OpenDevToolsWindowForFrame( 522 void DevToolsWindow::OpenDevToolsWindowForFrame(
522 Profile* profile, 523 Profile* profile,
523 const scoped_refptr<content::DevToolsAgentHost>& agent_host) { 524 const scoped_refptr<content::DevToolsAgentHost>& agent_host) {
524 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); 525 DevToolsWindow* window = FindDevToolsWindow(agent_host.get());
525 if (!window) { 526 if (!window) {
526 window = DevToolsWindow::Create(profile, GURL(), nullptr, false, false, 527 window = DevToolsWindow::Create(profile, GURL(), nullptr, false, false,
527 std::string(), false, std::string()); 528 std::string(), false, std::string(),
529 std::string());
528 if (!window) 530 if (!window)
529 return; 531 return;
530 window->bindings_->AttachTo(agent_host); 532 window->bindings_->AttachTo(agent_host);
531 } 533 }
532 window->ScheduleShow(DevToolsToggleAction::Show()); 534 window->ScheduleShow(DevToolsToggleAction::Show());
533 } 535 }
534 536
535 // static 537 // static
536 void DevToolsWindow::ToggleDevToolsWindow( 538 void DevToolsWindow::ToggleDevToolsWindow(
537 Browser* browser, 539 Browser* browser,
(...skipping 13 matching lines...) Expand all
551 // static 553 // static
552 void DevToolsWindow::OpenExternalFrontend( 554 void DevToolsWindow::OpenExternalFrontend(
553 Profile* profile, 555 Profile* profile,
554 const std::string& frontend_url, 556 const std::string& frontend_url,
555 const scoped_refptr<content::DevToolsAgentHost>& agent_host, 557 const scoped_refptr<content::DevToolsAgentHost>& agent_host,
556 bool is_worker, 558 bool is_worker,
557 bool is_v8_only) { 559 bool is_v8_only) {
558 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); 560 DevToolsWindow* window = FindDevToolsWindow(agent_host.get());
559 if (!window) { 561 if (!window) {
560 window = Create(profile, GURL(), nullptr, is_worker, is_v8_only, 562 window = Create(profile, GURL(), nullptr, is_worker, is_v8_only,
561 DevToolsUI::GetProxyURL(frontend_url).spec(), false, std::string()); 563 DevToolsUI::GetProxyURL(frontend_url).spec(), false,
564 std::string(), std::string());
562 if (!window) 565 if (!window)
563 return; 566 return;
564 window->bindings_->AttachTo(agent_host); 567 window->bindings_->AttachTo(agent_host);
565 window->close_on_detach_ = false; 568 window->close_on_detach_ = false;
566 } 569 }
567 570
568 window->ScheduleShow(DevToolsToggleAction::Show()); 571 window->ScheduleShow(DevToolsToggleAction::Show());
569 } 572 }
570 573
571 // static 574 // static
572 void DevToolsWindow::ToggleDevToolsWindow( 575 void DevToolsWindow::ToggleDevToolsWindow(
573 content::WebContents* inspected_web_contents, 576 content::WebContents* inspected_web_contents,
574 bool force_open, 577 bool force_open,
575 const DevToolsToggleAction& action, 578 const DevToolsToggleAction& action,
576 const std::string& settings) { 579 const std::string& settings) {
577 scoped_refptr<DevToolsAgentHost> agent( 580 scoped_refptr<DevToolsAgentHost> agent(
578 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); 581 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents));
579 DevToolsWindow* window = FindDevToolsWindow(agent.get()); 582 DevToolsWindow* window = FindDevToolsWindow(agent.get());
580 bool do_open = force_open; 583 bool do_open = force_open;
581 if (!window) { 584 if (!window) {
582 Profile* profile = Profile::FromBrowserContext( 585 Profile* profile = Profile::FromBrowserContext(
583 inspected_web_contents->GetBrowserContext()); 586 inspected_web_contents->GetBrowserContext());
584 content::RecordAction( 587 content::RecordAction(
585 base::UserMetricsAction("DevTools_InspectRenderer")); 588 base::UserMetricsAction("DevTools_InspectRenderer"));
586 window = Create(profile, GURL(), inspected_web_contents, 589 std::string panel = "";
587 false, false, std::string(), true, settings); 590 switch (action.type()) {
591 case DevToolsToggleAction::kInspect:
592 case DevToolsToggleAction::kShowElementsPanel:
593 panel = "elements";
594 break;
595 case DevToolsToggleAction::kShowConsolePanel:
596 panel = "console";
597 break;
598 case DevToolsToggleAction::kShow:
599 case DevToolsToggleAction::kToggle:
600 case DevToolsToggleAction::kReveal:
601 case DevToolsToggleAction::kNoOp:
602 break;
603 }
604 window = Create(profile, GURL(), inspected_web_contents, false, false,
605 std::string(), true, settings, panel);
588 if (!window) 606 if (!window)
589 return; 607 return;
590 window->bindings_->AttachTo(agent.get()); 608 window->bindings_->AttachTo(agent.get());
591 do_open = true; 609 do_open = true;
592 } 610 }
593 611
594 // Update toolbar to reflect DevTools changes. 612 // Update toolbar to reflect DevTools changes.
595 window->UpdateBrowserToolbar(); 613 window->UpdateBrowserToolbar();
596 614
597 // If window is docked and visible, we hide it on toggle. If window is 615 // If window is docked and visible, we hide it on toggle. If window is
598 // undocked, we show (activate) it. 616 // undocked, we show (activate) it.
599 if (!window->is_docked_ || do_open) 617 if (!window->is_docked_ || do_open)
600 window->ScheduleShow(action); 618 window->ScheduleShow(action);
601 else 619 else
602 window->CloseWindow(); 620 window->CloseWindow();
603 } 621 }
604 622
605 // static 623 // static
606 void DevToolsWindow::InspectElement( 624 void DevToolsWindow::InspectElement(
607 content::RenderFrameHost* inspected_frame_host, 625 content::RenderFrameHost* inspected_frame_host,
608 int x, 626 int x,
609 int y) { 627 int y) {
610 scoped_refptr<DevToolsAgentHost> agent( 628 scoped_refptr<DevToolsAgentHost> agent(
611 DevToolsAgentHost::GetOrCreateFor(inspected_frame_host)); 629 DevToolsAgentHost::GetOrCreateFor(inspected_frame_host));
612 bool should_measure_time = FindDevToolsWindow(agent.get()) == NULL; 630 bool should_measure_time = FindDevToolsWindow(agent.get()) == NULL;
613 base::TimeTicks start_time = base::TimeTicks::Now(); 631 base::TimeTicks start_time = base::TimeTicks::Now();
614 // TODO(loislo): we should initiate DevTools window opening from within 632 // TODO(loislo): we should initiate DevTools window opening from within
615 // renderer. Otherwise, we still can hit a race condition here. 633 // renderer. Otherwise, we still can hit a race condition here.
616 if (agent->GetType() == content::DevToolsAgentHost::kTypePage) { 634 if (agent->GetType() == content::DevToolsAgentHost::kTypePage) {
617 OpenDevToolsWindow(agent->GetWebContents()); 635 OpenDevToolsWindow(agent->GetWebContents(),
636 DevToolsToggleAction::ShowElementsPanel());
618 } else { 637 } else {
619 OpenDevToolsWindowForFrame(Profile::FromBrowserContext( 638 OpenDevToolsWindowForFrame(Profile::FromBrowserContext(
620 agent->GetBrowserContext()), agent); 639 agent->GetBrowserContext()), agent);
621 } 640 }
622 DevToolsWindow* window = FindDevToolsWindow(agent.get()); 641 DevToolsWindow* window = FindDevToolsWindow(agent.get());
623 if (window) { 642 if (window) {
624 agent->InspectElement(window->bindings_, x, y); 643 agent->InspectElement(window->bindings_, x, y);
625 if (should_measure_time) 644 if (should_measure_time)
626 window->inspect_element_start_time_ = start_time; 645 window->inspect_element_start_time_ = start_time;
627 } 646 }
(...skipping 14 matching lines...) Expand all
642 Show(DevToolsToggleAction::Show()); 661 Show(DevToolsToggleAction::Show());
643 } 662 }
644 } 663 }
645 664
646 void DevToolsWindow::Show(const DevToolsToggleAction& action) { 665 void DevToolsWindow::Show(const DevToolsToggleAction& action) {
647 if (life_stage_ == kClosing) 666 if (life_stage_ == kClosing)
648 return; 667 return;
649 668
650 if (action.type() == DevToolsToggleAction::kNoOp) 669 if (action.type() == DevToolsToggleAction::kNoOp)
651 return; 670 return;
652
653 if (is_docked_) { 671 if (is_docked_) {
654 DCHECK(can_dock_); 672 DCHECK(can_dock_);
655 Browser* inspected_browser = NULL; 673 Browser* inspected_browser = NULL;
656 int inspected_tab_index = -1; 674 int inspected_tab_index = -1;
657 FindInspectedBrowserAndTabIndex(GetInspectedWebContents(), 675 FindInspectedBrowserAndTabIndex(GetInspectedWebContents(),
658 &inspected_browser, 676 &inspected_browser,
659 &inspected_tab_index); 677 &inspected_tab_index);
660 DCHECK(inspected_browser); 678 DCHECK(inspected_browser);
661 DCHECK(inspected_tab_index != -1); 679 DCHECK(inspected_tab_index != -1);
662 680
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 851
834 // static 852 // static
835 DevToolsWindow* DevToolsWindow::Create( 853 DevToolsWindow* DevToolsWindow::Create(
836 Profile* profile, 854 Profile* profile,
837 const GURL& frontend_url, 855 const GURL& frontend_url,
838 content::WebContents* inspected_web_contents, 856 content::WebContents* inspected_web_contents,
839 bool shared_worker_frontend, 857 bool shared_worker_frontend,
840 bool v8_only_frontend, 858 bool v8_only_frontend,
841 const std::string& remote_frontend, 859 const std::string& remote_frontend,
842 bool can_dock, 860 bool can_dock,
843 const std::string& settings) { 861 const std::string& settings,
862 const std::string& panel) {
844 if (profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled) || 863 if (profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled) ||
845 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) 864 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
846 return nullptr; 865 return nullptr;
847 866
848 if (inspected_web_contents) { 867 if (inspected_web_contents) {
849 // Check for a place to dock. 868 // Check for a place to dock.
850 Browser* browser = NULL; 869 Browser* browser = NULL;
851 int tab; 870 int tab;
852 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents, 871 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents,
853 &browser, &tab) || 872 &browser, &tab) ||
854 browser->is_type_popup()) { 873 browser->is_type_popup()) {
855 can_dock = false; 874 can_dock = false;
856 } 875 }
857 } 876 }
858 877
859 // Create WebContents with devtools. 878 // Create WebContents with devtools.
860 GURL url(GetDevToolsURL(profile, frontend_url, 879 GURL url(GetDevToolsURL(profile, frontend_url, shared_worker_frontend,
861 shared_worker_frontend, 880 v8_only_frontend, remote_frontend, can_dock, panel));
862 v8_only_frontend,
863 remote_frontend,
864 can_dock));
865 std::unique_ptr<WebContents> main_web_contents( 881 std::unique_ptr<WebContents> main_web_contents(
866 WebContents::Create(WebContents::CreateParams(profile))); 882 WebContents::Create(WebContents::CreateParams(profile)));
867 main_web_contents->GetController().LoadURL( 883 main_web_contents->GetController().LoadURL(
868 DecorateFrontendURL(url), content::Referrer(), 884 DecorateFrontendURL(url), content::Referrer(),
869 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); 885 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string());
870 DevToolsUIBindings* bindings = 886 DevToolsUIBindings* bindings =
871 DevToolsUIBindings::ForWebContents(main_web_contents.get()); 887 DevToolsUIBindings::ForWebContents(main_web_contents.get());
872 if (!bindings) 888 if (!bindings)
873 return nullptr; 889 return nullptr;
874 if (!settings.empty()) 890 if (!settings.empty())
875 SetPreferencesFromJson(profile, settings); 891 SetPreferencesFromJson(profile, settings);
876 return new DevToolsWindow(profile, main_web_contents.release(), bindings, 892 return new DevToolsWindow(profile, main_web_contents.release(), bindings,
877 inspected_web_contents, can_dock); 893 inspected_web_contents, can_dock);
878 } 894 }
879 895
880 // static 896 // static
881 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, 897 GURL DevToolsWindow::GetDevToolsURL(Profile* profile,
882 const GURL& base_url, 898 const GURL& base_url,
883 bool shared_worker_frontend, 899 bool shared_worker_frontend,
884 bool v8_only_frontend, 900 bool v8_only_frontend,
885 const std::string& remote_frontend, 901 const std::string& remote_frontend,
886 bool can_dock) { 902 bool can_dock,
903 const std::string& panel) {
887 // Compatibility errors are encoded with data urls, pass them 904 // Compatibility errors are encoded with data urls, pass them
888 // through with no decoration. 905 // through with no decoration.
889 if (base_url.SchemeIs("data")) 906 if (base_url.SchemeIs("data"))
890 return base_url; 907 return base_url;
891 908
892 std::string frontend_url( 909 std::string frontend_url(
893 !remote_frontend.empty() ? 910 !remote_frontend.empty() ?
894 remote_frontend : 911 remote_frontend :
895 base_url.is_empty() ? chrome::kChromeUIDevToolsURL : base_url.spec()); 912 base_url.is_empty() ? chrome::kChromeUIDevToolsURL : base_url.spec());
896 std::string url_string( 913 std::string url_string(
897 frontend_url + 914 frontend_url +
898 ((frontend_url.find("?") == std::string::npos) ? "?" : "&")); 915 ((frontend_url.find("?") == std::string::npos) ? "?" : "&"));
899 if (shared_worker_frontend) 916 if (shared_worker_frontend)
900 url_string += "&isSharedWorker=true"; 917 url_string += "&isSharedWorker=true";
901 if (v8_only_frontend) 918 if (v8_only_frontend)
902 url_string += "&v8only=true"; 919 url_string += "&v8only=true";
903 if (remote_frontend.size()) { 920 if (remote_frontend.size()) {
904 url_string += "&remoteFrontend=true"; 921 url_string += "&remoteFrontend=true";
905 } else { 922 } else {
906 url_string += "&remoteBase=" + DevToolsUI::GetRemoteBaseURL().spec(); 923 url_string += "&remoteBase=" + DevToolsUI::GetRemoteBaseURL().spec();
907 } 924 }
908 if (can_dock) 925 if (can_dock)
909 url_string += "&can_dock=true"; 926 url_string += "&can_dock=true";
927 if (panel.size())
928 url_string += "&panel=" + panel;
910 return DevToolsUI::SanitizeFrontendURL(GURL(url_string)); 929 return DevToolsUI::SanitizeFrontendURL(GURL(url_string));
911 } 930 }
912 931
913 // static 932 // static
914 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( 933 DevToolsWindow* DevToolsWindow::FindDevToolsWindow(
915 DevToolsAgentHost* agent_host) { 934 DevToolsAgentHost* agent_host) {
916 if (!agent_host || g_instances == NULL) 935 if (!agent_host || g_instances == NULL)
917 return NULL; 936 return NULL;
918 DevToolsWindows* instances = g_instances.Pointer(); 937 DevToolsWindows* instances = g_instances.Pointer();
919 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); 938 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end();
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 BrowserWindow* DevToolsWindow::GetInspectedBrowserWindow() { 1310 BrowserWindow* DevToolsWindow::GetInspectedBrowserWindow() {
1292 Browser* browser = NULL; 1311 Browser* browser = NULL;
1293 int tab; 1312 int tab;
1294 return FindInspectedBrowserAndTabIndex(GetInspectedWebContents(), 1313 return FindInspectedBrowserAndTabIndex(GetInspectedWebContents(),
1295 &browser, &tab) ? 1314 &browser, &tab) ?
1296 browser->window() : NULL; 1315 browser->window() : NULL;
1297 } 1316 }
1298 1317
1299 void DevToolsWindow::DoAction(const DevToolsToggleAction& action) { 1318 void DevToolsWindow::DoAction(const DevToolsToggleAction& action) {
1300 switch (action.type()) { 1319 switch (action.type()) {
1301 case DevToolsToggleAction::kShowConsole: {
1302 base::StringValue panel_name("console");
1303 bindings_->CallClientFunction("DevToolsAPI.showPanel", &panel_name, NULL,
1304 NULL);
1305 break;
1306 }
1307 case DevToolsToggleAction::kInspect: 1320 case DevToolsToggleAction::kInspect:
1308 bindings_->CallClientFunction( 1321 bindings_->CallClientFunction("DevToolsAPI.enterInspectElementMode", NULL,
1309 "DevToolsAPI.enterInspectElementMode", NULL, NULL, NULL); 1322 NULL, NULL);
1310 break; 1323 break;
1311 1324
1325 case DevToolsToggleAction::kShowConsolePanel:
1312 case DevToolsToggleAction::kShow: 1326 case DevToolsToggleAction::kShow:
1313 case DevToolsToggleAction::kToggle: 1327 case DevToolsToggleAction::kToggle:
1314 // Do nothing. 1328 // Do nothing.
1315 break; 1329 break;
1316 1330
1317 case DevToolsToggleAction::kReveal: { 1331 case DevToolsToggleAction::kReveal: {
1318 const DevToolsToggleAction::RevealParams* params = 1332 const DevToolsToggleAction::RevealParams* params =
1319 action.params(); 1333 action.params();
1320 CHECK(params); 1334 CHECK(params);
1321 base::StringValue url_value(params->url); 1335 base::StringValue url_value(params->url);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 bool DevToolsWindow::ReloadInspectedWebContents(bool bypass_cache) { 1390 bool DevToolsWindow::ReloadInspectedWebContents(bool bypass_cache) {
1377 // Only route reload via front-end if the agent is attached. 1391 // Only route reload via front-end if the agent is attached.
1378 WebContents* wc = GetInspectedWebContents(); 1392 WebContents* wc = GetInspectedWebContents();
1379 if (!wc || wc->GetCrashedStatus() != base::TERMINATION_STATUS_STILL_RUNNING) 1393 if (!wc || wc->GetCrashedStatus() != base::TERMINATION_STATUS_STILL_RUNNING)
1380 return false; 1394 return false;
1381 base::FundamentalValue bypass_cache_value(bypass_cache); 1395 base::FundamentalValue bypass_cache_value(bypass_cache);
1382 bindings_->CallClientFunction("DevToolsAPI.reloadInspectedPage", 1396 bindings_->CallClientFunction("DevToolsAPI.reloadInspectedPage",
1383 &bypass_cache_value, nullptr, nullptr); 1397 &bypass_cache_value, nullptr, nullptr);
1384 return true; 1398 return true;
1385 } 1399 }
OLDNEW
« no previous file with comments | « chrome/browser/devtools/devtools_window.h ('k') | chrome/browser/ui/browser_command_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698