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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 CreateDevToolsBrowser(); | 559 CreateDevToolsBrowser(); |
560 | 560 |
561 if (should_show_window) { | 561 if (should_show_window) { |
562 browser_->window()->Show(); | 562 browser_->window()->Show(); |
563 web_contents_->GetView()->SetInitialFocus(); | 563 web_contents_->GetView()->SetInitialFocus(); |
564 } | 564 } |
565 | 565 |
566 ScheduleAction(action); | 566 ScheduleAction(action); |
567 } | 567 } |
568 | 568 |
| 569 // static |
| 570 bool DevToolsWindow::HandleBeforeUnload(content::WebContents* frontend_contents, |
| 571 bool proceed, bool* proceed_to_fire_unload) { |
| 572 DevToolsWindow* window = AsDevToolsWindow( |
| 573 frontend_contents->GetRenderViewHost()); |
| 574 DCHECK(window); |
| 575 if (!window->inspected_page_is_closing_) |
| 576 return false; |
| 577 window->BeforeUnloadFired(frontend_contents, proceed, |
| 578 proceed_to_fire_unload); |
| 579 return true; |
| 580 } |
| 581 |
| 582 // static |
| 583 bool DevToolsWindow::InterceptPageBeforeUnload(content::WebContents* contents) { |
| 584 DevToolsWindow* window = |
| 585 DevToolsWindow::GetInstanceForInspectedRenderViewHost( |
| 586 contents->GetRenderViewHost()); |
| 587 if (!window || window->inspected_page_is_closing_) |
| 588 return false; |
| 589 |
| 590 window->inspected_page_is_closing_ = true; |
| 591 // Handling devtools on devtools case |
| 592 if (!DevToolsWindow::InterceptPageBeforeUnload(window->web_contents())) { |
| 593 window->web_contents()->GetRenderViewHost()->FirePageBeforeUnload(false); |
| 594 } |
| 595 return true; |
| 596 } |
| 597 |
| 598 // static |
| 599 bool DevToolsWindow::NeedToFireBeforeUnload(content::WebContents* contents) { |
| 600 DevToolsWindow* window = |
| 601 DevToolsWindow::GetInstanceForInspectedRenderViewHost( |
| 602 contents->GetRenderViewHost()); |
| 603 return window && !window->inspected_page_is_closing_; |
| 604 } |
| 605 |
| 606 // static |
| 607 bool DevToolsWindow::ShouldCloseDevToolsBrowser(Browser* browser) { |
| 608 DCHECK(browser->is_devtools()); |
| 609 if (browser->tab_strip_model()->empty()) |
| 610 return true; |
| 611 content::WebContents* contents = |
| 612 browser->tab_strip_model()->GetWebContentsAt(0); |
| 613 DevToolsWindow* window = AsDevToolsWindow(contents->GetRenderViewHost()); |
| 614 DCHECK(window); |
| 615 return window->inspected_page_is_closing_; |
| 616 } |
| 617 |
| 618 // static |
| 619 void DevToolsWindow::PageClosingCanceled(content::WebContents* contents) { |
| 620 DevToolsWindow *window = |
| 621 DevToolsWindow::GetInstanceForInspectedRenderViewHost( |
| 622 contents->GetRenderViewHost()); |
| 623 if (!window) |
| 624 return; |
| 625 window->inspected_page_is_closing_ = false; |
| 626 // Propagate to DevTools opened on DevTools if any |
| 627 DevToolsWindow::PageClosingCanceled(window->web_contents()); |
| 628 } |
| 629 |
| 630 void DevToolsWindow::SetDockSideForTest(DevToolsDockSide dock_side) { |
| 631 SetDockSide(SideToString(dock_side)); |
| 632 } |
| 633 |
569 DevToolsWindow::DevToolsWindow(Profile* profile, | 634 DevToolsWindow::DevToolsWindow(Profile* profile, |
570 const GURL& url, | 635 const GURL& url, |
571 content::RenderViewHost* inspected_rvh, | 636 content::RenderViewHost* inspected_rvh, |
572 DevToolsDockSide dock_side) | 637 DevToolsDockSide dock_side) |
573 : profile_(profile), | 638 : profile_(profile), |
574 browser_(NULL), | 639 browser_(NULL), |
575 dock_side_(dock_side), | 640 dock_side_(dock_side), |
576 is_loaded_(false), | 641 is_loaded_(false), |
577 action_on_load_(DevToolsToggleAction::Show()), | 642 action_on_load_(DevToolsToggleAction::Show()), |
578 width_(-1), | 643 width_(-1), |
579 height_(-1), | 644 height_(-1), |
580 dock_side_before_minimized_(dock_side), | 645 dock_side_before_minimized_(dock_side), |
| 646 inspected_page_is_closing_(false), |
581 weak_factory_(this) { | 647 weak_factory_(this) { |
582 web_contents_ = | 648 web_contents_ = |
583 content::WebContents::Create(content::WebContents::CreateParams(profile)); | 649 content::WebContents::Create(content::WebContents::CreateParams(profile)); |
584 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); | 650 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); |
585 | 651 |
586 web_contents_->GetController().LoadURL(url, content::Referrer(), | 652 web_contents_->GetController().LoadURL(url, content::Referrer(), |
587 content::PAGE_TRANSITION_AUTO_TOPLEVEL, EmptyString()); | 653 content::PAGE_TRANSITION_AUTO_TOPLEVEL, EmptyString()); |
588 | 654 |
589 frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost( | 655 frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost( |
590 web_contents_, this)); | 656 web_contents_, this)); |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 inspected_window->UpdateDevTools(); | 874 inspected_window->UpdateDevTools(); |
809 // In case of docked web_contents_, we own it so delete here. | 875 // In case of docked web_contents_, we own it so delete here. |
810 delete web_contents_; | 876 delete web_contents_; |
811 | 877 |
812 delete this; | 878 delete this; |
813 } | 879 } |
814 | 880 |
815 void DevToolsWindow::BeforeUnloadFired(content::WebContents* tab, | 881 void DevToolsWindow::BeforeUnloadFired(content::WebContents* tab, |
816 bool proceed, | 882 bool proceed, |
817 bool* proceed_to_fire_unload) { | 883 bool* proceed_to_fire_unload) { |
818 if (proceed) { | 884 if (!inspected_page_is_closing_) { |
819 content::DevToolsManager::GetInstance()->ClientHostClosing( | 885 if (proceed) { |
820 frontend_host_.get()); | 886 content::DevToolsManager::GetInstance()->ClientHostClosing( |
| 887 frontend_host_.get()); |
| 888 } |
| 889 *proceed_to_fire_unload = proceed; |
| 890 } else { |
| 891 content::WebContents* inspected_web_contents = GetInspectedWebContents(); |
| 892 if (proceed) { |
| 893 inspected_web_contents->GetRenderViewHost()->FirePageBeforeUnload(false); |
| 894 } else { |
| 895 bool should_proceed; |
| 896 inspected_web_contents->GetDelegate()->BeforeUnloadFired( |
| 897 inspected_web_contents, false, &should_proceed); |
| 898 DCHECK(!should_proceed); |
| 899 } |
| 900 *proceed_to_fire_unload = false; |
821 } | 901 } |
822 *proceed_to_fire_unload = proceed; | |
823 } | 902 } |
824 | 903 |
825 bool DevToolsWindow::PreHandleKeyboardEvent( | 904 bool DevToolsWindow::PreHandleKeyboardEvent( |
826 content::WebContents* source, | 905 content::WebContents* source, |
827 const content::NativeWebKeyboardEvent& event, | 906 const content::NativeWebKeyboardEvent& event, |
828 bool* is_keyboard_shortcut) { | 907 bool* is_keyboard_shortcut) { |
829 if (IsDocked()) { | 908 if (IsDocked()) { |
830 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 909 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
831 if (inspected_window) { | 910 if (inspected_window) { |
832 return inspected_window->PreHandleKeyboardEvent(event, | 911 return inspected_window->PreHandleKeyboardEvent(event, |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1406 return inspected_contents_observer_ ? | 1485 return inspected_contents_observer_ ? |
1407 inspected_contents_observer_->web_contents() : NULL; | 1486 inspected_contents_observer_->web_contents() : NULL; |
1408 } | 1487 } |
1409 | 1488 |
1410 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { | 1489 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { |
1411 is_loaded_ = true; | 1490 is_loaded_ = true; |
1412 UpdateTheme(); | 1491 UpdateTheme(); |
1413 DoAction(); | 1492 DoAction(); |
1414 AddDevToolsExtensionsToClient(); | 1493 AddDevToolsExtensionsToClient(); |
1415 } | 1494 } |
OLD | NEW |