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_reader.h" | 10 #include "base/json/json_reader.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/prefs/scoped_user_pref_update.h" | 12 #include "base/prefs/scoped_user_pref_update.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/file_select_helper.h" | 15 #include "chrome/browser/file_select_helper.h" |
16 #include "chrome/browser/infobars/infobar_service.h" | 16 #include "chrome/browser/infobars/infobar_service.h" |
17 #include "chrome/browser/prefs/pref_service_syncable.h" | 17 #include "chrome/browser/prefs/pref_service_syncable.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/sessions/session_tab_helper.h" | 19 #include "chrome/browser/sessions/session_tab_helper.h" |
20 #include "chrome/browser/task_management/web_contents_tags.h" | 20 #include "chrome/browser/task_management/web_contents_tags.h" |
21 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
22 #include "chrome/browser/ui/browser_dialogs.h" | 22 #include "chrome/browser/ui/browser_dialogs.h" |
| 23 #include "chrome/browser/ui/browser_finder.h" |
23 #include "chrome/browser/ui/browser_iterator.h" | 24 #include "chrome/browser/ui/browser_iterator.h" |
24 #include "chrome/browser/ui/browser_list.h" | 25 #include "chrome/browser/ui/browser_list.h" |
25 #include "chrome/browser/ui/browser_tabstrip.h" | 26 #include "chrome/browser/ui/browser_tabstrip.h" |
26 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
27 #include "chrome/browser/ui/host_desktop.h" | 28 #include "chrome/browser/ui/host_desktop.h" |
28 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" | 29 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" |
29 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 30 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
30 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 31 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
31 #include "chrome/browser/ui/webui/devtools_ui.h" | 32 #include "chrome/browser/ui/webui/devtools_ui.h" |
32 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 return NULL; | 347 return NULL; |
347 | 348 |
348 // Not yet loaded window is treated as docked, but we should not present it | 349 // Not yet loaded window is treated as docked, but we should not present it |
349 // until we decided on docking. | 350 // until we decided on docking. |
350 bool is_docked_set = window->life_stage_ == kLoadCompleted || | 351 bool is_docked_set = window->life_stage_ == kLoadCompleted || |
351 window->life_stage_ == kIsDockedSet; | 352 window->life_stage_ == kIsDockedSet; |
352 if (!is_docked_set) | 353 if (!is_docked_set) |
353 return NULL; | 354 return NULL; |
354 | 355 |
355 // Undocked window should have toolbox web contents. | 356 // Undocked window should have toolbox web contents. |
356 if (!window->is_docked_ && !window->toolbox_web_contents_) | 357 if (!window->IsDocked() && !window->toolbox_web_contents_) |
357 return NULL; | 358 return NULL; |
358 | 359 |
359 if (out_strategy) | 360 if (out_strategy) |
360 out_strategy->CopyFrom(window->contents_resizing_strategy_); | 361 out_strategy->CopyFrom(window->contents_resizing_strategy_); |
361 | 362 |
362 return window->is_docked_ ? window->main_web_contents_ : | 363 return window->IsDocked() ? window->main_web_contents_ |
363 window->toolbox_web_contents_; | 364 : window->toolbox_web_contents_; |
364 } | 365 } |
365 | 366 |
366 // static | 367 // static |
367 DevToolsWindow* DevToolsWindow::GetInstanceForInspectedWebContents( | 368 DevToolsWindow* DevToolsWindow::GetInstanceForInspectedWebContents( |
368 WebContents* inspected_web_contents) { | 369 WebContents* inspected_web_contents) { |
369 if (!inspected_web_contents || g_instances == NULL) | 370 if (!inspected_web_contents || g_instances == NULL) |
370 return NULL; | 371 return NULL; |
371 DevToolsWindows* instances = g_instances.Pointer(); | 372 DevToolsWindows* instances = g_instances.Pointer(); |
372 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); | 373 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); |
373 ++it) { | 374 ++it) { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 return; | 497 return; |
497 window->bindings_->AttachTo(agent.get()); | 498 window->bindings_->AttachTo(agent.get()); |
498 do_open = true; | 499 do_open = true; |
499 } | 500 } |
500 | 501 |
501 // Update toolbar to reflect DevTools changes. | 502 // Update toolbar to reflect DevTools changes. |
502 window->UpdateBrowserToolbar(); | 503 window->UpdateBrowserToolbar(); |
503 | 504 |
504 // If window is docked and visible, we hide it on toggle. If window is | 505 // If window is docked and visible, we hide it on toggle. If window is |
505 // undocked, we show (activate) it. | 506 // undocked, we show (activate) it. |
506 if (!window->is_docked_ || do_open) | 507 if (!window->IsDocked() || do_open) |
507 window->ScheduleShow(action); | 508 window->ScheduleShow(action); |
508 else | 509 else |
509 window->CloseWindow(); | 510 window->CloseWindow(); |
510 } | 511 } |
511 | 512 |
512 // static | 513 // static |
513 void DevToolsWindow::InspectElement( | 514 void DevToolsWindow::InspectElement( |
514 content::WebContents* inspected_web_contents, | 515 content::WebContents* inspected_web_contents, |
515 int x, | 516 int x, |
516 int y) { | 517 int y) { |
(...skipping 15 matching lines...) Expand all Loading... |
532 if (life_stage_ == kLoadCompleted) { | 533 if (life_stage_ == kLoadCompleted) { |
533 Show(action); | 534 Show(action); |
534 return; | 535 return; |
535 } | 536 } |
536 | 537 |
537 // Action will be done only after load completed. | 538 // Action will be done only after load completed. |
538 action_on_load_ = action; | 539 action_on_load_ = action; |
539 | 540 |
540 if (!can_dock_) { | 541 if (!can_dock_) { |
541 // No harm to show always-undocked window right away. | 542 // No harm to show always-undocked window right away. |
542 is_docked_ = false; | 543 dock_requested_ = false; |
543 Show(DevToolsToggleAction::Show()); | 544 Show(DevToolsToggleAction::Show()); |
544 } | 545 } |
545 } | 546 } |
546 | 547 |
547 void DevToolsWindow::Show(const DevToolsToggleAction& action) { | 548 void DevToolsWindow::Show(const DevToolsToggleAction& action) { |
548 if (life_stage_ == kClosing) | 549 if (life_stage_ == kClosing) |
549 return; | 550 return; |
550 | 551 |
551 if (action.type() == DevToolsToggleAction::kNoOp) | 552 if (action.type() == DevToolsToggleAction::kNoOp) |
552 return; | 553 return; |
553 | 554 |
554 if (is_docked_) { | 555 if (IsDocked()) { |
555 DCHECK(can_dock_); | 556 DCHECK(can_dock_); |
556 Browser* inspected_browser = NULL; | 557 Browser* inspected_browser = NULL; |
557 int inspected_tab_index = -1; | 558 int inspected_tab_index = -1; |
558 FindInspectedBrowserAndTabIndex(GetInspectedWebContents(), | 559 FindInspectedBrowserAndTabIndex(GetInspectedWebContents(), |
559 &inspected_browser, | 560 &inspected_browser, |
560 &inspected_tab_index); | 561 &inspected_tab_index); |
561 DCHECK(inspected_browser); | 562 DCHECK(inspected_browser); |
562 DCHECK(inspected_tab_index != -1); | 563 DCHECK(inspected_tab_index != -1); |
563 | 564 |
564 // Tell inspected browser to update splitter and switch to inspected panel. | 565 // Tell inspected browser to update splitter and switch to inspected panel. |
(...skipping 13 matching lines...) Expand all Loading... |
578 | 579 |
579 PrefsTabHelper::CreateForWebContents(main_web_contents_); | 580 PrefsTabHelper::CreateForWebContents(main_web_contents_); |
580 main_web_contents_->GetRenderViewHost()->SyncRendererPrefs(); | 581 main_web_contents_->GetRenderViewHost()->SyncRendererPrefs(); |
581 | 582 |
582 DoAction(action); | 583 DoAction(action); |
583 return; | 584 return; |
584 } | 585 } |
585 | 586 |
586 // Avoid consecutive window switching if the devtools window has been opened | 587 // Avoid consecutive window switching if the devtools window has been opened |
587 // and the Inspect Element shortcut is pressed in the inspected tab. | 588 // and the Inspect Element shortcut is pressed in the inspected tab. |
| 589 Browser* browser = GetBrowser(); |
588 bool should_show_window = | 590 bool should_show_window = |
589 !browser_ || (action.type() != DevToolsToggleAction::kInspect); | 591 !browser || (action.type() != DevToolsToggleAction::kInspect); |
590 | 592 |
591 if (!browser_) | 593 if (!browser) |
592 CreateDevToolsBrowser(); | 594 browser = CreateDevToolsBrowser(); |
593 | 595 |
594 if (should_show_window) { | 596 if (should_show_window) { |
595 browser_->window()->Show(); | 597 browser->window()->Show(); |
596 main_web_contents_->SetInitialFocus(); | 598 main_web_contents_->SetInitialFocus(); |
597 } | 599 } |
598 if (toolbox_web_contents_) | 600 if (toolbox_web_contents_) |
599 UpdateBrowserWindow(); | 601 UpdateBrowserWindow(); |
600 | 602 |
601 DoAction(action); | 603 DoAction(action); |
602 } | 604 } |
603 | 605 |
604 // static | 606 // static |
605 bool DevToolsWindow::HandleBeforeUnload(WebContents* frontend_contents, | 607 bool DevToolsWindow::HandleBeforeUnload(WebContents* frontend_contents, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 | 674 |
673 DevToolsWindow::DevToolsWindow(Profile* profile, | 675 DevToolsWindow::DevToolsWindow(Profile* profile, |
674 WebContents* main_web_contents, | 676 WebContents* main_web_contents, |
675 DevToolsUIBindings* bindings, | 677 DevToolsUIBindings* bindings, |
676 WebContents* inspected_web_contents, | 678 WebContents* inspected_web_contents, |
677 bool can_dock) | 679 bool can_dock) |
678 : profile_(profile), | 680 : profile_(profile), |
679 main_web_contents_(main_web_contents), | 681 main_web_contents_(main_web_contents), |
680 toolbox_web_contents_(nullptr), | 682 toolbox_web_contents_(nullptr), |
681 bindings_(bindings), | 683 bindings_(bindings), |
682 browser_(nullptr), | 684 dock_requested_(true), |
683 is_docked_(true), | |
684 can_dock_(can_dock), | 685 can_dock_(can_dock), |
685 // This initialization allows external front-end to work without changes. | 686 // This initialization allows external front-end to work without changes. |
686 // We don't wait for docking call, but instead immediately show undocked. | 687 // We don't wait for docking call, but instead immediately show undocked. |
687 // Passing "dockSide=undocked" parameter ensures proper UI. | 688 // Passing "dockSide=undocked" parameter ensures proper UI. |
688 life_stage_(can_dock ? kNotLoaded : kIsDockedSet), | 689 life_stage_(can_dock ? kNotLoaded : kIsDockedSet), |
689 action_on_load_(DevToolsToggleAction::NoOp()), | 690 action_on_load_(DevToolsToggleAction::NoOp()), |
690 intercepted_page_beforeunload_(false) { | 691 intercepted_page_beforeunload_(false) { |
691 // Set up delegate, so we get fully-functional window immediately. | 692 // Set up delegate, so we get fully-functional window immediately. |
692 // It will not appear in UI though until |life_stage_ == kLoadCompleted|. | 693 // It will not appear in UI though until |life_stage_ == kLoadCompleted|. |
693 main_web_contents_->SetDelegate(this); | 694 main_web_contents_->SetDelegate(this); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 } | 840 } |
840 | 841 |
841 bindings_->Reattach(); | 842 bindings_->Reattach(); |
842 | 843 |
843 content::NavigationController::LoadURLParams load_url_params(params.url); | 844 content::NavigationController::LoadURLParams load_url_params(params.url); |
844 main_web_contents_->GetController().LoadURLWithParams(load_url_params); | 845 main_web_contents_->GetController().LoadURLWithParams(load_url_params); |
845 return main_web_contents_; | 846 return main_web_contents_; |
846 } | 847 } |
847 | 848 |
848 void DevToolsWindow::ActivateContents(WebContents* contents) { | 849 void DevToolsWindow::ActivateContents(WebContents* contents) { |
849 if (is_docked_) { | 850 Browser* browser = GetBrowser(); |
| 851 if (browser == nullptr) { |
850 WebContents* inspected_tab = GetInspectedWebContents(); | 852 WebContents* inspected_tab = GetInspectedWebContents(); |
851 if (inspected_tab) | 853 if (inspected_tab) |
852 inspected_tab->GetDelegate()->ActivateContents(inspected_tab); | 854 inspected_tab->GetDelegate()->ActivateContents(inspected_tab); |
853 } else if (browser_) { | 855 } else { |
854 browser_->window()->Activate(); | 856 browser->window()->Activate(); |
855 } | 857 } |
856 } | 858 } |
857 | 859 |
858 void DevToolsWindow::AddNewContents(WebContents* source, | 860 void DevToolsWindow::AddNewContents(WebContents* source, |
859 WebContents* new_contents, | 861 WebContents* new_contents, |
860 WindowOpenDisposition disposition, | 862 WindowOpenDisposition disposition, |
861 const gfx::Rect& initial_rect, | 863 const gfx::Rect& initial_rect, |
862 bool user_gesture, | 864 bool user_gesture, |
863 bool* was_blocked) { | 865 bool* was_blocked) { |
864 if (new_contents == toolbox_web_contents_) { | 866 if (new_contents == toolbox_web_contents_) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 toolbox_web_contents_ = new_contents; | 898 toolbox_web_contents_ = new_contents; |
897 | 899 |
898 // Tag the DevTools toolbox WebContents with its TaskManager specific | 900 // Tag the DevTools toolbox WebContents with its TaskManager specific |
899 // UserData so that it shows up in the task manager. | 901 // UserData so that it shows up in the task manager. |
900 task_management::WebContentsTags::CreateForDevToolsContents( | 902 task_management::WebContentsTags::CreateForDevToolsContents( |
901 toolbox_web_contents_); | 903 toolbox_web_contents_); |
902 } | 904 } |
903 } | 905 } |
904 | 906 |
905 void DevToolsWindow::CloseContents(WebContents* source) { | 907 void DevToolsWindow::CloseContents(WebContents* source) { |
906 CHECK(is_docked_); | 908 CHECK(IsDocked()); |
907 life_stage_ = kClosing; | 909 life_stage_ = kClosing; |
908 UpdateBrowserWindow(); | 910 UpdateBrowserWindow(); |
909 // In case of docked main_web_contents_, we own it so delete here. | 911 // In case of docked main_web_contents_, we own it so delete here. |
910 // Embedding DevTools window will be deleted as a result of | 912 // Embedding DevTools window will be deleted as a result of |
911 // DevToolsUIBindings destruction. | 913 // DevToolsUIBindings destruction. |
912 delete main_web_contents_; | 914 delete main_web_contents_; |
913 } | 915 } |
914 | 916 |
915 void DevToolsWindow::ContentsZoomChange(bool zoom_in) { | 917 void DevToolsWindow::ContentsZoomChange(bool zoom_in) { |
916 DCHECK(is_docked_); | 918 DCHECK(IsDocked()); |
917 ui_zoom::PageZoom::Zoom(main_web_contents_, zoom_in ? content::PAGE_ZOOM_IN | 919 ui_zoom::PageZoom::Zoom(main_web_contents_, zoom_in ? content::PAGE_ZOOM_IN |
918 : content::PAGE_ZOOM_OUT); | 920 : content::PAGE_ZOOM_OUT); |
919 } | 921 } |
920 | 922 |
921 void DevToolsWindow::BeforeUnloadFired(WebContents* tab, | 923 void DevToolsWindow::BeforeUnloadFired(WebContents* tab, |
922 bool proceed, | 924 bool proceed, |
923 bool* proceed_to_fire_unload) { | 925 bool* proceed_to_fire_unload) { |
924 if (!intercepted_page_beforeunload_) { | 926 if (!intercepted_page_beforeunload_) { |
925 // Docked devtools window closed directly. | 927 // Docked devtools window closed directly. |
926 if (proceed) | 928 if (proceed) |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 const blink::WebGestureEvent& event) { | 993 const blink::WebGestureEvent& event) { |
992 // Disable pinch zooming. | 994 // Disable pinch zooming. |
993 return event.type == blink::WebGestureEvent::GesturePinchBegin || | 995 return event.type == blink::WebGestureEvent::GesturePinchBegin || |
994 event.type == blink::WebGestureEvent::GesturePinchUpdate || | 996 event.type == blink::WebGestureEvent::GesturePinchUpdate || |
995 event.type == blink::WebGestureEvent::GesturePinchEnd; | 997 event.type == blink::WebGestureEvent::GesturePinchEnd; |
996 } | 998 } |
997 | 999 |
998 void DevToolsWindow::ActivateWindow() { | 1000 void DevToolsWindow::ActivateWindow() { |
999 if (life_stage_ != kLoadCompleted) | 1001 if (life_stage_ != kLoadCompleted) |
1000 return; | 1002 return; |
1001 if (is_docked_ && GetInspectedBrowserWindow()) | 1003 bool is_docked = IsDocked(); |
| 1004 if (is_docked && GetInspectedBrowserWindow()) { |
1002 main_web_contents_->Focus(); | 1005 main_web_contents_->Focus(); |
1003 else if (!is_docked_ && !browser_->window()->IsActive()) | 1006 } else if (!is_docked) { |
1004 browser_->window()->Activate(); | 1007 Browser* browser = GetBrowser(); |
| 1008 if (!browser->window()->IsActive()) |
| 1009 browser->window()->Activate(); |
| 1010 } |
1005 } | 1011 } |
1006 | 1012 |
1007 void DevToolsWindow::CloseWindow() { | 1013 void DevToolsWindow::CloseWindow() { |
1008 DCHECK(is_docked_); | 1014 DCHECK(IsDocked()); |
1009 life_stage_ = kClosing; | 1015 life_stage_ = kClosing; |
1010 main_web_contents_->DispatchBeforeUnload(false); | 1016 main_web_contents_->DispatchBeforeUnload(false); |
1011 } | 1017 } |
1012 | 1018 |
1013 void DevToolsWindow::SetInspectedPageBounds(const gfx::Rect& rect) { | 1019 void DevToolsWindow::SetInspectedPageBounds(const gfx::Rect& rect) { |
1014 DevToolsContentsResizingStrategy strategy(rect); | 1020 DevToolsContentsResizingStrategy strategy(rect); |
1015 if (contents_resizing_strategy_.Equals(strategy)) | 1021 if (contents_resizing_strategy_.Equals(strategy)) |
1016 return; | 1022 return; |
1017 | 1023 |
1018 contents_resizing_strategy_.CopyFrom(strategy); | 1024 contents_resizing_strategy_.CopyFrom(strategy); |
1019 UpdateBrowserWindow(); | 1025 UpdateBrowserWindow(); |
1020 } | 1026 } |
1021 | 1027 |
1022 void DevToolsWindow::InspectElementCompleted() { | 1028 void DevToolsWindow::InspectElementCompleted() { |
1023 if (!inspect_element_start_time_.is_null()) { | 1029 if (!inspect_element_start_time_.is_null()) { |
1024 UMA_HISTOGRAM_TIMES("DevTools.InspectElement", | 1030 UMA_HISTOGRAM_TIMES("DevTools.InspectElement", |
1025 base::TimeTicks::Now() - inspect_element_start_time_); | 1031 base::TimeTicks::Now() - inspect_element_start_time_); |
1026 inspect_element_start_time_ = base::TimeTicks(); | 1032 inspect_element_start_time_ = base::TimeTicks(); |
1027 } | 1033 } |
1028 } | 1034 } |
1029 | 1035 |
1030 void DevToolsWindow::SetIsDocked(bool dock_requested) { | 1036 void DevToolsWindow::SetIsDocked(bool dock_requested) { |
1031 if (life_stage_ == kClosing) | 1037 if (life_stage_ == kClosing) |
1032 return; | 1038 return; |
1033 | 1039 |
1034 DCHECK(can_dock_ || !dock_requested); | 1040 DCHECK(can_dock_ || !dock_requested); |
1035 if (!can_dock_) | 1041 if (!can_dock_) |
1036 dock_requested = false; | 1042 dock_requested = false; |
1037 | 1043 |
1038 bool was_docked = is_docked_; | 1044 bool was_docked = IsDocked(); |
1039 is_docked_ = dock_requested; | 1045 dock_requested_ = dock_requested; |
1040 | 1046 |
1041 if (life_stage_ != kLoadCompleted) { | 1047 if (life_stage_ != kLoadCompleted) { |
1042 // This is a first time call we waited for to initialize. | 1048 // This is a first time call we waited for to initialize. |
1043 life_stage_ = life_stage_ == kOnLoadFired ? kLoadCompleted : kIsDockedSet; | 1049 life_stage_ = life_stage_ == kOnLoadFired ? kLoadCompleted : kIsDockedSet; |
1044 if (life_stage_ == kLoadCompleted) | 1050 if (life_stage_ == kLoadCompleted) |
1045 LoadCompleted(); | 1051 LoadCompleted(); |
1046 return; | 1052 return; |
1047 } | 1053 } |
1048 | 1054 |
1049 if (dock_requested == was_docked) | 1055 if (dock_requested == was_docked) |
1050 return; | 1056 return; |
1051 | 1057 |
1052 if (dock_requested && !was_docked) { | 1058 if (dock_requested && !was_docked) { |
1053 // Detach window from the external devtools browser. It will lead to | 1059 DetachFromBrowser(); |
1054 // the browser object's close and delete. Remove observer first. | |
1055 TabStripModel* tab_strip_model = browser_->tab_strip_model(); | |
1056 tab_strip_model->DetachWebContentsAt( | |
1057 tab_strip_model->GetIndexOfWebContents(main_web_contents_)); | |
1058 browser_ = NULL; | |
1059 } else if (!dock_requested && was_docked) { | 1060 } else if (!dock_requested && was_docked) { |
1060 UpdateBrowserWindow(); | 1061 UpdateBrowserWindow(); |
1061 } | 1062 } |
1062 | 1063 |
1063 Show(DevToolsToggleAction::Show()); | 1064 Show(DevToolsToggleAction::Show()); |
1064 } | 1065 } |
1065 | 1066 |
1066 void DevToolsWindow::OpenInNewTab(const std::string& url) { | 1067 void DevToolsWindow::OpenInNewTab(const std::string& url) { |
1067 content::OpenURLParams params( | 1068 content::OpenURLParams params( |
1068 GURL(url), content::Referrer(), NEW_FOREGROUND_TAB, | 1069 GURL(url), content::Referrer(), NEW_FOREGROUND_TAB, |
1069 ui::PAGE_TRANSITION_LINK, false); | 1070 ui::PAGE_TRANSITION_LINK, false); |
1070 WebContents* inspected_web_contents = GetInspectedWebContents(); | 1071 WebContents* inspected_web_contents = GetInspectedWebContents(); |
1071 if (!inspected_web_contents || !inspected_web_contents->OpenURL(params)) { | 1072 if (!inspected_web_contents || !inspected_web_contents->OpenURL(params)) { |
| 1073 Browser* browser = GetBrowser(); |
1072 chrome::HostDesktopType host_desktop_type = | 1074 chrome::HostDesktopType host_desktop_type = |
1073 browser_ ? browser_->host_desktop_type() : chrome::GetActiveDesktop(); | 1075 browser ? browser->host_desktop_type() : chrome::GetActiveDesktop(); |
1074 | 1076 |
1075 chrome::ScopedTabbedBrowserDisplayer displayer(profile_, host_desktop_type); | 1077 chrome::ScopedTabbedBrowserDisplayer displayer(profile_, host_desktop_type); |
1076 chrome::AddSelectedTabWithURL(displayer.browser(), GURL(url), | 1078 chrome::AddSelectedTabWithURL(displayer.browser(), GURL(url), |
1077 ui::PAGE_TRANSITION_LINK); | 1079 ui::PAGE_TRANSITION_LINK); |
1078 } | 1080 } |
1079 } | 1081 } |
1080 | 1082 |
1081 void DevToolsWindow::SetWhitelistedShortcuts( | 1083 void DevToolsWindow::SetWhitelistedShortcuts( |
1082 const std::string& message) { | 1084 const std::string& message) { |
1083 event_forwarder_->SetWhitelistedShortcuts(message); | 1085 event_forwarder_->SetWhitelistedShortcuts(message); |
1084 } | 1086 } |
1085 | 1087 |
1086 void DevToolsWindow::InspectedContentsClosing() { | 1088 void DevToolsWindow::InspectedContentsClosing() { |
1087 intercepted_page_beforeunload_ = false; | 1089 intercepted_page_beforeunload_ = false; |
1088 life_stage_ = kClosing; | 1090 life_stage_ = kClosing; |
1089 main_web_contents_->ClosePage(); | 1091 main_web_contents_->ClosePage(); |
1090 } | 1092 } |
1091 | 1093 |
1092 InfoBarService* DevToolsWindow::GetInfoBarService() { | 1094 InfoBarService* DevToolsWindow::GetInfoBarService() { |
1093 return is_docked_ ? | 1095 return IsDocked() ? InfoBarService::FromWebContents(GetInspectedWebContents()) |
1094 InfoBarService::FromWebContents(GetInspectedWebContents()) : | 1096 : InfoBarService::FromWebContents(main_web_contents_); |
1095 InfoBarService::FromWebContents(main_web_contents_); | |
1096 } | 1097 } |
1097 | 1098 |
1098 void DevToolsWindow::RenderProcessGone(bool crashed) { | 1099 void DevToolsWindow::RenderProcessGone(bool crashed) { |
1099 // Docked DevToolsWindow owns its main_web_contents_ and must delete it. | 1100 // Docked DevToolsWindow owns its main_web_contents_ and must delete it. |
1100 // Undocked main_web_contents_ are owned and handled by browser. | 1101 // Undocked main_web_contents_ are owned and handled by browser. |
1101 // see crbug.com/369932 | 1102 // see crbug.com/369932 |
1102 if (is_docked_) { | 1103 if (IsDocked()) { |
1103 CloseContents(main_web_contents_); | 1104 CloseContents(main_web_contents_); |
1104 } else if (browser_ && crashed) { | 1105 } else if (crashed) { |
1105 browser_->window()->Close(); | 1106 DetachFromBrowser(); |
1106 } | 1107 } |
1107 } | 1108 } |
1108 | 1109 |
1109 void DevToolsWindow::OnLoadCompleted() { | 1110 void DevToolsWindow::OnLoadCompleted() { |
1110 // First seed inspected tab id for extension APIs. | 1111 // First seed inspected tab id for extension APIs. |
1111 WebContents* inspected_web_contents = GetInspectedWebContents(); | 1112 WebContents* inspected_web_contents = GetInspectedWebContents(); |
1112 if (inspected_web_contents) { | 1113 if (inspected_web_contents) { |
1113 SessionTabHelper* session_tab_helper = | 1114 SessionTabHelper* session_tab_helper = |
1114 SessionTabHelper::FromWebContents(inspected_web_contents); | 1115 SessionTabHelper::FromWebContents(inspected_web_contents); |
1115 if (session_tab_helper) { | 1116 if (session_tab_helper) { |
1116 base::FundamentalValue tabId(session_tab_helper->session_id().id()); | 1117 base::FundamentalValue tabId(session_tab_helper->session_id().id()); |
1117 bindings_->CallClientFunction("DevToolsAPI.setInspectedTabId", | 1118 bindings_->CallClientFunction("DevToolsAPI.setInspectedTabId", |
1118 &tabId, NULL, NULL); | 1119 &tabId, NULL, NULL); |
1119 } | 1120 } |
1120 } | 1121 } |
1121 | 1122 |
1122 if (life_stage_ == kClosing) | 1123 if (life_stage_ == kClosing) |
1123 return; | 1124 return; |
1124 | 1125 |
1125 // We could be in kLoadCompleted state already if frontend reloads itself. | 1126 // We could be in kLoadCompleted state already if frontend reloads itself. |
1126 if (life_stage_ != kLoadCompleted) { | 1127 if (life_stage_ != kLoadCompleted) { |
1127 // Load is completed when both kIsDockedSet and kOnLoadFired happened. | 1128 // Load is completed when both kIsDockedSet and kOnLoadFired happened. |
1128 // Here we set kOnLoadFired. | 1129 // Here we set kOnLoadFired. |
1129 life_stage_ = life_stage_ == kIsDockedSet ? kLoadCompleted : kOnLoadFired; | 1130 life_stage_ = life_stage_ == kIsDockedSet ? kLoadCompleted : kOnLoadFired; |
1130 } | 1131 } |
1131 if (life_stage_ == kLoadCompleted) | 1132 if (life_stage_ == kLoadCompleted) |
1132 LoadCompleted(); | 1133 LoadCompleted(); |
1133 } | 1134 } |
1134 | 1135 |
1135 void DevToolsWindow::CreateDevToolsBrowser() { | 1136 Browser* DevToolsWindow::CreateDevToolsBrowser() { |
1136 PrefService* prefs = profile_->GetPrefs(); | 1137 PrefService* prefs = profile_->GetPrefs(); |
1137 if (!prefs->GetDictionary(prefs::kAppWindowPlacement)->HasKey(kDevToolsApp)) { | 1138 if (!prefs->GetDictionary(prefs::kAppWindowPlacement)->HasKey(kDevToolsApp)) { |
1138 DictionaryPrefUpdate update(prefs, prefs::kAppWindowPlacement); | 1139 DictionaryPrefUpdate update(prefs, prefs::kAppWindowPlacement); |
1139 base::DictionaryValue* wp_prefs = update.Get(); | 1140 base::DictionaryValue* wp_prefs = update.Get(); |
1140 base::DictionaryValue* dev_tools_defaults = new base::DictionaryValue; | 1141 base::DictionaryValue* dev_tools_defaults = new base::DictionaryValue; |
1141 wp_prefs->Set(kDevToolsApp, dev_tools_defaults); | 1142 wp_prefs->Set(kDevToolsApp, dev_tools_defaults); |
1142 dev_tools_defaults->SetInteger("left", 100); | 1143 dev_tools_defaults->SetInteger("left", 100); |
1143 dev_tools_defaults->SetInteger("top", 100); | 1144 dev_tools_defaults->SetInteger("top", 100); |
1144 dev_tools_defaults->SetInteger("right", 740); | 1145 dev_tools_defaults->SetInteger("right", 740); |
1145 dev_tools_defaults->SetInteger("bottom", 740); | 1146 dev_tools_defaults->SetInteger("bottom", 740); |
1146 dev_tools_defaults->SetBoolean("maximized", false); | 1147 dev_tools_defaults->SetBoolean("maximized", false); |
1147 dev_tools_defaults->SetBoolean("always_on_top", false); | 1148 dev_tools_defaults->SetBoolean("always_on_top", false); |
1148 } | 1149 } |
1149 | 1150 |
1150 browser_ = new Browser(Browser::CreateParams::CreateForDevTools( | 1151 Browser* browser = new Browser(Browser::CreateParams::CreateForDevTools( |
1151 profile_, | 1152 profile_, chrome::GetHostDesktopTypeForNativeView( |
1152 chrome::GetHostDesktopTypeForNativeView( | 1153 main_web_contents_->GetNativeView()))); |
1153 main_web_contents_->GetNativeView()))); | 1154 browser->tab_strip_model()->AddWebContents(main_web_contents_, -1, |
1154 browser_->tab_strip_model()->AddWebContents( | 1155 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
1155 main_web_contents_, -1, ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 1156 TabStripModel::ADD_ACTIVE); |
1156 TabStripModel::ADD_ACTIVE); | |
1157 main_web_contents_->GetRenderViewHost()->SyncRendererPrefs(); | 1157 main_web_contents_->GetRenderViewHost()->SyncRendererPrefs(); |
| 1158 return browser; |
1158 } | 1159 } |
1159 | 1160 |
1160 BrowserWindow* DevToolsWindow::GetInspectedBrowserWindow() { | 1161 BrowserWindow* DevToolsWindow::GetInspectedBrowserWindow() { |
1161 Browser* browser = NULL; | 1162 Browser* browser = NULL; |
1162 int tab; | 1163 int tab; |
1163 return FindInspectedBrowserAndTabIndex(GetInspectedWebContents(), | 1164 return FindInspectedBrowserAndTabIndex(GetInspectedWebContents(), |
1164 &browser, &tab) ? | 1165 &browser, &tab) ? |
1165 browser->window() : NULL; | 1166 browser->window() : NULL; |
1166 } | 1167 } |
1167 | 1168 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 if (inspected_window) | 1206 if (inspected_window) |
1206 inspected_window->UpdateToolbar(NULL); | 1207 inspected_window->UpdateToolbar(NULL); |
1207 } | 1208 } |
1208 | 1209 |
1209 void DevToolsWindow::UpdateBrowserWindow() { | 1210 void DevToolsWindow::UpdateBrowserWindow() { |
1210 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 1211 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
1211 if (inspected_window) | 1212 if (inspected_window) |
1212 inspected_window->UpdateDevTools(); | 1213 inspected_window->UpdateDevTools(); |
1213 } | 1214 } |
1214 | 1215 |
| 1216 Browser* DevToolsWindow::GetBrowser() { |
| 1217 return chrome::FindBrowserWithWebContents(main_web_contents_); |
| 1218 } |
| 1219 |
| 1220 bool DevToolsWindow::IsDocked() { |
| 1221 if (GetBrowser() != nullptr) |
| 1222 return false; |
| 1223 return dock_requested_; |
| 1224 } |
| 1225 |
| 1226 void DevToolsWindow::DetachFromBrowser() { |
| 1227 Browser* browser = GetBrowser(); |
| 1228 if (browser) { |
| 1229 // Detach window from the external devtools browser. It will lead to |
| 1230 // the browser object's close and delete. Remove observer first. |
| 1231 TabStripModel* tab_strip_model = browser->tab_strip_model(); |
| 1232 tab_strip_model->DetachWebContentsAt( |
| 1233 tab_strip_model->GetIndexOfWebContents(main_web_contents_)); |
| 1234 } |
| 1235 } |
| 1236 |
1215 WebContents* DevToolsWindow::GetInspectedWebContents() { | 1237 WebContents* DevToolsWindow::GetInspectedWebContents() { |
1216 return inspected_contents_observer_ | 1238 return inspected_contents_observer_ |
1217 ? inspected_contents_observer_->web_contents() | 1239 ? inspected_contents_observer_->web_contents() |
1218 : NULL; | 1240 : NULL; |
1219 } | 1241 } |
1220 | 1242 |
1221 void DevToolsWindow::LoadCompleted() { | 1243 void DevToolsWindow::LoadCompleted() { |
1222 Show(action_on_load_); | 1244 Show(action_on_load_); |
1223 action_on_load_ = DevToolsToggleAction::NoOp(); | 1245 action_on_load_ = DevToolsToggleAction::NoOp(); |
1224 if (!load_completed_callback_.is_null()) { | 1246 if (!load_completed_callback_.is_null()) { |
1225 load_completed_callback_.Run(); | 1247 load_completed_callback_.Run(); |
1226 load_completed_callback_ = base::Closure(); | 1248 load_completed_callback_ = base::Closure(); |
1227 } | 1249 } |
1228 } | 1250 } |
1229 | 1251 |
1230 void DevToolsWindow::SetLoadCompletedCallback(const base::Closure& closure) { | 1252 void DevToolsWindow::SetLoadCompletedCallback(const base::Closure& closure) { |
1231 if (life_stage_ == kLoadCompleted || life_stage_ == kClosing) { | 1253 if (life_stage_ == kLoadCompleted || life_stage_ == kClosing) { |
1232 if (!closure.is_null()) | 1254 if (!closure.is_null()) |
1233 closure.Run(); | 1255 closure.Run(); |
1234 return; | 1256 return; |
1235 } | 1257 } |
1236 load_completed_callback_ = closure; | 1258 load_completed_callback_ = closure; |
1237 } | 1259 } |
1238 | 1260 |
1239 bool DevToolsWindow::ForwardKeyboardEvent( | 1261 bool DevToolsWindow::ForwardKeyboardEvent( |
1240 const content::NativeWebKeyboardEvent& event) { | 1262 const content::NativeWebKeyboardEvent& event) { |
1241 return event_forwarder_->ForwardEvent(event); | 1263 return event_forwarder_->ForwardEvent(event); |
1242 } | 1264 } |
OLD | NEW |