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 #include "chrome/browser/devtools/devtools_window.h" | 4 #include "chrome/browser/devtools/devtools_window.h" |
5 | 5 |
6 #include <algorithm> | 6 #include <algorithm> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 CreateDevToolsBrowser(); | 573 CreateDevToolsBrowser(); |
574 | 574 |
575 if (should_show_window) { | 575 if (should_show_window) { |
576 browser_->window()->Show(); | 576 browser_->window()->Show(); |
577 web_contents_->GetView()->SetInitialFocus(); | 577 web_contents_->GetView()->SetInitialFocus(); |
578 } | 578 } |
579 | 579 |
580 ScheduleAction(action); | 580 ScheduleAction(action); |
581 } | 581 } |
582 | 582 |
| 583 // static |
| 584 bool DevToolsWindow::HandleBeforeUnload(content::WebContents* frontend_contents, |
| 585 bool proceed, bool* proceed_to_fire_unload) { |
| 586 DevToolsWindow* window = AsDevToolsWindow( |
| 587 frontend_contents->GetRenderViewHost()); |
| 588 DCHECK(window); |
| 589 if (!window->inspected_page_is_closing_) |
| 590 return false; |
| 591 window->BeforeUnloadFired(frontend_contents, proceed, |
| 592 proceed_to_fire_unload); |
| 593 return true; |
| 594 } |
| 595 |
| 596 // static |
| 597 bool DevToolsWindow::InterceptPageBeforeUnload(content::WebContents* contents) { |
| 598 DevToolsWindow* window = |
| 599 DevToolsWindow::GetInstanceForInspectedRenderViewHost( |
| 600 contents->GetRenderViewHost()); |
| 601 if (!window || window->inspected_page_is_closing_) |
| 602 return false; |
| 603 |
| 604 window->inspected_page_is_closing_ = true; |
| 605 // Handling devtools on devtools case. |
| 606 if (!DevToolsWindow::InterceptPageBeforeUnload(window->web_contents())) { |
| 607 window->web_contents()->GetRenderViewHost()->FirePageBeforeUnload(false); |
| 608 } |
| 609 return true; |
| 610 } |
| 611 |
| 612 // static |
| 613 bool DevToolsWindow::NeedsToInterceptBeforeUnload( |
| 614 content::WebContents* contents) { |
| 615 DevToolsWindow* window = |
| 616 DevToolsWindow::GetInstanceForInspectedRenderViewHost( |
| 617 contents->GetRenderViewHost()); |
| 618 return window && !window->inspected_page_is_closing_; |
| 619 } |
| 620 |
| 621 // static |
| 622 bool DevToolsWindow::ShouldCloseDevToolsBrowser(Browser* browser) { |
| 623 DCHECK(browser->is_devtools()); |
| 624 if (browser->tab_strip_model()->empty()) |
| 625 return true; |
| 626 content::WebContents* contents = |
| 627 browser->tab_strip_model()->GetWebContentsAt(0); |
| 628 DevToolsWindow* window = AsDevToolsWindow(contents->GetRenderViewHost()); |
| 629 DCHECK(window); |
| 630 return window->inspected_page_is_closing_; |
| 631 } |
| 632 |
| 633 // static |
| 634 void DevToolsWindow::OnPageCloseCanceled(content::WebContents* contents) { |
| 635 DevToolsWindow *window = |
| 636 DevToolsWindow::GetInstanceForInspectedRenderViewHost( |
| 637 contents->GetRenderViewHost()); |
| 638 if (!window) |
| 639 return; |
| 640 window->inspected_page_is_closing_ = false; |
| 641 // Propagate to DevTools opened on DevTools if any. |
| 642 DevToolsWindow::OnPageCloseCanceled(window->web_contents()); |
| 643 } |
| 644 |
| 645 void DevToolsWindow::SetDockSideForTest(DevToolsDockSide dock_side) { |
| 646 SetDockSide(SideToString(dock_side)); |
| 647 } |
| 648 |
583 DevToolsWindow::DevToolsWindow(Profile* profile, | 649 DevToolsWindow::DevToolsWindow(Profile* profile, |
584 const GURL& url, | 650 const GURL& url, |
585 content::RenderViewHost* inspected_rvh, | 651 content::RenderViewHost* inspected_rvh, |
586 DevToolsDockSide dock_side) | 652 DevToolsDockSide dock_side) |
587 : profile_(profile), | 653 : profile_(profile), |
588 browser_(NULL), | 654 browser_(NULL), |
589 dock_side_(dock_side), | 655 dock_side_(dock_side), |
590 is_loaded_(false), | 656 is_loaded_(false), |
591 action_on_load_(DevToolsToggleAction::Show()), | 657 action_on_load_(DevToolsToggleAction::Show()), |
592 width_(-1), | 658 width_(-1), |
593 height_(-1), | 659 height_(-1), |
594 dock_side_before_minimized_(dock_side), | 660 dock_side_before_minimized_(dock_side), |
| 661 inspected_page_is_closing_(false), |
595 weak_factory_(this) { | 662 weak_factory_(this) { |
596 web_contents_ = | 663 web_contents_ = |
597 content::WebContents::Create(content::WebContents::CreateParams(profile)); | 664 content::WebContents::Create(content::WebContents::CreateParams(profile)); |
598 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); | 665 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); |
599 | 666 |
600 web_contents_->GetController().LoadURL(url, content::Referrer(), | 667 web_contents_->GetController().LoadURL(url, content::Referrer(), |
601 content::PAGE_TRANSITION_AUTO_TOPLEVEL, EmptyString()); | 668 content::PAGE_TRANSITION_AUTO_TOPLEVEL, EmptyString()); |
602 | 669 |
603 frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost( | 670 frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost( |
604 web_contents_, this)); | 671 web_contents_, this)); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 inspected_window->UpdateDevTools(); | 873 inspected_window->UpdateDevTools(); |
807 // In case of docked web_contents_, we own it so delete here. | 874 // In case of docked web_contents_, we own it so delete here. |
808 // Embedding DevTools window will be deleted as a result of | 875 // Embedding DevTools window will be deleted as a result of |
809 // WebContentsDestroyed callback. | 876 // WebContentsDestroyed callback. |
810 delete web_contents_; | 877 delete web_contents_; |
811 } | 878 } |
812 | 879 |
813 void DevToolsWindow::BeforeUnloadFired(content::WebContents* tab, | 880 void DevToolsWindow::BeforeUnloadFired(content::WebContents* tab, |
814 bool proceed, | 881 bool proceed, |
815 bool* proceed_to_fire_unload) { | 882 bool* proceed_to_fire_unload) { |
816 if (proceed) { | 883 if (!inspected_page_is_closing_) { |
817 content::DevToolsManager::GetInstance()->ClientHostClosing( | 884 if (proceed) { |
818 frontend_host_.get()); | 885 content::DevToolsManager::GetInstance()->ClientHostClosing( |
| 886 frontend_host_.get()); |
| 887 } |
| 888 *proceed_to_fire_unload = proceed; |
| 889 } else { |
| 890 content::WebContents* inspected_web_contents = GetInspectedWebContents(); |
| 891 if (proceed) { |
| 892 inspected_web_contents->GetRenderViewHost()->FirePageBeforeUnload(false); |
| 893 } else { |
| 894 bool should_proceed; |
| 895 inspected_web_contents->GetDelegate()->BeforeUnloadFired( |
| 896 inspected_web_contents, false, &should_proceed); |
| 897 DCHECK(!should_proceed); |
| 898 } |
| 899 *proceed_to_fire_unload = false; |
819 } | 900 } |
820 *proceed_to_fire_unload = proceed; | |
821 } | 901 } |
822 | 902 |
823 bool DevToolsWindow::PreHandleKeyboardEvent( | 903 bool DevToolsWindow::PreHandleKeyboardEvent( |
824 content::WebContents* source, | 904 content::WebContents* source, |
825 const content::NativeWebKeyboardEvent& event, | 905 const content::NativeWebKeyboardEvent& event, |
826 bool* is_keyboard_shortcut) { | 906 bool* is_keyboard_shortcut) { |
827 if (IsDocked()) { | 907 if (IsDocked()) { |
828 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 908 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
829 if (inspected_window) { | 909 if (inspected_window) { |
830 return inspected_window->PreHandleKeyboardEvent(event, | 910 return inspected_window->PreHandleKeyboardEvent(event, |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1414 return inspected_contents_observer_ ? | 1494 return inspected_contents_observer_ ? |
1415 inspected_contents_observer_->web_contents() : NULL; | 1495 inspected_contents_observer_->web_contents() : NULL; |
1416 } | 1496 } |
1417 | 1497 |
1418 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { | 1498 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { |
1419 is_loaded_ = true; | 1499 is_loaded_ = true; |
1420 UpdateTheme(); | 1500 UpdateTheme(); |
1421 DoAction(); | 1501 DoAction(); |
1422 AddDevToolsExtensionsToClient(); | 1502 AddDevToolsExtensionsToClient(); |
1423 } | 1503 } |
OLD | NEW |