Chromium Code Reviews| Index: content/browser/debugger/devtools_window.cc |
| diff --git a/content/browser/debugger/devtools_window.cc b/content/browser/debugger/devtools_window.cc |
| index 96af885f9f1587603778cc1df3a1c31e296c6411..a4c365c5185f0ac6235d43e3126dde0f8510a667 100644 |
| --- a/content/browser/debugger/devtools_window.cc |
| +++ b/content/browser/debugger/devtools_window.cc |
| @@ -2,6 +2,8 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include <algorithm> |
| + |
| #include "base/command_line.h" |
| #include "base/json/json_writer.h" |
| #include "base/stringprintf.h" |
| @@ -24,6 +26,7 @@ |
| #include "chrome/common/pref_names.h" |
| #include "chrome/common/render_messages.h" |
| #include "chrome/common/url_constants.h" |
| +#include "content/browser/browsing_instance.h" |
| #include "content/browser/debugger/devtools_manager.h" |
| #include "content/browser/debugger/devtools_window.h" |
| #include "content/browser/in_process_webkit/session_storage_namespace.h" |
| @@ -39,6 +42,8 @@ |
| const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp"; |
| +DevToolsWindow::DevToolsWindowList DevToolsWindow::instances_; |
| + |
| // static |
| TabContentsWrapper* DevToolsWindow::GetDevToolsContents( |
| TabContents* inspected_tab) { |
| @@ -46,22 +51,51 @@ TabContentsWrapper* DevToolsWindow::GetDevToolsContents( |
| return NULL; |
| } |
| - if (!DevToolsManager::GetInstance()) |
| + DevToolsManager* manager = DevToolsManager::GetInstance(); |
| + if (!manager) |
| return NULL; // Happens only in tests. |
| - DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> |
| - GetDevToolsClientHostFor(inspected_tab->render_view_host()); |
| - if (!client_host) { |
| - return NULL; |
| - } |
| - |
| - DevToolsWindow* window = client_host->AsDevToolsWindow(); |
| + DevToolsClientHost* client_host = manager-> |
| + GetDevToolsClientHostFor(inspected_tab->render_view_host()); |
| + DevToolsWindow* window = AsDevToolsWindow(client_host); |
| if (!window || !window->is_docked()) { |
| return NULL; |
| } |
| return window->tab_contents(); |
| } |
| +// static |
| +DevToolsWindow* DevToolsWindow::FindDevToolsWindow( |
| + RenderViewHost* window_rvh) { |
| + for (DevToolsWindowList::iterator it = instances_.begin(); |
| + it != instances_.end(); ++it) { |
| + if ((*it)->GetRenderViewHost() == window_rvh) |
| + return *it; |
| + } |
| + return NULL; |
| +} |
| + |
| +// static |
| +void DevToolsWindow::OpenDevToolsWindow(RenderViewHost* inspected_rvh) { |
| + ToggleDevToolsWindow(inspected_rvh, true, DEVTOOLS_TOGGLE_ACTION_NONE); |
| +} |
| + |
| +// static |
| +void DevToolsWindow::ToggleDevToolsWindow(RenderViewHost* inspected_rvh, |
| + DevToolsToggleAction action) { |
| + ToggleDevToolsWindow(inspected_rvh, false, action); |
| +} |
| + |
| +void DevToolsWindow::InspectElement(RenderViewHost* inspected_rvh, |
| + int x, |
| + int y) { |
| + DevToolsManager::GetInstance()->SendInspectElement(inspected_rvh, x, y); |
| + // TODO(loislo): we should initiate DevTools window opening from within |
| + // renderer. Otherwise, we still can hit a race condition here. |
| + OpenDevToolsWindow(inspected_rvh); |
| +} |
| + |
| + |
| DevToolsWindow::DevToolsWindow(Profile* profile, |
| RenderViewHost* inspected_rvh, |
| bool docked) |
| @@ -98,13 +132,16 @@ DevToolsWindow::DevToolsWindow(Profile* profile, |
| TabContents* tab = inspected_rvh->delegate()->GetAsTabContents(); |
| if (tab) |
| inspected_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab); |
| -} |
| -DevToolsWindow::~DevToolsWindow() { |
| + instances_.push_back(this); |
| } |
| -DevToolsWindow* DevToolsWindow::AsDevToolsWindow() { |
| - return this; |
| +DevToolsWindow::~DevToolsWindow() { |
| + DevToolsWindowList::iterator it = std::find(instances_.begin(), |
| + instances_.end(), |
| + this); |
| + DCHECK(it != instances_.end()); |
| + instances_.erase(it); |
| } |
| void DevToolsWindow::SendMessageToClient(const IPC::Message& message) { |
| @@ -196,6 +233,13 @@ void DevToolsWindow::Activate() { |
| void DevToolsWindow::SetDocked(bool docked) { |
| if (docked_ == docked) |
| return; |
| + |
| + if (!inspected_tab_) |
| + return; |
| + 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.
|
| + DCHECK(inspected_rvh); |
| + profile_->GetPrefs()->SetBoolean(prefs::kDevToolsOpenDocked, docked); |
| + |
| if (docked && (!GetInspectedBrowserWindow() || |
| IsInspectedBrowserPopupOrPanel())) { |
| // Cannot dock, avoid window flashing due to close-reopen cycle. |
| @@ -478,3 +522,49 @@ void DevToolsWindow::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
| inspected_window->HandleKeyboardEvent(event); |
| } |
| } |
| + |
| +// static |
| +void DevToolsWindow::ToggleDevToolsWindow( |
| + RenderViewHost* inspected_rvh, |
| + bool force_open, |
| + DevToolsToggleAction action) { |
| + DevToolsManager* manager = DevToolsManager::GetInstance(); |
| + DevToolsWindow* window = NULL; |
| + |
| + DevToolsClientHost* host = manager->GetDevToolsClientHostFor(inspected_rvh); |
| + if (host != NULL && AsDevToolsWindow(host) == NULL) { |
| + // Break remote debugging / extension debugging session. |
| + manager->UnregisterDevToolsClientHostFor(inspected_rvh); |
| + } |
| + |
| + bool do_open = force_open; |
| + if (!window) { |
|
pfeldman
2011/07/07 12:17:52
if (!host)
yurys
2011/07/07 12:30:40
The code was refactored.
|
| + Profile* profile = inspected_rvh->process()->profile(); |
| + bool docked = profile->GetPrefs()->GetBoolean(prefs::kDevToolsOpenDocked); |
| + window = new DevToolsWindow(profile, inspected_rvh, docked); |
| + manager->RegisterDevToolsClientHostFor(inspected_rvh, window); |
| + do_open = true; |
| + } |
|
pfeldman
2011/07/07 12:17:52
else {
window = AsDevToolsWindow(host)
}
yurys
2011/07/07 12:30:40
Rewrote this part.
|
| + |
| + // If window is docked and visible, we hide it on toggle. If window is |
| + // undocked, we show (activate) it. |
| + if (!window->is_docked() || do_open) { |
|
pfeldman
2011/07/07 12:17:52
remove {}
yurys
2011/07/07 12:30:40
Done.
|
| + window->Show(action); |
| + } else { |
| + manager->UnregisterDevToolsClientHostFor(inspected_rvh); |
| + } |
| +} |
| + |
| +// static |
| +DevToolsWindow* DevToolsWindow::AsDevToolsWindow( |
| + DevToolsClientHost* client_host) { |
| + if (!client_host) |
| + return NULL; |
| + DevToolsWindowList::iterator it = std::find(instances_.begin(), |
| + instances_.end(), |
| + client_host); |
| + if (it == instances_.end()) { |
|
pfeldman
2011/07/07 12:17:52
ditto
yurys
2011/07/07 12:30:40
Done.
|
| + return NULL; |
| + } |
| + return *it; |
| +} |