[GTK][WK2] Add document-loaded signal to WebKitWebPage

https://bugs.webkit.org/show_bug.cgi?id=110614

Patch by Manuel Rego Casasnovas <rego@igalia.com> on 2013-04-12
Reviewed by Carlos Garcia Campos.

Add a new signal document-loaded to WebKitWebPage that will be emitted
when the DOM document has been loaded for the main frame.

* UIProcess/API/gtk/tests/TestWebExtensions.cpp:
(documentLoadedCallback):
(testDocumentLoadedSignal):
(beforeAll): Add test for document-loaded signal.
* UIProcess/API/gtk/tests/WebExtensionTest.cpp:
(documentLoadedCallback):
(pageCreatedCallback):
(methodCallCallback): Add new D-Bus signal DocumentLoaded in order to
test document-loaded signal.
* WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:
(webkit_web_page_class_init):
(webkitWebPageCreate): Add document-loaded signal and emit it when
didFinishDocumentLoadForFrame is called.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@148281 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent e5fb6b6b
2013-04-12 Manuel Rego Casasnovas <rego@igalia.com>
[GTK][WK2] Add document-loaded signal to WebKitWebPage
https://bugs.webkit.org/show_bug.cgi?id=110614
Reviewed by Carlos Garcia Campos.
Add a new signal document-loaded to WebKitWebPage that will be emitted
when the DOM document has been loaded for the main frame.
* UIProcess/API/gtk/tests/TestWebExtensions.cpp:
(documentLoadedCallback):
(testDocumentLoadedSignal):
(beforeAll): Add test for document-loaded signal.
* UIProcess/API/gtk/tests/WebExtensionTest.cpp:
(documentLoadedCallback):
(pageCreatedCallback):
(methodCallCallback): Add new D-Bus signal DocumentLoaded in order to
test document-loaded signal.
* WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:
(webkit_web_page_class_init):
(webkitWebPageCreate): Add document-loaded signal and emit it when
didFinishDocumentLoadForFrame is called.
2013-04-12 Hanyee Kim <choco@company100.net>
[GTK] Webkit fails to build webkit2gtk-tests-resources.gresource.
......@@ -45,6 +45,33 @@ static void testWebExtension(WebViewTest* test, gconstpointer)
g_assert_cmpstr(title, ==, "WebKitGTK+ Web Extensions Test");
}
static void documentLoadedCallback(GDBusConnection*, const char*, const char*, const char*, const char*, GVariant*, WebViewTest* test)
{
g_main_loop_quit(test->m_mainLoop);
}
static void testDocumentLoadedSignal(WebViewTest* test, gconstpointer)
{
GRefPtr<GDBusProxy> proxy = adoptGRef(bus->createProxy("org.webkit.gtk.WebExtensionTest",
"/org/webkit/gtk/WebExtensionTest", "org.webkit.gtk.WebExtensionTest", test->m_mainLoop));
GDBusConnection* connection = g_dbus_proxy_get_connection(proxy.get());
guint id = g_dbus_connection_signal_subscribe(connection,
0,
"org.webkit.gtk.WebExtensionTest",
"DocumentLoaded",
"/org/webkit/gtk/WebExtensionTest",
0,
G_DBUS_SIGNAL_FLAGS_NONE,
reinterpret_cast<GDBusSignalCallback>(documentLoadedCallback),
test,
0);
g_assert(id);
test->loadHtml("<html><head><title>WebKitGTK+ Web Extensions Test</title></head><body></body></html>", 0);
g_main_loop_run(test->m_mainLoop);
g_dbus_connection_signal_unsubscribe(connection, id);
}
void beforeAll()
{
webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(), WEBKIT_TEST_WEB_EXTENSIONS_DIR);
......@@ -53,6 +80,7 @@ void beforeAll()
return;
WebViewTest::add("WebKitWebExtension", "dom-document-title", testWebExtension);
WebViewTest::add("WebKitWebExtension", "document-loaded-signal", testDocumentLoadedSignal);
}
void afterAll()
......
......@@ -30,10 +30,28 @@ static const char introspectionXML[] =
" <arg type='t' name='pageID' direction='in'/>"
" <arg type='s' name='title' direction='out'/>"
" </method>"
" <signal name='DocumentLoaded'/>"
" </interface>"
"</node>";
static void methodCallCallback(GDBusConnection*, const char* sender, const char* objectPath, const char* interfaceName, const char* methodName, GVariant* parameters, GDBusMethodInvocation* invocation, gpointer userData)
static void documentLoadedCallback(WebKitWebPage*, gpointer userData)
{
bool ok = g_dbus_connection_emit_signal(G_DBUS_CONNECTION(userData),
0,
"/org/webkit/gtk/WebExtensionTest",
"org.webkit.gtk.WebExtensionTest",
"DocumentLoaded",
0,
0);
g_assert(ok);
}
static void pageCreatedCallback(WebKitWebExtension*, WebKitWebPage* webPage, gpointer userData)
{
g_signal_connect(webPage, "document-loaded", G_CALLBACK(documentLoadedCallback), userData);
}
static void methodCallCallback(GDBusConnection* connection, const char* sender, const char* objectPath, const char* interfaceName, const char* methodName, GVariant* parameters, GDBusMethodInvocation* invocation, gpointer userData)
{
if (g_strcmp0(interfaceName, "org.webkit.gtk.WebExtensionTest"))
return;
......@@ -78,6 +96,8 @@ static void busAcquiredCallback(GDBusConnection* connection, const char* name, g
&error.outPtr());
if (!registrationID)
g_warning("Failed to register object: %s\n", error->message);
g_signal_connect(WEBKIT_WEB_EXTENSION(userData), "page-created", G_CALLBACK(pageCreatedCallback), connection);
}
extern "C" void webkit_web_extension_initialize(WebKitWebExtension* extension)
......
......@@ -23,6 +23,7 @@
#include "ImmutableDictionary.h"
#include "InjectedBundle.h"
#include "WKBundleAPICast.h"
#include "WKBundleFrame.h"
#include "WebFrame.h"
#include "WebKitDOMDocumentPrivate.h"
#include "WebKitPrivate.h"
......@@ -33,12 +34,28 @@
using namespace WebKit;
using namespace WebCore;
enum {
DOCUMENT_LOADED,
LAST_SIGNAL
};
struct _WebKitWebPagePrivate {
WebPage* webPage;
};
static guint signals[LAST_SIGNAL] = { 0, };
WEBKIT_DEFINE_TYPE(WebKitWebPage, webkit_web_page, G_TYPE_OBJECT)
static void didFinishDocumentLoadForFrame(WKBundlePageRef, WKBundleFrameRef frame, WKTypeRef*, const void *clientInfo)
{
if (!WKBundleFrameIsMainFrame(frame))
return;
g_signal_emit(WEBKIT_WEB_PAGE(clientInfo), signals[DOCUMENT_LOADED], 0);
}
static void didInitiateLoadForResource(WKBundlePageRef page, WKBundleFrameRef frame, uint64_t identifier, WKURLRequestRef request, bool pageLoadIsProvisional, const void*)
{
ImmutableDictionary::MapType message;
......@@ -100,6 +117,23 @@ static void didFailLoadForResource(WKBundlePageRef page, WKBundleFrameRef, uint6
static void webkit_web_page_class_init(WebKitWebPageClass* klass)
{
/**
* WebKitWebPage::document-loaded:
* @web_page: the #WebKitWebPage on which the signal is emitted
*
* This signal is emitted when the DOM document of a #WebKitWebPage has been
* loaded.
*
* You can wait for this signal to get the DOM document with
* webkit_web_page_get_dom_document().
*/
signals[DOCUMENT_LOADED] = g_signal_new(
"document-loaded",
G_TYPE_FROM_CLASS(klass),
G_SIGNAL_RUN_LAST,
0, 0, 0,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 0);
}
WebKitWebPage* webkitWebPageCreate(WebPage* webPage)
......@@ -107,6 +141,44 @@ WebKitWebPage* webkitWebPageCreate(WebPage* webPage)
WebKitWebPage* page = WEBKIT_WEB_PAGE(g_object_new(WEBKIT_TYPE_WEB_PAGE, NULL));
page->priv->webPage = webPage;
WKBundlePageLoaderClient loaderClient = {
kWKBundlePageResourceLoadClientCurrentVersion,
page,
0, // didStartProvisionalLoadForFrame
0, // didReceiveServerRedirectForProvisionalLoadForFrame
0, // didFailProvisionalLoadWithErrorForFrame
0, // didCommitLoadForFrame
didFinishDocumentLoadForFrame,
0, // didFinishLoadForFrame
0, // didFailLoadWithErrorForFrame
0, // didSameDocumentNavigationForFrame
0, // didReceiveTitleForFrame
0, // didFirstLayoutForFrame
0, // didFirstVisuallyNonEmptyLayoutForFrame
0, // didRemoveFrameFromHierarchy
0, // didDisplayInsecureContentForFrame
0, // didRunInsecureContentForFrame
0, // didClearWindowObjectForFrame
0, // didCancelClientRedirectForFrame
0, // willPerformClientRedirectForFrame
0, // didHandleOnloadEventsForFrame
0, // didLayoutForFrame
0, // didNewFirstVisuallyNonEmptyLayout
0, // didDetectXSSForFrame
0, // shouldGoToBackForwardListItem
0, // globalObjectIsAvailableForFrame
0, // willDisconnectDOMWindowExtensionFromGlobalObject
0, // didReconnectDOMWindowExtensionToGlobalObject
0, // willDestroyGlobalObjectForDOMWindowExtension
0, // didFinishProgress
0, // shouldForceUniversalAccessFromLocalURL
0, // didReceiveIntentForFrame_unavailable
0, // registerIntentServiceForFrame_unavailable
0, // didLayout
0, // featuresUsedInPage
};
WKBundlePageSetPageLoaderClient(toAPI(webPage), &loaderClient);
WKBundlePageResourceLoadClient resourceLoadClient = {
kWKBundlePageResourceLoadClientCurrentVersion,
page,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment