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

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

Issue 379963002: [WIP] Make extension APIs work in devtools APIs when docked. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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"
11 #include "base/prefs/scoped_user_pref_update.h" 11 #include "base/prefs/scoped_user_pref_update.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/chrome_page_zoom.h" 14 #include "chrome/browser/chrome_page_zoom.h"
15 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
15 #include "chrome/browser/file_select_helper.h" 16 #include "chrome/browser/file_select_helper.h"
16 #include "chrome/browser/infobars/infobar_service.h" 17 #include "chrome/browser/infobars/infobar_service.h"
17 #include "chrome/browser/prefs/pref_service_syncable.h" 18 #include "chrome/browser/prefs/pref_service_syncable.h"
18 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/sessions/session_tab_helper.h" 20 #include "chrome/browser/sessions/session_tab_helper.h"
20 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_dialogs.h" 22 #include "chrome/browser/ui/browser_dialogs.h"
22 #include "chrome/browser/ui/browser_iterator.h" 23 #include "chrome/browser/ui/browser_iterator.h"
23 #include "chrome/browser/ui/browser_list.h" 24 #include "chrome/browser/ui/browser_list.h"
24 #include "chrome/browser/ui/browser_window.h" 25 #include "chrome/browser/ui/browser_window.h"
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 agent_host, window->bindings_->frontend_host()); 487 agent_host, window->bindings_->frontend_host());
487 } 488 }
488 window->ScheduleShow(DevToolsToggleAction::Show()); 489 window->ScheduleShow(DevToolsToggleAction::Show());
489 } 490 }
490 491
491 // static 492 // static
492 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( 493 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow(
493 content::RenderViewHost* inspected_rvh, 494 content::RenderViewHost* inspected_rvh,
494 bool force_open, 495 bool force_open,
495 const DevToolsToggleAction& action) { 496 const DevToolsToggleAction& action) {
497 LOG(INFO) << "Toggling devtools window";
498
496 scoped_refptr<DevToolsAgentHost> agent( 499 scoped_refptr<DevToolsAgentHost> agent(
497 DevToolsAgentHost::GetOrCreateFor(inspected_rvh)); 500 DevToolsAgentHost::GetOrCreateFor(inspected_rvh));
498 content::DevToolsManager* manager = content::DevToolsManager::GetInstance(); 501 content::DevToolsManager* manager = content::DevToolsManager::GetInstance();
499 DevToolsWindow* window = FindDevToolsWindow(agent.get()); 502 DevToolsWindow* window = FindDevToolsWindow(agent.get());
500 bool do_open = force_open; 503 bool do_open = force_open;
501 if (!window) { 504 if (!window) {
505 LOG(INFO) << "No window";
506
502 Profile* profile = Profile::FromBrowserContext( 507 Profile* profile = Profile::FromBrowserContext(
503 inspected_rvh->GetProcess()->GetBrowserContext()); 508 inspected_rvh->GetProcess()->GetBrowserContext());
504 content::RecordAction( 509 content::RecordAction(
505 base::UserMetricsAction("DevTools_InspectRenderer")); 510 base::UserMetricsAction("DevTools_InspectRenderer"));
506 window = Create(profile, GURL(), inspected_rvh, false, false, true); 511 window = Create(profile, GURL(), inspected_rvh, false, false, true);
507 manager->RegisterDevToolsClientHostFor(agent.get(), 512 manager->RegisterDevToolsClientHostFor(agent.get(),
508 window->bindings_->frontend_host()); 513 window->bindings_->frontend_host());
509 do_open = true; 514 do_open = true;
510 } 515 }
511 516
517 // Attach an extensions WebContentsObserver for the devtools API.
518 content::WebContents* web_contents =
519 content::WebContents::FromRenderViewHost(inspected_rvh);
pfeldman 2014/07/10 13:44:36 I don't think inspected page contents should be in
520 if (web_contents) {
521 LOG(INFO) << "there is no web contents";
522 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
523 web_contents);
524 } else {
525 LOG(INFO) << "extensions attached";
526 }
527
528 LOG(INFO) << "attaching to the blah blah";
529 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
530 window->web_contents_for_test());
531
512 // Update toolbar to reflect DevTools changes. 532 // Update toolbar to reflect DevTools changes.
513 window->UpdateBrowserToolbar(); 533 window->UpdateBrowserToolbar();
514 534
515 // If window is docked and visible, we hide it on toggle. If window is 535 // If window is docked and visible, we hide it on toggle. If window is
516 // undocked, we show (activate) it. 536 // undocked, we show (activate) it.
517 if (!window->is_docked_ || do_open) 537 if (!window->is_docked_ || do_open)
518 window->ScheduleShow(action); 538 window->ScheduleShow(action);
519 else 539 else
520 window->CloseWindow(); 540 window->CloseWindow();
521 541
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 Browser* inspected_browser = NULL; 583 Browser* inspected_browser = NULL;
564 int inspected_tab_index = -1; 584 int inspected_tab_index = -1;
565 FindInspectedBrowserAndTabIndex(GetInspectedWebContents(), 585 FindInspectedBrowserAndTabIndex(GetInspectedWebContents(),
566 &inspected_browser, 586 &inspected_browser,
567 &inspected_tab_index); 587 &inspected_tab_index);
568 DCHECK(inspected_browser); 588 DCHECK(inspected_browser);
569 DCHECK(inspected_tab_index != -1); 589 DCHECK(inspected_tab_index != -1);
570 590
571 // Tell inspected browser to update splitter and switch to inspected panel. 591 // Tell inspected browser to update splitter and switch to inspected panel.
572 BrowserWindow* inspected_window = inspected_browser->window(); 592 BrowserWindow* inspected_window = inspected_browser->window();
573 main_web_contents_->SetDelegate(this); 593 main_web_contents_->SetDelegate(this);
dgozman 2014/07/09 20:13:36 The main difference between docked and undocked De
pfeldman 2014/07/10 13:44:36 It seems like ExtensionHostMsg_Request is dispatch
574 594
575 TabStripModel* tab_strip_model = inspected_browser->tab_strip_model(); 595 TabStripModel* tab_strip_model = inspected_browser->tab_strip_model();
576 tab_strip_model->ActivateTabAt(inspected_tab_index, true); 596 tab_strip_model->ActivateTabAt(inspected_tab_index, true);
577 597
578 inspected_window->UpdateDevTools(); 598 inspected_window->UpdateDevTools();
579 main_web_contents_->SetInitialFocus(); 599 main_web_contents_->SetInitialFocus();
580 inspected_window->Show(); 600 inspected_window->Show();
581 // On Aura, focusing once is not enough. Do it again. 601 // On Aura, focusing once is not enough. Do it again.
582 // Note that focusing only here but not before isn't enough either. We just 602 // Note that focusing only here but not before isn't enough either. We just
583 // need to focus twice. 603 // need to focus twice.
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 main_web_contents_->SetDelegate(this); 721 main_web_contents_->SetDelegate(this);
702 bindings_ = new DevToolsUIBindings( 722 bindings_ = new DevToolsUIBindings(
703 main_web_contents_, 723 main_web_contents_,
704 DevToolsUIBindings::ApplyThemeToURL(profile, url)); 724 DevToolsUIBindings::ApplyThemeToURL(profile, url));
705 // Bindings take ownership over devtools as its delegate. 725 // Bindings take ownership over devtools as its delegate.
706 bindings_->SetDelegate(this); 726 bindings_->SetDelegate(this);
707 727
708 g_instances.Get().push_back(this); 728 g_instances.Get().push_back(this);
709 729
710 // There is no inspected_rvh in case of shared workers. 730 // There is no inspected_rvh in case of shared workers.
711 if (inspected_rvh) 731 if (inspected_rvh) {
712 inspected_contents_observer_.reset(new ObserverWithAccessor( 732 inspected_contents_observer_.reset(new ObserverWithAccessor(
713 content::WebContents::FromRenderViewHost(inspected_rvh))); 733 content::WebContents::FromRenderViewHost(inspected_rvh)));
734 }
714 event_forwarder_.reset(new DevToolsEventForwarder(this)); 735 event_forwarder_.reset(new DevToolsEventForwarder(this));
736 LOG(INFO) << "Creating function dispatcher for devtools window";
737 extension_dispatcher_.reset(
738 new extensions::ExtensionFunctionDispatcher(profile, this));
715 } 739 }
716 740
717 // static 741 // static
718 DevToolsWindow* DevToolsWindow::Create( 742 DevToolsWindow* DevToolsWindow::Create(
719 Profile* profile, 743 Profile* profile,
720 const GURL& frontend_url, 744 const GURL& frontend_url,
721 content::RenderViewHost* inspected_rvh, 745 content::RenderViewHost* inspected_rvh,
722 bool shared_worker_frontend, 746 bool shared_worker_frontend,
723 bool external_frontend, 747 bool external_frontend,
724 bool can_dock) { 748 bool can_dock) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 manager->ClientHostClosing(bindings_->frontend_host()); 841 manager->ClientHostClosing(bindings_->frontend_host());
818 manager->RegisterDevToolsClientHostFor(agent_host.get(), 842 manager->RegisterDevToolsClientHostFor(agent_host.get(),
819 bindings_->frontend_host()); 843 bindings_->frontend_host());
820 844
821 content::NavigationController::LoadURLParams load_url_params(params.url); 845 content::NavigationController::LoadURLParams load_url_params(params.url);
822 main_web_contents_->GetController().LoadURLWithParams(load_url_params); 846 main_web_contents_->GetController().LoadURLWithParams(load_url_params);
823 return main_web_contents_; 847 return main_web_contents_;
824 } 848 }
825 849
826 void DevToolsWindow::ActivateContents(WebContents* contents) { 850 void DevToolsWindow::ActivateContents(WebContents* contents) {
851 LOG(INFO) << "web contents activated";
852 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
pfeldman 2014/07/10 13:44:36 I don't think you want to do this here. Wiring the
853 contents);
854
827 if (is_docked_) { 855 if (is_docked_) {
828 WebContents* inspected_tab = GetInspectedWebContents(); 856 WebContents* inspected_tab = GetInspectedWebContents();
829 inspected_tab->GetDelegate()->ActivateContents(inspected_tab); 857 inspected_tab->GetDelegate()->ActivateContents(inspected_tab);
830 } else { 858 } else {
831 browser_->window()->Activate(); 859 browser_->window()->Activate();
832 } 860 }
833 } 861 }
834 862
835 void DevToolsWindow::AddNewContents(WebContents* source, 863 void DevToolsWindow::AddNewContents(WebContents* source,
836 WebContents* new_contents, 864 WebContents* new_contents,
837 WindowOpenDisposition disposition, 865 WindowOpenDisposition disposition,
838 const gfx::Rect& initial_pos, 866 const gfx::Rect& initial_pos,
839 bool user_gesture, 867 bool user_gesture,
840 bool* was_blocked) { 868 bool* was_blocked) {
869 LOG(INFO) << "web contents added";
870 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
pfeldman 2014/07/10 13:44:36 ditto.
871 new_contents);
872
841 if (new_contents == toolbox_web_contents_) { 873 if (new_contents == toolbox_web_contents_) {
842 toolbox_web_contents_->SetDelegate( 874 toolbox_web_contents_->SetDelegate(
843 new DevToolsToolboxDelegate(toolbox_web_contents_, 875 new DevToolsToolboxDelegate(toolbox_web_contents_,
844 inspected_contents_observer_.get())); 876 inspected_contents_observer_.get()));
845 gfx::Size size = main_web_contents_->GetViewBounds().size(); 877 gfx::Size size = main_web_contents_->GetViewBounds().size();
846 if (toolbox_web_contents_->GetRenderWidgetHostView()) 878 if (toolbox_web_contents_->GetRenderWidgetHostView())
847 toolbox_web_contents_->GetRenderWidgetHostView()->SetSize(size); 879 toolbox_web_contents_->GetRenderWidgetHostView()->SetSize(size);
848 UpdateBrowserWindow(); 880 UpdateBrowserWindow();
849 return; 881 return;
850 } 882 }
851 883
852 WebContents* inspected_web_contents = GetInspectedWebContents(); 884 WebContents* inspected_web_contents = GetInspectedWebContents();
853 if (inspected_web_contents) { 885 if (inspected_web_contents) {
854 inspected_web_contents->GetDelegate()->AddNewContents( 886 inspected_web_contents->GetDelegate()->AddNewContents(
855 source, new_contents, disposition, initial_pos, user_gesture, 887 source, new_contents, disposition, initial_pos, user_gesture,
856 was_blocked); 888 was_blocked);
857 } 889 }
858 } 890 }
859 891
860 void DevToolsWindow::WebContentsCreated(WebContents* source_contents, 892 void DevToolsWindow::WebContentsCreated(WebContents* source_contents,
861 int opener_render_frame_id, 893 int opener_render_frame_id,
862 const base::string16& frame_name, 894 const base::string16& frame_name,
863 const GURL& target_url, 895 const GURL& target_url,
864 WebContents* new_contents) { 896 WebContents* new_contents) {
897 LOG(INFO) << "web contents created on " << target_url;
pfeldman 2014/07/10 13:44:35 ditto.
898 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
899 new_contents);
900
865 if (target_url.SchemeIs(content::kChromeDevToolsScheme) && 901 if (target_url.SchemeIs(content::kChromeDevToolsScheme) &&
866 target_url.query().find("toolbox=true") != std::string::npos) { 902 target_url.query().find("toolbox=true") != std::string::npos) {
867 CHECK(can_dock_); 903 CHECK(can_dock_);
868 toolbox_web_contents_ = new_contents; 904 toolbox_web_contents_ = new_contents;
869 } 905 }
870 } 906 }
871 907
872 void DevToolsWindow::CloseContents(WebContents* source) { 908 void DevToolsWindow::CloseContents(WebContents* source) {
873 CHECK(is_docked_); 909 CHECK(is_docked_);
874 // Do this first so that when GetDockedInstanceForInspectedTab is called 910 // Do this first so that when GetDockedInstanceForInspectedTab is called
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 } 1168 }
1133 1169
1134 void DevToolsWindow::RenderProcessGone() { 1170 void DevToolsWindow::RenderProcessGone() {
1135 // Docked DevToolsWindow owns its main_web_contents_ and must delete it. 1171 // Docked DevToolsWindow owns its main_web_contents_ and must delete it.
1136 // Undocked main_web_contents_ are owned and handled by browser. 1172 // Undocked main_web_contents_ are owned and handled by browser.
1137 // see crbug.com/369932 1173 // see crbug.com/369932
1138 if (is_docked_) 1174 if (is_docked_)
1139 CloseContents(main_web_contents_); 1175 CloseContents(main_web_contents_);
1140 } 1176 }
1141 1177
1178 extensions::WindowController* DevToolsWindow::GetExtensionWindowController()
1179 const {
1180 return NULL;
1181 }
1182
1183 content::WebContents* DevToolsWindow::GetAssociatedWebContents() const {
1184 return main_web_contents_;
1185 }
1186
1187 content::WebContents* DevToolsWindow::GetVisibleWebContents() const {
1188 return main_web_contents_;
1189 }
1190
1142 void DevToolsWindow::OnLoadCompleted() { 1191 void DevToolsWindow::OnLoadCompleted() {
1143 // First seed inspected tab id for extension APIs. 1192 // First seed inspected tab id for extension APIs.
1144 WebContents* inspected_web_contents = GetInspectedWebContents(); 1193 WebContents* inspected_web_contents = GetInspectedWebContents();
1145 if (inspected_web_contents) { 1194 if (inspected_web_contents) {
1146 SessionTabHelper* session_tab_helper = 1195 SessionTabHelper* session_tab_helper =
1147 SessionTabHelper::FromWebContents(inspected_web_contents); 1196 SessionTabHelper::FromWebContents(inspected_web_contents);
1148 if (session_tab_helper) { 1197 if (session_tab_helper) {
1149 base::FundamentalValue tabId(session_tab_helper->session_id().id()); 1198 base::FundamentalValue tabId(session_tab_helper->session_id().id());
1150 bindings_->CallClientFunction("WebInspector.setInspectedTabId", 1199 bindings_->CallClientFunction("WebInspector.setInspectedTabId",
1151 &tabId, NULL, NULL); 1200 &tabId, NULL, NULL);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 closure.Run(); 1311 closure.Run();
1263 return; 1312 return;
1264 } 1313 }
1265 load_completed_callback_ = closure; 1314 load_completed_callback_ = closure;
1266 } 1315 }
1267 1316
1268 bool DevToolsWindow::ForwardKeyboardEvent( 1317 bool DevToolsWindow::ForwardKeyboardEvent(
1269 const content::NativeWebKeyboardEvent& event) { 1318 const content::NativeWebKeyboardEvent& event) {
1270 return event_forwarder_->ForwardEvent(event); 1319 return event_forwarder_->ForwardEvent(event);
1271 } 1320 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698