OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/l10n_util.h" | 5 #include "app/l10n_util.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
8 #include "chrome/browser/browser_list.h" | 8 #include "chrome/browser/browser_list.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/browser_window.h" | 10 #include "chrome/browser/browser_window.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 void DevToolsWindow::Show(bool open_console) { | 117 void DevToolsWindow::Show(bool open_console) { |
118 if (docked_) { | 118 if (docked_) { |
119 // Just tell inspected browser to update splitter. | 119 // Just tell inspected browser to update splitter. |
120 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 120 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
121 if (inspected_window) { | 121 if (inspected_window) { |
122 tab_contents_->set_delegate(this); | 122 tab_contents_->set_delegate(this); |
123 inspected_window->UpdateDevTools(); | 123 inspected_window->UpdateDevTools(); |
| 124 SetAttachedWindow(); |
124 tab_contents_->view()->SetInitialFocus(); | 125 tab_contents_->view()->SetInitialFocus(); |
125 return; | 126 return; |
126 } else { | 127 } else { |
127 // Sometimes we don't know where to dock. Stay undocked. | 128 // Sometimes we don't know where to dock. Stay undocked. |
128 docked_ = false; | 129 docked_ = false; |
129 } | 130 } |
130 } | 131 } |
131 | 132 |
132 if (!browser_) | 133 if (!browser_) |
133 CreateDevToolsBrowser(); | 134 CreateDevToolsBrowser(); |
134 | 135 |
135 browser_->window()->Show(); | 136 browser_->window()->Show(); |
| 137 SetAttachedWindow(); |
136 tab_contents_->view()->SetInitialFocus(); | 138 tab_contents_->view()->SetInitialFocus(); |
137 | 139 |
138 if (open_console) { | 140 if (open_console) { |
139 if (is_loaded_) | 141 if (is_loaded_) |
140 OpenConsole(); | 142 OpenConsole(); |
141 else | 143 else |
142 open_console_on_load_ = true; | 144 open_console_on_load_ = true; |
143 } | 145 } |
| 146 |
144 } | 147 } |
145 | 148 |
146 void DevToolsWindow::Activate() { | 149 void DevToolsWindow::Activate() { |
147 if (!docked_) { | 150 if (!docked_) { |
148 if (!browser_->window()->IsActive()) { | 151 if (!browser_->window()->IsActive()) { |
149 browser_->window()->Activate(); | 152 browser_->window()->Activate(); |
150 } | 153 } |
151 } else { | 154 } else { |
152 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 155 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
153 if (inspected_window) | 156 if (inspected_window) |
154 inspected_window->FocusDevTools(); | 157 inspected_window->FocusDevTools(); |
155 } | 158 } |
156 } | 159 } |
157 | 160 |
158 void DevToolsWindow::SetDocked(bool docked) { | 161 void DevToolsWindow::SetDocked(bool docked) { |
159 if (docked_ == docked) { | 162 if (docked_ == docked) { |
160 return; | 163 return; |
161 } | 164 } |
| 165 if (docked && !GetInspectedBrowserWindow()) { |
| 166 // Cannot dock, avoid window flashing due to close-reopen cycle. |
| 167 return; |
| 168 } |
162 docked_ = docked; | 169 docked_ = docked; |
163 | 170 |
164 if (docked) { | 171 if (docked) { |
165 // Detach window from the external devtools browser. It will lead to | 172 // Detach window from the external devtools browser. It will lead to |
166 // the browser object's close and delete. Remove observer first. | 173 // the browser object's close and delete. Remove observer first. |
167 TabStripModel* tabstrip_model = browser_->tabstrip_model(); | 174 TabStripModel* tabstrip_model = browser_->tabstrip_model(); |
168 tabstrip_model->DetachTabContentsAt( | 175 tabstrip_model->DetachTabContentsAt( |
169 tabstrip_model->GetIndexOfTabContents(tab_contents_)); | 176 tabstrip_model->GetIndexOfTabContents(tab_contents_)); |
170 browser_ = NULL; | 177 browser_ = NULL; |
171 } else { | 178 } else { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 for (int i = 0; i < browser->tab_count(); ++i) { | 225 for (int i = 0; i < browser->tab_count(); ++i) { |
219 TabContents* tab_contents = browser->GetTabContentsAt(i); | 226 TabContents* tab_contents = browser->GetTabContentsAt(i); |
220 if (tab_contents == inspected_tab_) { | 227 if (tab_contents == inspected_tab_) { |
221 return browser->window(); | 228 return browser->window(); |
222 } | 229 } |
223 } | 230 } |
224 } | 231 } |
225 return NULL; | 232 return NULL; |
226 } | 233 } |
227 | 234 |
| 235 void DevToolsWindow::SetAttachedWindow() { |
| 236 tab_contents_->render_view_host()-> |
| 237 ExecuteJavascriptInWebFrame( |
| 238 L"", docked_ ? L"WebInspector.setAttachedWindow(true);" : |
| 239 L"WebInspector.setAttachedWindow(false);"); |
| 240 } |
| 241 |
228 void DevToolsWindow::Observe(NotificationType type, | 242 void DevToolsWindow::Observe(NotificationType type, |
229 const NotificationSource& source, | 243 const NotificationSource& source, |
230 const NotificationDetails& details) { | 244 const NotificationDetails& details) { |
231 if (type == NotificationType::LOAD_STOP) { | 245 if (type == NotificationType::LOAD_STOP) { |
232 tab_contents_->render_view_host()-> | 246 SetAttachedWindow(); |
233 ExecuteJavascriptInWebFrame( | |
234 L"", docked_ ? L"WebInspector.setAttachedWindow(true);" : | |
235 L"WebInspector.setAttachedWindow(false);"); | |
236 is_loaded_ = true; | 247 is_loaded_ = true; |
237 if (open_console_on_load_) { | 248 if (open_console_on_load_) { |
238 OpenConsole(); | 249 OpenConsole(); |
239 open_console_on_load_ = false; | 250 open_console_on_load_ = false; |
240 } | 251 } |
241 } else if (type == NotificationType::TAB_CLOSING) { | 252 } else if (type == NotificationType::TAB_CLOSING) { |
242 if (Source<NavigationController>(source).ptr() == | 253 if (Source<NavigationController>(source).ptr() == |
243 &tab_contents_->controller()) { | 254 &tab_contents_->controller()) { |
244 // This happens when browser closes all of its tabs as a result | 255 // This happens when browser closes all of its tabs as a result |
245 // of window.Close event. | 256 // of window.Close event. |
(...skipping 21 matching lines...) Expand all Loading... |
267 return false; | 278 return false; |
268 } | 279 } |
269 | 280 |
270 void DevToolsWindow::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { | 281 void DevToolsWindow::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
271 if (docked_) { | 282 if (docked_) { |
272 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); | 283 BrowserWindow* inspected_window = GetInspectedBrowserWindow(); |
273 if (inspected_window) | 284 if (inspected_window) |
274 inspected_window->HandleKeyboardEvent(event); | 285 inspected_window->HandleKeyboardEvent(event); |
275 } | 286 } |
276 } | 287 } |
OLD | NEW |