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 | 4 |
5 #include "chrome/browser/devtools/devtools_window.h" | 5 #include "chrome/browser/devtools/devtools_window.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 registry->RegisterBooleanPref( | 291 registry->RegisterBooleanPref( |
292 prefs::kDevToolsPortForwardingDefaultSet, | 292 prefs::kDevToolsPortForwardingDefaultSet, |
293 false, | 293 false, |
294 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 294 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
295 registry->RegisterDictionaryPref( | 295 registry->RegisterDictionaryPref( |
296 prefs::kDevToolsPortForwardingConfig, | 296 prefs::kDevToolsPortForwardingConfig, |
297 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 297 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
298 } | 298 } |
299 | 299 |
300 // static | 300 // static |
301 DevToolsWindow* DevToolsWindow::GetDockedInstanceForInspectedTab( | 301 DevToolsWindow* DevToolsWindow::GetInstanceForInspectedTab( |
302 content::WebContents* inspected_web_contents) { | 302 content::WebContents* inspected_web_contents) { |
303 if (!inspected_web_contents || | 303 if (!inspected_web_contents || |
304 !DevToolsAgentHost::HasFor(inspected_web_contents->GetRenderViewHost())) | 304 !DevToolsAgentHost::HasFor(inspected_web_contents->GetRenderViewHost())) |
305 return NULL; | 305 return NULL; |
306 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetOrCreateFor( | 306 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetOrCreateFor( |
307 inspected_web_contents->GetRenderViewHost())); | 307 inspected_web_contents->GetRenderViewHost())); |
308 DevToolsWindow* window = FindDevToolsWindow(agent.get()); | 308 DevToolsWindow* window = FindDevToolsWindow(agent.get()); |
309 return window ? window : NULL; | |
vsevik
2013/09/11 11:51:13
return window
lushnikov
2013/09/11 14:03:09
Done.
| |
310 } | |
311 | |
312 // static | |
313 DevToolsWindow* DevToolsWindow::GetDockedInstanceForInspectedTab( | |
314 content::WebContents* inspected_web_contents) { | |
315 DevToolsWindow* window = GetInstanceForInspectedTab(inspected_web_contents); | |
309 return (window && window->IsDocked()) ? window : NULL; | 316 return (window && window->IsDocked()) ? window : NULL; |
310 } | 317 } |
311 | 318 |
312 // static | 319 // static |
313 bool DevToolsWindow::IsDevToolsWindow(content::RenderViewHost* window_rvh) { | 320 bool DevToolsWindow::IsDevToolsWindow(content::RenderViewHost* window_rvh) { |
314 return AsDevToolsWindow(window_rvh) != NULL; | 321 return AsDevToolsWindow(window_rvh) != NULL; |
315 } | 322 } |
316 | 323 |
317 // static | 324 // static |
318 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( | 325 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
532 CreateDevToolsBrowser(); | 539 CreateDevToolsBrowser(); |
533 | 540 |
534 if (should_show_window) { | 541 if (should_show_window) { |
535 browser_->window()->Show(); | 542 browser_->window()->Show(); |
536 web_contents_->GetView()->SetInitialFocus(); | 543 web_contents_->GetView()->SetInitialFocus(); |
537 } | 544 } |
538 | 545 |
539 ScheduleAction(action); | 546 ScheduleAction(action); |
540 } | 547 } |
541 | 548 |
549 // static | |
550 void DevToolsWindow::HandleBeforeUnload(content::WebContents* frontend_contents, | |
551 bool proceed, bool* proceed_to_fire_unload) { | |
552 DevToolsWindow* window = AsDevToolsWindow( | |
553 frontend_contents->GetRenderViewHost()); | |
554 if (window) | |
555 window->BeforeUnloadFired(frontend_contents, proceed, | |
556 proceed_to_fire_unload); | |
557 } | |
558 | |
559 bool DevToolsWindow::InspectedPageWillClose() { | |
560 if (inspected_page_is_closing_) | |
561 return false; | |
562 inspected_page_is_closing_ = true; | |
563 closing_target_ = DEVTOOLS_CLOSING_TARGET_INSPECTED_PAGE; | |
564 web_contents_->GetRenderViewHost()->FirePageBeforeUnload(false); | |
565 return true; | |
566 } | |
567 | |
568 void DevToolsWindow::InspectedPageCancelClose() { | |
569 inspected_page_is_closing_ = false; | |
570 } | |
571 | |
542 DevToolsWindow::DevToolsWindow(Profile* profile, | 572 DevToolsWindow::DevToolsWindow(Profile* profile, |
543 const GURL& url, | 573 const GURL& url, |
544 content::RenderViewHost* inspected_rvh, | 574 content::RenderViewHost* inspected_rvh, |
545 DevToolsDockSide dock_side) | 575 DevToolsDockSide dock_side) |
546 : profile_(profile), | 576 : profile_(profile), |
547 browser_(NULL), | 577 browser_(NULL), |
548 dock_side_(dock_side), | 578 dock_side_(dock_side), |
549 is_loaded_(false), | 579 is_loaded_(false), |
550 action_on_load_(DEVTOOLS_TOGGLE_ACTION_SHOW), | 580 action_on_load_(DEVTOOLS_TOGGLE_ACTION_SHOW), |
551 weak_factory_(this), | 581 weak_factory_(this), |
552 width_(-1), | 582 width_(-1), |
553 height_(-1), | 583 height_(-1), |
554 dock_side_before_minimized_(dock_side) { | 584 dock_side_before_minimized_(dock_side), |
585 closing_target_(DEVTOOLS_CLOSING_TARGET_NONE), | |
586 inspected_page_is_closing_(false) { | |
555 web_contents_ = | 587 web_contents_ = |
556 content::WebContents::Create(content::WebContents::CreateParams(profile)); | 588 content::WebContents::Create(content::WebContents::CreateParams(profile)); |
557 frontend_contents_observer_.reset( | 589 frontend_contents_observer_.reset( |
558 new FrontendWebContentsObserver(web_contents_)); | 590 new FrontendWebContentsObserver(web_contents_)); |
559 | 591 |
560 web_contents_->GetController().LoadURL(url, content::Referrer(), | 592 web_contents_->GetController().LoadURL(url, content::Referrer(), |
561 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); | 593 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); |
562 | 594 |
563 frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost( | 595 frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost( |
564 web_contents_, this)); | 596 web_contents_, this)); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
772 bool* was_blocked) { | 804 bool* was_blocked) { |
773 content::WebContents* inspected_web_contents = GetInspectedWebContents(); | 805 content::WebContents* inspected_web_contents = GetInspectedWebContents(); |
774 if (inspected_web_contents) { | 806 if (inspected_web_contents) { |
775 inspected_web_contents->GetDelegate()->AddNewContents( | 807 inspected_web_contents->GetDelegate()->AddNewContents( |
776 source, new_contents, disposition, initial_pos, user_gesture, | 808 source, new_contents, disposition, initial_pos, user_gesture, |
777 was_blocked); | 809 was_blocked); |
778 } | 810 } |
779 } | 811 } |
780 | 812 |
781 void DevToolsWindow::CloseContents(content::WebContents* source) { | 813 void DevToolsWindow::CloseContents(content::WebContents* source) { |
814 // Update dev tools to reflect removed dev tools window. | |
815 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | |
816 if (inspected_window) | |
817 inspected_window->UpdateDevTools(); | |
818 // In case of docked web_contents_, we own it so delete here. | |
819 delete web_contents_; | |
820 | |
821 delete this; | |
822 } | |
823 | |
824 void DevToolsWindow::BeforeUnloadFired(content::WebContents* tab, | |
825 bool proceed, | |
826 bool* proceed_to_fire_unload) { | |
827 CHECK(closing_target_ != DEVTOOLS_CLOSING_TARGET_NONE); | |
vsevik
2013/09/11 11:51:13
According to http://www.chromium.org/developers/co
lushnikov
2013/09/11 14:03:09
Done.
| |
828 if (closing_target_ == DEVTOOLS_CLOSING_TARGET_DEVTOOLS) { | |
829 if (proceed) { | |
830 content::DevToolsManager::GetInstance()->ClientHostClosing( | |
831 frontend_host_.get()); | |
832 } | |
833 *proceed_to_fire_unload = proceed; | |
834 } else { | |
835 content::WebContents* inspected_web_contents = GetInspectedWebContents(); | |
836 if (proceed) { | |
837 inspected_web_contents->GetRenderViewHost()->FirePageBeforeUnload(false); | |
838 } else { | |
839 bool tmp; | |
840 inspected_web_contents->GetDelegate()->BeforeUnloadFired( | |
841 inspected_web_contents, false, &tmp); | |
842 CHECK(!tmp); | |
843 } | |
844 } | |
782 } | 845 } |
783 | 846 |
784 bool DevToolsWindow::PreHandleKeyboardEvent( | 847 bool DevToolsWindow::PreHandleKeyboardEvent( |
785 content::WebContents* source, | 848 content::WebContents* source, |
786 const content::NativeWebKeyboardEvent& event, | 849 const content::NativeWebKeyboardEvent& event, |
787 bool* is_keyboard_shortcut) { | 850 bool* is_keyboard_shortcut) { |
788 if (IsDocked()) { | 851 if (IsDocked()) { |
789 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 852 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
790 if (inspected_window) { | 853 if (inspected_window) { |
791 return inspected_window->PreHandleKeyboardEvent(event, | 854 return inspected_window->PreHandleKeyboardEvent(event, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
839 embedder_message_dispatcher_->Dispatch(message); | 902 embedder_message_dispatcher_->Dispatch(message); |
840 } | 903 } |
841 | 904 |
842 void DevToolsWindow::ActivateWindow() { | 905 void DevToolsWindow::ActivateWindow() { |
843 if (IsDocked() && GetInspectedBrowserWindow()) | 906 if (IsDocked() && GetInspectedBrowserWindow()) |
844 web_contents_->GetView()->Focus(); | 907 web_contents_->GetView()->Focus(); |
845 else if (!IsDocked() && !browser_->window()->IsActive()) | 908 else if (!IsDocked() && !browser_->window()->IsActive()) |
846 browser_->window()->Activate(); | 909 browser_->window()->Activate(); |
847 } | 910 } |
848 | 911 |
912 void DevToolsWindow::ActivateContents(content::WebContents* contents) { | |
vsevik
2013/09/11 11:51:13
I am not sure about this method, but why is it so
| |
913 if (IsDocked()) { | |
914 content::WebContents* inspected_tab = this->GetInspectedWebContents(); | |
915 inspected_tab->GetDelegate()->ActivateContents(inspected_tab); | |
916 } else { | |
917 browser_->window()->Activate(); | |
918 } | |
919 } | |
920 | |
849 void DevToolsWindow::CloseWindow() { | 921 void DevToolsWindow::CloseWindow() { |
850 DCHECK(IsDocked()); | 922 DCHECK(IsDocked()); |
851 content::DevToolsManager::GetInstance()->ClientHostClosing( | 923 closing_target_ = DEVTOOLS_CLOSING_TARGET_DEVTOOLS; |
vsevik
2013/09/11 11:51:13
Looks like this field is redundant.
lushnikov
2013/09/11 14:03:09
Done.
| |
852 frontend_host_.get()); | 924 web_contents_->GetRenderViewHost()->FirePageBeforeUnload(false); |
853 Hide(); | |
854 } | 925 } |
855 | 926 |
856 void DevToolsWindow::MoveWindow(int x, int y) { | 927 void DevToolsWindow::MoveWindow(int x, int y) { |
857 if (!IsDocked()) { | 928 if (!IsDocked()) { |
858 gfx::Rect bounds = browser_->window()->GetBounds(); | 929 gfx::Rect bounds = browser_->window()->GetBounds(); |
859 bounds.Offset(x, y); | 930 bounds.Offset(x, y); |
860 browser_->window()->SetBounds(bounds); | 931 browser_->window()->SetBounds(bounds); |
861 } | 932 } |
862 } | 933 } |
863 | 934 |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1185 void DevToolsWindow::UpdateFrontendDockSide() { | 1256 void DevToolsWindow::UpdateFrontendDockSide() { |
1186 base::StringValue dock_side(SideToString(dock_side_)); | 1257 base::StringValue dock_side(SideToString(dock_side_)); |
1187 CallClientFunction("InspectorFrontendAPI.setDockSide", &dock_side, NULL, | 1258 CallClientFunction("InspectorFrontendAPI.setDockSide", &dock_side, NULL, |
1188 NULL); | 1259 NULL); |
1189 base::FundamentalValue docked(IsDocked()); | 1260 base::FundamentalValue docked(IsDocked()); |
1190 CallClientFunction("InspectorFrontendAPI.setAttachedWindow", &docked, NULL, | 1261 CallClientFunction("InspectorFrontendAPI.setAttachedWindow", &docked, NULL, |
1191 NULL); | 1262 NULL); |
1192 } | 1263 } |
1193 | 1264 |
1194 void DevToolsWindow::Hide() { | 1265 void DevToolsWindow::Hide() { |
1195 if (IsDocked()) { | 1266 web_contents_->GetRenderViewHost()->ClosePage(); |
vsevik
2013/09/11 11:51:13
IS this correct in case of undocked devtools?
why
lushnikov
2013/09/11 14:03:09
The deletion of DevToolsWindow will happen in ::Ob
| |
1196 // Update dev tools to reflect removed dev tools window. | |
1197 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | |
1198 if (inspected_window) | |
1199 inspected_window->UpdateDevTools(); | |
1200 // In case of docked web_contents_, we own it so delete here. | |
1201 delete web_contents_; | |
1202 | |
1203 delete this; | |
1204 } else { | |
1205 // First, initiate self-destruct to free all the registrars. | |
1206 // Then close all tabs. Browser will take care of deleting web_contents_ | |
1207 // for us. | |
1208 Browser* browser = browser_; | |
1209 delete this; | |
1210 browser->tab_strip_model()->CloseAllTabs(); | |
1211 } | |
1212 } | 1267 } |
1213 | 1268 |
1214 void DevToolsWindow::ScheduleAction(DevToolsToggleAction action) { | 1269 void DevToolsWindow::ScheduleAction(DevToolsToggleAction action) { |
1215 action_on_load_ = action; | 1270 action_on_load_ = action; |
1216 if (is_loaded_) | 1271 if (is_loaded_) |
1217 DoAction(); | 1272 DoAction(); |
1218 } | 1273 } |
1219 | 1274 |
1220 void DevToolsWindow::DoAction() { | 1275 void DevToolsWindow::DoAction() { |
1221 UpdateFrontendDockSide(); | 1276 UpdateFrontendDockSide(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1328 | 1383 |
1329 void DevToolsWindow::Restore() { | 1384 void DevToolsWindow::Restore() { |
1330 if (dock_side_ == DEVTOOLS_DOCK_SIDE_MINIMIZED) | 1385 if (dock_side_ == DEVTOOLS_DOCK_SIDE_MINIMIZED) |
1331 SetDockSide(SideToString(dock_side_before_minimized_)); | 1386 SetDockSide(SideToString(dock_side_before_minimized_)); |
1332 } | 1387 } |
1333 | 1388 |
1334 content::WebContents* DevToolsWindow::GetInspectedWebContents() { | 1389 content::WebContents* DevToolsWindow::GetInspectedWebContents() { |
1335 return inspected_contents_observer_ ? | 1390 return inspected_contents_observer_ ? |
1336 inspected_contents_observer_->web_contents() : NULL; | 1391 inspected_contents_observer_->web_contents() : NULL; |
1337 } | 1392 } |
OLD | NEW |