[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

kov at webkit.org kov at webkit.org
Thu Apr 8 00:31:07 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit 71924f9683e9c03a5fa57afcc327ce386b1746dc
Author: kov at webkit.org <kov at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Dec 10 14:29:59 2009 +0000

            Reviewed by Xan Lopez.
    
            [GTK] Should provide an API to control the IconDatabase
            https://bugs.webkit.org/show_bug.cgi?id=32334
    
            First step towards a full IconDatabase API. This provides
            notification for pages with favicons, and lets clients handle
            them.
    
            * WebCoreSupport/FrameLoaderClientGtk.cpp:
            (WebKit::FrameLoaderClient::registerForIconNotification):
            (WebKit::FrameLoaderClient::dispatchDidReceiveIcon):
            * tests/resources/blank.ico: Added.
            * tests/testwebview.c: Added.
            (server_callback):
            (idle_quit_loop_cb):
            (icon_uri_changed_cb):
            (icon_loaded_cb):
            (test_webkit_web_view_icon_uri):
            (main):
            * webkit/webkitprivate.cpp:
            (closeIconDatabaseOnExit):
            (webkit_init):
            * webkit/webkitprivate.h:
            * webkit/webkitwebview.cpp:
            (webkit_web_view_get_property):
            (webkit_web_view_finalize):
            (webkit_web_view_class_init):
            (webkit_web_view_get_icon_uri):
            * webkit/webkitwebview.h:
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@51948 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/ChangeLog b/ChangeLog
index 38999c8..16d2dd9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-12-10  Gustavo Noronha Silva  <gustavo.noronha at collabora.co.uk>
+
+        Reviewed by Xan Lopez.
+
+        [GTK] Should provide an API to control the IconDatabase
+        https://bugs.webkit.org/show_bug.cgi?id=32334
+
+        Add test to make sure favicon reporting works.
+
+        * GNUmakefile.am:
+
 2009-12-09  Steve Block  <steveblock at google.com>
 
         Reviewed by Adam Barth.
diff --git a/GNUmakefile.am b/GNUmakefile.am
index d5fc693..3a0e398 100644
--- a/GNUmakefile.am
+++ b/GNUmakefile.am
@@ -595,6 +595,7 @@ TEST_PROGS += Programs/unittests/testhttpbackend \
 	Programs/unittests/testwebsettings \
 	Programs/unittests/testwebresource \
 	Programs/unittests/testwebdatasource \
+	Programs/unittests/testwebview \
 	Programs/unittests/testkeyevents
 
 # Add additional tests here
@@ -666,6 +667,11 @@ Programs_unittests_testwebdatasource_SOURCES = WebKit/gtk/tests/testwebdatasourc
 Programs_unittests_testwebdatasource_CFLAGS = $(webkit_tests_cflags)
 Programs_unittests_testwebdatasource_LDADD = $(webkit_tests_ldadd)
 
+Programs_unittests_testwebview_SOURCES = WebKit/gtk/tests/testwebview.c
+Programs_unittests_testwebview_CFLAGS = $(webkit_tests_cflags)
+Programs_unittests_testwebview_LDADD = $(webkit_tests_ldadd)
+Programs_unittests_testwebview_LDFLAGS = $(webkit_tests_ldflags)
+
 Programs_unittests_testhittestresult_SOURCES = WebKit/gtk/tests/testhittestresult.c
 Programs_unittests_testhittestresult_CFLAGS = $(webkit_tests_cflags)
 Programs_unittests_testhittestresult_LDADD = $(webkit_tests_ldadd)
diff --git a/WebKit/gtk/ChangeLog b/WebKit/gtk/ChangeLog
index dfac934..57bdbc3 100644
--- a/WebKit/gtk/ChangeLog
+++ b/WebKit/gtk/ChangeLog
@@ -1,3 +1,36 @@
+2009-12-10  Gustavo Noronha Silva  <gustavo.noronha at collabora.co.uk>
+
+        Reviewed by Xan Lopez.
+
+        [GTK] Should provide an API to control the IconDatabase
+        https://bugs.webkit.org/show_bug.cgi?id=32334
+
+        First step towards a full IconDatabase API. This provides
+        notification for pages with favicons, and lets clients handle
+        them.
+
+        * WebCoreSupport/FrameLoaderClientGtk.cpp:
+        (WebKit::FrameLoaderClient::registerForIconNotification):
+        (WebKit::FrameLoaderClient::dispatchDidReceiveIcon):
+        * tests/resources/blank.ico: Added.
+        * tests/testwebview.c: Added.
+        (server_callback):
+        (idle_quit_loop_cb):
+        (icon_uri_changed_cb):
+        (icon_loaded_cb):
+        (test_webkit_web_view_icon_uri):
+        (main):
+        * webkit/webkitprivate.cpp:
+        (closeIconDatabaseOnExit):
+        (webkit_init):
+        * webkit/webkitprivate.h:
+        * webkit/webkitwebview.cpp:
+        (webkit_web_view_get_property):
+        (webkit_web_view_finalize):
+        (webkit_web_view_class_init):
+        (webkit_web_view_get_icon_uri):
+        * webkit/webkitwebview.h:
+
 2009-12-08  Christian Dywan  <christian at twotoasts.de>
 
         Reviewed by Gustavo Noronha Silva.
diff --git a/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp b/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp
index fd135e4..bf68701 100644
--- a/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp
+++ b/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp
@@ -549,7 +549,7 @@ void FrameLoaderClient::didPerformFirstNavigation() const
 {
 }
 
-void FrameLoaderClient::registerForIconNotification(bool)
+void FrameLoaderClient::registerForIconNotification(bool shouldRegister)
 {
     notImplemented();
 }
@@ -702,7 +702,12 @@ void FrameLoaderClient::dispatchDidReceiveIcon()
 {
     WebKitWebView* webView = getViewFromFrame(m_frame);
 
-    g_signal_emit_by_name(webView, "icon-loaded", m_frame);
+    // Avoid reporting favicons for non-main frames.
+    if (m_frame != webkit_web_view_get_main_frame(webView))
+        return;
+
+    g_object_notify(G_OBJECT(webView), "icon-uri");
+    g_signal_emit_by_name(webView, "icon-loaded", webkit_web_view_get_icon_uri(webView));
 }
 
 void FrameLoaderClient::dispatchDidStartProvisionalLoad()
diff --git a/WebKit/gtk/tests/resources/blank.ico b/WebKit/gtk/tests/resources/blank.ico
new file mode 100644
index 0000000..ea848b9
Binary files /dev/null and b/WebKit/gtk/tests/resources/blank.ico differ
diff --git a/WebKit/gtk/tests/testwebview.c b/WebKit/gtk/tests/testwebview.c
new file mode 100644
index 0000000..e0921c0
--- /dev/null
+++ b/WebKit/gtk/tests/testwebview.c
@@ -0,0 +1,168 @@
+/*
+ * Copyright (C) 2008 Holger Hans Peter Freyther
+ * Copyright (C) 2009 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <glib.h>
+#include <glib/gstdio.h>
+#include <gtk/gtk.h>
+#include <webkit/webkit.h>
+
+#if GLIB_CHECK_VERSION(2, 16, 0) && GTK_CHECK_VERSION(2, 14, 0)
+
+GMainLoop* loop;
+SoupSession *session;
+char* base_uri;
+
+/* For real request testing */
+static void
+server_callback(SoupServer* server, SoupMessage* msg,
+                 const char* path, GHashTable* query,
+                 SoupClientContext* context, gpointer data)
+{
+    if (msg->method != SOUP_METHOD_GET) {
+        soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED);
+        return;
+    }
+
+    soup_message_set_status(msg, SOUP_STATUS_OK);
+
+    if (g_str_equal(path, "/favicon.ico")) {
+        char* contents;
+        gsize length;
+        GError* error = NULL;
+
+        g_file_get_contents("blank.ico", &contents, &length, &error);
+        g_assert(!error);
+
+        soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length);
+    } else {
+        char* contents = g_strdup("<html><body>test</body></html>");
+        soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, strlen(contents));
+    }
+
+    soup_message_body_complete(msg->response_body);
+}
+
+static gboolean idle_quit_loop_cb(gpointer data)
+{
+    g_main_loop_quit(loop);
+    return FALSE;
+}
+
+static void icon_uri_changed_cb(WebKitWebView* web_view, GParamSpec* pspec, gpointer data)
+{
+    gboolean* been_here = (gboolean*)data;
+    char* expected_uri;
+
+    g_assert_cmpstr(g_param_spec_get_name(pspec), ==, "icon-uri");
+
+    expected_uri = g_strdup_printf("%sfavicon.ico", base_uri);
+    g_assert_cmpstr(webkit_web_view_get_icon_uri(web_view), ==, expected_uri);
+    g_free(expected_uri);
+
+    *been_here = TRUE;
+}
+
+static void icon_loaded_cb(WebKitWebView* web_view, char* icon_uri, gpointer data)
+{
+    gboolean* been_here = (gboolean*)data;
+    char* expected_uri = g_strdup_printf("%sfavicon.ico", base_uri);
+    g_assert_cmpstr(icon_uri, ==, expected_uri);
+    g_free(expected_uri);
+
+    g_assert_cmpstr(icon_uri, ==, webkit_web_view_get_icon_uri(web_view));
+
+    *been_here = TRUE;
+}
+
+static void test_webkit_web_view_icon_uri()
+{
+    gboolean been_to_uri_changed = FALSE;
+    gboolean been_to_icon_loaded = FALSE;
+    WebKitWebView* view = WEBKIT_WEB_VIEW(webkit_web_view_new());
+    g_object_ref_sink(G_OBJECT(view));
+
+    loop = g_main_loop_new(NULL, TRUE);
+
+    g_object_connect(G_OBJECT(view),
+                     "signal::load-finished", idle_quit_loop_cb, NULL,
+                     "signal::notify::icon-uri", icon_uri_changed_cb, &been_to_uri_changed,
+                     "signal::icon-loaded", icon_loaded_cb, &been_to_icon_loaded,
+                     NULL);
+
+    webkit_web_view_load_uri(view, base_uri);
+
+    g_main_loop_run(loop);
+
+    g_assert(been_to_uri_changed);
+    g_assert(been_to_icon_loaded);
+
+    g_object_unref(view);
+}
+
+int main(int argc, char** argv)
+{
+    SoupServer* server;
+    SoupURI* soup_uri;
+    char* test_dir;
+    char* resources_dir;
+
+    g_thread_init(NULL);
+    gtk_test_init(&argc, &argv, NULL);
+
+    /* Hopefully make test independent of the path it's called from. */
+    test_dir = g_path_get_dirname(argv[0]);
+    resources_dir = g_build_path(G_DIR_SEPARATOR_S, test_dir,
+                                 "..", "..", "..", "..",
+                                 "WebKit", "gtk", "tests", "resources",
+                                 NULL);
+    g_free(test_dir);
+
+    g_chdir(resources_dir);
+    g_free(resources_dir);
+
+    server = soup_server_new(SOUP_SERVER_PORT, 0, NULL);
+    soup_server_run_async(server);
+
+    soup_server_add_handler(server, NULL, server_callback, NULL, NULL);
+
+    soup_uri = soup_uri_new("http://127.0.0.1/");
+    soup_uri_set_port(soup_uri, soup_server_get_port(server));
+
+    base_uri = soup_uri_to_string(soup_uri, FALSE);
+    soup_uri_free(soup_uri);
+
+    g_test_bug_base("https://bugs.webkit.org/");
+    g_test_add_func("/webkit/webview/icon-uri", test_webkit_web_view_icon_uri);
+
+    return g_test_run ();
+}
+
+#else
+int main(int argc, char** argv)
+{
+    g_critical("You will need at least glib-2.16.0 and gtk-2.14.0 to run the unit tests. Doing nothing now.");
+    return 0;
+}
+
+#endif
diff --git a/WebKit/gtk/webkit/webkitprivate.cpp b/WebKit/gtk/webkit/webkitprivate.cpp
index 0870d90..c80160c 100644
--- a/WebKit/gtk/webkit/webkitprivate.cpp
+++ b/WebKit/gtk/webkit/webkitprivate.cpp
@@ -28,6 +28,7 @@
 #include "FrameLoader.h"
 #include "FrameLoaderClientGtk.h"
 #include "HitTestResult.h"
+#include "IconDatabase.h"
 #include <libintl.h>
 #include "Logging.h"
 #include "PageCache.h"
@@ -40,6 +41,7 @@
 #include "ResourceResponse.h"
 #include <runtime/InitializeThreading.h>
 #include "SecurityOrigin.h"
+#include <stdlib.h>
 #include "webkitnetworkresponse.h"
 
 #if ENABLE(DATABASE)
@@ -225,6 +227,11 @@ static GtkWidget* currentToplevelCallback(WebKitSoupAuthDialog* feature, SoupMes
         return NULL;
 }
 
+static void closeIconDatabaseOnExit()
+{
+    iconDatabase()->close();
+}
+
 void webkit_init()
 {
     static bool isInitialized = false;
@@ -256,6 +263,13 @@ void webkit_init()
 
     Pasteboard::generalPasteboard()->setHelper(WebKit::pasteboardHelperInstance());
 
+    iconDatabase()->setEnabled(true);
+
+    GOwnPtr<gchar> iconDatabasePath(g_build_filename(g_get_user_data_dir(), "webkit", "icondatabase", NULL));
+    iconDatabase()->open(iconDatabasePath.get());
+
+    atexit(closeIconDatabaseOnExit);
+
     SoupSession* session = webkit_get_default_session();
 
     SoupSessionFeature* authDialog = static_cast<SoupSessionFeature*>(g_object_new(WEBKIT_TYPE_SOUP_AUTH_DIALOG, NULL));
diff --git a/WebKit/gtk/webkit/webkitprivate.h b/WebKit/gtk/webkit/webkitprivate.h
index bd95896..e17e79e 100644
--- a/WebKit/gtk/webkit/webkitprivate.h
+++ b/WebKit/gtk/webkit/webkitprivate.h
@@ -142,6 +142,8 @@ extern "C" {
         char* encoding;
         char* customEncoding;
 
+        char* iconURI;
+
         gboolean disposing;
         gboolean usePrimaryForPaste;
 
diff --git a/WebKit/gtk/webkit/webkitwebview.cpp b/WebKit/gtk/webkit/webkitwebview.cpp
index 2c55d09..bebd01a 100644
--- a/WebKit/gtk/webkit/webkitwebview.cpp
+++ b/WebKit/gtk/webkit/webkitwebview.cpp
@@ -59,6 +59,7 @@
 #include "HitTestResult.h"
 #include <glib/gi18n-lib.h>
 #include "GraphicsContext.h"
+#include "IconDatabase.h"
 #include "InspectorClientGtk.h"
 #include "FrameLoader.h"
 #include "FrameView.h"
@@ -133,7 +134,7 @@ enum {
     HOVERING_OVER_LINK,
     POPULATE_POPUP,
     STATUS_BAR_TEXT_CHANGED,
-    ICOND_LOADED,
+    ICON_LOADED,
     SELECTION_CHANGED,
     CONSOLE_MESSAGE,
     SCRIPT_ALERT,
@@ -172,7 +173,8 @@ enum {
     PROP_LOAD_STATUS,
     PROP_PROGRESS,
     PROP_ENCODING,
-    PROP_CUSTOM_ENCODING
+    PROP_CUSTOM_ENCODING,
+    PROP_ICON_URI
 };
 
 static guint webkit_web_view_signals[LAST_SIGNAL] = { 0, };
@@ -354,6 +356,9 @@ static void webkit_web_view_get_property(GObject* object, guint prop_id, GValue*
     case PROP_PROGRESS:
         g_value_set_double(value, webkit_web_view_get_progress(webView));
         break;
+    case PROP_ICON_URI:
+        g_value_set_string(value, webkit_web_view_get_icon_uri(webView));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
     }
@@ -1026,6 +1031,7 @@ static void webkit_web_view_finalize(GObject* object)
     g_free(priv->mainResourceIdentifier);
     g_free(priv->encoding);
     g_free(priv->customEncoding);
+    g_free(priv->iconURI);
 
     G_OBJECT_CLASS(webkit_web_view_parent_class)->finalize(object);
 }
@@ -1729,14 +1735,24 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)
             G_TYPE_NONE, 1,
             G_TYPE_STRING);
 
-    webkit_web_view_signals[ICOND_LOADED] = g_signal_new("icon-loaded",
+    /**
+     * WebKitWebView::icon-loaded:
+     * @web_view: the object on which the signal is emitted
+     * @icon_uri: the URI for the icon
+     *
+     * This signal is emitted when the main frame has got a favicon.
+     *
+     * Since: 1.1.18
+     */
+    webkit_web_view_signals[ICON_LOADED] = g_signal_new("icon-loaded",
             G_TYPE_FROM_CLASS(webViewClass),
             (GSignalFlags)G_SIGNAL_RUN_LAST,
             0,
             NULL,
             NULL,
-            g_cclosure_marshal_VOID__VOID,
-            G_TYPE_NONE, 0);
+            g_cclosure_marshal_VOID__STRING,
+            G_TYPE_NONE, 1,
+            G_TYPE_STRING);
 
     webkit_web_view_signals[SELECTION_CHANGED] = g_signal_new("selection-changed",
             G_TYPE_FROM_CLASS(webViewClass),
@@ -2377,6 +2393,20 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)
                                                         0.0, 1.0, 1.0,
                                                         WEBKIT_PARAM_READABLE));
 
+    /**
+     * WebKitWebView:icon-uri:
+     *
+     * The URI for the favicon for the #WebKitWebView.
+     *
+     * Since: 1.1.18
+     */
+    g_object_class_install_property(objectClass, PROP_ICON_URI,
+                                    g_param_spec_string("icon-uri",
+                                                        _("Icon URI"),
+                                                        _("The URI for the favicon for the #WebKitWebView."),
+                                                        NULL,
+                                                        WEBKIT_PARAM_READABLE));
+
     g_type_class_add_private(webViewClass, sizeof(WebKitWebViewPrivate));
 }
 
@@ -3965,3 +3995,27 @@ WebKitHitTestResult* webkit_web_view_get_hit_test_result(WebKitWebView* webView,
 
     return kit(mev.hitTestResult());
 }
+
+/**
+ * webkit_web_view_get_icon_uri:
+ * @web_view: the #WebKitWebView object
+ *
+ * Obtains the URI for the favicon for the given #WebKitWebView, or
+ * %NULL if there is none.
+ *
+ * Return value: the URI for the favicon, or %NULL
+ *
+ * Since: 1.1.18
+ */
+G_CONST_RETURN gchar* webkit_web_view_get_icon_uri(WebKitWebView* webView)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
+
+    Page* corePage = core(webView);
+    String iconURL = iconDatabase()->iconURLForPageURL(corePage->mainFrame()->loader()->url().prettyURL());
+
+    WebKitWebViewPrivate* priv = webView->priv;
+    g_free(priv->iconURI);
+    priv->iconURI = g_strdup(iconURL.utf8().data());
+    return priv->iconURI;
+}
diff --git a/WebKit/gtk/webkit/webkitwebview.h b/WebKit/gtk/webkit/webkitwebview.h
index 1297695..8dd7f39 100644
--- a/WebKit/gtk/webkit/webkitwebview.h
+++ b/WebKit/gtk/webkit/webkitwebview.h
@@ -366,6 +366,10 @@ webkit_web_view_get_view_source_mode            (WebKitWebView        *web_view)
 WEBKIT_API WebKitHitTestResult*
 webkit_web_view_get_hit_test_result             (WebKitWebView        *webView,
                                                  GdkEventButton       *event);
+
+WEBKIT_API G_CONST_RETURN gchar *
+webkit_web_view_get_icon_uri                    (WebKitWebView        *webView);
+
 G_END_DECLS
 
 #endif

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list