Last active
August 29, 2015 14:01
-
-
Save jturcotte/6e33d74a6abe879011af to your computer and use it in GitHub Desktop.
QtWebEngine DevTool fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From c01a0176ec22dbc6df6077abf8408d580f7f9cf7 Mon Sep 17 00:00:00 2001 | |
From: Jocelyn Turcotte <[email protected]> | |
Date: Thu, 6 Nov 2014 18:08:59 +0100 | |
Subject: [PATCH] Quick fix of the inspector | |
Change-Id: Ic00976b537d6a9b4279cf5dfbf33bed32ab0089a | |
--- | |
src/core/browser_context_qt.cpp | 12 +++- | |
src/core/browser_context_qt.h | 4 ++ | |
src/core/content_browser_client_qt.cpp | 10 --- | |
src/core/content_browser_client_qt.h | 4 -- | |
src/core/dev_tools_http_handler_delegate_qt.cpp | 87 ++++++++++++++++++++++++- | |
src/core/dev_tools_http_handler_delegate_qt.h | 3 +- | |
src/core/web_contents_adapter.cpp | 2 +- | |
tests/quicktestbrowser/quickwindow.qml | 1 + | |
8 files changed, 102 insertions(+), 21 deletions(-) | |
diff --git a/src/core/browser_context_qt.cpp b/src/core/browser_context_qt.cpp | |
index 4c17171..e4ef22f 100644 | |
--- a/src/core/browser_context_qt.cpp | |
+++ b/src/core/browser_context_qt.cpp | |
@@ -37,9 +37,10 @@ | |
#include "browser_context_qt.h" | |
#include "browser_context_adapter.h" | |
-#include "type_conversion.h" | |
+#include "dev_tools_http_handler_delegate_qt.h" | |
#include "qtwebenginecoreglobal.h" | |
#include "resource_context_qt.h" | |
+#include "type_conversion.h" | |
#include "url_request_context_getter_qt.h" | |
#include "base/files/scoped_temp_dir.h" | |
@@ -127,3 +128,12 @@ net::URLRequestContextGetter *BrowserContextQt::CreateRequestContext(content::Pr | |
static_cast<ResourceContextQt*>(resourceContext.get())->set_url_request_context_getter(url_request_getter_.get()); | |
return url_request_getter_.get(); | |
} | |
+ | |
+void BrowserContextQt::enableInspector(bool enable) | |
+{ | |
+ if (enable && !m_devtools) { | |
+ m_devtools.reset(new DevToolsHttpHandlerDelegateQt); | |
+ } else if (!enable && m_devtools) { | |
+ m_devtools.reset(); | |
+ } | |
+} | |
diff --git a/src/core/browser_context_qt.h b/src/core/browser_context_qt.h | |
index 4e18c1a..16d5422 100644 | |
--- a/src/core/browser_context_qt.h | |
+++ b/src/core/browser_context_qt.h | |
@@ -44,6 +44,7 @@ | |
#include "download_manager_delegate_qt.h" | |
class BrowserContextAdapter; | |
+class DevToolsHttpHandlerDelegateQt; | |
class BrowserContextQt : public content::BrowserContext | |
{ | |
@@ -67,10 +68,13 @@ public: | |
virtual content::PushMessagingService* GetPushMessagingService() Q_DECL_OVERRIDE; | |
net::URLRequestContextGetter *CreateRequestContext(content::ProtocolHandlerMap *protocol_handlers); | |
+ void enableInspector(bool enable); | |
+ | |
private: | |
scoped_ptr<content::ResourceContext> resourceContext; | |
scoped_refptr<net::URLRequestContextGetter> url_request_getter_; | |
scoped_ptr<DownloadManagerDelegateQt> downloadManagerDelegate; | |
+ scoped_ptr<DevToolsHttpHandlerDelegateQt> m_devtools; | |
BrowserContextAdapter *m_adapter; | |
DISALLOW_COPY_AND_ASSIGN(BrowserContextQt); | |
diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp | |
index f10dd75..223057c 100644 | |
--- a/src/core/content_browser_client_qt.cpp | |
+++ b/src/core/content_browser_client_qt.cpp | |
@@ -58,7 +58,6 @@ | |
#include "certificate_error_controller.h" | |
#include "certificate_error_controller_p.h" | |
#include "desktop_screen_qt.h" | |
-#include "dev_tools_http_handler_delegate_qt.h" | |
#include "media_capture_devices_dispatcher.h" | |
#include "resource_dispatcher_host_delegate_qt.h" | |
#include "web_contents_delegate_qt.h" | |
@@ -344,15 +343,6 @@ net::URLRequestContextGetter* ContentBrowserClientQt::CreateRequestContext(conte | |
return static_cast<BrowserContextQt*>(browser_context)->CreateRequestContext(protocol_handlers); | |
} | |
-void ContentBrowserClientQt::enableInspector(bool enable, content::BrowserContext* browser_context) | |
-{ | |
- if (enable && !m_devtools) { | |
- m_devtools.reset(new DevToolsHttpHandlerDelegateQt(browser_context)); | |
- } else if (!enable && m_devtools) { | |
- m_devtools.reset(); | |
- } | |
-} | |
- | |
void ContentBrowserClientQt::AllowCertificateError(int render_process_id, int render_frame_id, int cert_error, | |
const net::SSLInfo& ssl_info, const GURL& request_url, | |
ResourceType::Type resource_type, | |
diff --git a/src/core/content_browser_client_qt.h b/src/core/content_browser_client_qt.h | |
index 3a70e24..86b0dcb 100644 | |
--- a/src/core/content_browser_client_qt.h | |
+++ b/src/core/content_browser_client_qt.h | |
@@ -63,7 +63,6 @@ class GLShareGroup; | |
class BrowserContextQt; | |
class BrowserMainPartsQt; | |
-class DevToolsHttpHandlerDelegateQt; | |
class ResourceDispatcherHostDelegateQt; | |
class ShareGroupQtQuick; | |
@@ -93,11 +92,8 @@ public: | |
virtual net::URLRequestContextGetter *CreateRequestContext(content::BrowserContext *content_browser_context, content::ProtocolHandlerMap *protocol_handlers, content::URLRequestInterceptorScopedVector request_interceptorss) Q_DECL_OVERRIDE; | |
- void enableInspector(bool enable, content::BrowserContext *browser_context); | |
- | |
private: | |
BrowserMainPartsQt* m_browserMainParts; | |
- scoped_ptr<DevToolsHttpHandlerDelegateQt> m_devtools; | |
scoped_ptr<ResourceDispatcherHostDelegateQt> m_resourceDispatcherHostDelegate; | |
scoped_refptr<ShareGroupQtQuick> m_shareGroupQtQuick; | |
}; | |
diff --git a/src/core/dev_tools_http_handler_delegate_qt.cpp b/src/core/dev_tools_http_handler_delegate_qt.cpp | |
index 4f8992d..18bd6f4 100644 | |
--- a/src/core/dev_tools_http_handler_delegate_qt.cpp | |
+++ b/src/core/dev_tools_http_handler_delegate_qt.cpp | |
@@ -42,18 +42,92 @@ | |
#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; | |
-DevToolsHttpHandlerDelegateQt::DevToolsHttpHandlerDelegateQt(BrowserContext* browser_context) | |
- : m_browserContext(browser_context) | |
+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() | |
{ | |
const int defaultPort = 1337; | |
int listeningPort = defaultPort; | |
@@ -107,7 +181,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) | |
diff --git a/src/core/dev_tools_http_handler_delegate_qt.h b/src/core/dev_tools_http_handler_delegate_qt.h | |
index 06b690a..419a5c6 100644 | |
--- a/src/core/dev_tools_http_handler_delegate_qt.h | |
+++ b/src/core/dev_tools_http_handler_delegate_qt.h | |
@@ -54,7 +54,7 @@ class RenderViewHost; | |
class DevToolsHttpHandlerDelegateQt : public content::DevToolsHttpHandlerDelegate { | |
public: | |
- explicit DevToolsHttpHandlerDelegateQt(content::BrowserContext* browser_context); | |
+ explicit DevToolsHttpHandlerDelegateQt(); | |
virtual ~DevToolsHttpHandlerDelegateQt(); | |
// content::DevToolsHttpHandlerDelegate Overrides | |
@@ -69,7 +69,6 @@ public: | |
virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(net::StreamListenSocket::Delegate* delegate, std::string* name) Q_DECL_OVERRIDE; | |
private: | |
- content::BrowserContext* m_browserContext; | |
content::DevToolsHttpHandler* m_devtoolsHttpHandler; | |
}; | |
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp | |
index 0f71bbb..0c348bb 100644 | |
--- a/src/core/web_contents_adapter.cpp | |
+++ b/src/core/web_contents_adapter.cpp | |
@@ -623,7 +623,7 @@ qreal WebContentsAdapter::currentZoomFactor() const | |
void WebContentsAdapter::enableInspector(bool enable) | |
{ | |
- ContentBrowserClientQt::Get()->enableInspector(enable, browserContext()); | |
+ browserContext()->enableInspector(enable); | |
} | |
BrowserContextQt* WebContentsAdapter::browserContext() | |
diff --git a/tests/quicktestbrowser/quickwindow.qml b/tests/quicktestbrowser/quickwindow.qml | |
index 36668fc..b1ec78e 100644 | |
--- a/tests/quicktestbrowser/quickwindow.qml | |
+++ b/tests/quicktestbrowser/quickwindow.qml | |
@@ -328,6 +328,7 @@ ApplicationWindow { | |
] | |
experimental { | |
+ inspectable: true | |
isFullScreen: webEngineView.state == "FullScreen" && browserWindow.isFullScreen | |
onFullScreenRequested: { | |
if (fullScreen) { | |
-- | |
2.0.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment