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

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

Issue 7322004: DevTools: devtools manager should know nothing about DevToolsWindow (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments addressed Created 9 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
« no previous file with comments | « content/browser/debugger/devtools_window.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
6
5 #include "base/command_line.h" 7 #include "base/command_line.h"
6 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
7 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
8 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
9 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
10 #include "base/values.h" 12 #include "base/values.h"
11 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/prefs/pref_service.h" 15 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/prefs/scoped_user_pref_update.h" 16 #include "chrome/browser/prefs/scoped_user_pref_update.h"
15 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/sessions/restore_tab_helper.h" 18 #include "chrome/browser/sessions/restore_tab_helper.h"
17 #include "chrome/browser/tabs/tab_strip_model.h" 19 #include "chrome/browser/tabs/tab_strip_model.h"
18 #include "chrome/browser/themes/theme_service.h" 20 #include "chrome/browser/themes/theme_service.h"
19 #include "chrome/browser/themes/theme_service_factory.h" 21 #include "chrome/browser/themes/theme_service_factory.h"
20 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_list.h" 23 #include "chrome/browser/ui/browser_list.h"
22 #include "chrome/browser/ui/browser_window.h" 24 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
24 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
25 #include "chrome/common/render_messages.h" 27 #include "chrome/common/render_messages.h"
26 #include "chrome/common/url_constants.h" 28 #include "chrome/common/url_constants.h"
29 #include "content/browser/browsing_instance.h"
27 #include "content/browser/debugger/devtools_manager.h" 30 #include "content/browser/debugger/devtools_manager.h"
28 #include "content/browser/debugger/devtools_window.h" 31 #include "content/browser/debugger/devtools_window.h"
29 #include "content/browser/in_process_webkit/session_storage_namespace.h" 32 #include "content/browser/in_process_webkit/session_storage_namespace.h"
30 #include "content/browser/load_notification_details.h" 33 #include "content/browser/load_notification_details.h"
31 #include "content/browser/renderer_host/render_view_host.h" 34 #include "content/browser/renderer_host/render_view_host.h"
32 #include "content/browser/tab_contents/navigation_controller.h" 35 #include "content/browser/tab_contents/navigation_controller.h"
33 #include "content/browser/tab_contents/navigation_entry.h" 36 #include "content/browser/tab_contents/navigation_entry.h"
34 #include "content/browser/tab_contents/tab_contents.h" 37 #include "content/browser/tab_contents/tab_contents.h"
35 #include "content/browser/tab_contents/tab_contents_view.h" 38 #include "content/browser/tab_contents/tab_contents_view.h"
36 #include "content/common/bindings_policy.h" 39 #include "content/common/bindings_policy.h"
37 #include "content/common/notification_service.h" 40 #include "content/common/notification_service.h"
38 #include "grit/generated_resources.h" 41 #include "grit/generated_resources.h"
39 42
40 const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp"; 43 const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp";
41 44
45 DevToolsWindow::DevToolsWindowList DevToolsWindow::instances_;
46
42 // static 47 // static
43 TabContentsWrapper* DevToolsWindow::GetDevToolsContents( 48 TabContentsWrapper* DevToolsWindow::GetDevToolsContents(
44 TabContents* inspected_tab) { 49 TabContents* inspected_tab) {
45 if (!inspected_tab) { 50 if (!inspected_tab)
46 return NULL; 51 return NULL;
47 }
48 52
49 if (!DevToolsManager::GetInstance()) 53 DevToolsManager* manager = DevToolsManager::GetInstance();
54 if (!manager)
50 return NULL; // Happens only in tests. 55 return NULL; // Happens only in tests.
51 56
52 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> 57 DevToolsClientHost* client_host = manager->
53 GetDevToolsClientHostFor(inspected_tab->render_view_host()); 58 GetDevToolsClientHostFor(inspected_tab->render_view_host());
54 if (!client_host) { 59 DevToolsWindow* window = AsDevToolsWindow(client_host);
60 if (!window || !window->is_docked())
55 return NULL; 61 return NULL;
56 }
57
58 DevToolsWindow* window = client_host->AsDevToolsWindow();
59 if (!window || !window->is_docked()) {
60 return NULL;
61 }
62 return window->tab_contents(); 62 return window->tab_contents();
63 } 63 }
64 64
65 // static
66 DevToolsWindow* DevToolsWindow::FindDevToolsWindow(
67 RenderViewHost* window_rvh) {
68 for (DevToolsWindowList::iterator it = instances_.begin();
69 it != instances_.end(); ++it) {
70 if ((*it)->GetRenderViewHost() == window_rvh)
71 return *it;
72 }
73 return NULL;
74 }
75
76 // static
77 DevToolsWindow* DevToolsWindow::OpenDevToolsWindow(
78 RenderViewHost* inspected_rvh) {
79 return ToggleDevToolsWindow(inspected_rvh, true,
80 DEVTOOLS_TOGGLE_ACTION_NONE);
81 }
82
83 // static
84 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow(
85 RenderViewHost* inspected_rvh,
86 DevToolsToggleAction action) {
87 return ToggleDevToolsWindow(inspected_rvh, false, action);
88 }
89
90 void DevToolsWindow::InspectElement(RenderViewHost* inspected_rvh,
91 int x,
92 int y) {
93 DevToolsManager::GetInstance()->SendInspectElement(inspected_rvh, x, y);
94 // TODO(loislo): we should initiate DevTools window opening from within
95 // renderer. Otherwise, we still can hit a race condition here.
96 OpenDevToolsWindow(inspected_rvh);
97 }
98
99
65 DevToolsWindow::DevToolsWindow(Profile* profile, 100 DevToolsWindow::DevToolsWindow(Profile* profile,
66 RenderViewHost* inspected_rvh, 101 RenderViewHost* inspected_rvh,
67 bool docked) 102 bool docked)
68 : profile_(profile), 103 : profile_(profile),
69 inspected_tab_(NULL), 104 inspected_tab_(NULL),
70 browser_(NULL), 105 browser_(NULL),
71 docked_(docked), 106 docked_(docked),
72 is_loaded_(false), 107 is_loaded_(false),
73 action_on_load_(DEVTOOLS_TOGGLE_ACTION_NONE) { 108 action_on_load_(DEVTOOLS_TOGGLE_ACTION_NONE) {
74 // Create TabContents with devtools. 109 // Create TabContents with devtools.
(...skipping 16 matching lines...) Expand all
91 registrar_.Add(this, 126 registrar_.Add(this,
92 NotificationType::TAB_CLOSING, 127 NotificationType::TAB_CLOSING,
93 Source<NavigationController>(&tab_contents_->controller())); 128 Source<NavigationController>(&tab_contents_->controller()));
94 registrar_.Add( 129 registrar_.Add(
95 this, 130 this,
96 NotificationType::BROWSER_THEME_CHANGED, 131 NotificationType::BROWSER_THEME_CHANGED,
97 Source<ThemeService>(ThemeServiceFactory::GetForProfile(profile_))); 132 Source<ThemeService>(ThemeServiceFactory::GetForProfile(profile_)));
98 TabContents* tab = inspected_rvh->delegate()->GetAsTabContents(); 133 TabContents* tab = inspected_rvh->delegate()->GetAsTabContents();
99 if (tab) 134 if (tab)
100 inspected_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab); 135 inspected_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab);
136
137 instances_.push_back(this);
101 } 138 }
102 139
103 DevToolsWindow::~DevToolsWindow() { 140 DevToolsWindow::~DevToolsWindow() {
104 } 141 DevToolsWindowList::iterator it = std::find(instances_.begin(),
105 142 instances_.end(),
106 DevToolsWindow* DevToolsWindow::AsDevToolsWindow() { 143 this);
107 return this; 144 DCHECK(it != instances_.end());
145 instances_.erase(it);
108 } 146 }
109 147
110 void DevToolsWindow::SendMessageToClient(const IPC::Message& message) { 148 void DevToolsWindow::SendMessageToClient(const IPC::Message& message) {
111 RenderViewHost* target_host = 149 RenderViewHost* target_host =
112 tab_contents_->tab_contents()->render_view_host(); 150 tab_contents_->tab_contents()->render_view_host();
113 IPC::Message* m = new IPC::Message(message); 151 IPC::Message* m = new IPC::Message(message);
114 m->set_routing_id(target_host->routing_id()); 152 m->set_routing_id(target_host->routing_id());
115 target_host->Send(m); 153 target_host->Send(m);
116 } 154 }
117 155
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } else { 227 } else {
190 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); 228 BrowserWindow* inspected_window = GetInspectedBrowserWindow();
191 if (inspected_window) 229 if (inspected_window)
192 tab_contents_->view()->Focus(); 230 tab_contents_->view()->Focus();
193 } 231 }
194 } 232 }
195 233
196 void DevToolsWindow::SetDocked(bool docked) { 234 void DevToolsWindow::SetDocked(bool docked) {
197 if (docked_ == docked) 235 if (docked_ == docked)
198 return; 236 return;
237
238 if (!inspected_tab_)
239 return;
240
241 profile_->GetPrefs()->SetBoolean(prefs::kDevToolsOpenDocked, docked);
242
199 if (docked && (!GetInspectedBrowserWindow() || 243 if (docked && (!GetInspectedBrowserWindow() ||
200 IsInspectedBrowserPopupOrPanel())) { 244 IsInspectedBrowserPopupOrPanel())) {
201 // Cannot dock, avoid window flashing due to close-reopen cycle. 245 // Cannot dock, avoid window flashing due to close-reopen cycle.
202 return; 246 return;
203 } 247 }
204 docked_ = docked; 248 docked_ = docked;
205 249
206 if (docked) { 250 if (docked) {
207 // Detach window from the external devtools browser. It will lead to 251 // Detach window from the external devtools browser. It will lead to
208 // the browser object's close and delete. Remove observer first. 252 // the browser object's close and delete. Remove observer first.
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 if (docked_) { 515 if (docked_) {
472 if (event.windowsKeyCode == 0x08) { 516 if (event.windowsKeyCode == 0x08) {
473 // Do not navigate back in history on Windows (http://crbug.com/74156). 517 // Do not navigate back in history on Windows (http://crbug.com/74156).
474 return; 518 return;
475 } 519 }
476 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); 520 BrowserWindow* inspected_window = GetInspectedBrowserWindow();
477 if (inspected_window) 521 if (inspected_window)
478 inspected_window->HandleKeyboardEvent(event); 522 inspected_window->HandleKeyboardEvent(event);
479 } 523 }
480 } 524 }
525
526 // static
527 DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow(
528 RenderViewHost* inspected_rvh,
529 bool force_open,
530 DevToolsToggleAction action) {
531 DevToolsManager* manager = DevToolsManager::GetInstance();
532
533 DevToolsClientHost* host = manager->GetDevToolsClientHostFor(inspected_rvh);
534 DevToolsWindow* window = AsDevToolsWindow(host);
535 if (host != NULL && window == NULL) {
536 // Break remote debugging / extension debugging session.
537 manager->UnregisterDevToolsClientHostFor(inspected_rvh);
538 }
539
540 bool do_open = force_open;
541 if (!window) {
542 Profile* profile = inspected_rvh->process()->profile();
543 bool docked = profile->GetPrefs()->GetBoolean(prefs::kDevToolsOpenDocked);
544 window = new DevToolsWindow(profile, inspected_rvh, docked);
545 manager->RegisterDevToolsClientHostFor(inspected_rvh, window);
546 do_open = true;
547 }
548
549 // If window is docked and visible, we hide it on toggle. If window is
550 // undocked, we show (activate) it.
551 if (!window->is_docked() || do_open)
552 window->Show(action);
553 else
554 manager->UnregisterDevToolsClientHostFor(inspected_rvh);
555
556 return window;
557 }
558
559 // static
560 DevToolsWindow* DevToolsWindow::AsDevToolsWindow(
561 DevToolsClientHost* client_host) {
562 if (!client_host)
563 return NULL;
564 DevToolsWindowList::iterator it = std::find(instances_.begin(),
565 instances_.end(),
566 client_host);
567 if (it == instances_.end())
568 return NULL;
569 return *it;
570 }
OLDNEW
« no previous file with comments | « content/browser/debugger/devtools_window.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698