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

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

Issue 2566573002: DevTools: Open Elements panel sooner on Inspect Element (Closed)
Patch Set: Compatibility 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::kShowSecurityPanel:
596 panel = "security";
597 break;
598 case DevToolsToggleAction::kShowConsolePanel:
599 panel = "console";
600 break;
601 case DevToolsToggleAction::kShow:
602 case DevToolsToggleAction::kToggle:
603 case DevToolsToggleAction::kReveal:
604 case DevToolsToggleAction::kNoOp:
605 break;
606 }
607 window = Create(profile, GURL(), inspected_web_contents, false, false,
608 std::string(), true, settings, panel);
588 if (!window) 609 if (!window)
589 return; 610 return;
590 window->bindings_->AttachTo(agent.get()); 611 window->bindings_->AttachTo(agent.get());
591 do_open = true; 612 do_open = true;
592 } 613 }
593 614
594 // Update toolbar to reflect DevTools changes. 615 // Update toolbar to reflect DevTools changes.
595 window->UpdateBrowserToolbar(); 616 window->UpdateBrowserToolbar();
596 617
597 // If window is docked and visible, we hide it on toggle. If window is 618 // If window is docked and visible, we hide it on toggle. If window is
598 // undocked, we show (activate) it. 619 // undocked, we show (activate) it.
599 if (!window->is_docked_ || do_open) 620 if (!window->is_docked_ || do_open)
600 window->ScheduleShow(action); 621 window->ScheduleShow(action);
601 else 622 else
602 window->CloseWindow(); 623 window->CloseWindow();
603 } 624 }
604 625
605 // static 626 // static
606 void DevToolsWindow::InspectElement( 627 void DevToolsWindow::InspectElement(
607 content::RenderFrameHost* inspected_frame_host, 628 content::RenderFrameHost* inspected_frame_host,
608 int x, 629 int x,
609 int y) { 630 int y) {
610 scoped_refptr<DevToolsAgentHost> agent( 631 scoped_refptr<DevToolsAgentHost> agent(
611 DevToolsAgentHost::GetOrCreateFor(inspected_frame_host)); 632 DevToolsAgentHost::GetOrCreateFor(inspected_frame_host));
612 bool should_measure_time = FindDevToolsWindow(agent.get()) == NULL; 633 bool should_measure_time = FindDevToolsWindow(agent.get()) == NULL;
613 base::TimeTicks start_time = base::TimeTicks::Now(); 634 base::TimeTicks start_time = base::TimeTicks::Now();
614 // TODO(loislo): we should initiate DevTools window opening from within 635 // TODO(loislo): we should initiate DevTools window opening from within
615 // renderer. Otherwise, we still can hit a race condition here. 636 // renderer. Otherwise, we still can hit a race condition here.
616 if (agent->GetType() == content::DevToolsAgentHost::kTypePage) { 637 if (agent->GetType() == content::DevToolsAgentHost::kTypePage) {
617 OpenDevToolsWindow(agent->GetWebContents()); 638 OpenDevToolsWindow(agent->GetWebContents(),
639 DevToolsToggleAction::ShowElementsPanel());
618 } else { 640 } else {
619 OpenDevToolsWindowForFrame(Profile::FromBrowserContext( 641 OpenDevToolsWindowForFrame(Profile::FromBrowserContext(
620 agent->GetBrowserContext()), agent); 642 agent->GetBrowserContext()), agent);
621 } 643 }
622 DevToolsWindow* window = FindDevToolsWindow(agent.get()); 644 DevToolsWindow* window = FindDevToolsWindow(agent.get());
623 if (window) { 645 if (window) {
624 agent->InspectElement(window->bindings_, x, y); 646 agent->InspectElement(window->bindings_, x, y);
625 if (should_measure_time) 647 if (should_measure_time)
626 window->inspect_element_start_time_ = start_time; 648 window->inspect_element_start_time_ = start_time;
627 } 649 }
(...skipping 14 matching lines...) Expand all
642 Show(DevToolsToggleAction::Show()); 664 Show(DevToolsToggleAction::Show());
643 } 665 }
644 } 666 }
645 667
646 void DevToolsWindow::Show(const DevToolsToggleAction& action) { 668 void DevToolsWindow::Show(const DevToolsToggleAction& action) {
647 if (life_stage_ == kClosing) 669 if (life_stage_ == kClosing)
648 return; 670 return;
649 671
650 if (action.type() == DevToolsToggleAction::kNoOp) 672 if (action.type() == DevToolsToggleAction::kNoOp)
651 return; 673 return;
652
653 if (is_docked_) { 674 if (is_docked_) {
654 DCHECK(can_dock_); 675 DCHECK(can_dock_);
655 Browser* inspected_browser = NULL; 676 Browser* inspected_browser = NULL;
656 int inspected_tab_index = -1; 677 int inspected_tab_index = -1;
657 FindInspectedBrowserAndTabIndex(GetInspectedWebContents(), 678 FindInspectedBrowserAndTabIndex(GetInspectedWebContents(),
658 &inspected_browser, 679 &inspected_browser,
659 &inspected_tab_index); 680 &inspected_tab_index);
660 DCHECK(inspected_browser); 681 DCHECK(inspected_browser);
661 DCHECK(inspected_tab_index != -1); 682 DCHECK(inspected_tab_index != -1);
662 683
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 854
834 // static 855 // static
835 DevToolsWindow* DevToolsWindow::Create( 856 DevToolsWindow* DevToolsWindow::Create(
836 Profile* profile, 857 Profile* profile,
837 const GURL& frontend_url, 858 const GURL& frontend_url,
838 content::WebContents* inspected_web_contents, 859 content::WebContents* inspected_web_contents,
839 bool shared_worker_frontend, 860 bool shared_worker_frontend,
840 bool v8_only_frontend, 861 bool v8_only_frontend,
841 const std::string& remote_frontend, 862 const std::string& remote_frontend,
842 bool can_dock, 863 bool can_dock,
843 const std::string& settings) { 864 const std::string& settings,
865 const std::string& panel) {
844 if (profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled) || 866 if (profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled) ||
845 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) 867 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
846 return nullptr; 868 return nullptr;
847 869
848 if (inspected_web_contents) { 870 if (inspected_web_contents) {
849 // Check for a place to dock. 871 // Check for a place to dock.
850 Browser* browser = NULL; 872 Browser* browser = NULL;
851 int tab; 873 int tab;
852 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents, 874 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents,
853 &browser, &tab) || 875 &browser, &tab) ||
854 browser->is_type_popup()) { 876 browser->is_type_popup()) {
855 can_dock = false; 877 can_dock = false;
856 } 878 }
857 } 879 }
858 880
859 // Create WebContents with devtools. 881 // Create WebContents with devtools.
860 GURL url(GetDevToolsURL(profile, frontend_url, 882 GURL url(GetDevToolsURL(profile, frontend_url, shared_worker_frontend,
861 shared_worker_frontend, 883 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( 884 std::unique_ptr<WebContents> main_web_contents(
866 WebContents::Create(WebContents::CreateParams(profile))); 885 WebContents::Create(WebContents::CreateParams(profile)));
867 main_web_contents->GetController().LoadURL( 886 main_web_contents->GetController().LoadURL(
868 DecorateFrontendURL(url), content::Referrer(), 887 DecorateFrontendURL(url), content::Referrer(),
869 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); 888 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string());
870 DevToolsUIBindings* bindings = 889 DevToolsUIBindings* bindings =
871 DevToolsUIBindings::ForWebContents(main_web_contents.get()); 890 DevToolsUIBindings::ForWebContents(main_web_contents.get());
872 if (!bindings) 891 if (!bindings)
873 return nullptr; 892 return nullptr;
874 if (!settings.empty()) 893 if (!settings.empty())
875 SetPreferencesFromJson(profile, settings); 894 SetPreferencesFromJson(profile, settings);
876 return new DevToolsWindow(profile, main_web_contents.release(), bindings, 895 return new DevToolsWindow(profile, main_web_contents.release(), bindings,
877 inspected_web_contents, can_dock); 896 inspected_web_contents, can_dock);
878 } 897 }
879 898
880 // static 899 // static
881 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, 900 GURL DevToolsWindow::GetDevToolsURL(Profile* profile,
882 const GURL& base_url, 901 const GURL& base_url,
883 bool shared_worker_frontend, 902 bool shared_worker_frontend,
884 bool v8_only_frontend, 903 bool v8_only_frontend,
885 const std::string& remote_frontend, 904 const std::string& remote_frontend,
886 bool can_dock) { 905 bool can_dock,
906 const std::string& panel) {
887 // Compatibility errors are encoded with data urls, pass them 907 // Compatibility errors are encoded with data urls, pass them
888 // through with no decoration. 908 // through with no decoration.
889 if (base_url.SchemeIs("data")) 909 if (base_url.SchemeIs("data"))
890 return base_url; 910 return base_url;
891 911
892 std::string frontend_url( 912 std::string frontend_url(
893 !remote_frontend.empty() ? 913 !remote_frontend.empty() ?
894 remote_frontend : 914 remote_frontend :
895 base_url.is_empty() ? chrome::kChromeUIDevToolsURL : base_url.spec()); 915 base_url.is_empty() ? chrome::kChromeUIDevToolsURL : base_url.spec());
896 std::string url_string( 916 std::string url_string(
897 frontend_url + 917 frontend_url +
898 ((frontend_url.find("?") == std::string::npos) ? "?" : "&")); 918 ((frontend_url.find("?") == std::string::npos) ? "?" : "&"));
899 if (shared_worker_frontend) 919 if (shared_worker_frontend)
900 url_string += "&isSharedWorker=true"; 920 url_string += "&isSharedWorker=true";
901 if (v8_only_frontend) 921 if (v8_only_frontend)
902 url_string += "&v8only=true"; 922 url_string += "&v8only=true";
903 if (remote_frontend.size()) { 923 if (remote_frontend.size()) {
904 url_string += "&remoteFrontend=true"; 924 url_string += "&remoteFrontend=true";
905 } else { 925 } else {
906 url_string += "&remoteBase=" + DevToolsUI::GetRemoteBaseURL().spec(); 926 url_string += "&remoteBase=" + DevToolsUI::GetRemoteBaseURL().spec();
907 } 927 }
908 if (can_dock) 928 if (can_dock)
909 url_string += "&can_dock=true"; 929 url_string += "&can_dock=true";
930 if (panel.size())
931 url_string += "&panel=" + panel;
910 return DevToolsUI::SanitizeFrontendURL(GURL(url_string)); 932 return DevToolsUI::SanitizeFrontendURL(GURL(url_string));
911 } 933 }
912 934
913 // static 935 // static
914 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( 936 DevToolsWindow* DevToolsWindow::FindDevToolsWindow(
915 DevToolsAgentHost* agent_host) { 937 DevToolsAgentHost* agent_host) {
916 if (!agent_host || g_instances == NULL) 938 if (!agent_host || g_instances == NULL)
917 return NULL; 939 return NULL;
918 DevToolsWindows* instances = g_instances.Pointer(); 940 DevToolsWindows* instances = g_instances.Pointer();
919 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); 941 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() { 1313 BrowserWindow* DevToolsWindow::GetInspectedBrowserWindow() {
1292 Browser* browser = NULL; 1314 Browser* browser = NULL;
1293 int tab; 1315 int tab;
1294 return FindInspectedBrowserAndTabIndex(GetInspectedWebContents(), 1316 return FindInspectedBrowserAndTabIndex(GetInspectedWebContents(),
1295 &browser, &tab) ? 1317 &browser, &tab) ?
1296 browser->window() : NULL; 1318 browser->window() : NULL;
1297 } 1319 }
1298 1320
1299 void DevToolsWindow::DoAction(const DevToolsToggleAction& action) { 1321 void DevToolsWindow::DoAction(const DevToolsToggleAction& action) {
1300 switch (action.type()) { 1322 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::kShowSecurityPanel: { 1323 case DevToolsToggleAction::kShowSecurityPanel: {
1308 base::StringValue panel_name("security"); 1324 base::StringValue panel_name("security");
1309 bindings_->CallClientFunction("DevToolsAPI.showPanel", &panel_name, NULL, 1325 bindings_->CallClientFunction("DevToolsAPI.showPanel", &panel_name, NULL,
dgozman 2016/12/14 05:29:36 This call is not needed as well.
einbinder 2016/12/15 03:28:02 Removed.
1310 NULL); 1326 NULL);
1311 break; 1327 break;
1312 } 1328 }
1313 case DevToolsToggleAction::kInspect: 1329 case DevToolsToggleAction::kInspect:
1314 bindings_->CallClientFunction( 1330 bindings_->CallClientFunction("DevToolsAPI.enterInspectElementMode", NULL,
1315 "DevToolsAPI.enterInspectElementMode", NULL, NULL, NULL); 1331 NULL, NULL);
1316 break; 1332 break;
1317 1333
1334 case DevToolsToggleAction::kShowConsolePanel:
1318 case DevToolsToggleAction::kShow: 1335 case DevToolsToggleAction::kShow:
1319 case DevToolsToggleAction::kToggle: 1336 case DevToolsToggleAction::kToggle:
1320 // Do nothing. 1337 // Do nothing.
1321 break; 1338 break;
1322 1339
1323 case DevToolsToggleAction::kReveal: { 1340 case DevToolsToggleAction::kReveal: {
1324 const DevToolsToggleAction::RevealParams* params = 1341 const DevToolsToggleAction::RevealParams* params =
1325 action.params(); 1342 action.params();
1326 CHECK(params); 1343 CHECK(params);
1327 base::StringValue url_value(params->url); 1344 base::StringValue url_value(params->url);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 bool DevToolsWindow::ReloadInspectedWebContents(bool bypass_cache) { 1399 bool DevToolsWindow::ReloadInspectedWebContents(bool bypass_cache) {
1383 // Only route reload via front-end if the agent is attached. 1400 // Only route reload via front-end if the agent is attached.
1384 WebContents* wc = GetInspectedWebContents(); 1401 WebContents* wc = GetInspectedWebContents();
1385 if (!wc || wc->GetCrashedStatus() != base::TERMINATION_STATUS_STILL_RUNNING) 1402 if (!wc || wc->GetCrashedStatus() != base::TERMINATION_STATUS_STILL_RUNNING)
1386 return false; 1403 return false;
1387 base::FundamentalValue bypass_cache_value(bypass_cache); 1404 base::FundamentalValue bypass_cache_value(bypass_cache);
1388 bindings_->CallClientFunction("DevToolsAPI.reloadInspectedPage", 1405 bindings_->CallClientFunction("DevToolsAPI.reloadInspectedPage",
1389 &bypass_cache_value, nullptr, nullptr); 1406 &bypass_cache_value, nullptr, nullptr);
1390 return true; 1407 return true;
1391 } 1408 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698