diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2014-11-17 16:14:02 +0100 |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2014-11-18 16:25:10 +0100 |
commit | 333ff391c0eec8723d75b4b3002f3d535902f309 (patch) | |
tree | 6e61c30e8267202d31f7bc51eaa2b3eea8bd2924 | |
parent | c48fb156ce5baa4a759c1b83b31e1d968a986bdd (diff) |
Fix the inspector
Add the missing implementation of
DevToolsHttpHandlerDelegate::EnumerateTargets allowing WebEngineViews
to appear in the remote debugging's discovery page.
This code was mostly taken from
content/shell/browser/shell_devtools_delegate.cc
Change-Id: I2759d7c424adf4d7acb779a64e0083032691d9ba
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Reviewed-by: Andras Becsi <andras.becsi@digia.com>
-rw-r--r-- | src/core/dev_tools_http_handler_delegate_qt.cpp | 87 |
1 files changed, 86 insertions, 1 deletions
diff --git a/src/core/dev_tools_http_handler_delegate_qt.cpp b/src/core/dev_tools_http_handler_delegate_qt.cpp index 4f8992dab..1bb8ec1f1 100644 --- a/src/core/dev_tools_http_handler_delegate_qt.cpp +++ b/src/core/dev_tools_http_handler_delegate_qt.cpp @@ -34,6 +34,10 @@ ** ****************************************************************************/ +// Copyright 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 "dev_tools_http_handler_delegate_qt.h" #include <QByteArray> @@ -42,16 +46,90 @@ #include "base/command_line.h" #include "base/files/file_path.h" #include "base/strings/string_number_conversions.h" +#include "base/strings/utf_string_conversions.h" #include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_http_handler.h" #include "content/public/browser/devtools_target.h" +#include "content/public/browser/favicon_status.h" +#include "content/public/browser/navigation_entry.h" +#include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" +#include "content/public/browser/web_contents_delegate.h" #include "content/public/common/content_switches.h" #include "net/socket/stream_listen_socket.h" #include "net/socket/tcp_listen_socket.h" using namespace content; +namespace { + +const char kTargetTypePage[] = "page"; + +class Target : public content::DevToolsTarget { +public: + explicit Target(WebContents* web_contents); + + virtual std::string GetId() const OVERRIDE { return id_; } + virtual std::string GetParentId() const OVERRIDE { return std::string(); } + virtual std::string GetType() const OVERRIDE { return kTargetTypePage; } + virtual std::string GetTitle() const OVERRIDE { return title_; } + virtual std::string GetDescription() const OVERRIDE { return std::string(); } + virtual GURL GetURL() const OVERRIDE { return url_; } + virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; } + virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { + return last_activity_time_; + } + virtual bool IsAttached() const OVERRIDE { + return agent_host_->IsAttached(); + } + virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { + return agent_host_; + } + virtual bool Activate() const OVERRIDE; + virtual bool Close() const OVERRIDE; + +private: + scoped_refptr<DevToolsAgentHost> agent_host_; + std::string id_; + std::string title_; + GURL url_; + GURL favicon_url_; + base::TimeTicks last_activity_time_; +}; + +Target::Target(WebContents* web_contents) { + agent_host_ = DevToolsAgentHost::GetOrCreateFor(web_contents->GetRenderViewHost()); + id_ = agent_host_->GetId(); + title_ = base::UTF16ToUTF8(web_contents->GetTitle()); + url_ = web_contents->GetURL(); + content::NavigationController& controller = web_contents->GetController(); + content::NavigationEntry* entry = controller.GetActiveEntry(); + if (entry != NULL && entry->GetURL().is_valid()) + favicon_url_ = entry->GetFavicon().url; + last_activity_time_ = web_contents->GetLastActiveTime(); +} + +bool Target::Activate() const { + RenderViewHost* rvh = agent_host_->GetRenderViewHost(); + if (!rvh) + return false; + WebContents* web_contents = WebContents::FromRenderViewHost(rvh); + if (!web_contents) + return false; + web_contents->GetDelegate()->ActivateContents(web_contents); + return true; +} + +bool Target::Close() const { + RenderViewHost* rvh = agent_host_->GetRenderViewHost(); + if (!rvh) + return false; + rvh->ClosePage(); + return true; +} + +} // namespace + DevToolsHttpHandlerDelegateQt::DevToolsHttpHandlerDelegateQt(BrowserContext* browser_context) : m_browserContext(browser_context) { @@ -107,7 +185,14 @@ scoped_ptr<DevToolsTarget> DevToolsHttpHandlerDelegateQt::CreateNewTarget(const void DevToolsHttpHandlerDelegateQt::EnumerateTargets(TargetCallback callback) { - callback.Run(TargetList()); + TargetList targets; + std::vector<RenderViewHost*> rvh_list = content::DevToolsAgentHost::GetValidRenderViewHosts(); + for (std::vector<RenderViewHost*>::iterator it = rvh_list.begin(); it != rvh_list.end(); ++it) { + WebContents* web_contents = WebContents::FromRenderViewHost(*it); + if (web_contents) + targets.push_back(new Target(web_contents)); + } + callback.Run(targets); } scoped_ptr<net::StreamListenSocket> DevToolsHttpHandlerDelegateQt::CreateSocketForTethering(net::StreamListenSocket::Delegate* delegate, std::string* name) |