Chromium Code Reviews| 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. | |
|
jeremy
2013/11/13 10:52:34
// Handle case of DevTools inspecting another DevT
lushnikov
2013/11/13 13:39:08
Done.
| |
| 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::HasFiredBeforeUnloadEventForDevToolsBrowser( | |
| 623 Browser* browser) { | |
| 624 DCHECK(browser->is_devtools()); | |
| 625 if (browser->tab_strip_model()->empty()) | |
|
jeremy
2013/11/13 10:52:34
// When FastUnloadController is used, we may detac
lushnikov
2013/11/13 13:39:08
Done.
| |
| 626 return true; | |
| 627 content::WebContents* contents = | |
| 628 browser->tab_strip_model()->GetWebContentsAt(0); | |
| 629 DevToolsWindow* window = AsDevToolsWindow(contents->GetRenderViewHost()); | |
| 630 DCHECK(window); | |
| 631 return window->inspected_page_is_closing_; | |
| 632 } | |
| 633 | |
| 634 // static | |
| 635 void DevToolsWindow::OnPageCloseCanceled(content::WebContents* contents) { | |
| 636 DevToolsWindow *window = | |
| 637 DevToolsWindow::GetInstanceForInspectedRenderViewHost( | |
| 638 contents->GetRenderViewHost()); | |
| 639 if (!window) | |
| 640 return; | |
| 641 window->inspected_page_is_closing_ = false; | |
| 642 // Propagate to DevTools opened on DevTools if any. | |
| 643 DevToolsWindow::OnPageCloseCanceled(window->web_contents()); | |
| 644 } | |
| 645 | |
| 646 void DevToolsWindow::SetDockSideForTest(DevToolsDockSide dock_side) { | |
| 647 SetDockSide(SideToString(dock_side)); | |
| 648 } | |
| 649 | |
| 583 DevToolsWindow::DevToolsWindow(Profile* profile, | 650 DevToolsWindow::DevToolsWindow(Profile* profile, |
| 584 const GURL& url, | 651 const GURL& url, |
| 585 content::RenderViewHost* inspected_rvh, | 652 content::RenderViewHost* inspected_rvh, |
| 586 DevToolsDockSide dock_side) | 653 DevToolsDockSide dock_side) |
| 587 : profile_(profile), | 654 : profile_(profile), |
| 588 browser_(NULL), | 655 browser_(NULL), |
| 589 dock_side_(dock_side), | 656 dock_side_(dock_side), |
| 590 is_loaded_(false), | 657 is_loaded_(false), |
| 591 action_on_load_(DevToolsToggleAction::Show()), | 658 action_on_load_(DevToolsToggleAction::Show()), |
| 592 width_(-1), | 659 width_(-1), |
| 593 height_(-1), | 660 height_(-1), |
| 594 dock_side_before_minimized_(dock_side), | 661 dock_side_before_minimized_(dock_side), |
| 662 inspected_page_is_closing_(false), | |
| 595 weak_factory_(this) { | 663 weak_factory_(this) { |
| 596 web_contents_ = | 664 web_contents_ = |
| 597 content::WebContents::Create(content::WebContents::CreateParams(profile)); | 665 content::WebContents::Create(content::WebContents::CreateParams(profile)); |
| 598 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); | 666 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); |
| 599 | 667 |
| 600 web_contents_->GetController().LoadURL(url, content::Referrer(), | 668 web_contents_->GetController().LoadURL(url, content::Referrer(), |
| 601 content::PAGE_TRANSITION_AUTO_TOPLEVEL, EmptyString()); | 669 content::PAGE_TRANSITION_AUTO_TOPLEVEL, EmptyString()); |
| 602 | 670 |
| 603 frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost( | 671 frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost( |
| 604 web_contents_, this)); | 672 web_contents_, this)); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 806 inspected_window->UpdateDevTools(); | 874 inspected_window->UpdateDevTools(); |
| 807 // 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. |
| 808 // Embedding DevTools window will be deleted as a result of | 876 // Embedding DevTools window will be deleted as a result of |
| 809 // WebContentsDestroyed callback. | 877 // WebContentsDestroyed callback. |
| 810 delete web_contents_; | 878 delete web_contents_; |
| 811 } | 879 } |
| 812 | 880 |
| 813 void DevToolsWindow::BeforeUnloadFired(content::WebContents* tab, | 881 void DevToolsWindow::BeforeUnloadFired(content::WebContents* tab, |
| 814 bool proceed, | 882 bool proceed, |
| 815 bool* proceed_to_fire_unload) { | 883 bool* proceed_to_fire_unload) { |
| 816 if (proceed) { | 884 if (!inspected_page_is_closing_) { |
|
jeremy
2013/11/13 10:52:34
// Docked devtools window closed directly.
lushnikov
2013/11/13 13:39:08
Done.
| |
| 817 content::DevToolsManager::GetInstance()->ClientHostClosing( | 885 if (proceed) { |
| 818 frontend_host_.get()); | 886 content::DevToolsManager::GetInstance()->ClientHostClosing( |
| 887 frontend_host_.get()); | |
| 888 } | |
| 889 *proceed_to_fire_unload = proceed; | |
| 890 } else { | |
|
jeremy
2013/11/13 10:52:34
Closing as result of event from devtools content.
lushnikov
2013/11/13 13:39:08
Reworded, done.
| |
| 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; | |
| 819 } | 901 } |
| 820 *proceed_to_fire_unload = proceed; | |
| 821 } | 902 } |
| 822 | 903 |
| 823 bool DevToolsWindow::PreHandleKeyboardEvent( | 904 bool DevToolsWindow::PreHandleKeyboardEvent( |
| 824 content::WebContents* source, | 905 content::WebContents* source, |
| 825 const content::NativeWebKeyboardEvent& event, | 906 const content::NativeWebKeyboardEvent& event, |
| 826 bool* is_keyboard_shortcut) { | 907 bool* is_keyboard_shortcut) { |
| 827 if (IsDocked()) { | 908 if (IsDocked()) { |
| 828 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 909 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
| 829 if (inspected_window) { | 910 if (inspected_window) { |
| 830 return inspected_window->PreHandleKeyboardEvent(event, | 911 return inspected_window->PreHandleKeyboardEvent(event, |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1414 return inspected_contents_observer_ ? | 1495 return inspected_contents_observer_ ? |
| 1415 inspected_contents_observer_->web_contents() : NULL; | 1496 inspected_contents_observer_->web_contents() : NULL; |
| 1416 } | 1497 } |
| 1417 | 1498 |
| 1418 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { | 1499 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { |
| 1419 is_loaded_ = true; | 1500 is_loaded_ = true; |
| 1420 UpdateTheme(); | 1501 UpdateTheme(); |
| 1421 DoAction(); | 1502 DoAction(); |
| 1422 AddDevToolsExtensionsToClient(); | 1503 AddDevToolsExtensionsToClient(); |
| 1423 } | 1504 } |
| OLD | NEW |