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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
435 | 435 |
436 // static | 436 // static |
437 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( | 437 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( |
438 Profile* profile) { | 438 Profile* profile) { |
439 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); | 439 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); |
440 return Create(profile, GURL(), NULL, true, false, false, ""); | 440 return Create(profile, GURL(), NULL, true, false, false, ""); |
441 } | 441 } |
442 | 442 |
443 // static | 443 // static |
444 DevToolsWindow* DevToolsWindow::OpenDevToolsWindow( | 444 DevToolsWindow* DevToolsWindow::OpenDevToolsWindow( |
445 content::RenderViewHost* inspected_rvh) { | 445 content::WebContents* inspected_web_contents) { |
446 return ToggleDevToolsWindow( | 446 return ToggleDevToolsWindow( |
447 inspected_rvh, true, DevToolsToggleAction::Show(), ""); | 447 inspected_web_contents, true, DevToolsToggleAction::Show(), ""); |
448 } | 448 } |
449 | 449 |
450 // static | 450 // static |
451 DevToolsWindow* DevToolsWindow::OpenDevToolsWindow( | 451 DevToolsWindow* DevToolsWindow::OpenDevToolsWindow( |
452 content::RenderViewHost* inspected_rvh, | 452 content::WebContents* inspected_web_contents, |
453 const DevToolsToggleAction& action) { | 453 const DevToolsToggleAction& action) { |
454 return ToggleDevToolsWindow(inspected_rvh, true, action, ""); | 454 return ToggleDevToolsWindow(inspected_web_contents, true, action, ""); |
455 } | 455 } |
456 | 456 |
457 // static | 457 // static |
458 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( | 458 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( |
459 Browser* browser, | 459 Browser* browser, |
460 const DevToolsToggleAction& action) { | 460 const DevToolsToggleAction& action) { |
461 if (action.type() == DevToolsToggleAction::kToggle && | 461 if (action.type() == DevToolsToggleAction::kToggle && |
462 browser->is_devtools()) { | 462 browser->is_devtools()) { |
463 browser->tab_strip_model()->CloseAllTabs(); | 463 browser->tab_strip_model()->CloseAllTabs(); |
464 return NULL; | 464 return NULL; |
465 } | 465 } |
466 | 466 |
467 return ToggleDevToolsWindow( | 467 DevToolsWindow* result = ToggleDevToolsWindow( |
dgozman
2014/08/06 13:06:09
Unnecessary |result| variable.
pfeldman
2014/08/06 16:26:35
Done.
| |
468 browser->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), | 468 browser->tab_strip_model()->GetActiveWebContents(), |
469 action.type() == DevToolsToggleAction::kInspect, action, ""); | 469 action.type() == DevToolsToggleAction::kInspect, action, ""); |
470 | |
471 | |
472 return result; | |
470 } | 473 } |
471 | 474 |
472 // static | 475 // static |
473 void DevToolsWindow::OpenExternalFrontend( | 476 void DevToolsWindow::OpenExternalFrontend( |
474 Profile* profile, | 477 Profile* profile, |
475 const std::string& frontend_url, | 478 const std::string& frontend_url, |
476 content::DevToolsAgentHost* agent_host) { | 479 content::DevToolsAgentHost* agent_host) { |
477 DevToolsWindow* window = FindDevToolsWindow(agent_host); | 480 DevToolsWindow* window = FindDevToolsWindow(agent_host); |
478 if (!window) { | 481 if (!window) { |
479 window = Create(profile, DevToolsUI::GetProxyURL(frontend_url), NULL, | 482 window = Create(profile, DevToolsUI::GetProxyURL(frontend_url), NULL, |
480 false, true, false, ""); | 483 false, true, false, ""); |
481 content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( | 484 content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( |
482 agent_host, window->bindings_); | 485 agent_host, window->bindings_); |
483 } | 486 } |
484 window->ScheduleShow(DevToolsToggleAction::Show()); | 487 window->ScheduleShow(DevToolsToggleAction::Show()); |
485 } | 488 } |
486 | 489 |
487 // static | 490 // static |
488 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( | 491 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( |
489 content::RenderViewHost* inspected_rvh, | 492 content::WebContents* inspected_web_contents, |
490 bool force_open, | 493 bool force_open, |
491 const DevToolsToggleAction& action, | 494 const DevToolsToggleAction& action, |
492 const std::string& settings) { | 495 const std::string& settings) { |
493 scoped_refptr<DevToolsAgentHost> agent( | 496 scoped_refptr<DevToolsAgentHost> agent( |
494 DevToolsAgentHost::GetOrCreateFor(inspected_rvh)); | 497 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); |
495 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); | 498 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); |
496 DevToolsWindow* window = FindDevToolsWindow(agent.get()); | 499 DevToolsWindow* window = FindDevToolsWindow(agent.get()); |
497 bool do_open = force_open; | 500 bool do_open = force_open; |
498 if (!window) { | 501 if (!window) { |
499 Profile* profile = Profile::FromBrowserContext( | 502 Profile* profile = Profile::FromBrowserContext( |
500 inspected_rvh->GetProcess()->GetBrowserContext()); | 503 inspected_web_contents->GetBrowserContext()); |
501 content::RecordAction( | 504 content::RecordAction( |
502 base::UserMetricsAction("DevTools_InspectRenderer")); | 505 base::UserMetricsAction("DevTools_InspectRenderer")); |
503 window = Create( | 506 window = Create( |
504 profile, GURL(), inspected_rvh, false, false, true, settings); | 507 profile, GURL(), inspected_web_contents, false, false, true, settings); |
505 manager->RegisterDevToolsClientHostFor(agent.get(), window->bindings_); | 508 manager->RegisterDevToolsClientHostFor(agent.get(), window->bindings_); |
506 do_open = true; | 509 do_open = true; |
507 } | 510 } |
508 | 511 |
509 // Update toolbar to reflect DevTools changes. | 512 // Update toolbar to reflect DevTools changes. |
510 window->UpdateBrowserToolbar(); | 513 window->UpdateBrowserToolbar(); |
511 | 514 |
512 // If window is docked and visible, we hide it on toggle. If window is | 515 // If window is docked and visible, we hide it on toggle. If window is |
513 // undocked, we show (activate) it. | 516 // undocked, we show (activate) it. |
514 if (!window->is_docked_ || do_open) | 517 if (!window->is_docked_ || do_open) |
515 window->ScheduleShow(action); | 518 window->ScheduleShow(action); |
516 else | 519 else |
517 window->CloseWindow(); | 520 window->CloseWindow(); |
518 | 521 |
519 return window; | 522 return window; |
520 } | 523 } |
521 | 524 |
522 // static | 525 // static |
523 void DevToolsWindow::InspectElement(content::RenderViewHost* inspected_rvh, | 526 void DevToolsWindow::InspectElement( |
524 int x, | 527 content::WebContents* inspected_web_contents, int x, int y) { |
525 int y) { | |
526 scoped_refptr<DevToolsAgentHost> agent( | 528 scoped_refptr<DevToolsAgentHost> agent( |
527 DevToolsAgentHost::GetOrCreateFor(inspected_rvh)); | 529 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); |
528 agent->InspectElement(x, y); | 530 agent->InspectElement(x, y); |
529 bool should_measure_time = FindDevToolsWindow(agent.get()) == NULL; | 531 bool should_measure_time = FindDevToolsWindow(agent.get()) == NULL; |
530 base::TimeTicks start_time = base::TimeTicks::Now(); | 532 base::TimeTicks start_time = base::TimeTicks::Now(); |
531 // TODO(loislo): we should initiate DevTools window opening from within | 533 // TODO(loislo): we should initiate DevTools window opening from within |
532 // renderer. Otherwise, we still can hit a race condition here. | 534 // renderer. Otherwise, we still can hit a race condition here. |
533 DevToolsWindow* window = OpenDevToolsWindow(inspected_rvh); | 535 DevToolsWindow* window = OpenDevToolsWindow(inspected_web_contents); |
534 if (should_measure_time) | 536 if (should_measure_time) |
535 window->inspect_element_start_time_ = start_time; | 537 window->inspect_element_start_time_ = start_time; |
536 } | 538 } |
537 | 539 |
538 void DevToolsWindow::ScheduleShow(const DevToolsToggleAction& action) { | 540 void DevToolsWindow::ScheduleShow(const DevToolsToggleAction& action) { |
539 if (life_stage_ == kLoadCompleted) { | 541 if (life_stage_ == kLoadCompleted) { |
540 Show(action); | 542 Show(action); |
541 return; | 543 return; |
542 } | 544 } |
543 | 545 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
672 DevToolsWindow::GetInstanceForInspectedWebContents(contents); | 674 DevToolsWindow::GetInstanceForInspectedWebContents(contents); |
673 if (!window) | 675 if (!window) |
674 return; | 676 return; |
675 window->intercepted_page_beforeunload_ = false; | 677 window->intercepted_page_beforeunload_ = false; |
676 // Propagate to devtools opened on devtools if any. | 678 // Propagate to devtools opened on devtools if any. |
677 DevToolsWindow::OnPageCloseCanceled(window->main_web_contents_); | 679 DevToolsWindow::OnPageCloseCanceled(window->main_web_contents_); |
678 } | 680 } |
679 | 681 |
680 DevToolsWindow::DevToolsWindow(Profile* profile, | 682 DevToolsWindow::DevToolsWindow(Profile* profile, |
681 const GURL& url, | 683 const GURL& url, |
682 content::RenderViewHost* inspected_rvh, | 684 content::WebContents* inspected_web_contents, |
683 bool can_dock) | 685 bool can_dock) |
684 : profile_(profile), | 686 : profile_(profile), |
685 main_web_contents_( | 687 main_web_contents_( |
686 WebContents::Create(WebContents::CreateParams(profile))), | 688 WebContents::Create(WebContents::CreateParams(profile))), |
687 toolbox_web_contents_(NULL), | 689 toolbox_web_contents_(NULL), |
688 bindings_(NULL), | 690 bindings_(NULL), |
689 browser_(NULL), | 691 browser_(NULL), |
690 is_docked_(true), | 692 is_docked_(true), |
691 can_dock_(can_dock), | 693 can_dock_(can_dock), |
692 // This initialization allows external front-end to work without changes. | 694 // This initialization allows external front-end to work without changes. |
(...skipping 11 matching lines...) Expand all Loading... | |
704 // Bindings take ownership over devtools as its delegate. | 706 // Bindings take ownership over devtools as its delegate. |
705 bindings_->SetDelegate(this); | 707 bindings_->SetDelegate(this); |
706 // DevTools uses chrome_page_zoom::Zoom(), so main_web_contents_ requires a | 708 // DevTools uses chrome_page_zoom::Zoom(), so main_web_contents_ requires a |
707 // ZoomController. | 709 // ZoomController. |
708 ZoomController::CreateForWebContents(main_web_contents_); | 710 ZoomController::CreateForWebContents(main_web_contents_); |
709 ZoomController::FromWebContents(main_web_contents_) | 711 ZoomController::FromWebContents(main_web_contents_) |
710 ->SetShowsNotificationBubble(false); | 712 ->SetShowsNotificationBubble(false); |
711 | 713 |
712 g_instances.Get().push_back(this); | 714 g_instances.Get().push_back(this); |
713 | 715 |
714 // There is no inspected_rvh in case of shared workers. | 716 // There is no inspected_web_contents in case of shared workers. |
715 if (inspected_rvh) | 717 if (inspected_web_contents) |
716 inspected_contents_observer_.reset(new ObserverWithAccessor( | 718 inspected_contents_observer_.reset(new ObserverWithAccessor( |
717 content::WebContents::FromRenderViewHost(inspected_rvh))); | 719 inspected_web_contents)); |
718 | 720 |
719 // Initialize docked page to be of the right size. | 721 // Initialize docked page to be of the right size. |
720 WebContents* inspected_web_contents = GetInspectedWebContents(); | |
721 if (can_dock_ && inspected_web_contents) { | 722 if (can_dock_ && inspected_web_contents) { |
722 content::RenderWidgetHostView* inspected_view = | 723 content::RenderWidgetHostView* inspected_view = |
723 inspected_web_contents->GetRenderWidgetHostView(); | 724 inspected_web_contents->GetRenderWidgetHostView(); |
724 if (inspected_view && main_web_contents_->GetRenderWidgetHostView()) { | 725 if (inspected_view && main_web_contents_->GetRenderWidgetHostView()) { |
725 gfx::Size size = inspected_view->GetViewBounds().size(); | 726 gfx::Size size = inspected_view->GetViewBounds().size(); |
726 main_web_contents_->GetRenderWidgetHostView()->SetSize(size); | 727 main_web_contents_->GetRenderWidgetHostView()->SetSize(size); |
727 } | 728 } |
728 } | 729 } |
729 | 730 |
730 event_forwarder_.reset(new DevToolsEventForwarder(this)); | 731 event_forwarder_.reset(new DevToolsEventForwarder(this)); |
731 } | 732 } |
732 | 733 |
733 // static | 734 // static |
734 DevToolsWindow* DevToolsWindow::Create( | 735 DevToolsWindow* DevToolsWindow::Create( |
735 Profile* profile, | 736 Profile* profile, |
736 const GURL& frontend_url, | 737 const GURL& frontend_url, |
737 content::RenderViewHost* inspected_rvh, | 738 content::WebContents* inspected_web_contents, |
738 bool shared_worker_frontend, | 739 bool shared_worker_frontend, |
739 bool external_frontend, | 740 bool external_frontend, |
740 bool can_dock, | 741 bool can_dock, |
741 const std::string& settings) { | 742 const std::string& settings) { |
742 if (inspected_rvh) { | 743 if (inspected_web_contents) { |
743 // Check for a place to dock. | 744 // Check for a place to dock. |
744 Browser* browser = NULL; | 745 Browser* browser = NULL; |
745 int tab; | 746 int tab; |
746 WebContents* inspected_web_contents = | |
747 content::WebContents::FromRenderViewHost(inspected_rvh); | |
748 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents, | 747 if (!FindInspectedBrowserAndTabIndex(inspected_web_contents, |
749 &browser, &tab) || | 748 &browser, &tab) || |
750 inspected_rvh->GetMainFrame()->IsCrossProcessSubframe() || | |
751 browser->is_type_popup()) { | 749 browser->is_type_popup()) { |
752 can_dock = false; | 750 can_dock = false; |
753 } | 751 } |
754 } | 752 } |
755 | 753 |
756 // Create WebContents with devtools. | 754 // Create WebContents with devtools. |
757 GURL url(GetDevToolsURL(profile, frontend_url, | 755 GURL url(GetDevToolsURL(profile, frontend_url, |
758 shared_worker_frontend, | 756 shared_worker_frontend, |
759 external_frontend, | 757 external_frontend, |
760 can_dock, settings)); | 758 can_dock, settings)); |
761 return new DevToolsWindow(profile, url, inspected_rvh, can_dock); | 759 return new DevToolsWindow(profile, url, inspected_web_contents, can_dock); |
762 } | 760 } |
763 | 761 |
764 // static | 762 // static |
765 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, | 763 GURL DevToolsWindow::GetDevToolsURL(Profile* profile, |
766 const GURL& base_url, | 764 const GURL& base_url, |
767 bool shared_worker_frontend, | 765 bool shared_worker_frontend, |
768 bool external_frontend, | 766 bool external_frontend, |
769 bool can_dock, | 767 bool can_dock, |
770 const std::string& settings) { | 768 const std::string& settings) { |
771 // Compatibility errors are encoded with data urls, pass them | 769 // Compatibility errors are encoded with data urls, pass them |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1258 closure.Run(); | 1256 closure.Run(); |
1259 return; | 1257 return; |
1260 } | 1258 } |
1261 load_completed_callback_ = closure; | 1259 load_completed_callback_ = closure; |
1262 } | 1260 } |
1263 | 1261 |
1264 bool DevToolsWindow::ForwardKeyboardEvent( | 1262 bool DevToolsWindow::ForwardKeyboardEvent( |
1265 const content::NativeWebKeyboardEvent& event) { | 1263 const content::NativeWebKeyboardEvent& event) { |
1266 return event_forwarder_->ForwardEvent(event); | 1264 return event_forwarder_->ForwardEvent(event); |
1267 } | 1265 } |
OLD | NEW |