Title: [148666] trunk/Source/WebKit2
Revision
148666
Author
commit-qu...@webkit.org
Date
2013-04-18 05:02:30 -0700 (Thu, 18 Apr 2013)

Log Message

[GTK][WK2] Add WebKitWebPage::webkit_web_page_get_uri to WebKit2 GTK+ API
https://bugs.webkit.org/show_bug.cgi?id=111288

Patch by Manuel Rego Casasnovas <r...@igalia.com> on 2013-04-18
Reviewed by Anders Carlsson.

Add new property URI to WebKitWebPage providing a method
webkit_web_page_get_uri to get it and the signal "notify::uri" to
monitor changes in the URI.

* UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Include new method in
GTK+ doc.
* UIProcess/API/gtk/tests/TestLoaderClient.cpp:
(testWebPageURI):
(beforeAll):
(afterAll): Add test to check that WebKitWebPage URI matches with
WebKitWebView value. The tests is listening for changes in WebKitWebPage
URI via D-Bus and checks that value is the same than WebKitWebView URI.
It also checks that the order of the URIs in a redirection is right.
When the test finishes the signals are disconnected properly.
* UIProcess/API/gtk/tests/WebExtensionTest.cpp:
(uriChangedCallback):
(pageCreatedCallback): Add new D-Bus signal "URIChanged" connected to
"notify::uri" signal of WebKitWebPage.
* UIProcess/API/gtk/tests/WebKitTestBus.cpp:
(WebKitTestBus::getOrCreateConnection): Rename method connection() to
getOrCreateConnection().
(WebKitTestBus::createProxy): Use the new method name.
* UIProcess/API/gtk/tests/WebKitTestBus.h:
(WebKitTestBus::connection): Add public getter for m_connection.
(WebKitTestBus): Add private method header getOrCreateConnection().
* WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:
(_WebKitWebPagePrivate): Add new URI attribute.
(webkitWebPageSetURI): Method to set the URI and emit the "notify:uri"
signal if it has changed.
(didStartProvisionalLoadForFrame): At this point it use the unreachable
URL from provisional document loader if any. Otherwise, it uses the URL
from provisional document loader.
(didReceiveServerRedirectForProvisionalLoadForFrame): In the case of
redirections it works like for didStartProvisionalLoadForFrame getting
the unreachable URL if any.
(didSameDocumentNavigationForFrame): In this case it gets the URL from
the document loader.
(webkitWebPageGetProperty): Add code related to URI property.
(webkit_web_page_class_init): Add bits related to URI property.
(webkitWebPageCreate): Implement callbacks to monitor URI changes.
(webkit_web_page_get_uri): Return URI attribute.
* WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h: Add new method
header.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (148665 => 148666)


--- trunk/Source/WebKit2/ChangeLog	2013-04-18 10:35:37 UTC (rev 148665)
+++ trunk/Source/WebKit2/ChangeLog	2013-04-18 12:02:30 UTC (rev 148666)
@@ -1,3 +1,54 @@
+2013-04-18  Manuel Rego Casasnovas  <r...@igalia.com>
+
+        [GTK][WK2] Add WebKitWebPage::webkit_web_page_get_uri to WebKit2 GTK+ API
+        https://bugs.webkit.org/show_bug.cgi?id=111288
+
+        Reviewed by Anders Carlsson.
+
+        Add new property URI to WebKitWebPage providing a method
+        webkit_web_page_get_uri to get it and the signal "notify::uri" to
+        monitor changes in the URI.
+
+        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Include new method in
+        GTK+ doc.
+        * UIProcess/API/gtk/tests/TestLoaderClient.cpp:
+        (testWebPageURI):
+        (beforeAll):
+        (afterAll): Add test to check that WebKitWebPage URI matches with
+        WebKitWebView value. The tests is listening for changes in WebKitWebPage
+        URI via D-Bus and checks that value is the same than WebKitWebView URI.
+        It also checks that the order of the URIs in a redirection is right.
+        When the test finishes the signals are disconnected properly.
+        * UIProcess/API/gtk/tests/WebExtensionTest.cpp:
+        (uriChangedCallback):
+        (pageCreatedCallback): Add new D-Bus signal "URIChanged" connected to
+        "notify::uri" signal of WebKitWebPage.
+        * UIProcess/API/gtk/tests/WebKitTestBus.cpp:
+        (WebKitTestBus::getOrCreateConnection): Rename method connection() to
+        getOrCreateConnection().
+        (WebKitTestBus::createProxy): Use the new method name.
+        * UIProcess/API/gtk/tests/WebKitTestBus.h:
+        (WebKitTestBus::connection): Add public getter for m_connection.
+        (WebKitTestBus): Add private method header getOrCreateConnection().
+        * WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:
+        (_WebKitWebPagePrivate): Add new URI attribute.
+        (webkitWebPageSetURI): Method to set the URI and emit the "notify:uri"
+        signal if it has changed.
+        (didStartProvisionalLoadForFrame): At this point it use the unreachable
+        URL from provisional document loader if any. Otherwise, it uses the URL
+        from provisional document loader.
+        (didReceiveServerRedirectForProvisionalLoadForFrame): In the case of
+        redirections it works like for didStartProvisionalLoadForFrame getting
+        the unreachable URL if any.
+        (didSameDocumentNavigationForFrame): In this case it gets the URL from
+        the document loader.
+        (webkitWebPageGetProperty): Add code related to URI property.
+        (webkit_web_page_class_init): Add bits related to URI property.
+        (webkitWebPageCreate): Implement callbacks to monitor URI changes.
+        (webkit_web_page_get_uri): Return URI attribute.
+        * WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h: Add new method
+        header.
+
 2013-04-18  Xan Lopez  <x...@igalia.com>
 
         [GTK] When the WebProcess crashes, a signal should be emitted

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt (148665 => 148666)


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2013-04-18 10:35:37 UTC (rev 148665)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2013-04-18 12:02:30 UTC (rev 148666)
@@ -962,6 +962,7 @@
 WebKitWebPage
 webkit_web_page_get_dom_document
 webkit_web_page_get_id
+webkit_web_page_get_uri
 
 <SUBSECTION Standard>
 WebKitWebPageClass

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp (148665 => 148666)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp	2013-04-18 10:35:37 UTC (rev 148665)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp	2013-04-18 12:02:30 UTC (rev 148666)
@@ -22,11 +22,14 @@
 #include "config.h"
 
 #include "LoadTrackingTest.h"
+#include "WebKitTestBus.h"
 #include "WebKitTestServer.h"
+#include "WebViewTest.h"
 #include <gtk/gtk.h>
 #include <libsoup/soup.h>
 #include <wtf/text/CString.h>
 
+static WebKitTestBus* bus;
 static WebKitTestServer* kServer;
 
 static void testLoadingStatus(LoadTrackingTest* test, gconstpointer data)
@@ -280,6 +283,68 @@
     test->waitUntilLoadFinished();
 }
 
+class WebPageURITest: public WebViewTest {
+public:
+    MAKE_GLIB_TEST_FIXTURE(WebPageURITest);
+
+    static void webPageURIChangedCallback(GDBusConnection*, const char*, const char*, const char*, const char*, GVariant* result, WebPageURITest* test)
+    {
+        const char* uri;
+        g_variant_get(result, "(&s)", &uri);
+        test->m_webPageURIs.append(uri);
+    }
+
+    static void webViewURIChanged(GObject*, GParamSpec*, WebPageURITest* test)
+    {
+        test->m_webViewURIs.append(webkit_web_view_get_uri(test->m_webView));
+    }
+
+    WebPageURITest()
+    {
+        GRefPtr<GDBusProxy> proxy = adoptGRef(bus->createProxy("org.webkit.gtk.WebExtensionTest",
+            "/org/webkit/gtk/WebExtensionTest", "org.webkit.gtk.WebExtensionTest", m_mainLoop));
+        m_uriChangedSignalID = g_dbus_connection_signal_subscribe(
+            g_dbus_proxy_get_connection(proxy.get()),
+            0,
+            "org.webkit.gtk.WebExtensionTest",
+            "URIChanged",
+            "/org/webkit/gtk/WebExtensionTest",
+            0,
+            G_DBUS_SIGNAL_FLAGS_NONE,
+            reinterpret_cast<GDBusSignalCallback>(webPageURIChangedCallback),
+            this,
+            0);
+        g_assert(m_uriChangedSignalID);
+
+        g_signal_connect(m_webView, "notify::uri", G_CALLBACK(webViewURIChanged), this);
+    }
+
+    ~WebPageURITest()
+    {
+        g_signal_handlers_disconnect_matched(m_webView, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this);
+        g_dbus_connection_signal_unsubscribe(bus->connection(), m_uriChangedSignalID);
+    }
+
+    unsigned m_uriChangedSignalID;
+    Vector<CString> m_webPageURIs;
+    Vector<CString> m_webViewURIs;
+};
+
+static void testWebPageURI(WebPageURITest* test, gconstpointer)
+{
+    test->loadURI(kServer->getURIForPath("/redirect").data());
+    test->waitUntilLoadFinished();
+
+    g_assert_cmpint(test->m_webPageURIs.size(), ==, test->m_webViewURIs.size());
+    for (size_t i = 0; i < test->m_webPageURIs.size(); ++i)
+        ASSERT_CMP_CSTRING(test->m_webPageURIs[i], ==, test->m_webViewURIs[i]);
+
+    g_assert_cmpint(test->m_webPageURIs.size(), ==, 2);
+    ASSERT_CMP_CSTRING(test->m_webPageURIs[0], ==, kServer->getURIForPath("/redirect"));
+    ASSERT_CMP_CSTRING(test->m_webPageURIs[1], ==, kServer->getURIForPath("/normal"));
+
+}
+
 static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
 {
     static const char* responseString = "<html><body>Testing!Testing!Testing!Testing!Testing!Testing!Testing!"
@@ -318,6 +383,11 @@
 
 void beforeAll()
 {
+    webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(), WEBKIT_TEST_WEB_EXTENSIONS_DIR);
+    bus = new WebKitTestBus();
+    if (!bus->run())
+        return;
+
     kServer = new WebKitTestServer();
     kServer->run(serverCallback);
 
@@ -338,9 +408,11 @@
     ViewURITrackingTest::add("WebKitWebView", "active-uri", testWebViewActiveURI);
 
     ViewIsLoadingTest::add("WebKitWebView", "is-loading", testWebViewIsLoading);
+    WebPageURITest::add("WebKitWebPage", "get-uri", testWebPageURI);
 }
 
 void afterAll()
 {
+    delete bus;
     delete kServer;
 }

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebExtensionTest.cpp (148665 => 148666)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebExtensionTest.cpp	2013-04-18 10:35:37 UTC (rev 148665)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebExtensionTest.cpp	2013-04-18 12:02:30 UTC (rev 148666)
@@ -35,6 +35,9 @@
     "  <method name='AbortProcess'>"
     "  </method>"
     "  <signal name='DocumentLoaded'/>"
+    "  <signal name='URIChanged'>"
+    "   <arg type='s' name='uri' direction='out'/>"
+    "  </signal>"
     " </interface>"
     "</node>";
 
@@ -50,9 +53,23 @@
     g_assert(ok);
 }
 
+static void uriChangedCallback(WebKitWebPage* webPage, GParamSpec* pspec, gpointer userData)
+{
+    bool ok = g_dbus_connection_emit_signal(
+        G_DBUS_CONNECTION(userData),
+        0,
+        "/org/webkit/gtk/WebExtensionTest",
+        "org.webkit.gtk.WebExtensionTest",
+        "URIChanged",
+        g_variant_new("(s)", webkit_web_page_get_uri(webPage)),
+        0);
+    g_assert(ok);
+}
+
 static void pageCreatedCallback(WebKitWebExtension*, WebKitWebPage* webPage, gpointer userData)
 {
     g_signal_connect(webPage, "document-loaded", G_CALLBACK(documentLoadedCallback), userData);
+    g_signal_connect(webPage, "notify::uri", G_CALLBACK(uriChangedCallback), userData);
 }
 
 static void methodCallCallback(GDBusConnection* connection, const char* sender, const char* objectPath, const char* interfaceName, const char* methodName, GVariant* parameters, GDBusMethodInvocation* invocation, gpointer userData)

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.cpp (148665 => 148666)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.cpp	2013-04-18 10:35:37 UTC (rev 148665)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.cpp	2013-04-18 12:02:30 UTC (rev 148666)
@@ -69,7 +69,7 @@
         kill(m_pid, SIGTERM);
 }
 
-GDBusConnection* WebKitTestBus::connection()
+GDBusConnection* WebKitTestBus::getOrCreateConnection()
 {
     if (m_connection)
         return m_connection.get();
@@ -88,7 +88,7 @@
 
 GDBusProxy* WebKitTestBus::createProxy(const char* serviceName, const char* objectPath, const char* interfaceName, GMainLoop* mainLoop)
 {
-    unsigned watcherID = g_bus_watch_name_on_connection(connection(), serviceName, G_BUS_NAME_WATCHER_FLAGS_NONE, onNameAppeared, 0, mainLoop, 0);
+    unsigned watcherID = g_bus_watch_name_on_connection(getOrCreateConnection(), serviceName, G_BUS_NAME_WATCHER_FLAGS_NONE, onNameAppeared, 0, mainLoop, 0);
     g_main_loop_run(mainLoop);
     g_bus_unwatch_name(watcherID);
 

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.h (148665 => 148666)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.h	2013-04-18 10:35:37 UTC (rev 148665)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.h	2013-04-18 12:02:30 UTC (rev 148666)
@@ -31,9 +31,10 @@
 
     bool run();
     GDBusProxy* createProxy(const char* serviceName, const char* objectPath, const char* interfaceName, GMainLoop*);
+    GDBusConnection* connection() const { return m_connection.get(); }
 
 private:
-    GDBusConnection* connection();
+    GDBusConnection* getOrCreateConnection();
 
     pid_t m_pid;
     CString m_address;

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp (148665 => 148666)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp	2013-04-18 10:35:37 UTC (rev 148665)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp	2013-04-18 12:02:30 UTC (rev 148666)
@@ -31,8 +31,12 @@
 #include "WebKitPrivate.h"
 #include "WebKitWebPagePrivate.h"
 #include "WebProcess.h"
+#include <WebCore/Document.h>
+#include <WebCore/DocumentLoader.h>
 #include <WebCore/Frame.h>
 #include <WebCore/FrameView.h>
+#include <glib/gi18n-lib.h>
+#include <wtf/text/CString.h>
 
 using namespace WebKit;
 using namespace WebCore;
@@ -43,14 +47,64 @@
     LAST_SIGNAL
 };
 
+enum {
+    PROP_0,
+
+    PROP_URI
+};
+
 struct _WebKitWebPagePrivate {
     WebPage* webPage;
+
+    CString uri;
 };
 
 static guint signals[LAST_SIGNAL] = { 0, };
 
 WEBKIT_DEFINE_TYPE(WebKitWebPage, webkit_web_page, G_TYPE_OBJECT)
 
+static CString getProvisionalURLForFrame(WebFrame* webFrame)
+{
+    DocumentLoader* documentLoader = webFrame->coreFrame()->loader()->provisionalDocumentLoader();
+    if (!documentLoader->unreachableURL().isEmpty())
+        return documentLoader->unreachableURL().string().utf8();
+
+    return documentLoader->url().string().utf8();
+}
+
+static void webkitWebPageSetURI(WebKitWebPage* webPage, const CString& uri)
+{
+    if (webPage->priv->uri == uri)
+        return;
+
+    webPage->priv->uri = uri;
+    g_object_notify(G_OBJECT(webPage), "uri");
+}
+
+static void didStartProvisionalLoadForFrame(WKBundlePageRef, WKBundleFrameRef frame, WKTypeRef*, const void *clientInfo)
+{
+    if (!WKBundleFrameIsMainFrame(frame))
+        return;
+
+    webkitWebPageSetURI(WEBKIT_WEB_PAGE(clientInfo), getProvisionalURLForFrame(toImpl(frame)));
+}
+
+static void didReceiveServerRedirectForProvisionalLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo)
+{
+    if (!WKBundleFrameIsMainFrame(frame))
+        return;
+
+    webkitWebPageSetURI(WEBKIT_WEB_PAGE(clientInfo), getProvisionalURLForFrame(toImpl(frame)));
+}
+
+static void didSameDocumentNavigationForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKSameDocumentNavigationType type, WKTypeRef* userData, const void *clientInfo)
+{
+    if (!WKBundleFrameIsMainFrame(frame))
+        return;
+
+    webkitWebPageSetURI(WEBKIT_WEB_PAGE(clientInfo), toImpl(frame)->coreFrame()->document()->url().string().utf8());
+}
+
 static void didFinishDocumentLoadForFrame(WKBundlePageRef, WKBundleFrameRef frame, WKTypeRef*, const void *clientInfo)
 {
     if (!WKBundleFrameIsMainFrame(frame))
@@ -118,9 +172,41 @@
     WebProcess::shared().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidFailLoadForResource"), ImmutableDictionary::adopt(message).get());
 }
 
+static void webkitWebPageGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec)
+{
+    WebKitWebPage* webPage = WEBKIT_WEB_PAGE(object);
+
+    switch (propId) {
+    case PROP_URI:
+        g_value_set_string(value, webkit_web_page_get_uri(webPage));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
+    }
+}
+
 static void webkit_web_page_class_init(WebKitWebPageClass* klass)
 {
+    GObjectClass* gObjectClass = G_OBJECT_CLASS(klass);
+
+    gObjectClass->get_property = webkitWebPageGetProperty;
+
     /**
+     * WebKitWebPage:uri:
+     *
+     * The current active URI of the #WebKitWebPage.
+     */
+    g_object_class_install_property(
+        gObjectClass,
+        PROP_URI,
+        g_param_spec_string(
+            "uri",
+            _("URI"),
+            _("The current active URI of the web page"),
+            0,
+            WEBKIT_PARAM_READABLE));
+
+    /**
      * WebKitWebPage::document-loaded:
      * @web_page: the #WebKitWebPage on which the signal is emitted
      *
@@ -147,14 +233,14 @@
     WKBundlePageLoaderClient loaderClient = {
         kWKBundlePageResourceLoadClientCurrentVersion,
         page,
-        0, // didStartProvisionalLoadForFrame
-        0, // didReceiveServerRedirectForProvisionalLoadForFrame
+        didStartProvisionalLoadForFrame,
+        didReceiveServerRedirectForProvisionalLoadForFrame,
         0, // didFailProvisionalLoadWithErrorForFrame
         0, // didCommitLoadForFrame
         didFinishDocumentLoadForFrame,
         0, // didFinishLoadForFrame
         0, // didFailLoadWithErrorForFrame
-        0, // didSameDocumentNavigationForFrame
+        didSameDocumentNavigationForFrame,
         0, // didReceiveTitleForFrame
         0, // didFirstLayoutForFrame
         0, // didFirstVisuallyNonEmptyLayoutForFrame
@@ -267,3 +353,22 @@
 
     return webPage->priv->webPage->pageID();
 }
+
+/**
+ * webkit_web_page_get_uri:
+ * @web_page: a #WebKitWebPage
+ *
+ * Returns the current active URI of @web_page.
+ *
+ * You can monitor the active URI by connecting to the notify::uri
+ * signal of @web_page.
+ *
+ * Returns: the current active URI of @web_view or %NULL if nothing has been
+ *    loaded yet.
+ */
+const gchar* webkit_web_page_get_uri(WebKitWebPage* webPage)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEB_PAGE(webPage), 0);
+
+    return webPage->priv->uri.data();
+}

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h (148665 => 148666)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h	2013-04-18 10:35:37 UTC (rev 148665)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h	2013-04-18 12:02:30 UTC (rev 148666)
@@ -60,6 +60,9 @@
 WEBKIT_API guint64
 webkit_web_page_get_id           (WebKitWebPage *web_page);
 
+WEBKIT_API const gchar *
+webkit_web_page_get_uri (WebKitWebPage *web_page);
+
 G_END_DECLS
 
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to