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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 420 |
421 // static | 421 // static |
422 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( | 422 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( |
423 Profile* profile, | 423 Profile* profile, |
424 DevToolsAgentHost* worker_agent) { | 424 DevToolsAgentHost* worker_agent) { |
425 DevToolsWindow* window = FindDevToolsWindow(worker_agent); | 425 DevToolsWindow* window = FindDevToolsWindow(worker_agent); |
426 if (!window) { | 426 if (!window) { |
427 window = DevToolsWindow::CreateDevToolsWindowForWorker(profile); | 427 window = DevToolsWindow::CreateDevToolsWindowForWorker(profile); |
428 // Will disconnect the current client host if there is one. | 428 // Will disconnect the current client host if there is one. |
429 content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( | 429 content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( |
430 worker_agent, window->bindings_->frontend_host()); | 430 worker_agent, window->bindings_); |
431 } | 431 } |
432 window->ScheduleShow(DevToolsToggleAction::Show()); | 432 window->ScheduleShow(DevToolsToggleAction::Show()); |
433 return window; | 433 return window; |
434 } | 434 } |
435 | 435 |
436 // static | 436 // static |
437 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( | 437 DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker( |
438 Profile* profile) { | 438 Profile* profile) { |
439 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); | 439 content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker")); |
440 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... |
472 // static | 472 // static |
473 void DevToolsWindow::OpenExternalFrontend( | 473 void DevToolsWindow::OpenExternalFrontend( |
474 Profile* profile, | 474 Profile* profile, |
475 const std::string& frontend_url, | 475 const std::string& frontend_url, |
476 content::DevToolsAgentHost* agent_host) { | 476 content::DevToolsAgentHost* agent_host) { |
477 DevToolsWindow* window = FindDevToolsWindow(agent_host); | 477 DevToolsWindow* window = FindDevToolsWindow(agent_host); |
478 if (!window) { | 478 if (!window) { |
479 window = Create(profile, DevToolsUI::GetProxyURL(frontend_url), NULL, | 479 window = Create(profile, DevToolsUI::GetProxyURL(frontend_url), NULL, |
480 false, true, false, ""); | 480 false, true, false, ""); |
481 content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( | 481 content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( |
482 agent_host, window->bindings_->frontend_host()); | 482 agent_host, window->bindings_); |
483 } | 483 } |
484 window->ScheduleShow(DevToolsToggleAction::Show()); | 484 window->ScheduleShow(DevToolsToggleAction::Show()); |
485 } | 485 } |
486 | 486 |
487 // static | 487 // static |
488 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( | 488 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( |
489 content::RenderViewHost* inspected_rvh, | 489 content::RenderViewHost* inspected_rvh, |
490 bool force_open, | 490 bool force_open, |
491 const DevToolsToggleAction& action, | 491 const DevToolsToggleAction& action, |
492 const std::string& settings) { | 492 const std::string& settings) { |
493 scoped_refptr<DevToolsAgentHost> agent( | 493 scoped_refptr<DevToolsAgentHost> agent( |
494 DevToolsAgentHost::GetOrCreateFor(inspected_rvh)); | 494 DevToolsAgentHost::GetOrCreateFor(inspected_rvh)); |
495 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); | 495 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); |
496 DevToolsWindow* window = FindDevToolsWindow(agent.get()); | 496 DevToolsWindow* window = FindDevToolsWindow(agent.get()); |
497 bool do_open = force_open; | 497 bool do_open = force_open; |
498 if (!window) { | 498 if (!window) { |
499 Profile* profile = Profile::FromBrowserContext( | 499 Profile* profile = Profile::FromBrowserContext( |
500 inspected_rvh->GetProcess()->GetBrowserContext()); | 500 inspected_rvh->GetProcess()->GetBrowserContext()); |
501 content::RecordAction( | 501 content::RecordAction( |
502 base::UserMetricsAction("DevTools_InspectRenderer")); | 502 base::UserMetricsAction("DevTools_InspectRenderer")); |
503 window = Create( | 503 window = Create( |
504 profile, GURL(), inspected_rvh, false, false, true, settings); | 504 profile, GURL(), inspected_rvh, false, false, true, settings); |
505 manager->RegisterDevToolsClientHostFor(agent.get(), | 505 manager->RegisterDevToolsClientHostFor(agent.get(), window->bindings_); |
506 window->bindings_->frontend_host()); | |
507 do_open = true; | 506 do_open = true; |
508 } | 507 } |
509 | 508 |
510 // Update toolbar to reflect DevTools changes. | 509 // Update toolbar to reflect DevTools changes. |
511 window->UpdateBrowserToolbar(); | 510 window->UpdateBrowserToolbar(); |
512 | 511 |
513 // If window is docked and visible, we hide it on toggle. If window is | 512 // If window is docked and visible, we hide it on toggle. If window is |
514 // undocked, we show (activate) it. | 513 // undocked, we show (activate) it. |
515 if (!window->is_docked_ || do_open) | 514 if (!window->is_docked_ || do_open) |
516 window->ScheduleShow(action); | 515 window->ScheduleShow(action); |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 | 791 |
793 // static | 792 // static |
794 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( | 793 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( |
795 DevToolsAgentHost* agent_host) { | 794 DevToolsAgentHost* agent_host) { |
796 if (!agent_host || g_instances == NULL) | 795 if (!agent_host || g_instances == NULL) |
797 return NULL; | 796 return NULL; |
798 DevToolsWindows* instances = g_instances.Pointer(); | 797 DevToolsWindows* instances = g_instances.Pointer(); |
799 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); | 798 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); |
800 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); | 799 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); |
801 ++it) { | 800 ++it) { |
802 if (manager->GetDevToolsAgentHostFor((*it)->bindings_->frontend_host()) == | 801 if (manager->GetDevToolsAgentHostFor((*it)->bindings_) == agent_host) |
803 agent_host) | |
804 return *it; | 802 return *it; |
805 } | 803 } |
806 return NULL; | 804 return NULL; |
807 } | 805 } |
808 | 806 |
809 // static | 807 // static |
810 DevToolsWindow* DevToolsWindow::AsDevToolsWindow( | 808 DevToolsWindow* DevToolsWindow::AsDevToolsWindow( |
811 content::WebContents* web_contents) { | 809 content::WebContents* web_contents) { |
812 if (!web_contents || g_instances == NULL) | 810 if (!web_contents || g_instances == NULL) |
813 return NULL; | 811 return NULL; |
(...skipping 11 matching lines...) Expand all Loading... |
825 const content::OpenURLParams& params) { | 823 const content::OpenURLParams& params) { |
826 DCHECK(source == main_web_contents_); | 824 DCHECK(source == main_web_contents_); |
827 if (!params.url.SchemeIs(content::kChromeDevToolsScheme)) { | 825 if (!params.url.SchemeIs(content::kChromeDevToolsScheme)) { |
828 WebContents* inspected_web_contents = GetInspectedWebContents(); | 826 WebContents* inspected_web_contents = GetInspectedWebContents(); |
829 return inspected_web_contents ? | 827 return inspected_web_contents ? |
830 inspected_web_contents->OpenURL(params) : NULL; | 828 inspected_web_contents->OpenURL(params) : NULL; |
831 } | 829 } |
832 | 830 |
833 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); | 831 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); |
834 scoped_refptr<DevToolsAgentHost> agent_host( | 832 scoped_refptr<DevToolsAgentHost> agent_host( |
835 manager->GetDevToolsAgentHostFor(bindings_->frontend_host())); | 833 manager->GetDevToolsAgentHostFor(bindings_)); |
836 if (!agent_host.get()) | 834 if (!agent_host.get()) |
837 return NULL; | 835 return NULL; |
838 manager->ClientHostClosing(bindings_->frontend_host()); | 836 manager->ClientHostClosing(bindings_); |
839 manager->RegisterDevToolsClientHostFor(agent_host.get(), | 837 manager->RegisterDevToolsClientHostFor(agent_host.get(), |
840 bindings_->frontend_host()); | 838 bindings_); |
841 | 839 |
842 content::NavigationController::LoadURLParams load_url_params(params.url); | 840 content::NavigationController::LoadURLParams load_url_params(params.url); |
843 main_web_contents_->GetController().LoadURLWithParams(load_url_params); | 841 main_web_contents_->GetController().LoadURLWithParams(load_url_params); |
844 return main_web_contents_; | 842 return main_web_contents_; |
845 } | 843 } |
846 | 844 |
847 void DevToolsWindow::ActivateContents(WebContents* contents) { | 845 void DevToolsWindow::ActivateContents(WebContents* contents) { |
848 if (is_docked_) { | 846 if (is_docked_) { |
849 WebContents* inspected_tab = GetInspectedWebContents(); | 847 WebContents* inspected_tab = GetInspectedWebContents(); |
850 inspected_tab->GetDelegate()->ActivateContents(inspected_tab); | 848 inspected_tab->GetDelegate()->ActivateContents(inspected_tab); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 zoom_in ? content::PAGE_ZOOM_IN : content::PAGE_ZOOM_OUT); | 907 zoom_in ? content::PAGE_ZOOM_IN : content::PAGE_ZOOM_OUT); |
910 } | 908 } |
911 | 909 |
912 void DevToolsWindow::BeforeUnloadFired(WebContents* tab, | 910 void DevToolsWindow::BeforeUnloadFired(WebContents* tab, |
913 bool proceed, | 911 bool proceed, |
914 bool* proceed_to_fire_unload) { | 912 bool* proceed_to_fire_unload) { |
915 if (!intercepted_page_beforeunload_) { | 913 if (!intercepted_page_beforeunload_) { |
916 // Docked devtools window closed directly. | 914 // Docked devtools window closed directly. |
917 if (proceed) { | 915 if (proceed) { |
918 content::DevToolsManager::GetInstance()->ClientHostClosing( | 916 content::DevToolsManager::GetInstance()->ClientHostClosing( |
919 bindings_->frontend_host()); | 917 bindings_); |
920 } | 918 } |
921 *proceed_to_fire_unload = proceed; | 919 *proceed_to_fire_unload = proceed; |
922 } else { | 920 } else { |
923 // Inspected page is attempting to close. | 921 // Inspected page is attempting to close. |
924 WebContents* inspected_web_contents = GetInspectedWebContents(); | 922 WebContents* inspected_web_contents = GetInspectedWebContents(); |
925 if (proceed) { | 923 if (proceed) { |
926 inspected_web_contents->DispatchBeforeUnload(false); | 924 inspected_web_contents->DispatchBeforeUnload(false); |
927 } else { | 925 } else { |
928 bool should_proceed; | 926 bool should_proceed; |
929 inspected_web_contents->GetDelegate()->BeforeUnloadFired( | 927 inspected_web_contents->GetDelegate()->BeforeUnloadFired( |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 closure.Run(); | 1258 closure.Run(); |
1261 return; | 1259 return; |
1262 } | 1260 } |
1263 load_completed_callback_ = closure; | 1261 load_completed_callback_ = closure; |
1264 } | 1262 } |
1265 | 1263 |
1266 bool DevToolsWindow::ForwardKeyboardEvent( | 1264 bool DevToolsWindow::ForwardKeyboardEvent( |
1267 const content::NativeWebKeyboardEvent& event) { | 1265 const content::NativeWebKeyboardEvent& event) { |
1268 return event_forwarder_->ForwardEvent(event); | 1266 return event_forwarder_->ForwardEvent(event); |
1269 } | 1267 } |
OLD | NEW |