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