| 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->intercepted_page_beforeunload_) |
| 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->intercepted_page_beforeunload_) |
| 602 return false; |
| 603 |
| 604 window->intercepted_page_beforeunload_ = true; |
| 605 // Handle case of devtools inspecting another devtools instance by passing |
| 606 // the call up to the inspecting devtools instance. |
| 607 if (!DevToolsWindow::InterceptPageBeforeUnload(window->web_contents())) { |
| 608 window->web_contents()->GetRenderViewHost()->FirePageBeforeUnload(false); |
| 609 } |
| 610 return true; |
| 611 } |
| 612 |
| 613 // static |
| 614 bool DevToolsWindow::NeedsToInterceptBeforeUnload( |
| 615 content::WebContents* contents) { |
| 616 DevToolsWindow* window = |
| 617 DevToolsWindow::GetInstanceForInspectedRenderViewHost( |
| 618 contents->GetRenderViewHost()); |
| 619 return window && !window->intercepted_page_beforeunload_; |
| 620 } |
| 621 |
| 622 // static |
| 623 bool DevToolsWindow::HasFiredBeforeUnloadEventForDevToolsBrowser( |
| 624 Browser* browser) { |
| 625 DCHECK(browser->is_devtools()); |
| 626 // When FastUnloadController is used, devtools frontend will be detached |
| 627 // from the browser window at this point which means we've already fired |
| 628 // beforeunload. |
| 629 if (browser->tab_strip_model()->empty()) |
| 630 return true; |
| 631 content::WebContents* contents = |
| 632 browser->tab_strip_model()->GetWebContentsAt(0); |
| 633 DevToolsWindow* window = AsDevToolsWindow(contents->GetRenderViewHost()); |
| 634 DCHECK(window); |
| 635 return window->intercepted_page_beforeunload_; |
| 636 } |
| 637 |
| 638 // static |
| 639 void DevToolsWindow::OnPageCloseCanceled(content::WebContents* contents) { |
| 640 DevToolsWindow *window = |
| 641 DevToolsWindow::GetInstanceForInspectedRenderViewHost( |
| 642 contents->GetRenderViewHost()); |
| 643 if (!window) |
| 644 return; |
| 645 window->intercepted_page_beforeunload_ = false; |
| 646 // Propagate to devtools opened on devtools if any. |
| 647 DevToolsWindow::OnPageCloseCanceled(window->web_contents()); |
| 648 } |
| 649 |
| 650 void DevToolsWindow::SetDockSideForTest(DevToolsDockSide dock_side) { |
| 651 SetDockSide(SideToString(dock_side)); |
| 652 } |
| 653 |
| 583 DevToolsWindow::DevToolsWindow(Profile* profile, | 654 DevToolsWindow::DevToolsWindow(Profile* profile, |
| 584 const GURL& url, | 655 const GURL& url, |
| 585 content::RenderViewHost* inspected_rvh, | 656 content::RenderViewHost* inspected_rvh, |
| 586 DevToolsDockSide dock_side) | 657 DevToolsDockSide dock_side) |
| 587 : profile_(profile), | 658 : profile_(profile), |
| 588 browser_(NULL), | 659 browser_(NULL), |
| 589 dock_side_(dock_side), | 660 dock_side_(dock_side), |
| 590 is_loaded_(false), | 661 is_loaded_(false), |
| 591 action_on_load_(DevToolsToggleAction::Show()), | 662 action_on_load_(DevToolsToggleAction::Show()), |
| 592 width_(-1), | 663 width_(-1), |
| 593 height_(-1), | 664 height_(-1), |
| 594 dock_side_before_minimized_(dock_side), | 665 dock_side_before_minimized_(dock_side), |
| 666 intercepted_page_beforeunload_(false), |
| 595 weak_factory_(this) { | 667 weak_factory_(this) { |
| 596 web_contents_ = | 668 web_contents_ = |
| 597 content::WebContents::Create(content::WebContents::CreateParams(profile)); | 669 content::WebContents::Create(content::WebContents::CreateParams(profile)); |
| 598 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); | 670 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); |
| 599 | 671 |
| 600 web_contents_->GetController().LoadURL(url, content::Referrer(), | 672 web_contents_->GetController().LoadURL(url, content::Referrer(), |
| 601 content::PAGE_TRANSITION_AUTO_TOPLEVEL, EmptyString()); | 673 content::PAGE_TRANSITION_AUTO_TOPLEVEL, EmptyString()); |
| 602 | 674 |
| 603 frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost( | 675 frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost( |
| 604 web_contents_, this)); | 676 web_contents_, this)); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 inspected_window->UpdateDevTools(); | 878 inspected_window->UpdateDevTools(); |
| 807 // In case of docked web_contents_, we own it so delete here. | 879 // In case of docked web_contents_, we own it so delete here. |
| 808 // Embedding DevTools window will be deleted as a result of | 880 // Embedding DevTools window will be deleted as a result of |
| 809 // WebContentsDestroyed callback. | 881 // WebContentsDestroyed callback. |
| 810 delete web_contents_; | 882 delete web_contents_; |
| 811 } | 883 } |
| 812 | 884 |
| 813 void DevToolsWindow::BeforeUnloadFired(content::WebContents* tab, | 885 void DevToolsWindow::BeforeUnloadFired(content::WebContents* tab, |
| 814 bool proceed, | 886 bool proceed, |
| 815 bool* proceed_to_fire_unload) { | 887 bool* proceed_to_fire_unload) { |
| 816 if (proceed) { | 888 if (!intercepted_page_beforeunload_) { |
| 817 content::DevToolsManager::GetInstance()->ClientHostClosing( | 889 // Docked devtools window closed directly. |
| 818 frontend_host_.get()); | 890 if (proceed) { |
| 891 content::DevToolsManager::GetInstance()->ClientHostClosing( |
| 892 frontend_host_.get()); |
| 893 } |
| 894 *proceed_to_fire_unload = proceed; |
| 895 } else { |
| 896 // Inspected page is attempting to close. |
| 897 content::WebContents* inspected_web_contents = GetInspectedWebContents(); |
| 898 if (proceed) { |
| 899 inspected_web_contents->GetRenderViewHost()->FirePageBeforeUnload(false); |
| 900 } else { |
| 901 bool should_proceed; |
| 902 inspected_web_contents->GetDelegate()->BeforeUnloadFired( |
| 903 inspected_web_contents, false, &should_proceed); |
| 904 DCHECK(!should_proceed); |
| 905 } |
| 906 *proceed_to_fire_unload = false; |
| 819 } | 907 } |
| 820 *proceed_to_fire_unload = proceed; | |
| 821 } | 908 } |
| 822 | 909 |
| 823 bool DevToolsWindow::PreHandleKeyboardEvent( | 910 bool DevToolsWindow::PreHandleKeyboardEvent( |
| 824 content::WebContents* source, | 911 content::WebContents* source, |
| 825 const content::NativeWebKeyboardEvent& event, | 912 const content::NativeWebKeyboardEvent& event, |
| 826 bool* is_keyboard_shortcut) { | 913 bool* is_keyboard_shortcut) { |
| 827 if (IsDocked()) { | 914 if (IsDocked()) { |
| 828 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 915 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
| 829 if (inspected_window) { | 916 if (inspected_window) { |
| 830 return inspected_window->PreHandleKeyboardEvent(event, | 917 return inspected_window->PreHandleKeyboardEvent(event, |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 return inspected_contents_observer_ ? | 1501 return inspected_contents_observer_ ? |
| 1415 inspected_contents_observer_->web_contents() : NULL; | 1502 inspected_contents_observer_->web_contents() : NULL; |
| 1416 } | 1503 } |
| 1417 | 1504 |
| 1418 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { | 1505 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { |
| 1419 is_loaded_ = true; | 1506 is_loaded_ = true; |
| 1420 UpdateTheme(); | 1507 UpdateTheme(); |
| 1421 DoAction(); | 1508 DoAction(); |
| 1422 AddDevToolsExtensionsToClient(); | 1509 AddDevToolsExtensionsToClient(); |
| 1423 } | 1510 } |
| OLD | NEW |