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/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
296 bool DevToolsWindow::IsDevToolsWindow(content::RenderViewHost* window_rvh) { | 296 bool DevToolsWindow::IsDevToolsWindow(content::RenderViewHost* window_rvh) { |
297 return AsDevToolsWindow(window_rvh) != NULL; | 297 return AsDevToolsWindow(window_rvh) != NULL; |
298 } | 298 } |
299 | 299 |
300 // static | 300 // static |
301 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( | 301 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( |
302 Profile* profile, | 302 Profile* profile, |
303 DevToolsAgentHost* worker_agent) { | 303 DevToolsAgentHost* worker_agent) { |
304 DevToolsWindow* window = FindDevToolsWindow(worker_agent); | 304 DevToolsWindow* window = FindDevToolsWindow(worker_agent); |
305 if (!window) { | 305 if (!window) { |
306 window = DevToolsWindow::CreateDevToolsWindowForWorker(profile); | 306 window = DevToolsWindow::CreateDevToolsWindowForWorker( |
307 profile, worker_agent->IsWorkerPaused()); | |
307 // Will disconnect the current client host if there is one. | 308 // Will disconnect the current client host if there is one. |
308 content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( | 309 content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( |
309 worker_agent, window->bindings_->frontend_host()); | 310 worker_agent, window->bindings_->frontend_host()); |
310 } | 311 } |
311 window->ScheduleShow(DevToolsToggleAction::Show()); | 312 window->ScheduleShow(DevToolsToggleAction::Show()); |
312 return window; | 313 return window; |
313 } | 314 } |
314 | 315 |
315 // static | 316 // static |
316 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( | 317 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( |
317 Profile* profile) { | 318 Profile* profile, |
319 bool worker_paused) { | |
318 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); | 320 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); |
319 return Create(profile, GURL(), NULL, true, false, false); | 321 return Create(profile, GURL(), NULL, true, worker_paused, false, false); |
320 } | 322 } |
321 | 323 |
322 // static | 324 // static |
323 DevToolsWindow* DevToolsWindow::OpenDevToolsWindow( | 325 DevToolsWindow* DevToolsWindow::OpenDevToolsWindow( |
324 content::RenderViewHost* inspected_rvh) { | 326 content::RenderViewHost* inspected_rvh) { |
325 return ToggleDevToolsWindow( | 327 return ToggleDevToolsWindow( |
326 inspected_rvh, true, DevToolsToggleAction::Show()); | 328 inspected_rvh, true, DevToolsToggleAction::Show()); |
327 } | 329 } |
328 | 330 |
329 // static | 331 // static |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 action.type() == DevToolsToggleAction::kInspect, action); | 369 action.type() == DevToolsToggleAction::kInspect, action); |
368 } | 370 } |
369 | 371 |
370 // static | 372 // static |
371 void DevToolsWindow::OpenExternalFrontend( | 373 void DevToolsWindow::OpenExternalFrontend( |
372 Profile* profile, | 374 Profile* profile, |
373 const std::string& frontend_url, | 375 const std::string& frontend_url, |
374 content::DevToolsAgentHost* agent_host) { | 376 content::DevToolsAgentHost* agent_host) { |
375 DevToolsWindow* window = FindDevToolsWindow(agent_host); | 377 DevToolsWindow* window = FindDevToolsWindow(agent_host); |
376 if (!window) { | 378 if (!window) { |
377 window = Create(profile, DevToolsUI::GetProxyURL(frontend_url), NULL, | 379 window = Create(profile, |
378 false, true, false); | 380 DevToolsUI::GetProxyURL(frontend_url), |
381 NULL, | |
382 false, | |
383 false, | |
384 true, | |
385 false); | |
379 content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( | 386 content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( |
380 agent_host, window->bindings_->frontend_host()); | 387 agent_host, window->bindings_->frontend_host()); |
381 } | 388 } |
382 window->ScheduleShow(DevToolsToggleAction::Show()); | 389 window->ScheduleShow(DevToolsToggleAction::Show()); |
383 } | 390 } |
384 | 391 |
385 // static | 392 // static |
386 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( | 393 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( |
387 content::RenderViewHost* inspected_rvh, | 394 content::RenderViewHost* inspected_rvh, |
388 bool force_open, | 395 bool force_open, |
389 const DevToolsToggleAction& action) { | 396 const DevToolsToggleAction& action) { |
390 scoped_refptr<DevToolsAgentHost> agent( | 397 scoped_refptr<DevToolsAgentHost> agent( |
391 DevToolsAgentHost::GetOrCreateFor(inspected_rvh)); | 398 DevToolsAgentHost::GetOrCreateFor(inspected_rvh)); |
392 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); | 399 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); |
393 DevToolsWindow* window = FindDevToolsWindow(agent.get()); | 400 DevToolsWindow* window = FindDevToolsWindow(agent.get()); |
394 bool do_open = force_open; | 401 bool do_open = force_open; |
395 if (!window) { | 402 if (!window) { |
396 Profile* profile = Profile::FromBrowserContext( | 403 Profile* profile = Profile::FromBrowserContext( |
397 inspected_rvh->GetProcess()->GetBrowserContext()); | 404 inspected_rvh->GetProcess()->GetBrowserContext()); |
398 content::RecordAction( | 405 content::RecordAction( |
399 base::UserMetricsAction("DevTools_InspectRenderer")); | 406 base::UserMetricsAction("DevTools_InspectRenderer")); |
400 window = Create(profile, GURL(), inspected_rvh, false, false, true); | 407 window = Create(profile, GURL(), inspected_rvh, false, false, false, true); |
401 manager->RegisterDevToolsClientHostFor(agent.get(), | 408 manager->RegisterDevToolsClientHostFor(agent.get(), |
402 window->bindings_->frontend_host()); | 409 window->bindings_->frontend_host()); |
403 do_open = true; | 410 do_open = true; |
404 } | 411 } |
405 | 412 |
406 // Update toolbar to reflect DevTools changes. | 413 // Update toolbar to reflect DevTools changes. |
407 window->UpdateBrowserToolbar(); | 414 window->UpdateBrowserToolbar(); |
408 | 415 |
409 // If window is docked and visible, we hide it on toggle. If window is | 416 // If window is docked and visible, we hide it on toggle. If window is |
410 // undocked, we show (activate) it. | 417 // undocked, we show (activate) it. |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
615 g_instances.Get().push_back(this); | 622 g_instances.Get().push_back(this); |
616 | 623 |
617 // There is no inspected_rvh in case of shared workers. | 624 // There is no inspected_rvh in case of shared workers. |
618 if (inspected_rvh) | 625 if (inspected_rvh) |
619 inspected_contents_observer_.reset(new InspectedWebContentsObserver( | 626 inspected_contents_observer_.reset(new InspectedWebContentsObserver( |
620 content::WebContents::FromRenderViewHost(inspected_rvh))); | 627 content::WebContents::FromRenderViewHost(inspected_rvh))); |
621 event_forwarder_.reset(new DevToolsEventForwarder(this)); | 628 event_forwarder_.reset(new DevToolsEventForwarder(this)); |
622 } | 629 } |
623 | 630 |
624 // static | 631 // static |
625 DevToolsWindow* DevToolsWindow::Create( | 632 DevToolsWindow* DevToolsWindow::Create(Profile* profile, |
626 Profile* profile, | 633 const GURL& frontend_url, |
627 const GURL& frontend_url, | 634 content::RenderViewHost* inspected_rvh, |
628 content::RenderViewHost* inspected_rvh, | 635 bool shared_worker_frontend, |
629 bool shared_worker_frontend, | 636 bool worker_paused, |
pfeldman
2014/05/20 19:20:41
we should not pass state or capabilities-related p
| |
630 bool external_frontend, | 637 bool external_frontend, |
631 bool can_dock) { | 638 bool can_dock) { |
632 if (inspected_rvh) { | 639 if (inspected_rvh) { |
633 // Check for a place to dock. | 640 // Check for a place to dock. |
634 Browser* browser = NULL; | 641 Browser* browser = NULL; |
635 int tab; | 642 int tab; |
636 WebContents* inspected_web_contents = | 643 WebContents* inspected_web_contents = |
637 content::WebContents::FromRenderViewHost(inspected_rvh); | 644 content::WebContents::FromRenderViewHost(inspected_rvh); |
638 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents, | 645 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents, |
639 &browser, &tab) || | 646 &browser, &tab) || |
640 inspected_rvh->GetMainFrame()->IsCrossProcessSubframe() || | 647 inspected_rvh->GetMainFrame()->IsCrossProcessSubframe() || |
641 browser->is_type_popup()) { | 648 browser->is_type_popup()) { |
642 can_dock = false; | 649 can_dock = false; |
643 } | 650 } |
644 } | 651 } |
645 | 652 |
646 // Create WebContents with devtools. | 653 // Create WebContents with devtools. |
647 GURL url(GetDevToolsURL(profile, frontend_url, | 654 GURL url(GetDevToolsURL(profile, |
655 frontend_url, | |
648 shared_worker_frontend, | 656 shared_worker_frontend, |
657 worker_paused, | |
649 external_frontend, | 658 external_frontend, |
650 can_dock)); | 659 can_dock)); |
651 return new DevToolsWindow(profile, url, inspected_rvh, can_dock); | 660 return new DevToolsWindow(profile, url, inspected_rvh, can_dock); |
652 } | 661 } |
653 | 662 |
654 // static | 663 // static |
655 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, | 664 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, |
656 const GURL& base_url, | 665 const GURL& base_url, |
657 bool shared_worker_frontend, | 666 bool shared_worker_frontend, |
667 bool worker_paused, | |
658 bool external_frontend, | 668 bool external_frontend, |
659 bool can_dock) { | 669 bool can_dock) { |
660 // Compatibility errors are encoded with data urls, pass them | 670 // Compatibility errors are encoded with data urls, pass them |
661 // through with no decoration. | 671 // through with no decoration. |
662 if (base_url.SchemeIs("data")) | 672 if (base_url.SchemeIs("data")) |
663 return base_url; | 673 return base_url; |
664 | 674 |
665 std::string frontend_url( | 675 std::string frontend_url( |
666 base_url.is_empty() ? chrome::kChromeUIDevToolsURL : base_url.spec()); | 676 base_url.is_empty() ? chrome::kChromeUIDevToolsURL : base_url.spec()); |
667 std::string url_string( | 677 std::string url_string( |
668 frontend_url + | 678 frontend_url + |
669 ((frontend_url.find("?") == std::string::npos) ? "?" : "&")); | 679 ((frontend_url.find("?") == std::string::npos) ? "?" : "&")); |
670 if (shared_worker_frontend) | 680 if (shared_worker_frontend) |
671 url_string += "&isSharedWorker=true"; | 681 url_string += "&isSharedWorker=true"; |
682 if (worker_paused) | |
683 url_string += "&workerPaused=true"; | |
672 if (external_frontend) | 684 if (external_frontend) |
673 url_string += "&remoteFrontend=true"; | 685 url_string += "&remoteFrontend=true"; |
674 if (can_dock) | 686 if (can_dock) |
675 url_string += "&can_dock=true"; | 687 url_string += "&can_dock=true"; |
676 return GURL(url_string); | 688 return GURL(url_string); |
677 } | 689 } |
678 | 690 |
679 // static | 691 // static |
680 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( | 692 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( |
681 DevToolsAgentHost* agent_host) { | 693 DevToolsAgentHost* agent_host) { |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1176 closure.Run(); | 1188 closure.Run(); |
1177 return; | 1189 return; |
1178 } | 1190 } |
1179 load_completed_callback_ = closure; | 1191 load_completed_callback_ = closure; |
1180 } | 1192 } |
1181 | 1193 |
1182 bool DevToolsWindow::ForwardKeyboardEvent( | 1194 bool DevToolsWindow::ForwardKeyboardEvent( |
1183 const content::NativeWebKeyboardEvent& event) { | 1195 const content::NativeWebKeyboardEvent& event) { |
1184 return event_forwarder_->ForwardEvent(event); | 1196 return event_forwarder_->ForwardEvent(event); |
1185 } | 1197 } |
OLD | NEW |