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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 CreateDevToolsBrowser(); | 569 CreateDevToolsBrowser(); |
| 570 | 570 |
| 571 if (should_show_window) { | 571 if (should_show_window) { |
| 572 browser_->window()->Show(); | 572 browser_->window()->Show(); |
| 573 web_contents_->GetView()->SetInitialFocus(); | 573 web_contents_->GetView()->SetInitialFocus(); |
| 574 } | 574 } |
| 575 | 575 |
| 576 ScheduleAction(action); | 576 ScheduleAction(action); |
| 577 } | 577 } |
| 578 | 578 |
| 579 // static | |
| 580 bool DevToolsWindow::HandleBeforeUnload(content::WebContents* frontend_contents, | |
| 581 bool proceed, bool* proceed_to_fire_unload) { | |
| 582 DevToolsWindow* window = AsDevToolsWindow( | |
| 583 frontend_contents->GetRenderViewHost()); | |
| 584 DCHECK(window); | |
| 585 if (!window->inspected_page_is_closing_) | |
| 586 return false; | |
| 587 window->BeforeUnloadFired(frontend_contents, proceed, | |
| 588 proceed_to_fire_unload); | |
| 589 return true; | |
| 590 } | |
| 591 | |
| 592 // static | |
| 593 bool DevToolsWindow::InterceptPageBeforeUnload(content::WebContents* contents) { | |
| 594 DevToolsWindow* window = | |
| 595 DevToolsWindow::GetInstanceForInspectedRenderViewHost( | |
| 596 contents->GetRenderViewHost()); | |
| 597 if (!window || window->inspected_page_is_closing_) | |
| 598 return false; | |
| 599 | |
| 600 window->inspected_page_is_closing_ = true; | |
| 601 // Handling devtools on devtools case | |
|
jeremy
2013/11/07 14:18:34
nit - '.'
lushnikov
2013/11/07 17:18:10
Done.
| |
| 602 if (!DevToolsWindow::InterceptPageBeforeUnload(window->web_contents())) { | |
| 603 window->web_contents()->GetRenderViewHost()->FirePageBeforeUnload(false); | |
| 604 } | |
| 605 return true; | |
| 606 } | |
| 607 | |
| 608 // static | |
| 609 bool DevToolsWindow::NeedToFireBeforeUnload(content::WebContents* contents) { | |
| 610 DevToolsWindow* window = | |
| 611 DevToolsWindow::GetInstanceForInspectedRenderViewHost( | |
| 612 contents->GetRenderViewHost()); | |
| 613 return window && !window->inspected_page_is_closing_; | |
| 614 } | |
| 615 | |
| 616 // static | |
| 617 bool DevToolsWindow::ShouldCloseDevToolsBrowser(Browser* browser) { | |
| 618 DCHECK(browser->is_devtools()); | |
| 619 if (browser->tab_strip_model()->empty()) | |
| 620 return true; | |
| 621 content::WebContents* contents = | |
| 622 browser->tab_strip_model()->GetWebContentsAt(0); | |
| 623 DevToolsWindow* window = AsDevToolsWindow(contents->GetRenderViewHost()); | |
| 624 DCHECK(window); | |
| 625 return window->inspected_page_is_closing_; | |
| 626 } | |
| 627 | |
| 628 // static | |
| 629 void DevToolsWindow::PageClosingCanceled(content::WebContents* contents) { | |
| 630 DevToolsWindow *window = | |
| 631 DevToolsWindow::GetInstanceForInspectedRenderViewHost( | |
| 632 contents->GetRenderViewHost()); | |
| 633 if (!window) | |
| 634 return; | |
| 635 window->inspected_page_is_closing_ = false; | |
| 636 // Propagate to DevTools opened on DevTools if any | |
| 637 DevToolsWindow::PageClosingCanceled(window->web_contents()); | |
| 638 } | |
| 639 | |
| 640 void DevToolsWindow::SetDockSideForTest(DevToolsDockSide dock_side) { | |
| 641 SetDockSide(SideToString(dock_side)); | |
| 642 } | |
| 643 | |
| 579 DevToolsWindow::DevToolsWindow(Profile* profile, | 644 DevToolsWindow::DevToolsWindow(Profile* profile, |
| 580 const GURL& url, | 645 const GURL& url, |
| 581 content::RenderViewHost* inspected_rvh, | 646 content::RenderViewHost* inspected_rvh, |
| 582 DevToolsDockSide dock_side) | 647 DevToolsDockSide dock_side) |
| 583 : profile_(profile), | 648 : profile_(profile), |
| 584 browser_(NULL), | 649 browser_(NULL), |
| 585 dock_side_(dock_side), | 650 dock_side_(dock_side), |
| 586 is_loaded_(false), | 651 is_loaded_(false), |
| 587 action_on_load_(DevToolsToggleAction::Show()), | 652 action_on_load_(DevToolsToggleAction::Show()), |
| 588 width_(-1), | 653 width_(-1), |
| 589 height_(-1), | 654 height_(-1), |
| 590 dock_side_before_minimized_(dock_side), | 655 dock_side_before_minimized_(dock_side), |
| 656 inspected_page_is_closing_(false), | |
| 591 weak_factory_(this) { | 657 weak_factory_(this) { |
| 592 web_contents_ = | 658 web_contents_ = |
| 593 content::WebContents::Create(content::WebContents::CreateParams(profile)); | 659 content::WebContents::Create(content::WebContents::CreateParams(profile)); |
| 594 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); | 660 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); |
| 595 | 661 |
| 596 web_contents_->GetController().LoadURL(url, content::Referrer(), | 662 web_contents_->GetController().LoadURL(url, content::Referrer(), |
| 597 content::PAGE_TRANSITION_AUTO_TOPLEVEL, EmptyString()); | 663 content::PAGE_TRANSITION_AUTO_TOPLEVEL, EmptyString()); |
| 598 | 664 |
| 599 frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost( | 665 frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost( |
| 600 web_contents_, this)); | 666 web_contents_, this)); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 801 inspected_window->UpdateDevTools(); | 867 inspected_window->UpdateDevTools(); |
| 802 // In case of docked web_contents_, we own it so delete here. | 868 // In case of docked web_contents_, we own it so delete here. |
| 803 // Embedding DevTools window will be deleted as a result of | 869 // Embedding DevTools window will be deleted as a result of |
| 804 // WebContentsDestroyed callback. | 870 // WebContentsDestroyed callback. |
| 805 delete web_contents_; | 871 delete web_contents_; |
| 806 } | 872 } |
| 807 | 873 |
| 808 void DevToolsWindow::BeforeUnloadFired(content::WebContents* tab, | 874 void DevToolsWindow::BeforeUnloadFired(content::WebContents* tab, |
| 809 bool proceed, | 875 bool proceed, |
| 810 bool* proceed_to_fire_unload) { | 876 bool* proceed_to_fire_unload) { |
| 811 if (proceed) { | 877 if (!inspected_page_is_closing_) { |
| 812 content::DevToolsManager::GetInstance()->ClientHostClosing( | 878 if (proceed) { |
| 813 frontend_host_.get()); | 879 content::DevToolsManager::GetInstance()->ClientHostClosing( |
| 880 frontend_host_.get()); | |
| 881 } | |
| 882 *proceed_to_fire_unload = proceed; | |
| 883 } else { | |
| 884 content::WebContents* inspected_web_contents = GetInspectedWebContents(); | |
| 885 if (proceed) { | |
| 886 inspected_web_contents->GetRenderViewHost()->FirePageBeforeUnload(false); | |
| 887 } else { | |
| 888 bool should_proceed; | |
| 889 inspected_web_contents->GetDelegate()->BeforeUnloadFired( | |
| 890 inspected_web_contents, false, &should_proceed); | |
| 891 DCHECK(!should_proceed); | |
| 892 } | |
| 893 *proceed_to_fire_unload = false; | |
| 814 } | 894 } |
| 815 *proceed_to_fire_unload = proceed; | |
| 816 } | 895 } |
| 817 | 896 |
| 818 bool DevToolsWindow::PreHandleKeyboardEvent( | 897 bool DevToolsWindow::PreHandleKeyboardEvent( |
| 819 content::WebContents* source, | 898 content::WebContents* source, |
| 820 const content::NativeWebKeyboardEvent& event, | 899 const content::NativeWebKeyboardEvent& event, |
| 821 bool* is_keyboard_shortcut) { | 900 bool* is_keyboard_shortcut) { |
| 822 if (IsDocked()) { | 901 if (IsDocked()) { |
| 823 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 902 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
| 824 if (inspected_window) { | 903 if (inspected_window) { |
| 825 return inspected_window->PreHandleKeyboardEvent(event, | 904 return inspected_window->PreHandleKeyboardEvent(event, |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1409 return inspected_contents_observer_ ? | 1488 return inspected_contents_observer_ ? |
| 1410 inspected_contents_observer_->web_contents() : NULL; | 1489 inspected_contents_observer_->web_contents() : NULL; |
| 1411 } | 1490 } |
| 1412 | 1491 |
| 1413 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { | 1492 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { |
| 1414 is_loaded_ = true; | 1493 is_loaded_ = true; |
| 1415 UpdateTheme(); | 1494 UpdateTheme(); |
| 1416 DoAction(); | 1495 DoAction(); |
| 1417 AddDevToolsExtensionsToClient(); | 1496 AddDevToolsExtensionsToClient(); |
| 1418 } | 1497 } |
| OLD | NEW |