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 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 | 459 |
460 // static | 460 // static |
461 void DevToolsWindow::OpenDevToolsWindow( | 461 void DevToolsWindow::OpenDevToolsWindow( |
462 content::WebContents* inspected_web_contents) { | 462 content::WebContents* inspected_web_contents) { |
463 ToggleDevToolsWindow( | 463 ToggleDevToolsWindow( |
464 inspected_web_contents, true, DevToolsToggleAction::Show(), ""); | 464 inspected_web_contents, true, DevToolsToggleAction::Show(), ""); |
465 } | 465 } |
466 | 466 |
467 // static | 467 // static |
468 void DevToolsWindow::OpenDevToolsWindow( | 468 void DevToolsWindow::OpenDevToolsWindow( |
| 469 scoped_refptr<content::DevToolsAgentHost> agent_host, |
| 470 Profile* profile) { |
| 471 if (!profile) |
| 472 profile = Profile::FromBrowserContext(agent_host->GetBrowserContext()); |
| 473 |
| 474 if (!profile) |
| 475 return; |
| 476 |
| 477 std::string type = agent_host->GetType(); |
| 478 bool is_worker = type == DevToolsAgentHost::kTypeServiceWorker || |
| 479 type == DevToolsAgentHost::kTypeSharedWorker; |
| 480 |
| 481 if (!agent_host->GetFrontendURL().empty()) { |
| 482 bool is_v8_only = type == "node"; |
| 483 DevToolsWindow::OpenExternalFrontend(profile, agent_host->GetFrontendURL(), |
| 484 agent_host, is_worker, is_v8_only); |
| 485 return; |
| 486 } |
| 487 |
| 488 if (is_worker) { |
| 489 DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); |
| 490 return; |
| 491 } |
| 492 |
| 493 if (type == content::DevToolsAgentHost::kTypeFrame) { |
| 494 DevToolsWindow::OpenDevToolsWindowForFrame(profile, agent_host); |
| 495 return; |
| 496 } |
| 497 |
| 498 content::WebContents* web_contents = agent_host->GetWebContents(); |
| 499 if (web_contents) |
| 500 DevToolsWindow::OpenDevToolsWindow(web_contents); |
| 501 } |
| 502 |
| 503 // static |
| 504 void DevToolsWindow::OpenDevToolsWindow( |
469 content::WebContents* inspected_web_contents, | 505 content::WebContents* inspected_web_contents, |
470 const DevToolsToggleAction& action) { | 506 const DevToolsToggleAction& action) { |
471 ToggleDevToolsWindow(inspected_web_contents, true, action, ""); | 507 ToggleDevToolsWindow(inspected_web_contents, true, action, ""); |
472 } | 508 } |
473 | 509 |
474 // static | 510 // static |
475 void DevToolsWindow::OpenDevToolsWindow( | 511 void DevToolsWindow::OpenDevToolsWindowForFrame( |
476 Profile* profile, | 512 Profile* profile, |
477 const scoped_refptr<content::DevToolsAgentHost>& agent_host) { | 513 const scoped_refptr<content::DevToolsAgentHost>& agent_host) { |
478 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); | 514 DevToolsWindow* window = FindDevToolsWindow(agent_host.get()); |
479 if (!window) { | 515 if (!window) { |
480 window = DevToolsWindow::Create(profile, GURL(), nullptr, false, false, | 516 window = DevToolsWindow::Create(profile, GURL(), nullptr, false, false, |
481 std::string(), false, std::string()); | 517 std::string(), false, std::string()); |
482 if (!window) | 518 if (!window) |
483 return; | 519 return; |
484 window->bindings_->AttachTo(agent_host); | 520 window->bindings_->AttachTo(agent_host); |
485 } | 521 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 int y) { | 598 int y) { |
563 scoped_refptr<DevToolsAgentHost> agent( | 599 scoped_refptr<DevToolsAgentHost> agent( |
564 DevToolsAgentHost::GetOrCreateFor(inspected_frame_host)); | 600 DevToolsAgentHost::GetOrCreateFor(inspected_frame_host)); |
565 bool should_measure_time = FindDevToolsWindow(agent.get()) == NULL; | 601 bool should_measure_time = FindDevToolsWindow(agent.get()) == NULL; |
566 base::TimeTicks start_time = base::TimeTicks::Now(); | 602 base::TimeTicks start_time = base::TimeTicks::Now(); |
567 // TODO(loislo): we should initiate DevTools window opening from within | 603 // TODO(loislo): we should initiate DevTools window opening from within |
568 // renderer. Otherwise, we still can hit a race condition here. | 604 // renderer. Otherwise, we still can hit a race condition here. |
569 if (agent->GetType() == content::DevToolsAgentHost::kTypePage) { | 605 if (agent->GetType() == content::DevToolsAgentHost::kTypePage) { |
570 OpenDevToolsWindow(agent->GetWebContents()); | 606 OpenDevToolsWindow(agent->GetWebContents()); |
571 } else { | 607 } else { |
572 OpenDevToolsWindow(Profile::FromBrowserContext(agent->GetBrowserContext()), | 608 OpenDevToolsWindowForFrame(Profile::FromBrowserContext( |
573 agent); | 609 agent->GetBrowserContext()), agent); |
574 } | 610 } |
575 DevToolsWindow* window = FindDevToolsWindow(agent.get()); | 611 DevToolsWindow* window = FindDevToolsWindow(agent.get()); |
576 if (window) { | 612 if (window) { |
577 agent->InspectElement(window->bindings_, x, y); | 613 agent->InspectElement(window->bindings_, x, y); |
578 if (should_measure_time) | 614 if (should_measure_time) |
579 window->inspect_element_start_time_ = start_time; | 615 window->inspect_element_start_time_ = start_time; |
580 } | 616 } |
581 } | 617 } |
582 | 618 |
583 void DevToolsWindow::ScheduleShow(const DevToolsToggleAction& action) { | 619 void DevToolsWindow::ScheduleShow(const DevToolsToggleAction& action) { |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 else if (!is_docked_ && !browser_->window()->IsActive()) | 1107 else if (!is_docked_ && !browser_->window()->IsActive()) |
1072 browser_->window()->Activate(); | 1108 browser_->window()->Activate(); |
1073 } | 1109 } |
1074 | 1110 |
1075 void DevToolsWindow::CloseWindow() { | 1111 void DevToolsWindow::CloseWindow() { |
1076 DCHECK(is_docked_); | 1112 DCHECK(is_docked_); |
1077 life_stage_ = kClosing; | 1113 life_stage_ = kClosing; |
1078 main_web_contents_->DispatchBeforeUnload(); | 1114 main_web_contents_->DispatchBeforeUnload(); |
1079 } | 1115 } |
1080 | 1116 |
| 1117 void DevToolsWindow::Inspect(scoped_refptr<content::DevToolsAgentHost> host) { |
| 1118 DevToolsWindow::OpenDevToolsWindow(host, nullptr); |
| 1119 } |
| 1120 |
1081 void DevToolsWindow::SetInspectedPageBounds(const gfx::Rect& rect) { | 1121 void DevToolsWindow::SetInspectedPageBounds(const gfx::Rect& rect) { |
1082 DevToolsContentsResizingStrategy strategy(rect); | 1122 DevToolsContentsResizingStrategy strategy(rect); |
1083 if (contents_resizing_strategy_.Equals(strategy)) | 1123 if (contents_resizing_strategy_.Equals(strategy)) |
1084 return; | 1124 return; |
1085 | 1125 |
1086 contents_resizing_strategy_.CopyFrom(strategy); | 1126 contents_resizing_strategy_.CopyFrom(strategy); |
1087 UpdateBrowserWindow(); | 1127 UpdateBrowserWindow(); |
1088 } | 1128 } |
1089 | 1129 |
1090 void DevToolsWindow::InspectElementCompleted() { | 1130 void DevToolsWindow::InspectElementCompleted() { |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1321 bool DevToolsWindow::ReloadInspectedWebContents(bool bypass_cache) { | 1361 bool DevToolsWindow::ReloadInspectedWebContents(bool bypass_cache) { |
1322 // Only route reload via front-end if the agent is attached. | 1362 // Only route reload via front-end if the agent is attached. |
1323 WebContents* wc = GetInspectedWebContents(); | 1363 WebContents* wc = GetInspectedWebContents(); |
1324 if (!wc || wc->GetCrashedStatus() != base::TERMINATION_STATUS_STILL_RUNNING) | 1364 if (!wc || wc->GetCrashedStatus() != base::TERMINATION_STATUS_STILL_RUNNING) |
1325 return false; | 1365 return false; |
1326 base::FundamentalValue bypass_cache_value(bypass_cache); | 1366 base::FundamentalValue bypass_cache_value(bypass_cache); |
1327 bindings_->CallClientFunction("DevToolsAPI.reloadInspectedPage", | 1367 bindings_->CallClientFunction("DevToolsAPI.reloadInspectedPage", |
1328 &bypass_cache_value, nullptr, nullptr); | 1368 &bypass_cache_value, nullptr, nullptr); |
1329 return true; | 1369 return true; |
1330 } | 1370 } |
OLD | NEW |