Changeset 148666 in webkit


Ignore:
Timestamp:
Apr 18, 2013 5:02:30 AM (11 years ago)
Author:
commit-queue@webkit.org
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 <Manuel Rego Casasnovas> 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.

Location:
trunk/Source/WebKit2
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r148665 r148666  
     12013-04-18  Manuel Rego Casasnovas  <rego@igalia.com>
     2
     3        [GTK][WK2] Add WebKitWebPage::webkit_web_page_get_uri to WebKit2 GTK+ API
     4        https://bugs.webkit.org/show_bug.cgi?id=111288
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Add new property URI to WebKitWebPage providing a method
     9        webkit_web_page_get_uri to get it and the signal "notify::uri" to
     10        monitor changes in the URI.
     11
     12        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Include new method in
     13        GTK+ doc.
     14        * UIProcess/API/gtk/tests/TestLoaderClient.cpp:
     15        (testWebPageURI):
     16        (beforeAll):
     17        (afterAll): Add test to check that WebKitWebPage URI matches with
     18        WebKitWebView value. The tests is listening for changes in WebKitWebPage
     19        URI via D-Bus and checks that value is the same than WebKitWebView URI.
     20        It also checks that the order of the URIs in a redirection is right.
     21        When the test finishes the signals are disconnected properly.
     22        * UIProcess/API/gtk/tests/WebExtensionTest.cpp:
     23        (uriChangedCallback):
     24        (pageCreatedCallback): Add new D-Bus signal "URIChanged" connected to
     25        "notify::uri" signal of WebKitWebPage.
     26        * UIProcess/API/gtk/tests/WebKitTestBus.cpp:
     27        (WebKitTestBus::getOrCreateConnection): Rename method connection() to
     28        getOrCreateConnection().
     29        (WebKitTestBus::createProxy): Use the new method name.
     30        * UIProcess/API/gtk/tests/WebKitTestBus.h:
     31        (WebKitTestBus::connection): Add public getter for m_connection.
     32        (WebKitTestBus): Add private method header getOrCreateConnection().
     33        * WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:
     34        (_WebKitWebPagePrivate): Add new URI attribute.
     35        (webkitWebPageSetURI): Method to set the URI and emit the "notify:uri"
     36        signal if it has changed.
     37        (didStartProvisionalLoadForFrame): At this point it use the unreachable
     38        URL from provisional document loader if any. Otherwise, it uses the URL
     39        from provisional document loader.
     40        (didReceiveServerRedirectForProvisionalLoadForFrame): In the case of
     41        redirections it works like for didStartProvisionalLoadForFrame getting
     42        the unreachable URL if any.
     43        (didSameDocumentNavigationForFrame): In this case it gets the URL from
     44        the document loader.
     45        (webkitWebPageGetProperty): Add code related to URI property.
     46        (webkit_web_page_class_init): Add bits related to URI property.
     47        (webkitWebPageCreate): Implement callbacks to monitor URI changes.
     48        (webkit_web_page_get_uri): Return URI attribute.
     49        * WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h: Add new method
     50        header.
     51
    1522013-04-18  Xan Lopez  <xan@igalia.com>
    253
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt

    r148592 r148666  
    963963webkit_web_page_get_dom_document
    964964webkit_web_page_get_id
     965webkit_web_page_get_uri
    965966
    966967<SUBSECTION Standard>
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp

    r144652 r148666  
    2323
    2424#include "LoadTrackingTest.h"
     25#include "WebKitTestBus.h"
    2526#include "WebKitTestServer.h"
     27#include "WebViewTest.h"
    2628#include <gtk/gtk.h>
    2729#include <libsoup/soup.h>
    2830#include <wtf/text/CString.h>
    2931
     32static WebKitTestBus* bus;
    3033static WebKitTestServer* kServer;
    3134
     
    279282    test->goForward();
    280283    test->waitUntilLoadFinished();
     284}
     285
     286class WebPageURITest: public WebViewTest {
     287public:
     288    MAKE_GLIB_TEST_FIXTURE(WebPageURITest);
     289
     290    static void webPageURIChangedCallback(GDBusConnection*, const char*, const char*, const char*, const char*, GVariant* result, WebPageURITest* test)
     291    {
     292        const char* uri;
     293        g_variant_get(result, "(&s)", &uri);
     294        test->m_webPageURIs.append(uri);
     295    }
     296
     297    static void webViewURIChanged(GObject*, GParamSpec*, WebPageURITest* test)
     298    {
     299        test->m_webViewURIs.append(webkit_web_view_get_uri(test->m_webView));
     300    }
     301
     302    WebPageURITest()
     303    {
     304        GRefPtr<GDBusProxy> proxy = adoptGRef(bus->createProxy("org.webkit.gtk.WebExtensionTest",
     305            "/org/webkit/gtk/WebExtensionTest", "org.webkit.gtk.WebExtensionTest", m_mainLoop));
     306        m_uriChangedSignalID = g_dbus_connection_signal_subscribe(
     307            g_dbus_proxy_get_connection(proxy.get()),
     308            0,
     309            "org.webkit.gtk.WebExtensionTest",
     310            "URIChanged",
     311            "/org/webkit/gtk/WebExtensionTest",
     312            0,
     313            G_DBUS_SIGNAL_FLAGS_NONE,
     314            reinterpret_cast<GDBusSignalCallback>(webPageURIChangedCallback),
     315            this,
     316            0);
     317        g_assert(m_uriChangedSignalID);
     318
     319        g_signal_connect(m_webView, "notify::uri", G_CALLBACK(webViewURIChanged), this);
     320    }
     321
     322    ~WebPageURITest()
     323    {
     324        g_signal_handlers_disconnect_matched(m_webView, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this);
     325        g_dbus_connection_signal_unsubscribe(bus->connection(), m_uriChangedSignalID);
     326    }
     327
     328    unsigned m_uriChangedSignalID;
     329    Vector<CString> m_webPageURIs;
     330    Vector<CString> m_webViewURIs;
     331};
     332
     333static void testWebPageURI(WebPageURITest* test, gconstpointer)
     334{
     335    test->loadURI(kServer->getURIForPath("/redirect").data());
     336    test->waitUntilLoadFinished();
     337
     338    g_assert_cmpint(test->m_webPageURIs.size(), ==, test->m_webViewURIs.size());
     339    for (size_t i = 0; i < test->m_webPageURIs.size(); ++i)
     340        ASSERT_CMP_CSTRING(test->m_webPageURIs[i], ==, test->m_webViewURIs[i]);
     341
     342    g_assert_cmpint(test->m_webPageURIs.size(), ==, 2);
     343    ASSERT_CMP_CSTRING(test->m_webPageURIs[0], ==, kServer->getURIForPath("/redirect"));
     344    ASSERT_CMP_CSTRING(test->m_webPageURIs[1], ==, kServer->getURIForPath("/normal"));
     345
    281346}
    282347
     
    319384void beforeAll()
    320385{
     386    webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(), WEBKIT_TEST_WEB_EXTENSIONS_DIR);
     387    bus = new WebKitTestBus();
     388    if (!bus->run())
     389        return;
     390
    321391    kServer = new WebKitTestServer();
    322392    kServer->run(serverCallback);
     
    339409
    340410    ViewIsLoadingTest::add("WebKitWebView", "is-loading", testWebViewIsLoading);
     411    WebPageURITest::add("WebKitWebPage", "get-uri", testWebPageURI);
    341412}
    342413
    343414void afterAll()
    344415{
     416    delete bus;
    345417    delete kServer;
    346418}
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebExtensionTest.cpp

    r148665 r148666  
    3636    "  </method>"
    3737    "  <signal name='DocumentLoaded'/>"
     38    "  <signal name='URIChanged'>"
     39    "   <arg type='s' name='uri' direction='out'/>"
     40    "  </signal>"
    3841    " </interface>"
    3942    "</node>";
     
    5154}
    5255
     56static void uriChangedCallback(WebKitWebPage* webPage, GParamSpec* pspec, gpointer userData)
     57{
     58    bool ok = g_dbus_connection_emit_signal(
     59        G_DBUS_CONNECTION(userData),
     60        0,
     61        "/org/webkit/gtk/WebExtensionTest",
     62        "org.webkit.gtk.WebExtensionTest",
     63        "URIChanged",
     64        g_variant_new("(s)", webkit_web_page_get_uri(webPage)),
     65        0);
     66    g_assert(ok);
     67}
     68
    5369static void pageCreatedCallback(WebKitWebExtension*, WebKitWebPage* webPage, gpointer userData)
    5470{
    5571    g_signal_connect(webPage, "document-loaded", G_CALLBACK(documentLoadedCallback), userData);
     72    g_signal_connect(webPage, "notify::uri", G_CALLBACK(uriChangedCallback), userData);
    5673}
    5774
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.cpp

    r139305 r148666  
    7070}
    7171
    72 GDBusConnection* WebKitTestBus::connection()
     72GDBusConnection* WebKitTestBus::getOrCreateConnection()
    7373{
    7474    if (m_connection)
     
    8989GDBusProxy* WebKitTestBus::createProxy(const char* serviceName, const char* objectPath, const char* interfaceName, GMainLoop* mainLoop)
    9090{
    91     unsigned watcherID = g_bus_watch_name_on_connection(connection(), serviceName, G_BUS_NAME_WATCHER_FLAGS_NONE, onNameAppeared, 0, mainLoop, 0);
     91    unsigned watcherID = g_bus_watch_name_on_connection(getOrCreateConnection(), serviceName, G_BUS_NAME_WATCHER_FLAGS_NONE, onNameAppeared, 0, mainLoop, 0);
    9292    g_main_loop_run(mainLoop);
    9393    g_bus_unwatch_name(watcherID);
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.h

    r139305 r148666  
    3232    bool run();
    3333    GDBusProxy* createProxy(const char* serviceName, const char* objectPath, const char* interfaceName, GMainLoop*);
     34    GDBusConnection* connection() const { return m_connection.get(); }
    3435
    3536private:
    36     GDBusConnection* connection();
     37    GDBusConnection* getOrCreateConnection();
    3738
    3839    pid_t m_pid;
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp

    r148592 r148666  
    3232#include "WebKitWebPagePrivate.h"
    3333#include "WebProcess.h"
     34#include <WebCore/Document.h>
     35#include <WebCore/DocumentLoader.h>
    3436#include <WebCore/Frame.h>
    3537#include <WebCore/FrameView.h>
     38#include <glib/gi18n-lib.h>
     39#include <wtf/text/CString.h>
    3640
    3741using namespace WebKit;
     
    4448};
    4549
     50enum {
     51    PROP_0,
     52
     53    PROP_URI
     54};
     55
    4656struct _WebKitWebPagePrivate {
    4757    WebPage* webPage;
     58
     59    CString uri;
    4860};
    4961
     
    5163
    5264WEBKIT_DEFINE_TYPE(WebKitWebPage, webkit_web_page, G_TYPE_OBJECT)
     65
     66static CString getProvisionalURLForFrame(WebFrame* webFrame)
     67{
     68    DocumentLoader* documentLoader = webFrame->coreFrame()->loader()->provisionalDocumentLoader();
     69    if (!documentLoader->unreachableURL().isEmpty())
     70        return documentLoader->unreachableURL().string().utf8();
     71
     72    return documentLoader->url().string().utf8();
     73}
     74
     75static void webkitWebPageSetURI(WebKitWebPage* webPage, const CString& uri)
     76{
     77    if (webPage->priv->uri == uri)
     78        return;
     79
     80    webPage->priv->uri = uri;
     81    g_object_notify(G_OBJECT(webPage), "uri");
     82}
     83
     84static void didStartProvisionalLoadForFrame(WKBundlePageRef, WKBundleFrameRef frame, WKTypeRef*, const void *clientInfo)
     85{
     86    if (!WKBundleFrameIsMainFrame(frame))
     87        return;
     88
     89    webkitWebPageSetURI(WEBKIT_WEB_PAGE(clientInfo), getProvisionalURLForFrame(toImpl(frame)));
     90}
     91
     92static void didReceiveServerRedirectForProvisionalLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo)
     93{
     94    if (!WKBundleFrameIsMainFrame(frame))
     95        return;
     96
     97    webkitWebPageSetURI(WEBKIT_WEB_PAGE(clientInfo), getProvisionalURLForFrame(toImpl(frame)));
     98}
     99
     100static void didSameDocumentNavigationForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKSameDocumentNavigationType type, WKTypeRef* userData, const void *clientInfo)
     101{
     102    if (!WKBundleFrameIsMainFrame(frame))
     103        return;
     104
     105    webkitWebPageSetURI(WEBKIT_WEB_PAGE(clientInfo), toImpl(frame)->coreFrame()->document()->url().string().utf8());
     106}
    53107
    54108static void didFinishDocumentLoadForFrame(WKBundlePageRef, WKBundleFrameRef frame, WKTypeRef*, const void *clientInfo)
     
    119173}
    120174
     175static void webkitWebPageGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec)
     176{
     177    WebKitWebPage* webPage = WEBKIT_WEB_PAGE(object);
     178
     179    switch (propId) {
     180    case PROP_URI:
     181        g_value_set_string(value, webkit_web_page_get_uri(webPage));
     182        break;
     183    default:
     184        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
     185    }
     186}
     187
    121188static void webkit_web_page_class_init(WebKitWebPageClass* klass)
    122189{
     190    GObjectClass* gObjectClass = G_OBJECT_CLASS(klass);
     191
     192    gObjectClass->get_property = webkitWebPageGetProperty;
     193
     194    /**
     195     * WebKitWebPage:uri:
     196     *
     197     * The current active URI of the #WebKitWebPage.
     198     */
     199    g_object_class_install_property(
     200        gObjectClass,
     201        PROP_URI,
     202        g_param_spec_string(
     203            "uri",
     204            _("URI"),
     205            _("The current active URI of the web page"),
     206            0,
     207            WEBKIT_PARAM_READABLE));
     208
    123209    /**
    124210     * WebKitWebPage::document-loaded:
     
    148234        kWKBundlePageResourceLoadClientCurrentVersion,
    149235        page,
    150         0, // didStartProvisionalLoadForFrame
    151         0, // didReceiveServerRedirectForProvisionalLoadForFrame
     236        didStartProvisionalLoadForFrame,
     237        didReceiveServerRedirectForProvisionalLoadForFrame,
    152238        0, // didFailProvisionalLoadWithErrorForFrame
    153239        0, // didCommitLoadForFrame
     
    155241        0, // didFinishLoadForFrame
    156242        0, // didFailLoadWithErrorForFrame
    157         0, // didSameDocumentNavigationForFrame
     243        didSameDocumentNavigationForFrame,
    158244        0, // didReceiveTitleForFrame
    159245        0, // didFirstLayoutForFrame
     
    268354    return webPage->priv->webPage->pageID();
    269355}
     356
     357/**
     358 * webkit_web_page_get_uri:
     359 * @web_page: a #WebKitWebPage
     360 *
     361 * Returns the current active URI of @web_page.
     362 *
     363 * You can monitor the active URI by connecting to the notify::uri
     364 * signal of @web_page.
     365 *
     366 * Returns: the current active URI of @web_view or %NULL if nothing has been
     367 *    loaded yet.
     368 */
     369const gchar* webkit_web_page_get_uri(WebKitWebPage* webPage)
     370{
     371    g_return_val_if_fail(WEBKIT_IS_WEB_PAGE(webPage), 0);
     372
     373    return webPage->priv->uri.data();
     374}
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h

    r148592 r148666  
    6161webkit_web_page_get_id           (WebKitWebPage *web_page);
    6262
     63WEBKIT_API const gchar *
     64webkit_web_page_get_uri (WebKitWebPage *web_page);
     65
    6366G_END_DECLS
    6467
Note: See TracChangeset for help on using the changeset viewer.