Commit f968aaa7 authored by yurys@chromium.org's avatar yurys@chromium.org

Revert "DevTools: remove obsolete methods from DevToolsClientHost"

This reverts commit 111135

BUG=
TEST=

Review URL: http://codereview.chromium.org/8636010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111137 0039d316-1c4b-4281-b951-d872f2087c98
parent da5ba698
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
#include "base/lazy_instance.h"
#include "base/stringprintf.h" #include "base/stringprintf.h"
#include "base/string_number_conversions.h" #include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
...@@ -45,13 +44,6 @@ ...@@ -45,13 +44,6 @@
#include "content/public/common/bindings_policy.h" #include "content/public/common/bindings_policy.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
typedef std::vector<DevToolsWindow*> DevToolsWindowList;
namespace {
base::LazyInstance<DevToolsWindowList,
base::LeakyLazyInstanceTraits<DevToolsWindowList> >
g_instances = LAZY_INSTANCE_INITIALIZER;
} // namespace
const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp"; const char DevToolsWindow::kDevToolsApp[] = "DevToolsApp";
// static // static
...@@ -68,6 +60,9 @@ TabContentsWrapper* DevToolsWindow::GetDevToolsContents( ...@@ -68,6 +60,9 @@ TabContentsWrapper* DevToolsWindow::GetDevToolsContents(
return NULL; return NULL;
DevToolsManager* manager = DevToolsManager::GetInstance(); DevToolsManager* manager = DevToolsManager::GetInstance();
if (!manager)
return NULL; // Happens only in tests.
DevToolsClientHost* client_host = manager-> DevToolsClientHost* client_host = manager->
GetDevToolsClientHostFor(inspected_tab->render_view_host()); GetDevToolsClientHostFor(inspected_tab->render_view_host());
DevToolsWindow* window = AsDevToolsWindow(client_host); DevToolsWindow* window = AsDevToolsWindow(client_host);
...@@ -76,6 +71,15 @@ TabContentsWrapper* DevToolsWindow::GetDevToolsContents( ...@@ -76,6 +71,15 @@ TabContentsWrapper* DevToolsWindow::GetDevToolsContents(
return window->tab_contents(); return window->tab_contents();
} }
// static
DevToolsWindow* DevToolsWindow::FindDevToolsWindow(
RenderViewHost* window_rvh) {
DevToolsClientHost* client_host =
DevToolsClientHost::FindOwnerClientHost(window_rvh);
return client_host != NULL ? DevToolsWindow::AsDevToolsWindow(client_host)
: NULL;
}
// static // static
DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker( DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker(
Profile* profile, Profile* profile,
...@@ -159,7 +163,6 @@ DevToolsWindow::DevToolsWindow(TabContentsWrapper* tab_contents, ...@@ -159,7 +163,6 @@ DevToolsWindow::DevToolsWindow(TabContentsWrapper* tab_contents,
docked_(docked), docked_(docked),
is_loaded_(false), is_loaded_(false),
action_on_load_(DEVTOOLS_TOGGLE_ACTION_NONE) { action_on_load_(DEVTOOLS_TOGGLE_ACTION_NONE) {
g_instances.Get().push_back(this);
// Wipe out page icon so that the default application icon is used. // Wipe out page icon so that the default application icon is used.
NavigationEntry* entry = tab_contents_->controller().GetActiveEntry(); NavigationEntry* entry = tab_contents_->controller().GetActiveEntry();
entry->favicon().set_bitmap(SkBitmap()); entry->favicon().set_bitmap(SkBitmap());
...@@ -188,12 +191,6 @@ DevToolsWindow::DevToolsWindow(TabContentsWrapper* tab_contents, ...@@ -188,12 +191,6 @@ DevToolsWindow::DevToolsWindow(TabContentsWrapper* tab_contents,
} }
DevToolsWindow::~DevToolsWindow() { DevToolsWindow::~DevToolsWindow() {
DevToolsWindowList& instances = g_instances.Get();
DevToolsWindowList::iterator it = std::find(instances.begin(),
instances.end(),
this);
DCHECK(it != instances.end());
instances.erase(it);
} }
void DevToolsWindow::SendMessageToClient(const IPC::Message& message) { void DevToolsWindow::SendMessageToClient(const IPC::Message& message) {
...@@ -234,6 +231,10 @@ void DevToolsWindow::TabReplaced(TabContents* new_tab) { ...@@ -234,6 +231,10 @@ void DevToolsWindow::TabReplaced(TabContents* new_tab) {
inspected_tab_ = new_tab_wrapper; inspected_tab_ = new_tab_wrapper;
} }
RenderViewHost* DevToolsWindow::GetClientRenderViewHost() {
return tab_contents_->render_view_host();
}
void DevToolsWindow::Show(DevToolsToggleAction action) { void DevToolsWindow::Show(DevToolsToggleAction action) {
if (docked_) { if (docked_) {
Browser* inspected_browser; Browser* inspected_browser;
...@@ -645,15 +646,10 @@ DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow( ...@@ -645,15 +646,10 @@ DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow(
// static // static
DevToolsWindow* DevToolsWindow::AsDevToolsWindow( DevToolsWindow* DevToolsWindow::AsDevToolsWindow(
DevToolsClientHost* client_host) { DevToolsClientHost* client_host) {
if (!client_host || g_instances == NULL) if (!client_host)
return NULL; return NULL;
DevToolsWindowList& instances = g_instances.Get(); if (client_host->GetClientRenderViewHost() != NULL)
for (DevToolsWindowList::iterator it = instances.begin(); return static_cast<DevToolsWindow*>(client_host);
it != instances.end(); ++it) {
DevToolsClientHost* client = *it;
if (client == client_host)
return *it;
}
return NULL; return NULL;
} }
......
...@@ -43,6 +43,7 @@ class DevToolsWindow ...@@ -43,6 +43,7 @@ class DevToolsWindow
static const char kDevToolsApp[]; static const char kDevToolsApp[];
static void RegisterUserPrefs(PrefService* prefs); static void RegisterUserPrefs(PrefService* prefs);
static TabContentsWrapper* GetDevToolsContents(TabContents* inspected_tab); static TabContentsWrapper* GetDevToolsContents(TabContents* inspected_tab);
static DevToolsWindow* FindDevToolsWindow(RenderViewHost* window_rvh);
static DevToolsWindow* OpenDevToolsWindowForWorker( static DevToolsWindow* OpenDevToolsWindowForWorker(
Profile* profile, Profile* profile,
...@@ -59,6 +60,7 @@ class DevToolsWindow ...@@ -59,6 +60,7 @@ class DevToolsWindow
virtual void SendMessageToClient(const IPC::Message& message) OVERRIDE; virtual void SendMessageToClient(const IPC::Message& message) OVERRIDE;
virtual void InspectedTabClosing() OVERRIDE; virtual void InspectedTabClosing() OVERRIDE;
virtual void TabReplaced(TabContents* new_tab) OVERRIDE; virtual void TabReplaced(TabContents* new_tab) OVERRIDE;
virtual RenderViewHost* GetClientRenderViewHost() OVERRIDE;
RenderViewHost* GetRenderViewHost(); RenderViewHost* GetRenderViewHost();
void Show(DevToolsToggleAction action); void Show(DevToolsToggleAction action);
......
...@@ -2,14 +2,45 @@ ...@@ -2,14 +2,45 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/browser/debugger/devtools_client_host.h" #include <algorithm>
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "content/browser/debugger/devtools_client_host.h"
#include "content/browser/debugger/devtools_manager.h" #include "content/browser/debugger/devtools_manager.h"
typedef std::vector<DevToolsClientHost*> DevToolsClientHostList;
namespace {
base::LazyInstance<DevToolsClientHostList,
base::LeakyLazyInstanceTraits<DevToolsClientHostList> >
g_instances = LAZY_INSTANCE_INITIALIZER;
} // namespace
// static
DevToolsClientHost* DevToolsClientHost::FindOwnerClientHost(
RenderViewHost* client_rvh) {
for (DevToolsClientHostList::iterator it = g_instances.Get().begin();
it != g_instances.Get().end(); ++it) {
if ((*it)->GetClientRenderViewHost() == client_rvh)
return *it;
}
return NULL;
}
DevToolsClientHost::~DevToolsClientHost() { DevToolsClientHost::~DevToolsClientHost() {
DevToolsClientHostList::iterator it = std::find(g_instances.Get().begin(),
g_instances.Get().end(),
this);
DCHECK(it != g_instances.Get().end());
g_instances.Get().erase(it);
}
RenderViewHost* DevToolsClientHost::GetClientRenderViewHost() {
return NULL;
} }
DevToolsClientHost::DevToolsClientHost() : close_listener_(NULL) { DevToolsClientHost::DevToolsClientHost() : close_listener_(NULL) {
g_instances.Get().push_back(this);
} }
void DevToolsClientHost::ForwardToDevToolsAgent(const IPC::Message& message) { void DevToolsClientHost::ForwardToDevToolsAgent(const IPC::Message& message) {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <vector>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
...@@ -15,6 +16,7 @@ namespace IPC { ...@@ -15,6 +16,7 @@ namespace IPC {
class Message; class Message;
} }
class RenderViewHost;
class TabContents; class TabContents;
// Describes interface for managing devtools clients from browser process. There // Describes interface for managing devtools clients from browser process. There
...@@ -31,6 +33,8 @@ class CONTENT_EXPORT DevToolsClientHost { ...@@ -31,6 +33,8 @@ class CONTENT_EXPORT DevToolsClientHost {
DISALLOW_COPY_AND_ASSIGN(CloseListener); DISALLOW_COPY_AND_ASSIGN(CloseListener);
}; };
static DevToolsClientHost* FindOwnerClientHost(RenderViewHost* client_rvh);
virtual ~DevToolsClientHost(); virtual ~DevToolsClientHost();
// This method is called when tab inspected by this devtools client is // This method is called when tab inspected by this devtools client is
...@@ -52,6 +56,10 @@ class CONTENT_EXPORT DevToolsClientHost { ...@@ -52,6 +56,10 @@ class CONTENT_EXPORT DevToolsClientHost {
// TabStripModel::ReplaceTabContentsAt. // TabStripModel::ReplaceTabContentsAt.
virtual void TabReplaced(TabContents* new_tab) = 0; virtual void TabReplaced(TabContents* new_tab) = 0;
// Returns client (front-end) RenderViewHost implementation of this
// client host if applicable. NULL otherwise.
virtual RenderViewHost* GetClientRenderViewHost();
protected: protected:
DevToolsClientHost(); DevToolsClientHost();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment