This source file includes following definitions.
- GetDevToolsPathAsURL
- Show
- Show
- Activate
- Focus
- InspectElementAt
- Close
- agent_host_
- RenderViewCreated
- DocumentOnLoadCompletedInMainFrame
- WebContentsDestroyed
- InspectedContentsClosing
#include "content/shell/browser/shell_devtools_frontend.h"
#include "base/command_line.h"
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/browser/devtools_http_handler.h"
#include "content/public/browser/devtools_manager.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "content/public/common/content_client.h"
#include "content/shell/browser/shell.h"
#include "content/shell/browser/shell_browser_context.h"
#include "content/shell/browser/shell_browser_main_parts.h"
#include "content/shell/browser/shell_content_browser_client.h"
#include "content/shell/browser/shell_devtools_delegate.h"
#include "content/shell/common/shell_switches.h"
#include "net/base/net_util.h"
namespace content {
GURL GetDevToolsPathAsURL(const std::string& settings) {
base::FilePath dir_exe;
if (!PathService::Get(base::DIR_EXE, &dir_exe)) {
NOTREACHED();
return GURL();
}
#if defined(OS_MACOSX)
dir_exe = dir_exe.AppendASCII("../../..");
#endif
base::FilePath dev_tools_path = dir_exe.AppendASCII(
"resources/inspector/devtools.html");
GURL result = net::FilePathToFileURL(dev_tools_path);
if (!settings.empty())
result = GURL(base::StringPrintf("%s?settings=%s",
result.spec().c_str(),
settings.c_str()));
return result;
}
ShellDevToolsFrontend* ShellDevToolsFrontend::Show(
WebContents* inspected_contents) {
return ShellDevToolsFrontend::Show(inspected_contents, "");
}
ShellDevToolsFrontend* ShellDevToolsFrontend::Show(
WebContents* inspected_contents,
const std::string& settings) {
scoped_refptr<DevToolsAgentHost> agent(
DevToolsAgentHost::GetOrCreateFor(
inspected_contents->GetRenderViewHost()));
Shell* shell = Shell::CreateNewWindow(inspected_contents->GetBrowserContext(),
GURL(),
NULL,
MSG_ROUTING_NONE,
gfx::Size());
ShellDevToolsFrontend* devtools_frontend = new ShellDevToolsFrontend(
shell,
agent.get());
ShellDevToolsDelegate* delegate = ShellContentBrowserClient::Get()->
shell_browser_main_parts()->devtools_delegate();
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree))
shell->LoadURL(GetDevToolsPathAsURL(settings));
else
shell->LoadURL(delegate->devtools_http_handler()->GetFrontendURL());
return devtools_frontend;
}
void ShellDevToolsFrontend::Activate() {
frontend_shell_->ActivateContents(web_contents());
}
void ShellDevToolsFrontend::Focus() {
web_contents()->GetView()->Focus();
}
void ShellDevToolsFrontend::InspectElementAt(int x, int y) {
agent_host_->InspectElement(x, y);
}
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::DocumentOnLoadCompletedInMainFrame(int32 page_id) {
web_contents()->GetMainFrame()->ExecuteJavaScript(
base::ASCIIToUTF16("InspectorFrontendAPI.setUseSoftMenu(true);"));
}
void ShellDevToolsFrontend::WebContentsDestroyed(WebContents* web_contents) {
DevToolsManager::GetInstance()->ClientHostClosing(frontend_host_.get());
delete this;
}
void ShellDevToolsFrontend::InspectedContentsClosing() {
frontend_shell_->Close();
}
}