OLD | NEW |
---|---|
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 } | 52 } |
48 | 53 |
49 if (!DevToolsManager::GetInstance()) | 54 DevToolsManager* manager = DevToolsManager::GetInstance(); |
55 if (!manager) | |
50 return NULL; // Happens only in tests. | 56 return NULL; // Happens only in tests. |
51 | 57 |
52 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> | 58 DevToolsClientHost* client_host = manager-> |
53 GetDevToolsClientHostFor(inspected_tab->render_view_host()); | 59 GetDevToolsClientHostFor(inspected_tab->render_view_host()); |
54 if (!client_host) { | 60 DevToolsWindow* window = AsDevToolsWindow(client_host); |
55 return NULL; | |
56 } | |
57 | |
58 DevToolsWindow* window = client_host->AsDevToolsWindow(); | |
59 if (!window || !window->is_docked()) { | 61 if (!window || !window->is_docked()) { |
60 return NULL; | 62 return NULL; |
61 } | 63 } |
62 return window->tab_contents(); | 64 return window->tab_contents(); |
63 } | 65 } |
64 | 66 |
67 // static | |
68 DevToolsWindow* DevToolsWindow::FindDevToolsWindow( | |
69 RenderViewHost* window_rvh) { | |
70 for (DevToolsWindowList::iterator it = instances_.begin(); | |
71 it != instances_.end(); ++it) { | |
72 if ((*it)->GetRenderViewHost() == window_rvh) | |
73 return *it; | |
74 } | |
75 return NULL; | |
76 } | |
77 | |
78 // static | |
79 void DevToolsWindow::OpenDevToolsWindow(RenderViewHost* inspected_rvh) { | |
80 ToggleDevToolsWindow(inspected_rvh, true, DEVTOOLS_TOGGLE_ACTION_NONE); | |
81 } | |
82 | |
83 // static | |
84 void DevToolsWindow::ToggleDevToolsWindow(RenderViewHost* inspected_rvh, | |
85 DevToolsToggleAction action) { | |
86 ToggleDevToolsWindow(inspected_rvh, false, action); | |
87 } | |
88 | |
89 void DevToolsWindow::InspectElement(RenderViewHost* inspected_rvh, | |
90 int x, | |
91 int y) { | |
92 DevToolsManager::GetInstance()->SendInspectElement(inspected_rvh, x, y); | |
93 // TODO(loislo): we should initiate DevTools window opening from within | |
94 // renderer. Otherwise, we still can hit a race condition here. | |
95 OpenDevToolsWindow(inspected_rvh); | |
96 } | |
97 | |
98 | |
65 DevToolsWindow::DevToolsWindow(Profile* profile, | 99 DevToolsWindow::DevToolsWindow(Profile* profile, |
66 RenderViewHost* inspected_rvh, | 100 RenderViewHost* inspected_rvh, |
67 bool docked) | 101 bool docked) |
68 : profile_(profile), | 102 : profile_(profile), |
69 inspected_tab_(NULL), | 103 inspected_tab_(NULL), |
70 browser_(NULL), | 104 browser_(NULL), |
71 docked_(docked), | 105 docked_(docked), |
72 is_loaded_(false), | 106 is_loaded_(false), |
73 action_on_load_(DEVTOOLS_TOGGLE_ACTION_NONE) { | 107 action_on_load_(DEVTOOLS_TOGGLE_ACTION_NONE) { |
74 // Create TabContents with devtools. | 108 // Create TabContents with devtools. |
(...skipping 16 matching lines...) Expand all Loading... | |
91 registrar_.Add(this, | 125 registrar_.Add(this, |
92 NotificationType::TAB_CLOSING, | 126 NotificationType::TAB_CLOSING, |
93 Source<NavigationController>(&tab_contents_->controller())); | 127 Source<NavigationController>(&tab_contents_->controller())); |
94 registrar_.Add( | 128 registrar_.Add( |
95 this, | 129 this, |
96 NotificationType::BROWSER_THEME_CHANGED, | 130 NotificationType::BROWSER_THEME_CHANGED, |
97 Source<ThemeService>(ThemeServiceFactory::GetForProfile(profile_))); | 131 Source<ThemeService>(ThemeServiceFactory::GetForProfile(profile_))); |
98 TabContents* tab = inspected_rvh->delegate()->GetAsTabContents(); | 132 TabContents* tab = inspected_rvh->delegate()->GetAsTabContents(); |
99 if (tab) | 133 if (tab) |
100 inspected_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab); | 134 inspected_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab); |
135 | |
136 instances_.push_back(this); | |
101 } | 137 } |
102 | 138 |
103 DevToolsWindow::~DevToolsWindow() { | 139 DevToolsWindow::~DevToolsWindow() { |
104 } | 140 DevToolsWindowList::iterator it = std::find(instances_.begin(), |
105 | 141 instances_.end(), |
106 DevToolsWindow* DevToolsWindow::AsDevToolsWindow() { | 142 this); |
107 return this; | 143 DCHECK(it != instances_.end()); |
144 instances_.erase(it); | |
108 } | 145 } |
109 | 146 |
110 void DevToolsWindow::SendMessageToClient(const IPC::Message& message) { | 147 void DevToolsWindow::SendMessageToClient(const IPC::Message& message) { |
111 RenderViewHost* target_host = | 148 RenderViewHost* target_host = |
112 tab_contents_->tab_contents()->render_view_host(); | 149 tab_contents_->tab_contents()->render_view_host(); |
113 IPC::Message* m = new IPC::Message(message); | 150 IPC::Message* m = new IPC::Message(message); |
114 m->set_routing_id(target_host->routing_id()); | 151 m->set_routing_id(target_host->routing_id()); |
115 target_host->Send(m); | 152 target_host->Send(m); |
116 } | 153 } |
117 | 154 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 } else { | 226 } else { |
190 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 227 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
191 if (inspected_window) | 228 if (inspected_window) |
192 tab_contents_->view()->Focus(); | 229 tab_contents_->view()->Focus(); |
193 } | 230 } |
194 } | 231 } |
195 | 232 |
196 void DevToolsWindow::SetDocked(bool docked) { | 233 void DevToolsWindow::SetDocked(bool docked) { |
197 if (docked_ == docked) | 234 if (docked_ == docked) |
198 return; | 235 return; |
236 | |
237 if (!inspected_tab_) | |
238 return; | |
239 RenderViewHost* inspected_rvh = inspected_tab_->render_view_host(); | |
pfeldman
2011/07/07 12:17:52
Do you need this code?
yurys
2011/07/07 12:30:40
Removed.
| |
240 DCHECK(inspected_rvh); | |
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 Loading... | |
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 void DevToolsWindow::ToggleDevToolsWindow( | |
528 RenderViewHost* inspected_rvh, | |
529 bool force_open, | |
530 DevToolsToggleAction action) { | |
531 DevToolsManager* manager = DevToolsManager::GetInstance(); | |
532 DevToolsWindow* window = NULL; | |
533 | |
534 DevToolsClientHost* host = manager->GetDevToolsClientHostFor(inspected_rvh); | |
535 if (host != NULL && AsDevToolsWindow(host) == NULL) { | |
536 // Break remote debugging / extension debugging session. | |
537 manager->UnregisterDevToolsClientHostFor(inspected_rvh); | |
538 } | |
539 | |
540 bool do_open = force_open; | |
541 if (!window) { | |
pfeldman
2011/07/07 12:17:52
if (!host)
yurys
2011/07/07 12:30:40
The code was refactored.
| |
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 } | |
pfeldman
2011/07/07 12:17:52
else {
window = AsDevToolsWindow(host)
}
yurys
2011/07/07 12:30:40
Rewrote this part.
| |
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) { | |
pfeldman
2011/07/07 12:17:52
remove {}
yurys
2011/07/07 12:30:40
Done.
| |
552 window->Show(action); | |
553 } else { | |
554 manager->UnregisterDevToolsClientHostFor(inspected_rvh); | |
555 } | |
556 } | |
557 | |
558 // static | |
559 DevToolsWindow* DevToolsWindow::AsDevToolsWindow( | |
560 DevToolsClientHost* client_host) { | |
561 if (!client_host) | |
562 return NULL; | |
563 DevToolsWindowList::iterator it = std::find(instances_.begin(), | |
564 instances_.end(), | |
565 client_host); | |
566 if (it == instances_.end()) { | |
pfeldman
2011/07/07 12:17:52
ditto
yurys
2011/07/07 12:30:40
Done.
| |
567 return NULL; | |
568 } | |
569 return *it; | |
570 } | |
OLD | NEW |