// Copyright (c) 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "content/shell/shell_devtools_frontend.h" #include "content/public/browser/devtools_http_handler.h" #include "content/public/browser/devtools_manager.h" #include "content/public/browser/web_contents.h" #include "content/public/common/content_client.h" #include "content/shell/shell.h" #include "content/shell/shell_browser_context.h" #include "content/shell/shell_browser_main_parts.h" #include "content/shell/shell_content_browser_client.h" #include "content/shell/shell_devtools_delegate.h" namespace content { // static ShellDevToolsFrontend* ShellDevToolsFrontend::Show( WebContents* inspected_contents) { Shell* shell = Shell::CreateNewWindow(inspected_contents->GetBrowserContext(), GURL(), NULL, MSG_ROUTING_NONE, gfx::Size()); ShellDevToolsFrontend* devtools_frontend = new ShellDevToolsFrontend( shell, DevToolsAgentHost::GetFor(inspected_contents->GetRenderViewHost())); ShellContentBrowserClient* browser_client = static_cast( GetContentClient()->browser()); ShellDevToolsDelegate* delegate = browser_client->shell_browser_main_parts()->devtools_delegate(); shell->LoadURL(delegate->devtools_http_handler()->GetFrontendURL(NULL)); return devtools_frontend; } void ShellDevToolsFrontend::Focus() { web_contents()->Focus(); } void ShellDevToolsFrontend::Close() { frontend_shell_->Close(); } ShellDevToolsFrontend::ShellDevToolsFrontend(Shell* frontend_shell, DevToolsAgentHost* agent_host) : WebContentsObserver(frontend_shell->web_contents()), frontend_shell_(frontend_shell), agent_host_(agent_host) { frontend_host_.reset( DevToolsClientHost::CreateDevToolsFrontendHost(web_contents(), this)); } ShellDevToolsFrontend::~ShellDevToolsFrontend() { } void ShellDevToolsFrontend::RenderViewCreated( RenderViewHost* render_view_host) { DevToolsClientHost::SetupDevToolsFrontendClient( web_contents()->GetRenderViewHost()); DevToolsManager* manager = DevToolsManager::GetInstance(); manager->RegisterDevToolsClientHostFor(agent_host_.get(), frontend_host_.get()); } void ShellDevToolsFrontend::WebContentsDestroyed(WebContents* web_contents) { DevToolsManager::GetInstance()->ClientHostClosing(frontend_host_.get()); delete this; } void ShellDevToolsFrontend::InspectedContentsClosing() { frontend_shell_->Close(); } } // namespace content