| Index: content/browser/devtools/render_view_devtools_agent_host.cc
|
| diff --git a/content/browser/devtools/render_view_devtools_agent_host.cc b/content/browser/devtools/render_view_devtools_agent_host.cc
|
| index d58d168bd6fc5ddfbc417ec70b4656b59e2124f6..32f6746ff42e3d28d7c29af09cf7c7ac0a40f2ef 100644
|
| --- a/content/browser/devtools/render_view_devtools_agent_host.cc
|
| +++ b/content/browser/devtools/render_view_devtools_agent_host.cc
|
| @@ -42,23 +42,9 @@ base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER;
|
| static RenderViewDevToolsAgentHost* FindAgentHost(WebContents* web_contents) {
|
| if (g_instances == NULL)
|
| return NULL;
|
| - RenderViewHostDelegate* delegate =
|
| - static_cast<WebContentsImpl*>(web_contents);
|
| for (Instances::iterator it = g_instances.Get().begin();
|
| it != g_instances.Get().end(); ++it) {
|
| - RenderViewHost* rvh = (*it)->render_view_host();
|
| - if (rvh && rvh->GetDelegate() == delegate)
|
| - return *it;
|
| - }
|
| - return NULL;
|
| -}
|
| -
|
| -static RenderViewDevToolsAgentHost* FindAgentHost(RenderViewHost* rvh) {
|
| - if (g_instances == NULL)
|
| - return NULL;
|
| - for (Instances::iterator it = g_instances.Get().begin();
|
| - it != g_instances.Get().end(); ++it) {
|
| - if (rvh == (*it)->render_view_host())
|
| + if ((*it)->GetWebContents() == web_contents)
|
| return *it;
|
| }
|
| return NULL;
|
| @@ -75,42 +61,19 @@ DevToolsAgentHost::GetOrCreateFor(WebContents* web_contents) {
|
| }
|
|
|
| // static
|
| -scoped_refptr<DevToolsAgentHost>
|
| -DevToolsAgentHost::GetOrCreateFor(RenderViewHost* rvh) {
|
| - RenderViewDevToolsAgentHost* result = FindAgentHost(rvh);
|
| - if (!result)
|
| - result = new RenderViewDevToolsAgentHost(rvh);
|
| - return result;
|
| -}
|
| -
|
| -// static
|
| -bool DevToolsAgentHost::HasFor(RenderViewHost* rvh) {
|
| - return FindAgentHost(rvh) != NULL;
|
| +bool DevToolsAgentHost::HasFor(WebContents* web_contents) {
|
| + return FindAgentHost(web_contents) != NULL;
|
| }
|
|
|
| // static
|
| bool DevToolsAgentHost::IsDebuggerAttached(WebContents* web_contents) {
|
| - if (g_instances == NULL)
|
| - return false;
|
| - DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
|
| - if (!devtools_manager)
|
| - return false;
|
| - RenderViewHostDelegate* delegate =
|
| - static_cast<WebContentsImpl*>(web_contents);
|
| - for (Instances::iterator it = g_instances.Get().begin();
|
| - it != g_instances.Get().end(); ++it) {
|
| - RenderViewHost* rvh = (*it)->render_view_host_;
|
| - if (rvh && rvh->GetDelegate() != delegate)
|
| - continue;
|
| - if ((*it)->IsAttached())
|
| - return true;
|
| - }
|
| - return false;
|
| + RenderViewDevToolsAgentHost* agent_host = FindAgentHost(web_contents);
|
| + return agent_host && agent_host->IsAttached();
|
| }
|
|
|
| //static
|
| -std::vector<RenderViewHost*> DevToolsAgentHost::GetValidRenderViewHosts() {
|
| - std::vector<RenderViewHost*> result;
|
| +std::vector<WebContents*> DevToolsAgentHost::GetInspectableWebContents() {
|
| + std::set<WebContents*> set;
|
| scoped_ptr<RenderWidgetHostIterator> widgets(
|
| RenderWidgetHost::GetRenderWidgetHosts());
|
| while (RenderWidgetHost* widget = widgets->GetNextHost()) {
|
| @@ -122,23 +85,11 @@ std::vector<RenderViewHost*> DevToolsAgentHost::GetValidRenderViewHosts() {
|
|
|
| RenderViewHost* rvh = RenderViewHost::From(widget);
|
| WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
|
| - if (!web_contents)
|
| - continue;
|
| -
|
| - // Don't report a RenderViewHost if it is not the current RenderViewHost
|
| - // for some WebContents (this filters out pre-render RVHs and similar).
|
| - // However report a RenderViewHost created for an out of process iframe.
|
| - // TODO (kaznacheev): Revisit this when it is clear how OOP iframes
|
| - // interact with pre-rendering.
|
| - // TODO (kaznacheev): GetMainFrame() call is a temporary hack. Iterate over
|
| - // all RenderFrameHost instances when multiple OOP frames are supported.
|
| - if (rvh != web_contents->GetRenderViewHost() &&
|
| - !rvh->GetMainFrame()->IsCrossProcessSubframe()) {
|
| - continue;
|
| - }
|
| -
|
| - result.push_back(rvh);
|
| + if (web_contents)
|
| + set.insert(web_contents);
|
| }
|
| + std::vector<WebContents*> result(set.size());
|
| + std::copy(set.begin(), set.end(), result.begin());
|
| return result;
|
| }
|
|
|
| @@ -146,21 +97,14 @@ std::vector<RenderViewHost*> DevToolsAgentHost::GetValidRenderViewHosts() {
|
| void RenderViewDevToolsAgentHost::OnCancelPendingNavigation(
|
| RenderViewHost* pending,
|
| RenderViewHost* current) {
|
| - RenderViewDevToolsAgentHost* agent_host = FindAgentHost(pending);
|
| + WebContents* web_contents = WebContents::FromRenderViewHost(pending);
|
| + RenderViewDevToolsAgentHost* agent_host = FindAgentHost(web_contents);
|
| if (!agent_host)
|
| return;
|
| agent_host->DisconnectRenderViewHost();
|
| agent_host->ConnectRenderViewHost(current);
|
| }
|
|
|
| -// static
|
| -bool RenderViewDevToolsAgentHost::DispatchIPCMessage(
|
| - RenderViewHost* source,
|
| - const IPC::Message& message) {
|
| - RenderViewDevToolsAgentHost* agent_host = FindAgentHost(source);
|
| - return agent_host && agent_host->DispatchIPCMessage(message);
|
| -}
|
| -
|
| RenderViewDevToolsAgentHost::RenderViewDevToolsAgentHost(RenderViewHost* rvh)
|
| : render_view_host_(NULL),
|
| overrides_handler_(new RendererOverridesHandler(this)),
|
| @@ -179,8 +123,8 @@ RenderViewDevToolsAgentHost::RenderViewDevToolsAgentHost(RenderViewHost* rvh)
|
| AddRef(); // Balanced in RenderViewHostDestroyed.
|
| }
|
|
|
| -RenderViewHost* RenderViewDevToolsAgentHost::GetRenderViewHost() {
|
| - return render_view_host_;
|
| +WebContents* RenderViewDevToolsAgentHost::GetWebContents() {
|
| + return web_contents();
|
| }
|
|
|
| void RenderViewDevToolsAgentHost::DispatchOnInspectorBackend(
|
| @@ -285,7 +229,7 @@ void RenderViewDevToolsAgentHost::InnerClientDetachedFromRenderer() {
|
| it != g_instances.Get().end(); ++it) {
|
| if (*it == this || !(*it)->IsAttached())
|
| continue;
|
| - RenderViewHost* rvh = (*it)->render_view_host();
|
| + RenderViewHost* rvh = (*it)->render_view_host_;
|
| if (rvh && rvh->GetProcess() == render_process_host)
|
| process_has_agents = true;
|
| }
|
| @@ -363,6 +307,17 @@ void RenderViewDevToolsAgentHost::RenderProcessGone(
|
| }
|
| }
|
|
|
| +bool RenderViewDevToolsAgentHost::OnMessageReceived(
|
| + const IPC::Message& message,
|
| + RenderFrameHost* render_frame_host) {
|
| + return DispatchIPCMessage(message);
|
| +}
|
| +
|
| +bool RenderViewDevToolsAgentHost::OnMessageReceived(
|
| + const IPC::Message& message) {
|
| + return DispatchIPCMessage(message);
|
| +}
|
| +
|
| void RenderViewDevToolsAgentHost::DidAttachInterstitialPage() {
|
| if (!render_view_host_)
|
| return;
|
| @@ -407,6 +362,14 @@ void RenderViewDevToolsAgentHost::ClearRenderViewHost() {
|
| render_view_host_ = NULL;
|
| }
|
|
|
| +void RenderViewDevToolsAgentHost::DisconnectWebContents() {
|
| + DisconnectRenderViewHost();
|
| +}
|
| +
|
| +void RenderViewDevToolsAgentHost::ConnectWebContents(WebContents* wc) {
|
| + ConnectRenderViewHost(wc->GetRenderViewHost());
|
| +}
|
| +
|
| void RenderViewDevToolsAgentHost::ConnectRenderViewHost(RenderViewHost* rvh) {
|
| SetRenderViewHost(rvh);
|
| if (IsAttached())
|
|
|