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

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

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