| 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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 return; | 443 return; |
| 444 window->bindings_->AttachTo(worker_agent); | 444 window->bindings_->AttachTo(worker_agent); |
| 445 } | 445 } |
| 446 window->ScheduleShow(DevToolsToggleAction::Show()); | 446 window->ScheduleShow(DevToolsToggleAction::Show()); |
| 447 } | 447 } |
| 448 | 448 |
| 449 // static | 449 // static |
| 450 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( | 450 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( |
| 451 Profile* profile) { | 451 Profile* profile) { |
| 452 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); | 452 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); |
| 453 return Create(profile, GURL(), NULL, true, std::string(), false, ""); | 453 return Create(profile, GURL(), NULL, true, false, std::string(), false, ""); |
| 454 } | 454 } |
| 455 | 455 |
| 456 // static | 456 // static |
| 457 void DevToolsWindow::OpenDevToolsWindow( | 457 void DevToolsWindow::OpenDevToolsWindow( |
| 458 content::WebContents* inspected_web_contents) { | 458 content::WebContents* inspected_web_contents) { |
| 459 ToggleDevToolsWindow( | 459 ToggleDevToolsWindow( |
| 460 inspected_web_contents, true, DevToolsToggleAction::Show(), ""); | 460 inspected_web_contents, true, DevToolsToggleAction::Show(), ""); |
| 461 } | 461 } |
| 462 | 462 |
| 463 // static | 463 // static |
| 464 void DevToolsWindow::OpenDevToolsWindow( | 464 void DevToolsWindow::OpenDevToolsWindow( |
| 465 content::WebContents* inspected_web_contents, | 465 content::WebContents* inspected_web_contents, |
| 466 const DevToolsToggleAction& action) { | 466 const DevToolsToggleAction& action) { |
| 467 ToggleDevToolsWindow(inspected_web_contents, true, action, ""); | 467 ToggleDevToolsWindow(inspected_web_contents, true, action, ""); |
| 468 } | 468 } |
| 469 | 469 |
| 470 // static | 470 // static |
| 471 void DevToolsWindow::OpenDevToolsWindow( | 471 void DevToolsWindow::OpenDevToolsWindow( |
| 472 Profile* profile, | 472 Profile* profile, |
| 473 const scoped_refptr<content::DevToolsAgentHost>& agent_host) { | 473 const scoped_refptr<content::DevToolsAgentHost>& agent_host) { |
| 474 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); | 474 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); |
| 475 if (!window) { | 475 if (!window) { |
| 476 window = DevToolsWindow::Create( | 476 window = DevToolsWindow::Create(profile, GURL(), nullptr, false, false, |
| 477 profile, GURL(), nullptr, false, std::string(), false, std::string()); | 477 std::string(), false, std::string()); |
| 478 if (!window) | 478 if (!window) |
| 479 return; | 479 return; |
| 480 window->bindings_->AttachTo(agent_host); | 480 window->bindings_->AttachTo(agent_host); |
| 481 } | 481 } |
| 482 window->ScheduleShow(DevToolsToggleAction::Show()); | 482 window->ScheduleShow(DevToolsToggleAction::Show()); |
| 483 } | 483 } |
| 484 | 484 |
| 485 // static | 485 // static |
| 486 void DevToolsWindow::ToggleDevToolsWindow( | 486 void DevToolsWindow::ToggleDevToolsWindow( |
| 487 Browser* browser, | 487 Browser* browser, |
| 488 const DevToolsToggleAction& action) { | 488 const DevToolsToggleAction& action) { |
| 489 if (action.type() == DevToolsToggleAction::kToggle && | 489 if (action.type() == DevToolsToggleAction::kToggle && |
| 490 browser->is_devtools()) { | 490 browser->is_devtools()) { |
| 491 browser->tab_strip_model()->CloseAllTabs(); | 491 browser->tab_strip_model()->CloseAllTabs(); |
| 492 return; | 492 return; |
| 493 } | 493 } |
| 494 | 494 |
| 495 ToggleDevToolsWindow( | 495 ToggleDevToolsWindow( |
| 496 browser->tab_strip_model()->GetActiveWebContents(), | 496 browser->tab_strip_model()->GetActiveWebContents(), |
| 497 action.type() == DevToolsToggleAction::kInspect, | 497 action.type() == DevToolsToggleAction::kInspect, |
| 498 action, ""); | 498 action, ""); |
| 499 } | 499 } |
| 500 | 500 |
| 501 // static | 501 // static |
| 502 void DevToolsWindow::OpenExternalFrontend( | 502 void DevToolsWindow::OpenExternalFrontend( |
| 503 Profile* profile, | 503 Profile* profile, |
| 504 const std::string& frontend_url, | 504 const std::string& frontend_url, |
| 505 const scoped_refptr<content::DevToolsAgentHost>& agent_host, | 505 const scoped_refptr<content::DevToolsAgentHost>& agent_host, |
| 506 bool isWorker) { | 506 bool is_worker, |
| 507 bool is_v8_only) { |
| 507 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); | 508 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); |
| 508 if (!window) { | 509 if (!window) { |
| 509 window = Create(profile, GURL(), nullptr, isWorker, | 510 window = Create(profile, GURL(), nullptr, is_worker, is_v8_only, |
| 510 DevToolsUI::GetProxyURL(frontend_url).spec(), false, std::string()); | 511 DevToolsUI::GetProxyURL(frontend_url).spec(), false, std::string()); |
| 511 if (!window) | 512 if (!window) |
| 512 return; | 513 return; |
| 513 window->bindings_->AttachTo(agent_host); | 514 window->bindings_->AttachTo(agent_host); |
| 514 } | 515 } |
| 515 | 516 |
| 516 window->ScheduleShow(DevToolsToggleAction::Show()); | 517 window->ScheduleShow(DevToolsToggleAction::Show()); |
| 517 } | 518 } |
| 518 | 519 |
| 519 // static | 520 // static |
| 520 void DevToolsWindow::ToggleDevToolsWindow( | 521 void DevToolsWindow::ToggleDevToolsWindow( |
| 521 content::WebContents* inspected_web_contents, | 522 content::WebContents* inspected_web_contents, |
| 522 bool force_open, | 523 bool force_open, |
| 523 const DevToolsToggleAction& action, | 524 const DevToolsToggleAction& action, |
| 524 const std::string& settings) { | 525 const std::string& settings) { |
| 525 scoped_refptr<DevToolsAgentHost> agent( | 526 scoped_refptr<DevToolsAgentHost> agent( |
| 526 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); | 527 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); |
| 527 DevToolsWindow* window = FindDevToolsWindow(agent.get()); | 528 DevToolsWindow* window = FindDevToolsWindow(agent.get()); |
| 528 bool do_open = force_open; | 529 bool do_open = force_open; |
| 529 if (!window) { | 530 if (!window) { |
| 530 Profile* profile = Profile::FromBrowserContext( | 531 Profile* profile = Profile::FromBrowserContext( |
| 531 inspected_web_contents->GetBrowserContext()); | 532 inspected_web_contents->GetBrowserContext()); |
| 532 content::RecordAction( | 533 content::RecordAction( |
| 533 base::UserMetricsAction("DevTools_InspectRenderer")); | 534 base::UserMetricsAction("DevTools_InspectRenderer")); |
| 534 window = Create(profile, GURL(), inspected_web_contents, | 535 window = Create(profile, GURL(), inspected_web_contents, |
| 535 false, std::string(), true, settings); | 536 false, false, std::string(), true, settings); |
| 536 if (!window) | 537 if (!window) |
| 537 return; | 538 return; |
| 538 window->bindings_->AttachTo(agent.get()); | 539 window->bindings_->AttachTo(agent.get()); |
| 539 do_open = true; | 540 do_open = true; |
| 540 } | 541 } |
| 541 | 542 |
| 542 // Update toolbar to reflect DevTools changes. | 543 // Update toolbar to reflect DevTools changes. |
| 543 window->UpdateBrowserToolbar(); | 544 window->UpdateBrowserToolbar(); |
| 544 | 545 |
| 545 // If window is docked and visible, we hide it on toggle. If window is | 546 // If window is docked and visible, we hide it on toggle. If window is |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 for (const auto& callback : copy) | 776 for (const auto& callback : copy) |
| 776 callback.Run(this); | 777 callback.Run(this); |
| 777 } | 778 } |
| 778 | 779 |
| 779 // static | 780 // static |
| 780 DevToolsWindow* DevToolsWindow::Create( | 781 DevToolsWindow* DevToolsWindow::Create( |
| 781 Profile* profile, | 782 Profile* profile, |
| 782 const GURL& frontend_url, | 783 const GURL& frontend_url, |
| 783 content::WebContents* inspected_web_contents, | 784 content::WebContents* inspected_web_contents, |
| 784 bool shared_worker_frontend, | 785 bool shared_worker_frontend, |
| 786 bool v8_only_frontend, |
| 785 const std::string& remote_frontend, | 787 const std::string& remote_frontend, |
| 786 bool can_dock, | 788 bool can_dock, |
| 787 const std::string& settings) { | 789 const std::string& settings) { |
| 788 if (profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled) || | 790 if (profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled) || |
| 789 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) | 791 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) |
| 790 return nullptr; | 792 return nullptr; |
| 791 | 793 |
| 792 if (inspected_web_contents) { | 794 if (inspected_web_contents) { |
| 793 // Check for a place to dock. | 795 // Check for a place to dock. |
| 794 Browser* browser = NULL; | 796 Browser* browser = NULL; |
| 795 int tab; | 797 int tab; |
| 796 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents, | 798 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents, |
| 797 &browser, &tab) || | 799 &browser, &tab) || |
| 798 browser->is_type_popup()) { | 800 browser->is_type_popup()) { |
| 799 can_dock = false; | 801 can_dock = false; |
| 800 } | 802 } |
| 801 } | 803 } |
| 802 | 804 |
| 803 // Create WebContents with devtools. | 805 // Create WebContents with devtools. |
| 804 GURL url(GetDevToolsURL(profile, frontend_url, | 806 GURL url(GetDevToolsURL(profile, frontend_url, |
| 805 shared_worker_frontend, | 807 shared_worker_frontend, |
| 808 v8_only_frontend, |
| 806 remote_frontend, | 809 remote_frontend, |
| 807 can_dock)); | 810 can_dock)); |
| 808 std::unique_ptr<WebContents> main_web_contents( | 811 std::unique_ptr<WebContents> main_web_contents( |
| 809 WebContents::Create(WebContents::CreateParams(profile))); | 812 WebContents::Create(WebContents::CreateParams(profile))); |
| 810 main_web_contents->GetController().LoadURL( | 813 main_web_contents->GetController().LoadURL( |
| 811 DecorateFrontendURL(url), content::Referrer(), | 814 DecorateFrontendURL(url), content::Referrer(), |
| 812 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); | 815 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); |
| 813 DevToolsUIBindings* bindings = | 816 DevToolsUIBindings* bindings = |
| 814 DevToolsUIBindings::ForWebContents(main_web_contents.get()); | 817 DevToolsUIBindings::ForWebContents(main_web_contents.get()); |
| 815 if (!bindings) | 818 if (!bindings) |
| 816 return nullptr; | 819 return nullptr; |
| 817 if (!settings.empty()) | 820 if (!settings.empty()) |
| 818 SetPreferencesFromJson(profile, settings); | 821 SetPreferencesFromJson(profile, settings); |
| 819 return new DevToolsWindow(profile, main_web_contents.release(), bindings, | 822 return new DevToolsWindow(profile, main_web_contents.release(), bindings, |
| 820 inspected_web_contents, can_dock); | 823 inspected_web_contents, can_dock); |
| 821 } | 824 } |
| 822 | 825 |
| 823 // static | 826 // static |
| 824 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, | 827 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, |
| 825 const GURL& base_url, | 828 const GURL& base_url, |
| 826 bool shared_worker_frontend, | 829 bool shared_worker_frontend, |
| 830 bool v8_only_frontend, |
| 827 const std::string& remote_frontend, | 831 const std::string& remote_frontend, |
| 828 bool can_dock) { | 832 bool can_dock) { |
| 829 // Compatibility errors are encoded with data urls, pass them | 833 // Compatibility errors are encoded with data urls, pass them |
| 830 // through with no decoration. | 834 // through with no decoration. |
| 831 if (base_url.SchemeIs("data")) | 835 if (base_url.SchemeIs("data")) |
| 832 return base_url; | 836 return base_url; |
| 833 | 837 |
| 834 std::string frontend_url( | 838 std::string frontend_url( |
| 835 !remote_frontend.empty() ? | 839 !remote_frontend.empty() ? |
| 836 remote_frontend : | 840 remote_frontend : |
| 837 base_url.is_empty() ? chrome::kChromeUIDevToolsURL : base_url.spec()); | 841 base_url.is_empty() ? chrome::kChromeUIDevToolsURL : base_url.spec()); |
| 838 std::string url_string( | 842 std::string url_string( |
| 839 frontend_url + | 843 frontend_url + |
| 840 ((frontend_url.find("?") == std::string::npos) ? "?" : "&")); | 844 ((frontend_url.find("?") == std::string::npos) ? "?" : "&")); |
| 841 if (shared_worker_frontend) | 845 if (shared_worker_frontend) |
| 842 url_string += "&isSharedWorker=true"; | 846 url_string += "&isSharedWorker=true"; |
| 847 if (v8_only_frontend) |
| 848 url_string += "&v8only=true"; |
| 843 if (remote_frontend.size()) { | 849 if (remote_frontend.size()) { |
| 844 url_string += "&remoteFrontend=true"; | 850 url_string += "&remoteFrontend=true"; |
| 845 } else { | 851 } else { |
| 846 url_string += "&remoteBase=" + DevToolsUI::GetRemoteBaseURL().spec(); | 852 url_string += "&remoteBase=" + DevToolsUI::GetRemoteBaseURL().spec(); |
| 847 } | 853 } |
| 848 if (can_dock) | 854 if (can_dock) |
| 849 url_string += "&can_dock=true"; | 855 url_string += "&can_dock=true"; |
| 850 return GURL(url_string); | 856 return GURL(url_string); |
| 851 } | 857 } |
| 852 | 858 |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1314 bool DevToolsWindow::ReloadInspectedWebContents(bool bypass_cache) { | 1320 bool DevToolsWindow::ReloadInspectedWebContents(bool bypass_cache) { |
| 1315 // Only route reload via front-end if the agent is attached. | 1321 // Only route reload via front-end if the agent is attached. |
| 1316 WebContents* wc = GetInspectedWebContents(); | 1322 WebContents* wc = GetInspectedWebContents(); |
| 1317 if (!wc || wc->GetCrashedStatus() != base::TERMINATION_STATUS_STILL_RUNNING) | 1323 if (!wc || wc->GetCrashedStatus() != base::TERMINATION_STATUS_STILL_RUNNING) |
| 1318 return false; | 1324 return false; |
| 1319 base::FundamentalValue bypass_cache_value(bypass_cache); | 1325 base::FundamentalValue bypass_cache_value(bypass_cache); |
| 1320 bindings_->CallClientFunction("DevToolsAPI.reloadInspectedPage", | 1326 bindings_->CallClientFunction("DevToolsAPI.reloadInspectedPage", |
| 1321 &bypass_cache_value, nullptr, nullptr); | 1327 &bypass_cache_value, nullptr, nullptr); |
| 1322 return true; | 1328 return true; |
| 1323 } | 1329 } |
| OLD | NEW |