diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2014-11-17 16:52:33 +0100 |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2015-01-22 16:22:12 +0100 |
commit | 35630628d927d95bd5b7a8720e982294e7281b15 (patch) | |
tree | dd39f51154b5448140da3a455731a13779f9d7d6 /src/core/dev_tools_http_handler_delegate_qt.cpp | |
parent | 9d9268ae1ce34a853b48d3b7189dba6448c38033 (diff) |
Replace the inspectable property with an environment variable
The current implementation would enable or disable the inspector
globally when the inspectable property was set on a WebEngineView,
overwriting the value previously set by other pages.
Instead of havind default port for the debugging server and having
to enable debugging on individual pages, use an environment variable,
QTWEBENGINE_REMOTE_DEBUGGING, to enable the debugging server for the
whole application at the same time as specifying the port. The format
is the same as for QTWEBKIT_INSPECTOR_SERVER in QtWebKit.
QTWEBENGINE_REMOTE_DEBUGGING is set by default in quicktestbrowser
to ease development.
This also keeps the input reading from the --remote-debugging-port
command line switch for convenience, but its usage should be
considered internal.
This patch also take the opportunity to remove the unused
DevToolsHttpHandlerDelegateQt::m_browserContext and to move the
ownership from ContentBrowserClientQt to WebEngineContext since
the list of inspectable pages isn't bound to the BrowserContext
anyway.
Change-Id: I772687f88f4feee0cc14dd182b0129cc0ea384dd
Reviewed-by: Pierre Rossi <pierre.rossi@theqtcompany.com>
Diffstat (limited to 'src/core/dev_tools_http_handler_delegate_qt.cpp')
-rw-r--r-- | src/core/dev_tools_http_handler_delegate_qt.cpp | 53 |
1 files changed, 40 insertions, 13 deletions
diff --git a/src/core/dev_tools_http_handler_delegate_qt.cpp b/src/core/dev_tools_http_handler_delegate_qt.cpp index 561a86f2a..4b866a6bc 100644 --- a/src/core/dev_tools_http_handler_delegate_qt.cpp +++ b/src/core/dev_tools_http_handler_delegate_qt.cpp @@ -40,6 +40,8 @@ #include "dev_tools_http_handler_delegate_qt.h" +#include "type_conversion.h" + #include <QByteArray> #include <QFile> @@ -56,6 +58,7 @@ #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_delegate.h" #include "content/public/common/content_switches.h" +#include "net/base/ip_endpoint.h" #include "net/socket/stream_listen_socket.h" #include "net/socket/tcp_server_socket.h" @@ -140,26 +143,50 @@ bool Target::Close() const { } // namespace -DevToolsHttpHandlerDelegateQt::DevToolsHttpHandlerDelegateQt(BrowserContext* browser_context) - : m_browserContext(browser_context) +DevToolsHttpHandlerDelegateQt::DevToolsHttpHandlerDelegateQt() + : m_devtoolsHttpHandler(0) + , m_bindAddress(QLatin1String("127.0.0.1")) + , m_port(0) { - const int defaultPort = 1337; - int listeningPort = defaultPort; + const QString inspectorEnv = QString::fromUtf8(qgetenv("QTWEBENGINE_REMOTE_DEBUGGING")); const CommandLine &commandLine = *CommandLine::ForCurrentProcess(); + QString portStr; + if (commandLine.HasSwitch(switches::kRemoteDebuggingPort)) { - std::string portString = - commandLine.GetSwitchValueASCII(switches::kRemoteDebuggingPort); - int portInt = 0; - if (base::StringToInt(portString, &portInt) && portInt > 0 && portInt < 65535) - listeningPort = portInt; - } - scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory> factory(new TCPServerSocketFactory("0.0.0.0", listeningPort, 1)); - m_devtoolsHttpHandler = DevToolsHttpHandler::Start(factory.Pass(), std::string(), this, base::FilePath()); + portStr = QString::fromStdString(commandLine.GetSwitchValueASCII(switches::kRemoteDebuggingPort)); + } else if (!inspectorEnv.isEmpty()) { + int portColonPos = inspectorEnv.lastIndexOf(':'); + if (portColonPos != -1) { + portStr = inspectorEnv.mid(portColonPos + 1); + m_bindAddress = inspectorEnv.mid(0, portColonPos); + } else + portStr = inspectorEnv; + } else + return; + + bool ok = false; + m_port = portStr.toInt(&ok); + if (ok && m_port > 0 && m_port < 65535) { + scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory> factory(new TCPServerSocketFactory(m_bindAddress.toStdString(), m_port, 1)); + m_devtoolsHttpHandler = DevToolsHttpHandler::Start(factory.Pass(), std::string(), this, base::FilePath()); + } else + qWarning("Invalid port given for the inspector server \"%s\". Examples of valid input: \"12345\" or \"192.168.2.14:12345\" (with the address of one of this host's network interface).", qPrintable(portStr)); } DevToolsHttpHandlerDelegateQt::~DevToolsHttpHandlerDelegateQt() { - m_devtoolsHttpHandler->Stop(); + // Stop() takes care of deleting the DevToolsHttpHandler. + if (m_devtoolsHttpHandler) + m_devtoolsHttpHandler->Stop(); +} + +void DevToolsHttpHandlerDelegateQt::Initialized(const net::IPEndPoint& ip_address) +{ + if (ip_address.address().size()) { + QString addressAndPort = QString::fromStdString(ip_address.ToString()); + qWarning("Remote debugging server started successfully. Try pointing a Chromium-based browser to http://%s", qPrintable(addressAndPort)); + } else + qWarning("Couldn't start the inspector server on bind address \"%s\" and port \"%d\". In case of invalid input, try something like: \"12345\" or \"192.168.2.14:12345\" (with the address of one of this host's interface).", qPrintable(m_bindAddress), m_port); } std::string DevToolsHttpHandlerDelegateQt::GetDiscoveryPageHTML() |