Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: chrome/browser/devtools/devtools_window.cc

Issue 23835007: DevTools: Do not close devtools if there are dirty files in workspace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: improving TestDevToolsOnDevTools test Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 if (!window || !window->inspected_page_is_closing_)
575 return false;
576 window->BeforeUnloadFired(frontend_contents, proceed,
577 proceed_to_fire_unload);
578 return true;
579 }
580
581 // static
582 bool DevToolsWindow::InterceptPageBeforeUnload(content::WebContents* contents) {
583 DevToolsWindow* window =
584 DevToolsWindow::GetInstanceForInspectedRenderViewHost(
585 contents->GetRenderViewHost());
586 if (!window)
587 return false;
588
589 if (window->inspected_page_is_closing_)
590 return false;
591 window->inspected_page_is_closing_ = true;
592 // Handling devtools on devtools case
593 if (!DevToolsWindow::InterceptPageBeforeUnload(window->web_contents())) {
594 window->web_contents()->GetRenderViewHost()->FirePageBeforeUnload(false);
595 }
596 return true;
597 }
598
599 // static
600 bool DevToolsWindow::NeedToFireBeforeUnload(content::WebContents* contents) {
601 DevToolsWindow *window = AsDevToolsWindow(contents->GetRenderViewHost());
vsevik 2013/11/05 08:36:17 remove this
lushnikov 2013/11/05 12:12:07 Done.
602 if (!window) {
603 window = DevToolsWindow::GetInstanceForInspectedRenderViewHost(
604 contents->GetRenderViewHost());
605 if (!window)
606 return contents->NeedToFireBeforeUnload();
607 }
608 return !window->inspected_page_is_closing_;
609 }
610
611 // static
612 bool DevToolsWindow::ShouldCloseDevToolsBrowser(Browser* browser) {
613 DCHECK(browser->is_devtools());
614 if (browser->tab_strip_model()->empty())
615 return true;
616 content::WebContents* contents =
617 browser->tab_strip_model()->GetWebContentsAt(0);
618 DevToolsWindow* window = AsDevToolsWindow(contents->GetRenderViewHost());
619 DCHECK(window);
620 return window->inspected_page_is_closing_;
621 }
622
623 void DevToolsWindow::InspectedPageCancelClose() {
624 inspected_page_is_closing_ = false;
625 // Propogate to DevTools opened on DevTools if any
vsevik 2013/11/05 08:36:17 propagate
lushnikov 2013/11/05 12:12:07 Done.
626 DevToolsWindow *window =
627 DevToolsWindow::GetInstanceForInspectedRenderViewHost(
628 web_contents_->GetRenderViewHost());
629 if (window) {
630 window->InspectedPageCancelClose();
631 }
632 }
633
634 void DevToolsWindow::SetDockSideForTest(DevToolsDockSide dock_side) {
635 SetDockSide(SideToString(dock_side));
636 }
637
569 DevToolsWindow::DevToolsWindow(Profile* profile, 638 DevToolsWindow::DevToolsWindow(Profile* profile,
570 const GURL& url, 639 const GURL& url,
571 content::RenderViewHost* inspected_rvh, 640 content::RenderViewHost* inspected_rvh,
572 DevToolsDockSide dock_side) 641 DevToolsDockSide dock_side)
573 : profile_(profile), 642 : profile_(profile),
574 browser_(NULL), 643 browser_(NULL),
575 dock_side_(dock_side), 644 dock_side_(dock_side),
576 is_loaded_(false), 645 is_loaded_(false),
577 action_on_load_(DevToolsToggleAction::Show()), 646 action_on_load_(DevToolsToggleAction::Show()),
578 width_(-1), 647 width_(-1),
579 height_(-1), 648 height_(-1),
580 dock_side_before_minimized_(dock_side), 649 dock_side_before_minimized_(dock_side),
650 inspected_page_is_closing_(false),
581 weak_factory_(this) { 651 weak_factory_(this) {
582 web_contents_ = 652 web_contents_ =
583 content::WebContents::Create(content::WebContents::CreateParams(profile)); 653 content::WebContents::Create(content::WebContents::CreateParams(profile));
584 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); 654 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this));
585 655
586 web_contents_->GetController().LoadURL(url, content::Referrer(), 656 web_contents_->GetController().LoadURL(url, content::Referrer(),
587 content::PAGE_TRANSITION_AUTO_TOPLEVEL, EmptyString()); 657 content::PAGE_TRANSITION_AUTO_TOPLEVEL, EmptyString());
588 658
589 frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost( 659 frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost(
590 web_contents_, this)); 660 web_contents_, this));
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 inspected_window->UpdateDevTools(); 878 inspected_window->UpdateDevTools();
809 // 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.
810 delete web_contents_; 880 delete web_contents_;
811 881
812 delete this; 882 delete this;
813 } 883 }
814 884
815 void DevToolsWindow::BeforeUnloadFired(content::WebContents* tab, 885 void DevToolsWindow::BeforeUnloadFired(content::WebContents* tab,
816 bool proceed, 886 bool proceed,
817 bool* proceed_to_fire_unload) { 887 bool* proceed_to_fire_unload) {
818 if (proceed) { 888 if (!inspected_page_is_closing_) {
819 content::DevToolsManager::GetInstance()->ClientHostClosing( 889 if (proceed) {
820 frontend_host_.get()); 890 content::DevToolsManager::GetInstance()->ClientHostClosing(
891 frontend_host_.get());
892 }
893 *proceed_to_fire_unload = proceed;
894 } else {
895 content::WebContents* inspected_web_contents = GetInspectedWebContents();
896 if (proceed) {
897 inspected_web_contents->GetRenderViewHost()->FirePageBeforeUnload(false);
898 } else {
899 bool should_proceed;
900 inspected_web_contents->GetDelegate()->BeforeUnloadFired(
901 inspected_web_contents, false, &should_proceed);
902 DCHECK(!should_proceed);
903 }
904 *proceed_to_fire_unload = false;
821 } 905 }
822 *proceed_to_fire_unload = proceed;
823 } 906 }
824 907
825 bool DevToolsWindow::PreHandleKeyboardEvent( 908 bool DevToolsWindow::PreHandleKeyboardEvent(
826 content::WebContents* source, 909 content::WebContents* source,
827 const content::NativeWebKeyboardEvent& event, 910 const content::NativeWebKeyboardEvent& event,
828 bool* is_keyboard_shortcut) { 911 bool* is_keyboard_shortcut) {
829 if (IsDocked()) { 912 if (IsDocked()) {
830 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); 913 BrowserWindow* inspected_window = GetInspectedBrowserWindow();
831 if (inspected_window) { 914 if (inspected_window) {
832 return inspected_window->PreHandleKeyboardEvent(event, 915 return inspected_window->PreHandleKeyboardEvent(event,
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 return inspected_contents_observer_ ? 1489 return inspected_contents_observer_ ?
1407 inspected_contents_observer_->web_contents() : NULL; 1490 inspected_contents_observer_->web_contents() : NULL;
1408 } 1491 }
1409 1492
1410 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() { 1493 void DevToolsWindow::DocumentOnLoadCompletedInMainFrame() {
1411 is_loaded_ = true; 1494 is_loaded_ = true;
1412 UpdateTheme(); 1495 UpdateTheme();
1413 DoAction(); 1496 DoAction();
1414 AddDevToolsExtensionsToClient(); 1497 AddDevToolsExtensionsToClient();
1415 } 1498 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698