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

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

Issue 8636010: Revert "DevTools: remove obsolete methods from DevToolsClientHost" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/lazy_instance.h"
10 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
11 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
12 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 12 #include "base/values.h"
14 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/debugger/devtools_file_util.h" 14 #include "chrome/browser/debugger/devtools_file_util.h"
16 #include "chrome/browser/debugger/devtools_window.h" 15 #include "chrome/browser/debugger/devtools_window.h"
17 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/prefs/pref_service.h" 17 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/browser/prefs/scoped_user_pref_update.h" 18 #include "chrome/browser/prefs/scoped_user_pref_update.h"
(...skipping 18 matching lines...) Expand all
38 #include "content/browser/tab_contents/navigation_controller.h" 37 #include "content/browser/tab_contents/navigation_controller.h"
39 #include "content/browser/tab_contents/navigation_entry.h" 38 #include "content/browser/tab_contents/navigation_entry.h"
40 #include "content/browser/tab_contents/tab_contents.h" 39 #include "content/browser/tab_contents/tab_contents.h"
41 #include "content/browser/tab_contents/tab_contents_view.h" 40 #include "content/browser/tab_contents/tab_contents_view.h"
42 #include "content/common/devtools_messages.h" 41 #include "content/common/devtools_messages.h"
43 #include "content/public/browser/content_browser_client.h" 42 #include "content/public/browser/content_browser_client.h"
44 #include "content/public/browser/notification_source.h" 43 #include "content/public/browser/notification_source.h"
45 #include "content/public/common/bindings_policy.h" 44 #include "content/public/common/bindings_policy.h"
46 #include "grit/generated_resources.h" 45 #include "grit/generated_resources.h"
47 46
48 typedef std::vector<DevToolsWindow*> DevToolsWindowList;
49 namespace {
50 base::LazyInstance<DevToolsWindowList,
51 base::LeakyLazyInstanceTraits<DevToolsWindowList> >
52 g_instances = LAZY_INSTANCE_INITIALIZER;
53 } // namespace
54
55 const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp"; 47 const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp";
56 48
57 // static 49 // static
58 void DevToolsWindow::RegisterUserPrefs(PrefService* prefs) { 50 void DevToolsWindow::RegisterUserPrefs(PrefService* prefs) {
59 prefs->RegisterBooleanPref(prefs::kDevToolsOpenDocked, 51 prefs->RegisterBooleanPref(prefs::kDevToolsOpenDocked,
60 true, 52 true,
61 PrefService::UNSYNCABLE_PREF); 53 PrefService::UNSYNCABLE_PREF);
62 } 54 }
63 55
64 // static 56 // static
65 TabContentsWrapper* DevToolsWindow::GetDevToolsContents( 57 TabContentsWrapper* DevToolsWindow::GetDevToolsContents(
66 TabContents* inspected_tab) { 58 TabContents* inspected_tab) {
67 if (!inspected_tab) 59 if (!inspected_tab)
68 return NULL; 60 return NULL;
69 61
70 DevToolsManager* manager = DevToolsManager::GetInstance(); 62 DevToolsManager* manager = DevToolsManager::GetInstance();
63 if (!manager)
64 return NULL; // Happens only in tests.
65
71 DevToolsClientHost* client_host = manager-> 66 DevToolsClientHost* client_host = manager->
72 GetDevToolsClientHostFor(inspected_tab->render_view_host()); 67 GetDevToolsClientHostFor(inspected_tab->render_view_host());
73 DevToolsWindow* window = AsDevToolsWindow(client_host); 68 DevToolsWindow* window = AsDevToolsWindow(client_host);
74 if (!window || !window->is_docked()) 69 if (!window || !window->is_docked())
75 return NULL; 70 return NULL;
76 return window->tab_contents(); 71 return window->tab_contents();
77 } 72 }
78 73
79 // static 74 // static
75 DevToolsWindow* DevToolsWindow::FindDevToolsWindow(
76 RenderViewHost* window_rvh) {
77 DevToolsClientHost* client_host =
78 DevToolsClientHost::FindOwnerClientHost(window_rvh);
79 return client_host != NULL ? DevToolsWindow::AsDevToolsWindow(client_host)
80 : NULL;
81 }
82
83 // static
80 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( 84 DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker(
81 Profile* profile, 85 Profile* profile,
82 DevToolsAgentHost* worker_agent) { 86 DevToolsAgentHost* worker_agent) {
83 DevToolsWindow* window; 87 DevToolsWindow* window;
84 DevToolsClientHost* client = 88 DevToolsClientHost* client =
85 DevToolsManager::GetInstance()->GetDevToolsClientHostFor(worker_agent); 89 DevToolsManager::GetInstance()->GetDevToolsClientHostFor(worker_agent);
86 if (client) { 90 if (client) {
87 window = AsDevToolsWindow(client); 91 window = AsDevToolsWindow(client);
88 if (!window) 92 if (!window)
89 return NULL; 93 return NULL;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 RenderViewHost* inspected_rvh, 156 RenderViewHost* inspected_rvh,
153 bool docked) 157 bool docked)
154 : RenderViewHostObserver(tab_contents->render_view_host()), 158 : RenderViewHostObserver(tab_contents->render_view_host()),
155 profile_(profile), 159 profile_(profile),
156 inspected_tab_(NULL), 160 inspected_tab_(NULL),
157 tab_contents_(tab_contents), 161 tab_contents_(tab_contents),
158 browser_(NULL), 162 browser_(NULL),
159 docked_(docked), 163 docked_(docked),
160 is_loaded_(false), 164 is_loaded_(false),
161 action_on_load_(DEVTOOLS_TOGGLE_ACTION_NONE) { 165 action_on_load_(DEVTOOLS_TOGGLE_ACTION_NONE) {
162 g_instances.Get().push_back(this);
163 // Wipe out page icon so that the default application icon is used. 166 // Wipe out page icon so that the default application icon is used.
164 NavigationEntry* entry = tab_contents_->controller().GetActiveEntry(); 167 NavigationEntry* entry = tab_contents_->controller().GetActiveEntry();
165 entry->favicon().set_bitmap(SkBitmap()); 168 entry->favicon().set_bitmap(SkBitmap());
166 entry->favicon().set_is_valid(true); 169 entry->favicon().set_is_valid(true);
167 170
168 // Register on-load actions. 171 // Register on-load actions.
169 registrar_.Add( 172 registrar_.Add(
170 this, 173 this,
171 content::NOTIFICATION_LOAD_STOP, 174 content::NOTIFICATION_LOAD_STOP,
172 content::Source<NavigationController>(&tab_contents_->controller())); 175 content::Source<NavigationController>(&tab_contents_->controller()));
173 registrar_.Add( 176 registrar_.Add(
174 this, 177 this,
175 content::NOTIFICATION_TAB_CLOSING, 178 content::NOTIFICATION_TAB_CLOSING,
176 content::Source<NavigationController>(&tab_contents_->controller())); 179 content::Source<NavigationController>(&tab_contents_->controller()));
177 registrar_.Add( 180 registrar_.Add(
178 this, 181 this,
179 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 182 chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
180 content::Source<ThemeService>( 183 content::Source<ThemeService>(
181 ThemeServiceFactory::GetForProfile(profile_))); 184 ThemeServiceFactory::GetForProfile(profile_)));
182 // There is no inspected_rvh in case of shared workers. 185 // There is no inspected_rvh in case of shared workers.
183 if (inspected_rvh) { 186 if (inspected_rvh) {
184 TabContents* tab = inspected_rvh->delegate()->GetAsTabContents(); 187 TabContents* tab = inspected_rvh->delegate()->GetAsTabContents();
185 if (tab) 188 if (tab)
186 inspected_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab); 189 inspected_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab);
187 } 190 }
188 } 191 }
189 192
190 DevToolsWindow::~DevToolsWindow() { 193 DevToolsWindow::~DevToolsWindow() {
191 DevToolsWindowList& instances = g_instances.Get();
192 DevToolsWindowList::iterator it = std::find(instances.begin(),
193 instances.end(),
194 this);
195 DCHECK(it != instances.end());
196 instances.erase(it);
197 } 194 }
198 195
199 void DevToolsWindow::SendMessageToClient(const IPC::Message& message) { 196 void DevToolsWindow::SendMessageToClient(const IPC::Message& message) {
200 RenderViewHost* target_host = tab_contents_->render_view_host(); 197 RenderViewHost* target_host = tab_contents_->render_view_host();
201 IPC::Message* m = new IPC::Message(message); 198 IPC::Message* m = new IPC::Message(message);
202 m->set_routing_id(target_host->routing_id()); 199 m->set_routing_id(target_host->routing_id());
203 target_host->Send(m); 200 target_host->Send(m);
204 } 201 }
205 202
206 void DevToolsWindow::InspectedTabClosing() { 203 void DevToolsWindow::InspectedTabClosing() {
(...skipping 20 matching lines...) Expand all
227 void DevToolsWindow::TabReplaced(TabContents* new_tab) { 224 void DevToolsWindow::TabReplaced(TabContents* new_tab) {
228 TabContentsWrapper* new_tab_wrapper = 225 TabContentsWrapper* new_tab_wrapper =
229 TabContentsWrapper::GetCurrentWrapperForContents(new_tab); 226 TabContentsWrapper::GetCurrentWrapperForContents(new_tab);
230 DCHECK(new_tab_wrapper); 227 DCHECK(new_tab_wrapper);
231 if (!new_tab_wrapper) 228 if (!new_tab_wrapper)
232 return; 229 return;
233 DCHECK_EQ(profile_, new_tab_wrapper->profile()); 230 DCHECK_EQ(profile_, new_tab_wrapper->profile());
234 inspected_tab_ = new_tab_wrapper; 231 inspected_tab_ = new_tab_wrapper;
235 } 232 }
236 233
234 RenderViewHost* DevToolsWindow::GetClientRenderViewHost() {
235 return tab_contents_->render_view_host();
236 }
237
237 void DevToolsWindow::Show(DevToolsToggleAction action) { 238 void DevToolsWindow::Show(DevToolsToggleAction action) {
238 if (docked_) { 239 if (docked_) {
239 Browser* inspected_browser; 240 Browser* inspected_browser;
240 int inspected_tab_index; 241 int inspected_tab_index;
241 // Tell inspected browser to update splitter and switch to inspected panel. 242 // Tell inspected browser to update splitter and switch to inspected panel.
242 if (!IsInspectedBrowserPopupOrPanel() && 243 if (!IsInspectedBrowserPopupOrPanel() &&
243 FindInspectedBrowserAndTabIndex(&inspected_browser, 244 FindInspectedBrowserAndTabIndex(&inspected_browser,
244 &inspected_tab_index)) { 245 &inspected_tab_index)) {
245 BrowserWindow* inspected_window = inspected_browser->window(); 246 BrowserWindow* inspected_window = inspected_browser->window();
246 tab_contents_->tab_contents()->set_delegate(this); 247 tab_contents_->tab_contents()->set_delegate(this);
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 window->Show(action); 639 window->Show(action);
639 else 640 else
640 manager->UnregisterDevToolsClientHostFor(inspected_rvh); 641 manager->UnregisterDevToolsClientHostFor(inspected_rvh);
641 642
642 return window; 643 return window;
643 } 644 }
644 645
645 // static 646 // static
646 DevToolsWindow* DevToolsWindow::AsDevToolsWindow( 647 DevToolsWindow* DevToolsWindow::AsDevToolsWindow(
647 DevToolsClientHost* client_host) { 648 DevToolsClientHost* client_host) {
648 if (!client_host || g_instances == NULL) 649 if (!client_host)
649 return NULL; 650 return NULL;
650 DevToolsWindowList& instances = g_instances.Get(); 651 if (client_host->GetClientRenderViewHost() != NULL)
651 for (DevToolsWindowList::iterator it = instances.begin(); 652 return static_cast<DevToolsWindow*>(client_host);
652 it != instances.end(); ++it) {
653 DevToolsClientHost* client = *it;
654 if (client == client_host)
655 return *it;
656 }
657 return NULL; 653 return NULL;
658 } 654 }
659 655
660 void DevToolsWindow::RenderViewHostDestroyed(RenderViewHost* rvh) { 656 void DevToolsWindow::RenderViewHostDestroyed(RenderViewHost* rvh) {
661 // Don't delete |this| here, do it on NOTIFICATION_TAB_CLOSING event. 657 // Don't delete |this| here, do it on NOTIFICATION_TAB_CLOSING event.
662 } 658 }
663 659
664 bool DevToolsWindow::OnMessageReceived(const IPC::Message& message) { 660 bool DevToolsWindow::OnMessageReceived(const IPC::Message& message) {
665 bool handled = true; 661 bool handled = true;
666 IPC_BEGIN_MESSAGE_MAP(DevToolsWindow, message) 662 IPC_BEGIN_MESSAGE_MAP(DevToolsWindow, message)
(...skipping 19 matching lines...) Expand all
686 RequestSetDocked(false); 682 RequestSetDocked(false);
687 } 683 }
688 684
689 content::JavaScriptDialogCreator* DevToolsWindow::GetJavaScriptDialogCreator() { 685 content::JavaScriptDialogCreator* DevToolsWindow::GetJavaScriptDialogCreator() {
690 if (inspected_tab_ && inspected_tab_->tab_contents()->delegate()) { 686 if (inspected_tab_ && inspected_tab_->tab_contents()->delegate()) {
691 return inspected_tab_->tab_contents()->delegate()-> 687 return inspected_tab_->tab_contents()->delegate()->
692 GetJavaScriptDialogCreator(); 688 GetJavaScriptDialogCreator();
693 } 689 }
694 return TabContentsDelegate::GetJavaScriptDialogCreator(); 690 return TabContentsDelegate::GetJavaScriptDialogCreator();
695 } 691 }
OLDNEW
« no previous file with comments | « chrome/browser/debugger/devtools_window.h ('k') | content/browser/debugger/devtools_client_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698