Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: chrome/browser/devtools/devtools_window.cc

Issue 449043002: [DevTools] Make DevTools clients talk directly to DevToolsAgentHost instead of using DevToolsManage… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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_->InspectAgentHost(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 30 matching lines...) Expand all
471 467
472 // static 468 // static
473 void DevToolsWindow::OpenExternalFrontend( 469 void DevToolsWindow::OpenExternalFrontend(
474 Profile* profile, 470 Profile* profile,
475 const std::string& frontend_url, 471 const std::string& frontend_url,
476 content::DevToolsAgentHost* agent_host) { 472 content::DevToolsAgentHost* agent_host) {
477 DevToolsWindow* window = FindDevToolsWindow(agent_host); 473 DevToolsWindow* window = FindDevToolsWindow(agent_host);
478 if (!window) { 474 if (!window) {
479 window = Create(profile, DevToolsUI::GetProxyURL(frontend_url), NULL, 475 window = Create(profile, DevToolsUI::GetProxyURL(frontend_url), NULL,
480 false, true, false, ""); 476 false, true, false, "");
481 content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( 477 window->bindings_->InspectAgentHost(agent_host);
482 agent_host, window->bindings_);
483 } 478 }
484 window->ScheduleShow(DevToolsToggleAction::Show()); 479 window->ScheduleShow(DevToolsToggleAction::Show());
485 } 480 }
486 481
487 // static 482 // static
488 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( 483 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow(
489 content::RenderViewHost* inspected_rvh, 484 content::RenderViewHost* inspected_rvh,
490 bool force_open, 485 bool force_open,
491 const DevToolsToggleAction& action, 486 const DevToolsToggleAction& action,
492 const std::string& settings) { 487 const std::string& settings) {
493 scoped_refptr<DevToolsAgentHost> agent( 488 scoped_refptr<DevToolsAgentHost> agent(
494 DevToolsAgentHost::GetOrCreateFor(inspected_rvh)); 489 DevToolsAgentHost::GetOrCreateFor(inspected_rvh));
495 content::DevToolsManager* manager = content::DevToolsManager::GetInstance();
496 DevToolsWindow* window = FindDevToolsWindow(agent.get()); 490 DevToolsWindow* window = FindDevToolsWindow(agent.get());
497 bool do_open = force_open; 491 bool do_open = force_open;
498 if (!window) { 492 if (!window) {
499 Profile* profile = Profile::FromBrowserContext( 493 Profile* profile = Profile::FromBrowserContext(
500 inspected_rvh->GetProcess()->GetBrowserContext()); 494 inspected_rvh->GetProcess()->GetBrowserContext());
501 content::RecordAction( 495 content::RecordAction(
502 base::UserMetricsAction("DevTools_InspectRenderer")); 496 base::UserMetricsAction("DevTools_InspectRenderer"));
503 window = Create( 497 window = Create(
504 profile, GURL(), inspected_rvh, false, false, true, settings); 498 profile, GURL(), inspected_rvh, false, false, true, settings);
505 manager->RegisterDevToolsClientHostFor(agent.get(), window->bindings_); 499 window->bindings_->InspectAgentHost(agent.get());
506 do_open = true; 500 do_open = true;
507 } 501 }
508 502
509 // Update toolbar to reflect DevTools changes. 503 // Update toolbar to reflect DevTools changes.
510 window->UpdateBrowserToolbar(); 504 window->UpdateBrowserToolbar();
511 505
512 // If window is docked and visible, we hide it on toggle. If window is 506 // If window is docked and visible, we hide it on toggle. If window is
513 // undocked, we show (activate) it. 507 // undocked, we show (activate) it.
514 if (!window->is_docked_ || do_open) 508 if (!window->is_docked_ || do_open)
515 window->ScheduleShow(action); 509 window->ScheduleShow(action);
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 url_string += "&settings=" + settings; 782 url_string += "&settings=" + settings;
789 return GURL(url_string); 783 return GURL(url_string);
790 } 784 }
791 785
792 // static 786 // static
793 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( 787 DevToolsWindow* DevToolsWindow::FindDevToolsWindow(
794 DevToolsAgentHost* agent_host) { 788 DevToolsAgentHost* agent_host) {
795 if (!agent_host || g_instances == NULL) 789 if (!agent_host || g_instances == NULL)
796 return NULL; 790 return NULL;
797 DevToolsWindows* instances = g_instances.Pointer(); 791 DevToolsWindows* instances = g_instances.Pointer();
798 content::DevToolsManager* manager = content::DevToolsManager::GetInstance();
799 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); 792 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end();
800 ++it) { 793 ++it) {
801 if (manager->GetDevToolsAgentHostFor((*it)->bindings_) == agent_host) 794 if ((*it)->bindings_->agent_host() == agent_host)
pfeldman 2014/08/07 15:40:30 You could try matching bindings client here instea
dgozman 2014/08/07 16:51:52 Using IsAttachedTo.
802 return *it; 795 return *it;
803 } 796 }
804 return NULL; 797 return NULL;
805 } 798 }
806 799
807 // static 800 // static
808 DevToolsWindow* DevToolsWindow::AsDevToolsWindow( 801 DevToolsWindow* DevToolsWindow::AsDevToolsWindow(
809 content::WebContents* web_contents) { 802 content::WebContents* web_contents) {
810 if (!web_contents || g_instances == NULL) 803 if (!web_contents || g_instances == NULL)
811 return NULL; 804 return NULL;
812 DevToolsWindows* instances = g_instances.Pointer(); 805 DevToolsWindows* instances = g_instances.Pointer();
813 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end(); 806 for (DevToolsWindows::iterator it(instances->begin()); it != instances->end();
814 ++it) { 807 ++it) {
815 if ((*it)->main_web_contents_ == web_contents) 808 if ((*it)->main_web_contents_ == web_contents)
816 return *it; 809 return *it;
817 } 810 }
818 return NULL; 811 return NULL;
819 } 812 }
820 813
821 WebContents* DevToolsWindow::OpenURLFromTab( 814 WebContents* DevToolsWindow::OpenURLFromTab(
822 WebContents* source, 815 WebContents* source,
823 const content::OpenURLParams& params) { 816 const content::OpenURLParams& params) {
824 DCHECK(source == main_web_contents_); 817 DCHECK(source == main_web_contents_);
825 if (!params.url.SchemeIs(content::kChromeDevToolsScheme)) { 818 if (!params.url.SchemeIs(content::kChromeDevToolsScheme)) {
826 WebContents* inspected_web_contents = GetInspectedWebContents(); 819 WebContents* inspected_web_contents = GetInspectedWebContents();
827 return inspected_web_contents ? 820 return inspected_web_contents ?
828 inspected_web_contents->OpenURL(params) : NULL; 821 inspected_web_contents->OpenURL(params) : NULL;
829 } 822 }
830 823
831 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); 824 if (!bindings_->agent_host())
832 scoped_refptr<DevToolsAgentHost> agent_host(
833 manager->GetDevToolsAgentHostFor(bindings_));
834 if (!agent_host.get())
835 return NULL; 825 return NULL;
836 manager->ClientHostClosing(bindings_); 826 bindings_->InspectAgentHost(bindings_->agent_host());
pfeldman 2014/08/07 15:40:30 bindings->Reattach()
dgozman 2014/08/07 16:51:52 Done.
837 manager->RegisterDevToolsClientHostFor(agent_host.get(),
838 bindings_);
839 827
840 content::NavigationController::LoadURLParams load_url_params(params.url); 828 content::NavigationController::LoadURLParams load_url_params(params.url);
841 main_web_contents_->GetController().LoadURLWithParams(load_url_params); 829 main_web_contents_->GetController().LoadURLWithParams(load_url_params);
842 return main_web_contents_; 830 return main_web_contents_;
843 } 831 }
844 832
845 void DevToolsWindow::ActivateContents(WebContents* contents) { 833 void DevToolsWindow::ActivateContents(WebContents* contents) {
846 if (is_docked_) { 834 if (is_docked_) {
847 WebContents* inspected_tab = GetInspectedWebContents(); 835 WebContents* inspected_tab = GetInspectedWebContents();
848 inspected_tab->GetDelegate()->ActivateContents(inspected_tab); 836 inspected_tab->GetDelegate()->ActivateContents(inspected_tab);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 DCHECK(is_docked_); 893 DCHECK(is_docked_);
906 chrome_page_zoom::Zoom(main_web_contents_, 894 chrome_page_zoom::Zoom(main_web_contents_,
907 zoom_in ? content::PAGE_ZOOM_IN : content::PAGE_ZOOM_OUT); 895 zoom_in ? content::PAGE_ZOOM_IN : content::PAGE_ZOOM_OUT);
908 } 896 }
909 897
910 void DevToolsWindow::BeforeUnloadFired(WebContents* tab, 898 void DevToolsWindow::BeforeUnloadFired(WebContents* tab,
911 bool proceed, 899 bool proceed,
912 bool* proceed_to_fire_unload) { 900 bool* proceed_to_fire_unload) {
913 if (!intercepted_page_beforeunload_) { 901 if (!intercepted_page_beforeunload_) {
914 // Docked devtools window closed directly. 902 // Docked devtools window closed directly.
915 if (proceed) { 903 if (proceed)
916 content::DevToolsManager::GetInstance()->ClientHostClosing( 904 bindings_->InspectAgentHost(NULL);
pfeldman 2014/08/07 15:40:30 bindings_->Detach()
dgozman 2014/08/07 16:51:51 Done.
917 bindings_);
918 }
919 *proceed_to_fire_unload = proceed; 905 *proceed_to_fire_unload = proceed;
920 } else { 906 } else {
921 // Inspected page is attempting to close. 907 // Inspected page is attempting to close.
922 WebContents* inspected_web_contents = GetInspectedWebContents(); 908 WebContents* inspected_web_contents = GetInspectedWebContents();
923 if (proceed) { 909 if (proceed) {
924 inspected_web_contents->DispatchBeforeUnload(false); 910 inspected_web_contents->DispatchBeforeUnload(false);
925 } else { 911 } else {
926 bool should_proceed; 912 bool should_proceed;
927 inspected_web_contents->GetDelegate()->BeforeUnloadFired( 913 inspected_web_contents->GetDelegate()->BeforeUnloadFired(
928 inspected_web_contents, false, &should_proceed); 914 inspected_web_contents, false, &should_proceed);
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 closure.Run(); 1244 closure.Run();
1259 return; 1245 return;
1260 } 1246 }
1261 load_completed_callback_ = closure; 1247 load_completed_callback_ = closure;
1262 } 1248 }
1263 1249
1264 bool DevToolsWindow::ForwardKeyboardEvent( 1250 bool DevToolsWindow::ForwardKeyboardEvent(
1265 const content::NativeWebKeyboardEvent& event) { 1251 const content::NativeWebKeyboardEvent& event) {
1266 return event_forwarder_->ForwardEvent(event); 1252 return event_forwarder_->ForwardEvent(event);
1267 } 1253 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698