| Differences between
and this patch
- a/Source/WebKit2/ChangeLog +104 lines
Lines 1-3 a/Source/WebKit2/ChangeLog_sec1
1
2012-09-27  Mario Sanchez Prada  <msanchez@igalia.com>
2
3
        [WK2][GTK] Implement new Favicons API
4
        https://bugs.webkit.org/show_bug.cgi?id=96476
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        New object wrapping the internal IconDatabase from WebCore,
9
        providing a simple asynchronous API to retrieve the favicon
10
        associated to a page URL, and two more functions to simple query
11
        the internal database for the URI of the icon associated to a
12
        page, if any, and to clear the state of the internal database.
13
14
        * UIProcess/API/gtk/WebKitFaviconDatabase.cpp: Added.
15
        (_WebKitFaviconDatabasePrivate):
16
        (webkit_favicon_database_init):
17
        (webkitFaviconDatabaseFinalize):
18
        (webkit_favicon_database_class_init):
19
        (GetFaviconSurfaceAsyncData): New structure used to pass data
20
        across the asynchronous implementation of get_favicon().
21
        (GetFaviconSurfaceAsyncData::~GetFaviconSurfaceAsyncData):
22
        Disconnects the cancellable if needed.
23
        (getIconSurfaceSynchronously): Synchronously returns a pointer to
24
        the cairo_surface with the icon's data, if available.
25
        (deletePendingIconRequests): Removes the full list of
26
        icon requests for a page URL.
27
        (processPendingIconsForURI): Process any icon request that
28
        might be still pending.
29
        (iconDataReadyForPageURLCallback): Called from WebIconDatabase
30
        when new data is ready for a favicon.
31
        (webkitFaviconDatabaseCreate): Create the WebKitFaviconDatabase
32
        object and initializes the API client for WKIconDatabaseClient.
33
        (getOrCreatePendingIconRequests): Returns (if available) or
34
        creates a new icon request, to be appended to the list of requests
35
        for the same page URL.
36
        (getIconSurfaceCancelled): Handle the case of a request being
37
        cancelled. Must happen on the main thread.
38
        (getIconSurfaceCancelledCallback): Callback used with
39
        g_cancellable_connect(), which ensure getIconSurfaceCancelled() is
40
        called from the main thread.
41
        (setErrorForAsyncResult): Helper to set errors in the result.
42
        (webkit_favicon_database_error_quark): New function, providint the
43
        new error domain for errors of type WebKitFaviconDatabaseError.
44
        (webkit_favicon_database_get_favicon): New API function, providing
45
        an asynchronous mechanism to query the favicon for a page URL.
46
        (webkit_favicon_database_get_favicon_finish): New API function to
47
        finish the asyncrhonous request started with get_favicon().
48
        (webkit_favicon_database_get_favicon_uri): New API function
49
        to easily retrieve, if available, the URI of a favicon.
50
        (webkit_favicon_database_clear): New API function to clear the
51
        state of the internal icon database.
52
        * UIProcess/API/gtk/WebKitFaviconDatabase.h: Added.
53
        (_WebKitFaviconDatabase):
54
        (_WebKitFaviconDatabaseClass):
55
        * UIProcess/API/gtk/WebKitFaviconDatabasePrivate.h: Added to
56
        internally expose webkitFaviconDatabaseCreate() to WebKitWebContext.
57
        * UIProcess/API/gtk/WebKitPrivate.h: Import WebKit2/WKIconDatabase.h.
58
        * GNUmakefile.list.am: Added new files.
59
60
        Add a new getter in WebIconDatabase for m_urlImportCompleted.
61
62
        * UIProcess/WebIconDatabase.cpp:
63
        (WebKit::WebIconDatabase::isUrlImportCompleted): Added this simple
64
        getter to allow knowing from WebKitFaviconDatabase whether the
65
        initial import has finished, needed for making some decisions.
66
        (WebKit):
67
        * UIProcess/WebIconDatabase.h:
68
        (WebIconDatabase):
69
70
        New API in WebKitWebContext to allow obtaining a valid instance of
71
        WebKitFaviconDatabase and to set/get the local path to be used.
72
73
        * UIProcess/API/gtk/WebKitWebContext.cpp:
74
        (_WebKitWebContextPrivate):
75
        (webkit_web_context_set_favicon_database_path): New API to allow
76
        setting a path for the icon database, other than the default one.
77
        (webkit_web_context_get_favicon_database_path): New API to
78
        retrieve the path for the icon database currently in use.
79
        (webkit_web_context_get_favicon_database): New API to get a valid
80
        and properly initialized instance of WebKitFaviconDatabase.
81
        * UIProcess/API/gtk/WebKitWebContext.h:
82
83
        Make sure we have a default path set for the icon database.
84
85
        * UIProcess/gtk/WebContextGtk.cpp:
86
        (WebKit::WebContext::platformDefaultIconDatabasePath): Return the
87
        default path to be used for the icon database.
88
89
        Add unit tests for checking this new API.
90
91
        * UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp: Added.
92
        (serverCallback): Callback for the test server.
93
        (testSetDirectory): New unit test, checks the ability to set and
94
        get a specific directory path for the icon database.
95
        (testClearDatabase): New unit test, checks the ability to clear
96
        the data in the icon database.
97
        (testGetFavicon): New unit test, checks the ability to get a
98
        favicon from the icon database in different situations.
99
        (testGetFaviconURI): New unit test, checks the ability to retrieve
100
        the URI for the favicon, if any, associated to a web page.
101
        (deleteDatabaseFiles): Helper function to remove temporary files.
102
        (beforeAll): Initialize the test server and add the unit tests.
103
        (afterAll): Delete the test server and clean up.
104
1
2012-09-27  Jinwoo Song  <jinwoo7.song@samsung.com>
105
2012-09-27  Jinwoo Song  <jinwoo7.song@samsung.com>
2
106
3
        [EFL][WK2] Add callback functions for WKPageFindClient
107
        [EFL][WK2] Add callback functions for WKPageFindClient
- a/Source/WebKit2/GNUmakefile.list.am +4 lines
Lines 104-109 webkit2gtk_h_api += \ a/Source/WebKit2/GNUmakefile.list.am_sec1
104
	$(WebKit2)/UIProcess/API/gtk/WebKitDownload.h \
104
	$(WebKit2)/UIProcess/API/gtk/WebKitDownload.h \
105
	$(WebKit2)/UIProcess/API/gtk/WebKitEditingCommands.h \
105
	$(WebKit2)/UIProcess/API/gtk/WebKitEditingCommands.h \
106
	$(WebKit2)/UIProcess/API/gtk/WebKitError.h \
106
	$(WebKit2)/UIProcess/API/gtk/WebKitError.h \
107
	$(WebKit2)/UIProcess/API/gtk/WebKitFaviconDatabase.h \
107
	$(WebKit2)/UIProcess/API/gtk/WebKitFileChooserRequest.h \
108
	$(WebKit2)/UIProcess/API/gtk/WebKitFileChooserRequest.h \
108
	$(WebKit2)/UIProcess/API/gtk/WebKitFindController.h \
109
	$(WebKit2)/UIProcess/API/gtk/WebKitFindController.h \
109
	$(WebKit2)/UIProcess/API/gtk/WebKitFormSubmissionRequest.h \
110
	$(WebKit2)/UIProcess/API/gtk/WebKitFormSubmissionRequest.h \
Lines 643-648 webkit2_sources += \ a/Source/WebKit2/GNUmakefile.list.am_sec2
643
	Source/WebKit2/UIProcess/API/gtk/WebKitEditingCommands.h \
644
	Source/WebKit2/UIProcess/API/gtk/WebKitEditingCommands.h \
644
	Source/WebKit2/UIProcess/API/gtk/WebKitError.h \
645
	Source/WebKit2/UIProcess/API/gtk/WebKitError.h \
645
	Source/WebKit2/UIProcess/API/gtk/WebKitError.cpp \
646
	Source/WebKit2/UIProcess/API/gtk/WebKitError.cpp \
647
	Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabase.h \
648
	Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabase.cpp \
649
	Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabasePrivate.h \
646
	Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequest.cpp \
650
	Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequest.cpp \
647
	Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequest.h \
651
	Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequest.h \
648
	Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequestPrivate.h \
652
	Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequestPrivate.h \
- a/Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabase.cpp +409 lines
Line 0 a/Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabase.cpp_sec1
1
/*
2
 * Copyright (C) 2012 Igalia S.L.
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2,1 of the License, or (at your option) any later version.
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Library General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Library General Public License
15
 * along with this library; see the file COPYING.LIB.  If not, write to
16
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 * Boston, MA 02110-1301, USA.
18
 */
19
20
#include "config.h"
21
#include "WebKitFaviconDatabase.h"
22
23
#include "WebIconDatabase.h"
24
#include "WebKitFaviconDatabasePrivate.h"
25
#include "WebKitPrivate.h"
26
#include "WebKitWebContext.h"
27
#include <WebCore/FileSystem.h>
28
#include <WebCore/Image.h>
29
#include <WebCore/IntSize.h>
30
#include <WebCore/RefPtrCairo.h>
31
#include <glib/gi18n-lib.h>
32
#include <wtf/MainThread.h>
33
#include <wtf/gobject/GOwnPtr.h>
34
#include <wtf/gobject/GRefPtr.h>
35
#include <wtf/text/CString.h>
36
37
using namespace WebKit;
38
39
enum {
40
    ICON_READY,
41
42
    LAST_SIGNAL
43
};
44
45
static guint signals[LAST_SIGNAL] = { 0, };
46
47
typedef Vector<GRefPtr<GSimpleAsyncResult> > PendingIconRequestVector;
48
typedef HashMap<String, PendingIconRequestVector*> PendingIconRequestMap;
49
50
struct _WebKitFaviconDatabasePrivate {
51
    RefPtr<WebIconDatabase> iconDatabase;
52
    PendingIconRequestMap pendingIconRequests;
53
};
54
55
G_DEFINE_TYPE(WebKitFaviconDatabase, webkit_favicon_database, G_TYPE_OBJECT)
56
57
static void closeIconDatabaseIfNeeded(WebKitFaviconDatabase* database)
58
{
59
    WebKitFaviconDatabasePrivate* priv = database->priv;
60
    if (priv->iconDatabase->isOpen())
61
        priv->iconDatabase->close();
62
}
63
64
static void webkit_favicon_database_init(WebKitFaviconDatabase* manager)
65
{
66
    WebKitFaviconDatabasePrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(manager, WEBKIT_TYPE_FAVICON_DATABASE, WebKitFaviconDatabasePrivate);
67
    manager->priv = priv;
68
    new (priv) WebKitFaviconDatabasePrivate();
69
}
70
71
static void webkitFaviconDatabaseFinalize(GObject* object)
72
{
73
    WebKitFaviconDatabase* database = WEBKIT_FAVICON_DATABASE(object);
74
    WebKitFaviconDatabasePrivate* priv = database->priv;
75
76
    closeIconDatabaseIfNeeded(database);
77
    priv->~WebKitFaviconDatabasePrivate();
78
79
    G_OBJECT_CLASS(webkit_favicon_database_parent_class)->finalize(object);
80
}
81
82
static void webkit_favicon_database_class_init(WebKitFaviconDatabaseClass* faviconDatabaseClass)
83
{
84
    GObjectClass* gObjectClass = G_OBJECT_CLASS(faviconDatabaseClass);
85
    gObjectClass->finalize = webkitFaviconDatabaseFinalize;
86
87
    /**
88
     * WebKitFaviconDatabase::favicon-ready:
89
     * @database: the object on which the signal is emitted
90
     * @page_uri: the URI of the Web page containing the icon.
91
     *
92
     * This signal gets emitted when the favicon of @page_uri is
93
     * ready. This means that the favicon's data is ready to be used
94
     * by the application, either because it has been loaded from the
95
     * network, if it's the first time it gets retrieved, or because
96
     * it has been already imported from the icon database.
97
     */
98
    signals[ICON_READY] =
99
        g_signal_new("favicon-ready",
100
                     G_TYPE_FROM_CLASS(faviconDatabaseClass),
101
                     G_SIGNAL_RUN_LAST,
102
                     0, 0, 0,
103
                     g_cclosure_marshal_VOID__STRING,
104
                     G_TYPE_NONE, 1,
105
                     G_TYPE_STRING);
106
107
    g_type_class_add_private(faviconDatabaseClass, sizeof(WebKitFaviconDatabasePrivate));
108
}
109
110
struct GetFaviconSurfaceAsyncData {
111
    GRefPtr<WebKitFaviconDatabase> faviconDatabase;
112
    String pageURL;
113
    RefPtr<cairo_surface_t> icon;
114
    GRefPtr<GCancellable> cancellable;
115
    unsigned long cancelledId;
116
117
    ~GetFaviconSurfaceAsyncData()
118
    {
119
        if (cancelledId)
120
            g_cancellable_disconnect(cancellable.get(), cancelledId);
121
    }
122
};
123
WEBKIT_DEFINE_ASYNC_DATA_STRUCT(GetFaviconSurfaceAsyncData)
124
125
static cairo_surface_t* getIconSurfaceSynchronously(WebKitFaviconDatabase* database, const String& pageURL)
126
{
127
    ASSERT(isMainThread());
128
129
    WebKitFaviconDatabasePrivate* priv = database->priv;
130
131
    // The exact size we pass is irrelevant to the iconDatabase code.
132
    // We must pass something greater than 0x0 to get an icon.
133
    WebCore::NativeImagePtr icon = priv->iconDatabase->nativeImageForPageURL(pageURL, WebCore::IntSize(1, 1));
134
    if (!icon)
135
        return 0;
136
137
    return icon ? icon->surface() : 0;
138
}
139
140
static void deletePendingIconRequests(WebKitFaviconDatabase* database, PendingIconRequestVector* requests, const String& pageURL)
141
{
142
    database->priv->pendingIconRequests.remove(pageURL);
143
    delete requests;
144
}
145
146
static void processPendingIconsForURI(WebKitFaviconDatabase* database, const String& pageURL)
147
{
148
    PendingIconRequestVector* icons = database->priv->pendingIconRequests.get(pageURL);
149
    if (!icons)
150
        return;
151
152
    for (size_t i = 0; i < icons->size(); ++i) {
153
        GSimpleAsyncResult* result = icons->at(i).get();
154
        GetFaviconSurfaceAsyncData* data = static_cast<GetFaviconSurfaceAsyncData*>(g_simple_async_result_get_op_res_gpointer(result));
155
        data->icon = getIconSurfaceSynchronously(database, pageURL);
156
157
        g_simple_async_result_complete(result);
158
    }
159
    deletePendingIconRequests(database, icons, pageURL);
160
}
161
162
static void iconDataReadyForPageURLCallback(WKIconDatabaseRef wkIconDatabase, WKURLRef wkPageURL, const void* clientInfo)
163
{
164
    ASSERT(isMainThread());
165
166
    WebKitFaviconDatabase* database = WEBKIT_FAVICON_DATABASE(clientInfo);
167
    String pageURLString = toImpl(wkPageURL)->string();
168
169
    database->priv->iconDatabase->retainIconForPageURL(pageURLString);
170
    processPendingIconsForURI(database, pageURLString);
171
    g_signal_emit(database, signals[ICON_READY], 0, pageURLString.utf8().data());
172
}
173
174
WebKitFaviconDatabase* webkitFaviconDatabaseCreate(WebIconDatabase* iconDatabase)
175
{
176
    WebKitFaviconDatabase* faviconDatabase = WEBKIT_FAVICON_DATABASE(g_object_new(WEBKIT_TYPE_FAVICON_DATABASE, NULL));
177
    faviconDatabase->priv->iconDatabase = iconDatabase;
178
179
    WKIconDatabaseClient wkIconDatabaseClient = {
180
        kWKIconDatabaseClientCurrentVersion,
181
        faviconDatabase, // clientInfo
182
        0, // didChangeIconForPageURLCallback
183
        0, // didRemoveAllIconsCallback
184
        iconDataReadyForPageURLCallback,
185
    };
186
    WKIconDatabaseSetIconDatabaseClient(toAPI(iconDatabase), &wkIconDatabaseClient);
187
    return faviconDatabase;
188
}
189
190
static PendingIconRequestVector* getOrCreatePendingIconRequests(WebKitFaviconDatabase* database, const String& pageURL)
191
{
192
    PendingIconRequestVector* icons = database->priv->pendingIconRequests.get(pageURL);
193
    if (!icons) {
194
        icons = new PendingIconRequestVector;
195
        database->priv->pendingIconRequests.set(pageURL, icons);
196
    }
197
198
    return icons;
199
}
200
201
static void getIconSurfaceCancelled(void* userData)
202
{
203
    GSimpleAsyncResult* result = static_cast<GSimpleAsyncResult*>(userData);
204
205
    // Get the data we might need and complete the request.
206
    GetFaviconSurfaceAsyncData* data = static_cast<GetFaviconSurfaceAsyncData*>(g_simple_async_result_get_op_res_gpointer(result));
207
    WebKitFaviconDatabase* database = data->faviconDatabase.get();
208
    String pageURL = data->pageURL;
209
210
    g_simple_async_result_complete(result);
211
212
    PendingIconRequestVector* icons = database->priv->pendingIconRequests.get(pageURL);
213
    if (!icons)
214
        return;
215
216
    size_t itemIndex = icons->find(result);
217
    if (itemIndex != notFound)
218
        icons->remove(itemIndex);
219
    if (icons->isEmpty())
220
        deletePendingIconRequests(database, icons, pageURL);
221
}
222
223
static void getIconSurfaceCancelledCallback(GCancellable* cancellable, GSimpleAsyncResult* result)
224
{
225
    // Handle cancelled in a in idle since it might be called from any thread.
226
    callOnMainThread(getIconSurfaceCancelled, result);
227
}
228
229
static void setErrorForAsyncResult(GSimpleAsyncResult* result, WebKitFaviconDatabaseError error, const String& pageURL = String())
230
{
231
    ASSERT(result);
232
233
    switch (error) {
234
    case WEBKIT_FAVICON_DATABASE_ERROR_NOT_INITIALIZED:
235
        g_simple_async_result_set_error(result, WEBKIT_FAVICON_DATABASE_ERROR, error, _("Favicons database not initialized yet"));
236
        break;
237
238
    case WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_NOT_FOUND:
239
        g_simple_async_result_set_error(result, WEBKIT_FAVICON_DATABASE_ERROR, error, _("Page %s does not have a favicon"), pageURL.utf8().data());
240
        break;
241
242
    default:
243
        ASSERT_NOT_REACHED();
244
    }
245
}
246
247
GQuark webkit_favicon_database_error_quark(void)
248
{
249
    return g_quark_from_static_string("WebKitFaviconDatabaseError");
250
}
251
252
/**
253
 * webkit_favicon_database_get_favicon:
254
 * @database: a #WebKitFaviconDatabase
255
 * @page_uri: URI of the page for which we want to retrieve the favicon
256
 * @cancellable: (allow-none): A #GCancellable or %NULL.
257
 * @callback: (scope async): A #GAsyncReadyCallback to call when the request is
258
 *            satisfied or %NULL if you don't care about the result.
259
 * @user_data: (closure): The data to pass to @callback.
260
 *
261
 * Asynchronously obtains a #cairo_surface_t of the favicon for the
262
 * given page URI. It returns the cached icon if it's in the database
263
 * asynchronously waiting for the icon to be read from the database.
264
 *
265
 * This is an asynchronous method. When the operation is finished, callback will
266
 * be invoked. You can then call webkit_favicon_database_get_favicon_finish()
267
 * to get the result of the operation.
268
 */
269
void webkit_favicon_database_get_favicon(WebKitFaviconDatabase* database, const gchar* pageURI, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData)
270
{
271
    g_return_if_fail(WEBKIT_IS_FAVICON_DATABASE(database));
272
    g_return_if_fail(pageURI);
273
274
    GRefPtr<GSimpleAsyncResult> result = adoptGRef(g_simple_async_result_new(G_OBJECT(database), callback, userData, reinterpret_cast<gpointer>(webkit_favicon_database_get_favicon)));
275
    GetFaviconSurfaceAsyncData* data = createGetFaviconSurfaceAsyncData();
276
    g_simple_async_result_set_op_res_gpointer(result.get(), data, reinterpret_cast<GDestroyNotify>(destroyGetFaviconSurfaceAsyncData));
277
    data->faviconDatabase = database;
278
    data->pageURL = String::fromUTF8(pageURI);
279
    data->cancellable = cancellable;
280
    if (cancellable) {
281
        data->cancelledId =
282
            g_cancellable_connect(cancellable, G_CALLBACK(getIconSurfaceCancelledCallback), result.get(), 0);
283
        g_simple_async_result_set_check_cancellable(result.get(), cancellable);
284
    }
285
286
    WebKitFaviconDatabasePrivate* priv = database->priv;
287
    WebIconDatabase* iconDatabaseImpl = priv->iconDatabase.get();
288
    if (!iconDatabaseImpl->isOpen()) {
289
        setErrorForAsyncResult(result.get(), WEBKIT_FAVICON_DATABASE_ERROR_NOT_INITIALIZED);
290
        g_simple_async_result_complete_in_idle(result.get());
291
        return;
292
    }
293
294
    if (data->pageURL.isEmpty() || data->pageURL.startsWith("about:")) {
295
        setErrorForAsyncResult(result.get(), WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_NOT_FOUND, data->pageURL);
296
        g_simple_async_result_complete_in_idle(result.get());
297
        return;
298
    }
299
300
    // We ask for the icon directly. If we don't get the icon data now,
301
    // we'll be notified later (even if the database is still importing icons).
302
    data->icon = getIconSurfaceSynchronously(database, data->pageURL);
303
304
    // If there's not a valid icon, but there's an iconURL registered,
305
    // or it's still not registered but the import process hasn't
306
    // finished yet, we need to wait for iconDataReadyForPage to be
307
    // called before making and informed decision.
308
    String iconURLForPageURL;
309
    iconDatabaseImpl->synchronousIconURLForPageURL(data->pageURL, iconURLForPageURL);
310
    if (!data->icon && (!iconURLForPageURL.isEmpty() || !iconDatabaseImpl->isUrlImportCompleted())) {
311
        PendingIconRequestVector* icons = getOrCreatePendingIconRequests(database, data->pageURL);
312
        ASSERT(icons);
313
        icons->append(result);
314
        return;
315
    }
316
317
    // If we reached this point without a valid icon, which means that
318
    // there's no iconURL registered for this pageURI and the
319
    // urlImport process has already finished, or do have a valid icon
320
    // but it's an empty image, that means there's no favicon.
321
    if (!data->icon || !cairo_image_surface_get_data(data->icon.get()))
322
        setErrorForAsyncResult(result.get(), WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_NOT_FOUND, data->pageURL);
323
324
    // Complete the asynchronous process;
325
    g_simple_async_result_complete_in_idle(result.get());
326
}
327
328
/**
329
 * webkit_favicon_database_get_favicon_finish:
330
 * @database: a #WebKitFaviconDatabase
331
 * @result: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to webkit_favicon_database_get_favicon()
332
 * @error: (allow-none): Return location for error or %NULL.
333
 *
334
 * Finishes an operation started with webkit_favicon_database_get_favicon().
335
 *
336
 * Returns: (transfer full): a new reference to a #cairo_surface_t, or
337
 * %NULL in case of error.
338
 */
339
cairo_surface_t* webkit_favicon_database_get_favicon_finish(WebKitFaviconDatabase* database, GAsyncResult* result, GError** error)
340
{
341
    GSimpleAsyncResult* simpleResult = G_SIMPLE_ASYNC_RESULT(result);
342
    g_warn_if_fail(g_simple_async_result_get_source_tag(simpleResult) == webkit_favicon_database_get_favicon);
343
344
    if (g_simple_async_result_propagate_error(simpleResult, error))
345
        return 0;
346
347
    GetFaviconSurfaceAsyncData* data = static_cast<GetFaviconSurfaceAsyncData*>(g_simple_async_result_get_op_res_gpointer(simpleResult));
348
    ASSERT(data);
349
350
    // Return the icon is we can get it already.
351
    if (data->icon)
352
        return cairo_surface_reference(data->icon.get());
353
354
    // If the icon is not available at this stage, investigate why
355
    // and come up with a descriptive, and hopefully helpful, error.
356
    String iconURLForPageURL;
357
    database->priv->iconDatabase->synchronousIconURLForPageURL(data->pageURL, iconURLForPageURL);
358
359
    if (iconURLForPageURL.isEmpty()) {
360
        // If there's no icon URL in the database at this point, we can
361
        // conclude there's no favicon at all for the requested page URL.
362
        g_set_error(error, WEBKIT_FAVICON_DATABASE_ERROR, WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_NOT_FOUND,
363
                    _("Page %s does not have a favicon"), data->pageURL.utf8().data());
364
    } else {
365
        // If the icon URL is known it obviously means that the icon data
366
        // hasn't been retrieved yet, so report that it's 'unknown'.
367
        g_set_error(error, WEBKIT_FAVICON_DATABASE_ERROR, WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_UNKNOWN,
368
                    _("Unknown favicon for page %s"), data->pageURL.utf8().data());
369
    }
370
371
    return 0;
372
}
373
374
/**
375
 * webkit_favicon_database_get_favicon_uri:
376
 * @database: a #WebKitFaviconDatabase
377
 * @page_uri: URI of the page containing the icon
378
 *
379
 * Obtains the URI of the favicon for the given @page_uri.
380
 *
381
 * Returns: a newly allocated URI for the favicon, or %NULL if the
382
 * database doesn't have a favicon for @page_uri.
383
 */
384
gchar* webkit_favicon_database_get_favicon_uri(WebKitFaviconDatabase* database, const gchar* pageURL)
385
{
386
    g_return_val_if_fail(WEBKIT_IS_FAVICON_DATABASE(database), 0);
387
    g_return_val_if_fail(pageURL, 0);
388
    ASSERT(isMainThread());
389
390
    String iconURLForPageURL;
391
    database->priv->iconDatabase->synchronousIconURLForPageURL(String::fromUTF8(pageURL), iconURLForPageURL);
392
    if (iconURLForPageURL.isEmpty())
393
        return 0;
394
395
    return g_strdup(iconURLForPageURL.utf8().data());
396
}
397
398
/**
399
 * webkit_favicon_database_clear:
400
 * @database: a #WebKitFaviconDatabase
401
 *
402
 * Clears all icons from the database.
403
 */
404
void webkit_favicon_database_clear(WebKitFaviconDatabase* database)
405
{
406
    g_return_if_fail(WEBKIT_IS_FAVICON_DATABASE(database));
407
408
    database->priv->iconDatabase->removeAllIcons();
409
}
- a/Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabase.h +94 lines
Line 0 a/Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabase.h_sec1
1
/*
2
 * Copyright (C) 2012 Igalia S.L.
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2,1 of the License, or (at your option) any later version.
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Library General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Library General Public License
15
 * along with this library; see the file COPYING.LIB.  If not, write to
16
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 * Boston, MA 02110-1301, USA.
18
 */
19
20
#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
21
#error "Only <webkit2/webkit2.h> can be included directly."
22
#endif
23
24
#ifndef WebKitFaviconDatabase_h
25
#define WebKitFaviconDatabase_h
26
27
#include <cairo.h>
28
#include <gio/gio.h>
29
#include <glib-object.h>
30
#include <webkit2/WebKitDefines.h>
31
32
G_BEGIN_DECLS
33
34
#define WEBKIT_TYPE_FAVICON_DATABASE            (webkit_favicon_database_get_type())
35
#define WEBKIT_FAVICON_DATABASE(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_FAVICON_DATABASE, WebKitFaviconDatabase))
36
#define WEBKIT_IS_FAVICON_DATABASE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_FAVICON_DATABASE))
37
#define WEBKIT_FAVICON_DATABASE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_FAVICON_DATABASE, WebKitFaviconDatabaseClass))
38
#define WEBKIT_IS_FAVICON_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_FAVICON_DATABASE))
39
#define WEBKIT_FAVICON_DATABASE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_FAVICON_DATABASE, WebKitFaviconDatabaseClass))
40
#define WEBKIT_FAVICON_DATABASE_ERROR           (webkit_favicon_database_error_quark())
41
42
typedef struct _WebKitFaviconDatabase        WebKitFaviconDatabase;
43
typedef struct _WebKitFaviconDatabaseClass   WebKitFaviconDatabaseClass;
44
typedef struct _WebKitFaviconDatabasePrivate WebKitFaviconDatabasePrivate;
45
46
struct _WebKitFaviconDatabase {
47
    GObject parent;
48
49
    WebKitFaviconDatabasePrivate *priv;
50
};
51
52
struct _WebKitFaviconDatabaseClass {
53
    GObjectClass parent_class;
54
};
55
56
/**
57
 * WebKitFaviconDatabaseError:
58
 * @WEBKIT_FAVICON_DATABASE_ERROR_NOT_INITIALIZED: The #WebKitFaviconDatabase has not been initialized yet
59
 * @WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_NOT_FOUND: There is not an icon available for the requested URL
60
 * @WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_UNKNOWN: There might be an icon for the requested URL, but its data is unknown at the moment
61
 *
62
 * Enum values used to denote the various errors related to the #WebKitFaviconDatabase.
63
 **/
64
typedef enum {
65
    WEBKIT_FAVICON_DATABASE_ERROR_NOT_INITIALIZED,
66
    WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_NOT_FOUND,
67
    WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_UNKNOWN
68
} WebKitFaviconDatabaseError;
69
70
WEBKIT_API GQuark
71
webkit_favicon_database_error_quark               (void);
72
73
WEBKIT_API GType
74
webkit_favicon_database_get_type                  (void);
75
76
WEBKIT_API void
77
webkit_favicon_database_get_favicon               (WebKitFaviconDatabase *database,
78
                                                   const gchar           *page_uri,
79
                                                   GCancellable          *cancellable,
80
                                                   GAsyncReadyCallback    callback,
81
                                                   gpointer               user_data);
82
WEBKIT_API cairo_surface_t *
83
webkit_favicon_database_get_favicon_finish        (WebKitFaviconDatabase *database,
84
                                                   GAsyncResult          *result,
85
                                                   GError               **error);
86
WEBKIT_API gchar *
87
webkit_favicon_database_get_favicon_uri           (WebKitFaviconDatabase *database,
88
                                                   const gchar           *page_uri);
89
WEBKIT_API void
90
webkit_favicon_database_clear                     (WebKitFaviconDatabase *database);
91
92
G_END_DECLS
93
94
#endif
- a/Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabasePrivate.h +30 lines
Line 0 a/Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabasePrivate.h_sec1
1
/*
2
 * Copyright (C) 2012 Igalia S.L.
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Library General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2 of the License, or (at your option) any later version.
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Library General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Library General Public License
15
 * along with this library; see the file COPYING.LIB.  If not, write to
16
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 * Boston, MA 02110-1301, USA.
18
 */
19
20
#ifndef WebKitFaviconDatabasePrivate_h
21
#define WebKitFaviconDatabasePrivate_h
22
23
#include "WebIconDatabase.h"
24
#include "WebKitFaviconDatabase.h"
25
26
using namespace WebKit;
27
28
WebKitFaviconDatabase* webkitFaviconDatabaseCreate(WebIconDatabase*);
29
30
#endif // WebKitFaviconDatabasePrivate_h
- a/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h +1 lines
Lines 34-39 a/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h_sec1
34
#include <WebKit2/WKGeolocationManager.h>
34
#include <WebKit2/WKGeolocationManager.h>
35
#include <WebKit2/WKGeolocationPermissionRequest.h>
35
#include <WebKit2/WKGeolocationPermissionRequest.h>
36
#include <WebKit2/WKGeolocationPosition.h>
36
#include <WebKit2/WKGeolocationPosition.h>
37
#include <WebKit2/WKIconDatabase.h>
37
#include <WebKit2/WKInspector.h>
38
#include <WebKit2/WKInspector.h>
38
#include <WebKit2/WKInspectorClientGtk.h>
39
#include <WebKit2/WKInspectorClientGtk.h>
39
#include <WebKit2/WKRetainPtr.h>
40
#include <WebKit2/WKRetainPtr.h>
- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp +95 lines
Lines 24-29 a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp_sec1
24
#include "WebKitCookieManagerPrivate.h"
24
#include "WebKitCookieManagerPrivate.h"
25
#include "WebKitDownloadClient.h"
25
#include "WebKitDownloadClient.h"
26
#include "WebKitDownloadPrivate.h"
26
#include "WebKitDownloadPrivate.h"
27
#include "WebKitFaviconDatabasePrivate.h"
27
#include "WebKitGeolocationProvider.h"
28
#include "WebKitGeolocationProvider.h"
28
#include "WebKitPluginPrivate.h"
29
#include "WebKitPluginPrivate.h"
29
#include "WebKitPrivate.h"
30
#include "WebKitPrivate.h"
Lines 33-38 a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp_sec2
33
#include "WebKitURISchemeRequestPrivate.h"
34
#include "WebKitURISchemeRequestPrivate.h"
34
#include "WebKitWebContextPrivate.h"
35
#include "WebKitWebContextPrivate.h"
35
#include <WebCore/FileSystem.h>
36
#include <WebCore/FileSystem.h>
37
#include <WebCore/IconDatabase.h>
36
#include <WebCore/Language.h>
38
#include <WebCore/Language.h>
37
#include <wtf/HashMap.h>
39
#include <wtf/HashMap.h>
38
#include <wtf/OwnPtr.h>
40
#include <wtf/OwnPtr.h>
Lines 96-101 struct _WebKitWebContextPrivate { a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp_sec3
96
    WKRetainPtr<WKContextRef> context;
98
    WKRetainPtr<WKContextRef> context;
97
99
98
    GRefPtr<WebKitCookieManager> cookieManager;
100
    GRefPtr<WebKitCookieManager> cookieManager;
101
    GRefPtr<WebKitFaviconDatabase> faviconDatabase;
99
    GRefPtr<WebKitSecurityManager> securityManager;
102
    GRefPtr<WebKitSecurityManager> securityManager;
100
    WKRetainPtr<WKSoupRequestManagerRef> requestManager;
103
    WKRetainPtr<WKSoupRequestManagerRef> requestManager;
101
    URISchemeHandlerMap uriSchemeHandlers;
104
    URISchemeHandlerMap uriSchemeHandlers;
Lines 106-111 struct _WebKitWebContextPrivate { a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp_sec4
106
#if ENABLE(SPELLCHECK)
109
#if ENABLE(SPELLCHECK)
107
    OwnPtr<WebKitTextChecker> textChecker;
110
    OwnPtr<WebKitTextChecker> textChecker;
108
#endif
111
#endif
112
    CString faviconDatabasePath;
109
};
113
};
110
114
111
static guint signals[LAST_SIGNAL] = { 0, };
115
static guint signals[LAST_SIGNAL] = { 0, };
Lines 324-329 WebKitCookieManager* webkit_web_context_get_cookie_manager(WebKitWebContext* con a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp_sec5
324
}
328
}
325
329
326
/**
330
/**
331
 * webkit_web_context_set_favicon_database_directory:
332
 * @context: a #WebKitWebContext
333
 * @path: (allow-none): an absolute path to the icon database
334
 * directory or %NULL to use the defaults
335
 *
336
 * Set the directory path to be used to store the favicons database
337
 * for @context on disk. Passing %NULL as @path means using the
338
 * default directory for the platform (see g_get_user_data_dir()).
339
 *
340
 * If you want to use a different path for the favicon database, this
341
 * method must be called before the database is created by
342
 * webkit_web_context_get_favicon_database(). Note that a
343
 * #WebKitWebView could use the favicon database, so this should also
344
 * be called before loading any web page.
345
 *
346
 * This function is expected to be called only once, further calls for
347
 * the same instance of #WebKitWebContext after calling
348
 * webkit_web_context_get_favicon_database() won't cause any effect.
349
 */
350
void webkit_web_context_set_favicon_database_directory(WebKitWebContext* context, const gchar* path)
351
{
352
    g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
353
354
    // Calling this method twice is a programming error.
355
    g_return_if_fail(!context->priv->faviconDatabase);
356
357
    if (path)
358
        context->priv->faviconDatabasePath = WebCore::filenameToString(path).utf8();
359
}
360
361
/**
362
 * webkit_web_context_get_favicon_database_path:
363
 * @context: a #WebKitWebContext
364
 *
365
 * Get the directory path being used to store the favicons database
366
 * for @context. This function will always return the same path after
367
 * having called webkit_web_context_get_favicon_database() for the
368
 * first time. See webkit_web_context_set_favicon_database_directory()
369
 * for more details.
370
 *
371
 * Returns: (transfer none): the path of the directory of the favicons
372
 * database associated with @context.
373
 */
374
const gchar* webkit_web_context_get_favicon_database_directory(WebKitWebContext *context)
375
{
376
    g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0);
377
378
    WebKitWebContextPrivate* priv = context->priv;
379
380
    // Use default if a different path has not been previously set.
381
    if (priv->faviconDatabasePath.isNull())
382
        priv->faviconDatabasePath = toImpl(priv->context.get())->iconDatabasePath().utf8();
383
384
    return priv->faviconDatabasePath.data();
385
}
386
387
/**
388
 * webkit_web_context_get_favicon_database:
389
 * @context: a #WebKitWebContext
390
 *
391
 * Get the #WebKitFaviconDatabase associated with @context. If you
392
 * want the database to be stored in a directory other than the default
393
 * one, you need to call
394
 * webkit_web_context_set_favicon_database_directory() before the first
395
 * time you use this function.
396
 *
397
 * Returns: (transfer none): the #WebKitFaviconDatabase of @context.
398
 */
399
WebKitFaviconDatabase* webkit_web_context_get_favicon_database(WebKitWebContext* context)
400
{
401
    g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0);
402
403
    WebKitWebContextPrivate* priv = context->priv;
404
405
    if (priv->faviconDatabase)
406
        return priv->faviconDatabase.get();
407
408
    // Build the full path to the icon database file on disk.
409
    GOwnPtr<gchar> faviconDatabasePath(g_build_filename(webkit_web_context_get_favicon_database_directory(context),
410
                                                        WebCore::IconDatabase::defaultDatabaseFilename().utf8().data(),
411
                                                        NULL));
412
413
    // Calling the setter in WebContext will cause the icon database to be opened.
414
    WebContext* webContext = toImpl(priv->context.get());
415
    webContext->setIconDatabasePath(WebCore::filenameToString(faviconDatabasePath.get()));
416
    priv->faviconDatabase = adoptGRef(webkitFaviconDatabaseCreate(webContext->iconDatabase()));
417
418
    return priv->faviconDatabase.get();
419
}
420
421
/**
327
 * webkit_web_context_get_security_manager:
422
 * webkit_web_context_get_security_manager:
328
 * @context: a #WebKitWebContext
423
 * @context: a #WebKitWebContext
329
 *
424
 *
- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h +10 lines
Lines 28-33 a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h_sec1
28
#include <webkit2/WebKitCookieManager.h>
28
#include <webkit2/WebKitCookieManager.h>
29
#include <webkit2/WebKitDefines.h>
29
#include <webkit2/WebKitDefines.h>
30
#include <webkit2/WebKitDownload.h>
30
#include <webkit2/WebKitDownload.h>
31
#include <webkit2/WebKitFaviconDatabase.h>
31
#include <webkit2/WebKitSecurityManager.h>
32
#include <webkit2/WebKitSecurityManager.h>
32
#include <webkit2/WebKitURISchemeRequest.h>
33
#include <webkit2/WebKitURISchemeRequest.h>
33
34
Lines 114-119 webkit_web_context_download_uri (WebKitWebContext a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h_sec2
114
WEBKIT_API WebKitCookieManager *
115
WEBKIT_API WebKitCookieManager *
115
webkit_web_context_get_cookie_manager               (WebKitWebContext              *context);
116
webkit_web_context_get_cookie_manager               (WebKitWebContext              *context);
116
117
118
WEBKIT_API WebKitFaviconDatabase *
119
webkit_web_context_get_favicon_database             (WebKitWebContext              *context);
120
121
WEBKIT_API void
122
webkit_web_context_set_favicon_database_directory   (WebKitWebContext              *context,
123
                                                     const gchar                   *path);
124
WEBKIT_API const gchar *
125
webkit_web_context_get_favicon_database_directory   (WebKitWebContext              *context);
126
117
WEBKIT_API WebKitSecurityManager *
127
WEBKIT_API WebKitSecurityManager *
118
webkit_web_context_get_security_manager             (WebKitWebContext              *context);
128
webkit_web_context_get_security_manager             (WebKitWebContext              *context);
119
129
- a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml +1 lines
Lines 30-35 a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml_sec1
30
    <xi:include href="xml/WebKitPrintOperation.xml"/>
30
    <xi:include href="xml/WebKitPrintOperation.xml"/>
31
    <xi:include href="xml/WebKitWebResource.xml"/>
31
    <xi:include href="xml/WebKitWebResource.xml"/>
32
    <xi:include href="xml/WebKitError.xml"/>
32
    <xi:include href="xml/WebKitError.xml"/>
33
    <xi:include href="xml/WebKitFaviconDatabase.xml"/>
33
    <xi:include href="xml/WebKitFileChooserRequest.xml"/>
34
    <xi:include href="xml/WebKitFileChooserRequest.xml"/>
34
    <xi:include href="xml/WebKitFindController.xml"/>
35
    <xi:include href="xml/WebKitFindController.xml"/>
35
    <xi:include href="xml/WebKitCookieManager.xml"/>
36
    <xi:include href="xml/WebKitCookieManager.xml"/>
- a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt +28 lines
Lines 30-35 webkit_web_context_set_cache_model a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt_sec1
30
webkit_web_context_clear_cache
30
webkit_web_context_clear_cache
31
webkit_web_context_download_uri
31
webkit_web_context_download_uri
32
webkit_web_context_get_cookie_manager
32
webkit_web_context_get_cookie_manager
33
webkit_web_context_get_favicon_database
34
webkit_web_context_set_favicon_database_directory
35
webkit_web_context_get_favicon_database_directory
33
webkit_web_context_get_security_manager
36
webkit_web_context_get_security_manager
34
webkit_web_context_set_additional_plugins_directory
37
webkit_web_context_set_additional_plugins_directory
35
webkit_web_context_get_plugins
38
webkit_web_context_get_plugins
Lines 602-607 webkit_javascript_error_quark a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt_sec2
602
</SECTION>
605
</SECTION>
603
606
604
<SECTION>
607
<SECTION>
608
<FILE>WebKitFaviconDatabase</FILE>
609
WebKitFaviconDatabase
610
WEBKIT_FAVICON_DATABASE_ERROR
611
WebKitFaviconDatabaseError
612
webkit_favicon_database_get_favicon
613
webkit_favicon_database_get_favicon_finish
614
webkit_favicon_database_get_favicon_uri
615
webkit_favicon_database_clear
616
617
<SUBSECTION Standard>
618
WebKitFaviconDatabaseClass
619
WEBKIT_TYPE_FAVICON_DATABASE
620
WEBKIT_FAVICON_DATABASE
621
WEBKIT_IS_FAVICON_DATABASE
622
WEBKIT_FAVICON_DATABASE_CLASS
623
WEBKIT_IS_FAVICON_DATABASE_CLASS
624
WEBKIT_FAVICON_DATABASE_GET_CLASS
625
626
<SUBSECTION Private>
627
WebKitFaviconDatabasePrivate
628
webkit_favicon_database_get_type
629
webkit_favicon_database_error_quark
630
</SECTION>
631
632
<SECTION>
605
<FILE>WebKitFileChooserRequest</FILE>
633
<FILE>WebKitFileChooserRequest</FILE>
606
WebKitFileChooserRequest
634
WebKitFileChooserRequest
607
webkit_file_chooser_request_get_mime_types
635
webkit_file_chooser_request_get_mime_types
- a/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am +7 lines
Lines 11-16 TEST_PROGS += \ a/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am_sec1
11
	Programs/WebKit2APITests/TestResources \
11
	Programs/WebKit2APITests/TestResources \
12
	Programs/WebKit2APITests/TestSSL \
12
	Programs/WebKit2APITests/TestSSL \
13
	Programs/WebKit2APITests/TestWebKitVersion \
13
	Programs/WebKit2APITests/TestWebKitVersion \
14
	Programs/WebKit2APITests/TestWebKitFaviconDatabase \
14
	Programs/WebKit2APITests/TestWebKitFindController \
15
	Programs/WebKit2APITests/TestWebKitFindController \
15
	Programs/WebKit2APITests/TestWebKitPolicyClient \
16
	Programs/WebKit2APITests/TestWebKitPolicyClient \
16
	Programs/WebKit2APITests/TestWebKitSettings \
17
	Programs/WebKit2APITests/TestWebKitSettings \
Lines 141-146 Programs_WebKit2APITests_TestPrinting_CPPFLAGS = $(webkit2_tests_cppflags) $(GTK a/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am_sec2
141
Programs_WebKit2APITests_TestPrinting_LDADD = $(webkit2_tests_ldadd) $(GTK_UNIX_PRINTING_LIBS)
142
Programs_WebKit2APITests_TestPrinting_LDADD = $(webkit2_tests_ldadd) $(GTK_UNIX_PRINTING_LIBS)
142
Programs_WebKit2APITests_TestPrinting_LDFLAGS = $(webkit2_tests_ldflags)
143
Programs_WebKit2APITests_TestPrinting_LDFLAGS = $(webkit2_tests_ldflags)
143
144
145
Programs_WebKit2APITests_TestWebKitFaviconDatabase_SOURCES = \
146
	Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp
147
Programs_WebKit2APITests_TestWebKitFaviconDatabase_CPPFLAGS = $(webkit2_tests_cppflags)
148
Programs_WebKit2APITests_TestWebKitFaviconDatabase_LDADD = $(webkit2_tests_ldadd)
149
Programs_WebKit2APITests_TestWebKitFaviconDatabase_LDFLAGS = $(webkit2_tests_ldflags)
150
144
Programs_WebKit2APITests_TestWebKitFindController_SOURCES = \
151
Programs_WebKit2APITests_TestWebKitFindController_SOURCES = \
145
	Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp
152
	Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp
146
Programs_WebKit2APITests_TestWebKitFindController_CPPFLAGS = $(webkit2_tests_cppflags)
153
Programs_WebKit2APITests_TestWebKitFindController_CPPFLAGS = $(webkit2_tests_cppflags)
- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp +237 lines
Line 0 a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp_sec1
1
/*
2
 * Copyright (C) 2012 Igalia S.L.
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2,1 of the License, or (at your option) any later version.
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Library General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Library General Public License
15
 * along with this library; see the file COPYING.LIB.  If not, write to
16
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 * Boston, MA 02110-1301, USA.
18
 */
19
20
#include "config.h"
21
22
#include "WebKitTestServer.h"
23
#include "WebViewTest.h"
24
#include <glib/gstdio.h>
25
#include <libsoup/soup.h>
26
#include <wtf/gobject/GOwnPtr.h>
27
28
static WebKitTestServer* kServer;
29
static char* kTempDirectory;
30
31
class FaviconDatabaseTest: public WebViewTest {
32
public:
33
    MAKE_GLIB_TEST_FIXTURE(FaviconDatabaseTest);
34
35
    FaviconDatabaseTest()
36
        : m_webContext(webkit_web_context_get_default())
37
        , m_iconReadySignalReceived(false)
38
        , m_iconIsValid(false)
39
    {
40
    }
41
42
    ~FaviconDatabaseTest()
43
    {
44
        WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(m_webContext);
45
        g_signal_handlers_disconnect_matched(database, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this);
46
    }
47
48
    static void iconReadyCallback(WebKitFaviconDatabase* database, const char* pageURI, FaviconDatabaseTest* test)
49
    {
50
        g_assert_cmpstr(webkit_web_view_get_uri(test->m_webView), ==, pageURI);
51
        test->m_iconReadySignalReceived = true;
52
    }
53
54
    static void getFaviconCallback(GObject* sourceObject, GAsyncResult* result, void* data)
55
    {
56
        FaviconDatabaseTest* test = static_cast<FaviconDatabaseTest*>(data);
57
        cairo_surface_t* favicon = webkit_favicon_database_get_favicon_finish(WEBKIT_FAVICON_DATABASE(sourceObject), result, 0);
58
        if (favicon)
59
            cairo_surface_destroy(favicon);
60
        g_main_loop_quit(test->m_mainLoop);
61
    }
62
63
    static void askForIconAfterLoad(FaviconDatabaseTest* test)
64
    {
65
        WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(test->m_webContext);
66
        webkit_favicon_database_get_favicon(database, kServer->getURIForPath("/").data(), 0, getFaviconCallback, test);
67
        g_signal_connect(database, "favicon-ready", G_CALLBACK(iconReadyCallback), test);
68
    }
69
70
    static void loadChangedCallback(WebKitWebView*, WebKitLoadEvent loadEvent, FaviconDatabaseTest* test)
71
    {
72
        if (loadEvent == WEBKIT_LOAD_FINISHED)
73
            askForIconAfterLoad(test);
74
    }
75
76
    static void loadFailedCallback(WebKitWebView*, WebKitLoadEvent, const char*, GError*, FaviconDatabaseTest* test)
77
    {
78
        askForIconAfterLoad(test);
79
    }
80
81
    void askForIconAndWaitForIconReadySignal()
82
    {
83
        g_signal_connect(m_webView, "load-changed", G_CALLBACK(loadChangedCallback), this);
84
        g_signal_connect(m_webView, "load-failed", G_CALLBACK(loadFailedCallback), this);
85
86
        webkit_web_view_load_uri(m_webView, kServer->getURIForPath("/").data());
87
        g_main_loop_run(m_mainLoop);
88
89
        g_signal_handlers_disconnect_matched(m_webView, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this);
90
    }
91
92
    static void getValidFaviconCallback(GObject* sourceObject, GAsyncResult* result, void* data)
93
    {
94
        FaviconDatabaseTest* test = static_cast<FaviconDatabaseTest*>(data);
95
96
        GError* error = 0;
97
        cairo_surface_t* favicon = webkit_favicon_database_get_favicon_finish(WEBKIT_FAVICON_DATABASE(sourceObject), result, &error);
98
        g_assert(favicon);
99
        g_assert(!error);
100
101
        test->m_iconIsValid = true;
102
        cairo_surface_destroy(favicon);
103
104
        g_main_loop_quit(test->m_mainLoop);
105
    }
106
107
    static void getInvalidFaviconCallback(GObject* sourceObject, GAsyncResult* result, void* data)
108
    {
109
        FaviconDatabaseTest* test = static_cast<FaviconDatabaseTest*>(data);
110
111
        GError* error = 0;
112
        cairo_surface_t* favicon = webkit_favicon_database_get_favicon_finish(WEBKIT_FAVICON_DATABASE(sourceObject), result, &error);
113
        g_assert(!favicon);
114
        g_assert(error && WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_NOT_FOUND);
115
116
        test->m_iconIsValid = false;
117
        g_main_loop_quit(test->m_mainLoop);
118
    }
119
120
    void askAndWaitForValidFavicon()
121
    {
122
        WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(m_webContext);
123
        webkit_favicon_database_get_favicon(database, kServer->getURIForPath("/").data(), 0, getValidFaviconCallback, this);
124
        g_main_loop_run(m_mainLoop);
125
    }
126
127
    void askAndWaitForInvalidFavicon()
128
    {
129
        WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(m_webContext);
130
        webkit_favicon_database_get_favicon(database, "http://www.webkitgtk.org/", 0, getInvalidFaviconCallback, this);
131
        g_main_loop_run(m_mainLoop);
132
    }
133
134
    WebKitWebContext* m_webContext;
135
    bool m_iconReadySignalReceived;
136
    bool m_iconIsValid;
137
};
138
139
static void
140
serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable* query, SoupClientContext* context, void* data)
141
{
142
    if (message->method != SOUP_METHOD_GET) {
143
        soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
144
        return;
145
    }
146
147
    soup_message_set_status(message, SOUP_STATUS_OK);
148
149
    char* contents;
150
    gsize length;
151
    if (g_str_equal(path, "/favicon.ico")) {
152
        GOwnPtr<char> pathToFavicon(g_build_filename(Test::getWebKit1TestResoucesDir().data(), "blank.ico", NULL));
153
154
        gboolean result = g_file_get_contents(pathToFavicon.get(), &contents, &length, 0);
155
        g_assert(result);
156
    } else {
157
        contents = g_strdup("<html><body>test</body></html>");
158
        length = strlen(contents);
159
    }
160
161
    soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, contents, length);
162
    soup_message_body_complete(message->response_body);
163
}
164
165
static void testSetDirectory(FaviconDatabaseTest* test, gconstpointer)
166
{
167
    webkit_web_context_set_favicon_database_directory(test->m_webContext, kTempDirectory);
168
    g_assert_cmpstr(kTempDirectory, ==, webkit_web_context_get_favicon_database_directory(test->m_webContext));
169
}
170
171
static void testClearDatabase(FaviconDatabaseTest* test, gconstpointer)
172
{
173
    WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(test->m_webContext);
174
    webkit_favicon_database_clear(database);
175
176
    GOwnPtr<char> iconURI(webkit_favicon_database_get_favicon_uri(database, kServer->getURIForPath("/").data()));
177
    g_assert(!iconURI);
178
}
179
180
static void testGetFavicon(FaviconDatabaseTest* test, gconstpointer)
181
{
182
    test->m_iconReadySignalReceived = false;
183
    test->askForIconAndWaitForIconReadySignal();
184
    g_assert(test->m_iconReadySignalReceived);
185
186
    test->m_iconIsValid = false;
187
    test->askAndWaitForValidFavicon();
188
    g_assert(test->m_iconIsValid);
189
190
    test->askAndWaitForInvalidFavicon();
191
    g_assert(!test->m_iconIsValid);
192
}
193
194
static void testGetFaviconURI(FaviconDatabaseTest* test, gconstpointer)
195
{
196
    WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(test->m_webContext);
197
198
    const char* baseURI = kServer->getURIForPath("/").data();
199
    GOwnPtr<char> iconURI(webkit_favicon_database_get_favicon_uri(database, baseURI));
200
    g_assert_cmpstr(iconURI.get(), ==, kServer->getURIForPath("/favicon.ico").data());
201
}
202
203
static void deleteDatabaseFiles()
204
{
205
    if (!g_file_test(kTempDirectory, G_FILE_TEST_IS_DIR))
206
        return;
207
208
    GOwnPtr<char> filename(g_build_filename(kTempDirectory, "WebpageIcons.db", NULL));
209
    g_unlink(filename.get());
210
211
    filename.set(g_build_filename(kTempDirectory, "WebpageIcons.db-journal", NULL));
212
    g_unlink(filename.get());
213
214
    g_rmdir(kTempDirectory);
215
}
216
217
void beforeAll()
218
{
219
    // Start a soup server for testing.
220
    kServer = new WebKitTestServer();
221
    kServer->run(serverCallback);
222
223
    kTempDirectory = g_dir_make_tmp("WebKit2Tests-XXXXXX", 0);
224
    g_assert(kTempDirectory);
225
226
    // Add tests to the suite.
227
    FaviconDatabaseTest::add("WebKitFaviconDatabase", "set-directory", testSetDirectory);
228
    FaviconDatabaseTest::add("WebKitFaviconDatabase", "get-favicon", testGetFavicon);
229
    FaviconDatabaseTest::add("WebKitFaviconDatabase", "get-favicon-uri", testGetFaviconURI);
230
    FaviconDatabaseTest::add("WebKitFaviconDatabase", "clear-database", testClearDatabase);
231
}
232
233
void afterAll()
234
{
235
    delete kServer;
236
    deleteDatabaseFiles();
237
}
- a/Source/WebKit2/UIProcess/API/gtk/webkit2.h +1 lines
Lines 34-39 a/Source/WebKit2/UIProcess/API/gtk/webkit2.h_sec1
34
#include <webkit2/WebKitEditingCommands.h>
34
#include <webkit2/WebKitEditingCommands.h>
35
#include <webkit2/WebKitEnumTypes.h>
35
#include <webkit2/WebKitEnumTypes.h>
36
#include <webkit2/WebKitError.h>
36
#include <webkit2/WebKitError.h>
37
#include <webkit2/WebKitFaviconDatabase.h>
37
#include <webkit2/WebKitFileChooserRequest.h>
38
#include <webkit2/WebKitFileChooserRequest.h>
38
#include <webkit2/WebKitFindController.h>
39
#include <webkit2/WebKitFindController.h>
39
#include <webkit2/WebKitFormSubmissionRequest.h>
40
#include <webkit2/WebKitFormSubmissionRequest.h>
- a/Source/WebKit2/UIProcess/WebIconDatabase.cpp +5 lines
Lines 208-213 bool WebIconDatabase::isOpen() a/Source/WebKit2/UIProcess/WebIconDatabase.cpp_sec1
208
    return m_iconDatabaseImpl && m_iconDatabaseImpl->isOpen();
208
    return m_iconDatabaseImpl && m_iconDatabaseImpl->isOpen();
209
}
209
}
210
210
211
bool WebIconDatabase::isUrlImportCompleted()
212
{
213
    return m_urlImportCompleted;
214
}
215
211
void WebIconDatabase::removeAllIcons()
216
void WebIconDatabase::removeAllIcons()
212
{
217
{
213
    m_iconDatabaseImpl->removeAllIcons();   
218
    m_iconDatabaseImpl->removeAllIcons();   
- a/Source/WebKit2/UIProcess/WebIconDatabase.h +1 lines
Lines 82-87 public: a/Source/WebKit2/UIProcess/WebIconDatabase.h_sec1
82
    WebCore::Image* imageForPageURL(const String&, const WebCore::IntSize& iconSize = WebCore::IntSize(32, 32));
82
    WebCore::Image* imageForPageURL(const String&, const WebCore::IntSize& iconSize = WebCore::IntSize(32, 32));
83
    WebCore::NativeImagePtr nativeImageForPageURL(const String&, const WebCore::IntSize& iconSize = WebCore::IntSize(32, 32));
83
    WebCore::NativeImagePtr nativeImageForPageURL(const String&, const WebCore::IntSize& iconSize = WebCore::IntSize(32, 32));
84
    bool isOpen();
84
    bool isOpen();
85
    bool isUrlImportCompleted();
85
86
86
    void removeAllIcons();
87
    void removeAllIcons();
87
    void checkIntegrityBeforeOpening();
88
    void checkIntegrityBeforeOpening();
- a/Source/WebKit2/UIProcess/gtk/WebContextGtk.cpp -3 / +2 lines
Lines 53-60 String WebContext::platformDefaultDatabaseDirectory() const a/Source/WebKit2/UIProcess/gtk/WebContextGtk.cpp_sec1
53
53
54
String WebContext::platformDefaultIconDatabasePath() const
54
String WebContext::platformDefaultIconDatabasePath() const
55
{
55
{
56
    // FIXME: Implement.
56
    GOwnPtr<gchar> databaseDirectory(g_build_filename(g_get_user_data_dir(), "webkitgtk", "icondatabase", NULL));
57
    return WTF::String();
57
    return WebCore::filenameToString(databaseDirectory.get());
58
}
58
}
59
59
60
String WebContext::platformDefaultLocalStorageDirectory() const
60
String WebContext::platformDefaultLocalStorageDirectory() const
61
- 

Return to Bug 96476