[GTK] Add inspector API to WebKit2 GTK+
https://bugs.webkit.org/show_bug.cgi?id=87113
Reviewed by Martin Robinson.
* GNUmakefile.list.am: Add new files to compilation.
* UIProcess/API/C/gtk/WKInspectorClientGtk.cpp: Added.
(WKInspectorSetInspectorClientGtk):
* UIProcess/API/C/gtk/WKInspectorClientGtk.h: Added.
* UIProcess/API/gtk/WebKitPrivate.h:
* UIProcess/API/gtk/WebKitWebInspector.cpp: Added.
(webkitWebInspectorFinalize):
(webkit_web_inspector_init):
(webkit_web_inspector_class_init):
(openWindow): Emit WebKitWebInspector::open-window singal.
(didClose): Emit WebKitWebInspector::closed signal.
(bringToFront): Emit WebKitWebInspector::bring-to-front singal.
(inspectedURLChanged): Set the inspected URI and emit
GObject::notify signal if it changed.
(attach): Emit WebKitWebInspector::attach signal.
(detach): Emit WebKitWebInspector::detach signal.
(didChangeAttachedHeight): Set the attached height and emit
GObject::notify signal if it changed.
(webkitWebInspectorCreate): Ceate a new WebKitWebInspector object
for the given WKInspector. Also initialize and set the inspector
client.
(webkit_web_inspector_get_web_view): Return the web view used to
render the inspector.
(webkit_web_inspector_get_inspected_uri): Return the URI that is
being inspected.
(webkit_web_inspector_is_attached): Whether the inspector view is
currently attached.
(webkit_web_inspector_attach): Request to attach the inspector.
(webkit_web_inspector_detach): Request to detach the inspector.
(webkit_web_inspector_show): Request to show the inspector.
(webkit_web_inspector_close): Request to close the inspector.
(webkit_web_inspector_get_attached_height): Return the height that
the inspector view should have when attached.
* UIProcess/API/gtk/WebKitWebInspector.h: Added.
* UIProcess/API/gtk/WebKitWebInspectorPrivate.h: Added.
* UIProcess/API/gtk/WebKitWebView.cpp:
(webkit_web_view_get_inspector): Return the WebKitWebInspector
associated to the web view.
* UIProcess/API/gtk/WebKitWebView.h:
* UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add new section for
WebKitWebInspector.
* UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Ad new symbols.
* UIProcess/API/gtk/docs/webkit2gtk.types: Add
webkit_web_inspector_get_type.
* UIProcess/API/gtk/tests/GNUmakefile.am: Add new test for the
inspector API.
* UIProcess/API/gtk/tests/TestInspector.cpp: Added.
(testInspectorDefault):
(testInspectorCustom):
(testInspectorWindowDestroyed):
(beforeAll):
(afterAll):
* UIProcess/API/gtk/tests/WebViewTest.cpp:
(WebViewTest::showInWindowAndWaitUntilMapped): Add optional
parameter to create a toplevel or popup window.
(WebViewTest::resizeView): Helper function to set the widget
allocation to a given size.
* UIProcess/API/gtk/tests/WebViewTest.h:
* UIProcess/API/gtk/webkit2.h: Include WebKitWebInspector.h
* UIProcess/WebInspectorProxy.h:
(WebKit::WebInspectorProxy::inspectorView): Return the view used
to render the inspector.
* UIProcess/gtk/WebInspectorClientGtk.cpp: Added.
(WebKit::WebInspectorClientGtk::openWindow):
(WebKit::WebInspectorClientGtk::didClose):
(WebKit::WebInspectorClientGtk::bringToFront):
(WebKit::WebInspectorClientGtk::inspectedURLChanged):
(WebKit::WebInspectorClientGtk::attach):
(WebKit::WebInspectorClientGtk::detach):
(WebKit::WebInspectorClientGtk::didChangeAttachedHeight):
* UIProcess/gtk/WebInspectorClientGtk.h: Added.
* UIProcess/gtk/WebInspectorProxyGtk.cpp:
(WebKit::inspectorViewDestroyed): Close the inspector page when
the inspector view is destroyed, instead of when the inspector
window is deleted, because the inspector view can now be inside a
window created by the user.
(WebKit::WebInspectorProxy::initializeInspectorClientGtk):
Initialze the inspector client.
(WebKit::WebInspectorProxy::platformCreateInspectorPage): Add a
weak pointer to the inspector view to make sure it's NULL when
destroyed.
(WebKit::WebInspectorProxy::createInspectorWindow): Call
openWindow on the inspector client, and return early if the
callback was handled.
(WebKit::WebInspectorProxy::platformOpen): Connect to destroy
signal of the inspector view to close the page when the view is
destroyed.
(WebKit::WebInspectorProxy::platformDidClose): Call didClose on
the inspector client.
(WebKit::WebInspectorProxy::platformBringToFront): Call
bringToFront on the inspector client, and return early if the
callback was handled.
(WebKit::WebInspectorProxy::platformInspectedURLChanged): Call
inspectedURLChanged on the inspector client.
(WebKit::WebInspectorProxy::platformAttach): Call attach on the
inspector client and return if the callback was handled.
(WebKit::WebInspectorProxy::platformDetach): Call detach on the
inspector client and return if the callback was handled.
(WebKit::WebInspectorProxy::platformSetAttachedWindowHeight): Call
didChangeAttachedHeight on the inspector client.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@118146 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebKit2/UIProcess/gtk/WebInspectorClientGtk.cpp b/Source/WebKit2/UIProcess/gtk/WebInspectorClientGtk.cpp
new file mode 100644
index 0000000..448f423
--- /dev/null
+++ b/Source/WebKit2/UIProcess/gtk/WebInspectorClientGtk.cpp
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebInspectorClientGtk.h"
+
+#include "WKAPICast.h"
+#include "WKSharedAPICast.h"
+#include <wtf/text/WTFString.h>
+
+namespace WebKit {
+
+bool WebInspectorClientGtk::openWindow(WebInspectorProxy* inspector)
+{
+ if (!m_client.openWindow)
+ return false;
+ return m_client.openWindow(toAPI(inspector), m_client.clientInfo);
+}
+
+void WebInspectorClientGtk::didClose(WebInspectorProxy* inspector)
+{
+ if (!m_client.didClose)
+ return;
+ m_client.didClose(toAPI(inspector), m_client.clientInfo);
+}
+
+bool WebInspectorClientGtk::bringToFront(WebInspectorProxy* inspector)
+{
+ if (!m_client.bringToFront)
+ return false;
+ return m_client.bringToFront(toAPI(inspector), m_client.clientInfo);
+}
+
+void WebInspectorClientGtk::inspectedURLChanged(WebInspectorProxy* inspector, const String& url)
+{
+ if (!m_client.inspectedURLChanged)
+ return;
+ m_client.inspectedURLChanged(toAPI(inspector), toAPI(url.impl()), m_client.clientInfo);
+}
+
+bool WebInspectorClientGtk::attach(WebInspectorProxy* inspector)
+{
+ if (!m_client.attach)
+ return false;
+ return m_client.attach(toAPI(inspector), m_client.clientInfo);
+}
+
+bool WebInspectorClientGtk::detach(WebInspectorProxy* inspector)
+{
+ if (!m_client.detach)
+ return false;
+ return m_client.detach(toAPI(inspector), m_client.clientInfo);
+}
+
+void WebInspectorClientGtk::didChangeAttachedHeight(WebInspectorProxy* inspector, unsigned height)
+{
+ if (!m_client.didChangeAttachedHeight)
+ return;
+ m_client.didChangeAttachedHeight(toAPI(inspector), height, m_client.clientInfo);
+}
+
+} // namespace WebKit
diff --git a/Source/WebKit2/UIProcess/gtk/WebInspectorClientGtk.h b/Source/WebKit2/UIProcess/gtk/WebInspectorClientGtk.h
new file mode 100644
index 0000000..89d0f73
--- /dev/null
+++ b/Source/WebKit2/UIProcess/gtk/WebInspectorClientGtk.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebInspectorClientGtk_h
+#define WebInspectorClientGtk_h
+
+#include "APIClient.h"
+#include "WKInspectorClientGtk.h"
+
+#include <wtf/text/WTFString.h>
+
+namespace WebKit {
+
+class APIObject;
+class WebInspectorProxy;
+
+class WebInspectorClientGtk : public APIClient<WKInspectorClientGtk, kWKInspectorClientGtkCurrentVersion> {
+public:
+ bool openWindow(WebInspectorProxy*);
+ void didClose(WebInspectorProxy*);
+ bool bringToFront(WebInspectorProxy*);
+ void inspectedURLChanged(WebInspectorProxy*, const String& url);
+ bool attach(WebInspectorProxy*);
+ bool detach(WebInspectorProxy*);
+ void didChangeAttachedHeight(WebInspectorProxy*, unsigned height);
+};
+
+} // namespace WebKit
+
+#endif // WebInspectorClientGtk_h
diff --git a/Source/WebKit2/UIProcess/gtk/WebInspectorProxyGtk.cpp b/Source/WebKit2/UIProcess/gtk/WebInspectorProxyGtk.cpp
index 7d27dfd..425d799 100644
--- a/Source/WebKit2/UIProcess/gtk/WebInspectorProxyGtk.cpp
+++ b/Source/WebKit2/UIProcess/gtk/WebInspectorProxyGtk.cpp
@@ -54,15 +54,18 @@
return inspectorFilesPath;
}
-static gboolean inspectorWindowClosed(GtkWidget* window, GdkEvent*, gpointer userData)
+static void inspectorViewDestroyed(GtkWidget*, gpointer userData)
{
WebInspectorProxy* inspectorProxy = static_cast<WebInspectorProxy*>(userData);
// Inform WebProcess about webinspector closure. Not doing so,
// results in failure of subsequent invocation of webinspector.
inspectorProxy->close();
+}
- return FALSE;
+void WebInspectorProxy::initializeInspectorClientGtk(const WKInspectorClientGtk* inspectorClient)
+{
+ m_client.initialize(inspectorClient);
}
WebPageProxy* WebInspectorProxy::platformCreateInspectorPage()
@@ -70,11 +73,15 @@
ASSERT(m_page);
ASSERT(!m_inspectorView);
m_inspectorView = GTK_WIDGET(webkitWebViewBaseCreate(page()->process()->context(), inspectorPageGroup()));
+ g_object_add_weak_pointer(G_OBJECT(m_inspectorView), reinterpret_cast<void**>(&m_inspectorView));
return webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(m_inspectorView));
}
void WebInspectorProxy::createInspectorWindow()
{
+ if (m_client.openWindow(this))
+ return;
+
ASSERT(!m_inspectorWindow);
m_inspectorWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
@@ -84,7 +91,6 @@
gtk_window_set_title(GTK_WINDOW(m_inspectorWindow), _("Web Inspector"));
gtk_window_set_default_size(GTK_WINDOW(m_inspectorWindow), initialWindowWidth, initialWindowHeight);
- g_signal_connect(m_inspectorWindow, "delete-event", G_CALLBACK(inspectorWindowClosed), this);
gtk_container_add(GTK_CONTAINER(m_inspectorWindow), m_inspectorView);
gtk_widget_show(m_inspectorView);
@@ -102,10 +108,16 @@
platformAttach();
else
createInspectorWindow();
+ g_signal_connect(m_inspectorView, "destroy", G_CALLBACK(inspectorViewDestroyed), this);
}
void WebInspectorProxy::platformDidClose()
{
+ if (m_inspectorView)
+ g_signal_handlers_disconnect_by_func(m_inspectorView, reinterpret_cast<void*>(inspectorViewDestroyed), this);
+
+ m_client.didClose(this);
+
if (m_inspectorWindow) {
gtk_widget_destroy(m_inspectorWindow);
m_inspectorWindow = 0;
@@ -115,6 +127,9 @@
void WebInspectorProxy::platformBringToFront()
{
+ if (m_client.bringToFront(this))
+ return;
+
GtkWidget* parent = gtk_widget_get_toplevel(m_inspectorView);
if (WebCore::widgetIsOnscreenToplevelWindow(parent))
gtk_window_present(GTK_WINDOW(parent));
@@ -130,6 +145,8 @@
void WebInspectorProxy::platformInspectedURLChanged(const String& url)
{
+ m_client.inspectedURLChanged(this, url);
+
if (!m_inspectorWindow)
return;
GOwnPtr<gchar> title(g_strdup_printf("%s - %s", _("Web Inspector"), url.utf8().data()));
@@ -165,6 +182,9 @@
m_inspectorWindow = 0;
}
+ if (m_client.attach(this))
+ return;
+
gtk_container_add(GTK_CONTAINER(m_page->viewWidget()), m_inspectorView);
gtk_widget_show(m_inspectorView);
}
@@ -175,7 +195,9 @@
return;
GRefPtr<GtkWidget> inspectorView = m_inspectorView;
- gtk_container_remove(GTK_CONTAINER(m_page->viewWidget()), m_inspectorView);
+ if (!m_client.detach(this))
+ gtk_container_remove(GTK_CONTAINER(m_page->viewWidget()), m_inspectorView);
+
if (!m_isVisible)
return;
@@ -186,6 +208,8 @@
{
if (!m_isAttached)
return;
+
+ m_client.didChangeAttachedHeight(this, height);
webkitWebViewBaseSetInspectorViewHeight(WEBKIT_WEB_VIEW_BASE(m_page->viewWidget()), height);
}