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/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
28 #include "chrome/browser/ui/webui/devtools_ui.h" | 28 #include "chrome/browser/ui/webui/devtools_ui.h" |
29 #include "chrome/browser/ui/zoom/zoom_controller.h" | 29 #include "chrome/browser/ui/zoom/zoom_controller.h" |
30 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
31 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
32 #include "chrome/common/render_messages.h" | 32 #include "chrome/common/render_messages.h" |
33 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
34 #include "components/pref_registry/pref_registry_syncable.h" | 34 #include "components/pref_registry/pref_registry_syncable.h" |
35 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
36 #include "content/public/browser/devtools_agent_host.h" | 36 #include "content/public/browser/devtools_agent_host.h" |
37 #include "content/public/browser/devtools_client_host.h" | |
38 #include "content/public/browser/devtools_manager.h" | |
39 #include "content/public/browser/native_web_keyboard_event.h" | 37 #include "content/public/browser/native_web_keyboard_event.h" |
40 #include "content/public/browser/navigation_controller.h" | 38 #include "content/public/browser/navigation_controller.h" |
41 #include "content/public/browser/navigation_entry.h" | 39 #include "content/public/browser/navigation_entry.h" |
42 #include "content/public/browser/render_frame_host.h" | 40 #include "content/public/browser/render_frame_host.h" |
43 #include "content/public/browser/render_process_host.h" | 41 #include "content/public/browser/render_process_host.h" |
44 #include "content/public/browser/render_view_host.h" | 42 #include "content/public/browser/render_view_host.h" |
45 #include "content/public/browser/render_widget_host_view.h" | 43 #include "content/public/browser/render_widget_host_view.h" |
46 #include "content/public/browser/user_metrics.h" | 44 #include "content/public/browser/user_metrics.h" |
47 #include "content/public/browser/web_contents.h" | 45 #include "content/public/browser/web_contents.h" |
48 #include "content/public/common/content_client.h" | 46 #include "content/public/common/content_client.h" |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 return false; | 416 return false; |
419 } | 417 } |
420 | 418 |
421 // static | 419 // static |
422 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( | 420 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( |
423 Profile* profile, | 421 Profile* profile, |
424 DevToolsAgentHost* worker_agent) { | 422 DevToolsAgentHost* worker_agent) { |
425 DevToolsWindow* window = FindDevToolsWindow(worker_agent); | 423 DevToolsWindow* window = FindDevToolsWindow(worker_agent); |
426 if (!window) { | 424 if (!window) { |
427 window = DevToolsWindow::CreateDevToolsWindowForWorker(profile); | 425 window = DevToolsWindow::CreateDevToolsWindowForWorker(profile); |
428 // Will disconnect the current client host if there is one. | 426 window->bindings_->AttachTo(worker_agent); |
429 content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( | |
430 worker_agent, window->bindings_); | |
431 } | 427 } |
432 window->ScheduleShow(DevToolsToggleAction::Show()); | 428 window->ScheduleShow(DevToolsToggleAction::Show()); |
433 return window; | 429 return window; |
434 } | 430 } |
435 | 431 |
436 // static | 432 // static |
437 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( | 433 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( |
438 Profile* profile) { | 434 Profile* profile) { |
439 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); | 435 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); |
440 return Create(profile, GURL(), NULL, true, false, false, ""); | 436 return Create(profile, GURL(), NULL, true, false, false, ""); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 | 468 |
473 // static | 469 // static |
474 void DevToolsWindow::OpenExternalFrontend( | 470 void DevToolsWindow::OpenExternalFrontend( |
475 Profile* profile, | 471 Profile* profile, |
476 const std::string& frontend_url, | 472 const std::string& frontend_url, |
477 content::DevToolsAgentHost* agent_host) { | 473 content::DevToolsAgentHost* agent_host) { |
478 DevToolsWindow* window = FindDevToolsWindow(agent_host); | 474 DevToolsWindow* window = FindDevToolsWindow(agent_host); |
479 if (!window) { | 475 if (!window) { |
480 window = Create(profile, DevToolsUI::GetProxyURL(frontend_url), NULL, | 476 window = Create(profile, DevToolsUI::GetProxyURL(frontend_url), NULL, |
481 false, true, false, ""); | 477 false, true, false, ""); |
482 content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( | 478 window->bindings_->AttachTo(agent_host); |
483 agent_host, window->bindings_); | |
484 } | 479 } |
485 window->ScheduleShow(DevToolsToggleAction::Show()); | 480 window->ScheduleShow(DevToolsToggleAction::Show()); |
486 } | 481 } |
487 | 482 |
488 // static | 483 // static |
489 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( | 484 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( |
490 content::WebContents* inspected_web_contents, | 485 content::WebContents* inspected_web_contents, |
491 bool force_open, | 486 bool force_open, |
492 const DevToolsToggleAction& action, | 487 const DevToolsToggleAction& action, |
493 const std::string& settings) { | 488 const std::string& settings) { |
494 scoped_refptr<DevToolsAgentHost> agent( | 489 scoped_refptr<DevToolsAgentHost> agent( |
495 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); | 490 DevToolsAgentHost::GetOrCreateFor(inspected_web_contents)); |
496 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); | |
497 DevToolsWindow* window = FindDevToolsWindow(agent.get()); | 491 DevToolsWindow* window = FindDevToolsWindow(agent.get()); |
498 bool do_open = force_open; | 492 bool do_open = force_open; |
499 if (!window) { | 493 if (!window) { |
500 Profile* profile = Profile::FromBrowserContext( | 494 Profile* profile = Profile::FromBrowserContext( |
501 inspected_web_contents->GetBrowserContext()); | 495 inspected_web_contents->GetBrowserContext()); |
502 content::RecordAction( | 496 content::RecordAction( |
503 base::UserMetricsAction("DevTools_InspectRenderer")); | 497 base::UserMetricsAction("DevTools_InspectRenderer")); |
504 window = Create( | 498 window = Create( |
505 profile, GURL(), inspected_web_contents, false, false, true, settings); | 499 profile, GURL(), inspected_web_contents, false, false, true, settings); |
506 manager->RegisterDevToolsClientHostFor(agent.get(), window->bindings_); | 500 window->bindings_->AttachTo(agent.get()); |
507 do_open = true; | 501 do_open = true; |
508 } | 502 } |
509 | 503 |
510 // Update toolbar to reflect DevTools changes. | 504 // Update toolbar to reflect DevTools changes. |
511 window->UpdateBrowserToolbar(); | 505 window->UpdateBrowserToolbar(); |
512 | 506 |
513 // If window is docked and visible, we hide it on toggle. If window is | 507 // If window is docked and visible, we hide it on toggle. If window is |
514 // undocked, we show (activate) it. | 508 // undocked, we show (activate) it. |
515 if (!window->is_docked_ || do_open) | 509 if (!window->is_docked_ || do_open) |
516 window->ScheduleShow(action); | 510 window->ScheduleShow(action); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 url_string += "&settings=" + settings; | 780 url_string += "&settings=" + settings; |
787 return GURL(url_string); | 781 return GURL(url_string); |
788 } | 782 } |
789 | 783 |
790 // static | 784 // static |
791 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( | 785 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( |
792 DevToolsAgentHost* agent_host) { | 786 DevToolsAgentHost* agent_host) { |
793 if (!agent_host || g_instances == NULL) | 787 if (!agent_host || g_instances == NULL) |
794 return NULL; | 788 return NULL; |
795 DevToolsWindows* instances = g_instances.Pointer(); | 789 DevToolsWindows* instances = g_instances.Pointer(); |
796 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); | |
797 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); | 790 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); |
798 ++it) { | 791 ++it) { |
799 if (manager->GetDevToolsAgentHostFor((*it)->bindings_) == agent_host) | 792 if ((*it)->bindings_->IsAttachedTo(agent_host)) |
800 return *it; | 793 return *it; |
801 } | 794 } |
802 return NULL; | 795 return NULL; |
803 } | 796 } |
804 | 797 |
805 // static | 798 // static |
806 DevToolsWindow* DevToolsWindow::AsDevToolsWindow( | 799 DevToolsWindow* DevToolsWindow::AsDevToolsWindow( |
807 content::WebContents* web_contents) { | 800 content::WebContents* web_contents) { |
808 if (!web_contents || g_instances == NULL) | 801 if (!web_contents || g_instances == NULL) |
809 return NULL; | 802 return NULL; |
810 DevToolsWindows* instances = g_instances.Pointer(); | 803 DevToolsWindows* instances = g_instances.Pointer(); |
811 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); | 804 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); |
812 ++it) { | 805 ++it) { |
813 if ((*it)->main_web_contents_ == web_contents) | 806 if ((*it)->main_web_contents_ == web_contents) |
814 return *it; | 807 return *it; |
815 } | 808 } |
816 return NULL; | 809 return NULL; |
817 } | 810 } |
818 | 811 |
819 WebContents* DevToolsWindow::OpenURLFromTab( | 812 WebContents* DevToolsWindow::OpenURLFromTab( |
820 WebContents* source, | 813 WebContents* source, |
821 const content::OpenURLParams& params) { | 814 const content::OpenURLParams& params) { |
822 DCHECK(source == main_web_contents_); | 815 DCHECK(source == main_web_contents_); |
823 if (!params.url.SchemeIs(content::kChromeDevToolsScheme)) { | 816 if (!params.url.SchemeIs(content::kChromeDevToolsScheme)) { |
824 WebContents* inspected_web_contents = GetInspectedWebContents(); | 817 WebContents* inspected_web_contents = GetInspectedWebContents(); |
825 return inspected_web_contents ? | 818 return inspected_web_contents ? |
826 inspected_web_contents->OpenURL(params) : NULL; | 819 inspected_web_contents->OpenURL(params) : NULL; |
827 } | 820 } |
828 | 821 |
829 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); | 822 bindings_->Reattach(); |
830 scoped_refptr<DevToolsAgentHost> agent_host( | |
831 manager->GetDevToolsAgentHostFor(bindings_)); | |
832 if (!agent_host.get()) | |
833 return NULL; | |
834 manager->ClientHostClosing(bindings_); | |
835 manager->RegisterDevToolsClientHostFor(agent_host.get(), | |
836 bindings_); | |
837 | 823 |
838 content::NavigationController::LoadURLParams load_url_params(params.url); | 824 content::NavigationController::LoadURLParams load_url_params(params.url); |
839 main_web_contents_->GetController().LoadURLWithParams(load_url_params); | 825 main_web_contents_->GetController().LoadURLWithParams(load_url_params); |
840 return main_web_contents_; | 826 return main_web_contents_; |
841 } | 827 } |
842 | 828 |
843 void DevToolsWindow::ActivateContents(WebContents* contents) { | 829 void DevToolsWindow::ActivateContents(WebContents* contents) { |
844 if (is_docked_) { | 830 if (is_docked_) { |
845 WebContents* inspected_tab = GetInspectedWebContents(); | 831 WebContents* inspected_tab = GetInspectedWebContents(); |
846 inspected_tab->GetDelegate()->ActivateContents(inspected_tab); | 832 inspected_tab->GetDelegate()->ActivateContents(inspected_tab); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 DCHECK(is_docked_); | 889 DCHECK(is_docked_); |
904 chrome_page_zoom::Zoom(main_web_contents_, | 890 chrome_page_zoom::Zoom(main_web_contents_, |
905 zoom_in ? content::PAGE_ZOOM_IN : content::PAGE_ZOOM_OUT); | 891 zoom_in ? content::PAGE_ZOOM_IN : content::PAGE_ZOOM_OUT); |
906 } | 892 } |
907 | 893 |
908 void DevToolsWindow::BeforeUnloadFired(WebContents* tab, | 894 void DevToolsWindow::BeforeUnloadFired(WebContents* tab, |
909 bool proceed, | 895 bool proceed, |
910 bool* proceed_to_fire_unload) { | 896 bool* proceed_to_fire_unload) { |
911 if (!intercepted_page_beforeunload_) { | 897 if (!intercepted_page_beforeunload_) { |
912 // Docked devtools window closed directly. | 898 // Docked devtools window closed directly. |
913 if (proceed) { | 899 if (proceed) |
914 content::DevToolsManager::GetInstance()->ClientHostClosing( | 900 bindings_->Detach(); |
915 bindings_); | |
916 } | |
917 *proceed_to_fire_unload = proceed; | 901 *proceed_to_fire_unload = proceed; |
918 } else { | 902 } else { |
919 // Inspected page is attempting to close. | 903 // Inspected page is attempting to close. |
920 WebContents* inspected_web_contents = GetInspectedWebContents(); | 904 WebContents* inspected_web_contents = GetInspectedWebContents(); |
921 if (proceed) { | 905 if (proceed) { |
922 inspected_web_contents->DispatchBeforeUnload(false); | 906 inspected_web_contents->DispatchBeforeUnload(false); |
923 } else { | 907 } else { |
924 bool should_proceed; | 908 bool should_proceed; |
925 inspected_web_contents->GetDelegate()->BeforeUnloadFired( | 909 inspected_web_contents->GetDelegate()->BeforeUnloadFired( |
926 inspected_web_contents, false, &should_proceed); | 910 inspected_web_contents, false, &should_proceed); |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1246 closure.Run(); | 1230 closure.Run(); |
1247 return; | 1231 return; |
1248 } | 1232 } |
1249 load_completed_callback_ = closure; | 1233 load_completed_callback_ = closure; |
1250 } | 1234 } |
1251 | 1235 |
1252 bool DevToolsWindow::ForwardKeyboardEvent( | 1236 bool DevToolsWindow::ForwardKeyboardEvent( |
1253 const content::NativeWebKeyboardEvent& event) { | 1237 const content::NativeWebKeyboardEvent& event) { |
1254 return event_forwarder_->ForwardEvent(event); | 1238 return event_forwarder_->ForwardEvent(event); |
1255 } | 1239 } |
OLD | NEW |