1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/shell/browser/shell_devtools_delegate.h"
10 #include "base/command_line.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "content/public/browser/devtools_http_handler.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/public/common/content_switches.h"
15 #include "content/public/common/url_constants.h"
16 #include "content/shell/browser/shell.h"
17 #include "grit/shell_resources.h"
18 #include "net/socket/tcp_listen_socket.h"
19 #include "ui/base/resource/resource_bundle.h"
21 #if defined(OS_ANDROID)
22 #include "content/public/browser/android/devtools_auth.h"
23 #include "net/socket/unix_domain_socket_posix.h"
28 net::StreamListenSocketFactory
* CreateSocketFactory() {
29 const CommandLine
& command_line
= *CommandLine::ForCurrentProcess();
30 #if defined(OS_ANDROID)
31 std::string socket_name
= "content_shell_devtools_remote";
32 if (command_line
.HasSwitch(switches::kRemoteDebuggingSocketName
)) {
33 socket_name
= command_line
.GetSwitchValueASCII(
34 switches::kRemoteDebuggingSocketName
);
36 return new net::UnixDomainSocketWithAbstractNamespaceFactory(
37 socket_name
, "", base::Bind(&content::CanUserConnectToDevTools
));
39 // See if the user specified a port on the command line (useful for
40 // automation). If not, use an ephemeral port by specifying 0.
42 if (command_line
.HasSwitch(switches::kRemoteDebuggingPort
)) {
44 std::string port_str
=
45 command_line
.GetSwitchValueASCII(switches::kRemoteDebuggingPort
);
46 if (base::StringToInt(port_str
, &temp_port
) &&
47 temp_port
> 0 && temp_port
< 65535) {
50 DLOG(WARNING
) << "Invalid http debugger port number " << temp_port
;
53 return new net::TCPListenSocketFactory("127.0.0.1", port
);
60 ShellDevToolsDelegate::ShellDevToolsDelegate(BrowserContext
* browser_context
)
61 : browser_context_(browser_context
) {
62 // Note that Content Shell always used bundled DevTools frontend,
63 // even on Android, because the shell is used for running layout tests.
64 devtools_http_handler_
=
65 DevToolsHttpHandler::Start(CreateSocketFactory(), std::string(), this);
68 ShellDevToolsDelegate::~ShellDevToolsDelegate() {
71 void ShellDevToolsDelegate::Stop() {
72 // The call below destroys this.
73 devtools_http_handler_
->Stop();
76 std::string
ShellDevToolsDelegate::GetDiscoveryPageHTML() {
77 return ResourceBundle::GetSharedInstance().GetRawDataResource(
78 IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE
).as_string();
81 bool ShellDevToolsDelegate::BundlesFrontendResources() {
85 base::FilePath
ShellDevToolsDelegate::GetDebugFrontendDir() {
86 return base::FilePath();
89 std::string
ShellDevToolsDelegate::GetPageThumbnailData(const GURL
& url
) {
93 RenderViewHost
* ShellDevToolsDelegate::CreateNewTarget() {
94 Shell
* shell
= Shell::CreateNewWindow(browser_context_
,
99 return shell
->web_contents()->GetRenderViewHost();
102 DevToolsHttpHandlerDelegate::TargetType
103 ShellDevToolsDelegate::GetTargetType(RenderViewHost
*) {
104 return kTargetTypeTab
;
107 std::string
ShellDevToolsDelegate::GetViewDescription(
108 content::RenderViewHost
*) {
109 return std::string();
112 scoped_ptr
<net::StreamListenSocket
>
113 ShellDevToolsDelegate::CreateSocketForTethering(
114 net::StreamListenSocket::Delegate
* delegate
,
116 return scoped_ptr
<net::StreamListenSocket
>();
119 } // namespace content