From aa8dbecd8a1e31a571e3e0c2b3ab082f7c6cd382 Mon Sep 17 00:00:00 2001 From: "carlosgc@webkit.org" Date: Tue, 27 Sep 2011 18:06:06 +0000 Subject: [PATCH] [GTK] Add WebKitWebContext to GTK API https://bugs.webkit.org/show_bug.cgi?id=67931 Reviewed by Philippe Normand. Initial implementation of WebKitWebContext for WebKit2 GTK API. * GNUmakefile.am: Add new files to compilation. * UIProcess/API/gtk/WebKitWebContext.cpp: Added. (webkitWebContextFinalize): (webkit_web_context_init): (webkit_web_context_class_init): (createDefaultWebContext): (webkit_web_context_get_default): * UIProcess/API/gtk/WebKitWebContext.h: Added. * UIProcess/API/gtk/tests/testwebcontext.c: (testWebContextDefault): (main): * UIProcess/API/gtk/webkit2.h: Add . git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96133 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebKit2/ChangeLog | 23 +++++++ Source/WebKit2/GNUmakefile.am | 36 ++++++++++ .../WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp | 77 ++++++++++++++++++++++ .../WebKit2/UIProcess/API/gtk/WebKitWebContext.h | 64 ++++++++++++++++++ .../UIProcess/API/gtk/tests/testwebcontext.c | 41 ++++++++++++ Source/WebKit2/UIProcess/API/gtk/webkit2.h | 1 + 6 files changed, 242 insertions(+) create mode 100644 Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp create mode 100644 Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h create mode 100644 Source/WebKit2/UIProcess/API/gtk/tests/testwebcontext.c diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog index ac3a8fd..0fd7afa 100644 --- a/Source/WebKit2/ChangeLog +++ b/Source/WebKit2/ChangeLog @@ -1,3 +1,26 @@ +2011-09-27 Carlos Garcia Campos + + + [GTK] Add WebKitWebContext to GTK API + https://bugs.webkit.org/show_bug.cgi?id=67931 + + Reviewed by Philippe Normand. + + Initial implementation of WebKitWebContext for WebKit2 GTK API. + + * GNUmakefile.am: Add new files to compilation. + * UIProcess/API/gtk/WebKitWebContext.cpp: Added. + (webkitWebContextFinalize): + (webkit_web_context_init): + (webkit_web_context_class_init): + (createDefaultWebContext): + (webkit_web_context_get_default): + * UIProcess/API/gtk/WebKitWebContext.h: Added. + * UIProcess/API/gtk/tests/testwebcontext.c: + (testWebContextDefault): + (main): + * UIProcess/API/gtk/webkit2.h: Add . + 2011-09-27 Sheriff Bot Unreviewed, rolling out r96108, r96111, r96113, and r96116. diff --git a/Source/WebKit2/GNUmakefile.am b/Source/WebKit2/GNUmakefile.am index 22e092e..9f31ab2 100644 --- a/Source/WebKit2/GNUmakefile.am +++ b/Source/WebKit2/GNUmakefile.am @@ -69,6 +69,7 @@ libwebkit2gtk_@WEBKITGTK_API_MAJOR_VERSION@_@WEBKITGTK_API_MINOR_VERSION@_la_HEA libwebkit2gtkincludedir = $(libwebkitgtkincludedir)/webkit2 libwebkit2gtkinclude_HEADERS = \ + $(WebKit2)/UIProcess/API/gtk/WebKitWebContext.h \ $(WebKit2)/UIProcess/API/gtk/WebKitWebView.h \ $(WebKit2)/UIProcess/API/gtk/WebKitWebViewBase.h \ $(WebKit2)/UIProcess/API/gtk/webkit2.h @@ -452,6 +453,8 @@ libwebkit2gtk_@WEBKITGTK_API_MAJOR_VERSION@_@WEBKITGTK_API_MINOR_VERSION@_la_SOU Source/WebKit2/UIProcess/API/cpp/WKRetainPtr.h \ Source/WebKit2/UIProcess/API/gtk/PageClientImpl.h \ Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp \ + Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h \ + Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp \ Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h \ Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp \ Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.h \ @@ -982,6 +985,39 @@ CLEANFILES += \ DISTCLEANFILES += \ $(top_builddir)/WebKit2/webkit2gtk-@WEBKITGTK_API_VERSION@.pc +# Unit tests +TEST_PROGS += \ + Programs/unittests/webkit2/testwebcontext + +noinst_PROGRAMS += $(TEST_PROGS) +webkit2_tests_cflags = \ + -I$(srcdir)/Source \ + -I$(srcdir)/Source/WebKit2 \ + -I$(top_builddir)/DerivedSources/WebKit2/include \ + -I$(top_builddir)/DerivedSources/WebKit2/include/webkit2gtk \ + -I$(srcdir)/Source/WebKit2/UIProcess/API/gtk \ + $(global_cflags) \ + $(global_cppflags) \ + $(GLIB_CFLAGS) \ + $(GTK_CFLAGS) \ + $(LIBSOUP_CFLAGS) + +webkit2_tests_ldadd = \ + libjavascriptcoregtk-@WEBKITGTK_API_MAJOR_VERSION@.@WEBKITGTK_API_MINOR_VERSION@.la \ + libwebkit2gtk-@WEBKITGTK_API_MAJOR_VERSION@.@WEBKITGTK_API_MINOR_VERSION@.la \ + $(GLIB_LIBS) \ + $(GTK_LIBS) \ + $(LIBSOUP_LIBS) + +webkit2_tests_ldflags = \ + -no-install \ + -no-fast-install + +Programs_unittests_webkit2_testwebcontext_SOURCES = Source/WebKit2/UIProcess/API/gtk/tests/testwebcontext.c +Programs_unittests_webkit2_testwebcontext_CFLAGS = $(webkit2_tests_cflags) +Programs_unittests_webkit2_testwebcontext_LDADD = $(webkit2_tests_ldadd) +Programs_unittests_webkit2_testwebcontext_LDFLAGS = $(webkit2_tests_ldflags) + # WebKitWebProcess libexec_PROGRAMS += \ Programs/WebKitWebProcess diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp new file mode 100644 index 0000000..88a09a2 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2011 Igalia S.L. + * + * 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 "config.h" +#include "WebKitWebContext.h" + +#include +#include + +struct _WebKitWebContextPrivate { + WKContextRef context; +}; + +G_DEFINE_TYPE(WebKitWebContext, webkit_web_context, G_TYPE_OBJECT) + +static void webkitWebContextFinalize(GObject* object) +{ + WebKitWebContext* context = WEBKIT_WEB_CONTEXT(object); + + WKRelease(context->priv->context); + context->priv->context = 0; +} + +static void webkit_web_context_init(WebKitWebContext* webContext) +{ + WebKitWebContextPrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(webContext, WEBKIT_TYPE_WEB_CONTEXT, WebKitWebContextPrivate); + webContext->priv = priv; + new (priv) WebKitWebContextPrivate(); +} + +static void webkit_web_context_class_init(WebKitWebContextClass* webContextClass) +{ + GObjectClass* gObjectClass = G_OBJECT_CLASS(webContextClass); + gObjectClass->finalize = webkitWebContextFinalize; + + g_type_class_add_private(webContextClass, sizeof(WebKitWebContextPrivate)); +} + + +static gpointer createDefaultWebContext(gpointer) +{ + WebKitWebContext* webContext = WEBKIT_WEB_CONTEXT(g_object_new(WEBKIT_TYPE_WEB_CONTEXT, NULL)); + webContext->priv->context = WKContextGetSharedProcessContext(); + WKContextSetCacheModel(webContext->priv->context, kWKCacheModelPrimaryWebBrowser); + return webContext; +} + +/** + * webkit_web_context_get_default: + * + * Gets the default web context + * + * Returns: (transfer none) a #WebKitWebContext + */ +WebKitWebContext* webkit_web_context_get_default(void) +{ + static GOnce onceInit = G_ONCE_INIT; + return WEBKIT_WEB_CONTEXT(g_once(&onceInit, createDefaultWebContext, 0)); +} + + diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h new file mode 100644 index 0000000..c29ffb6 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2011 Igalia S.L. + * + * 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. + */ + +#ifndef WebKitWebContext_h +#define WebKitWebContext_h + +#include +#include + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_WEB_CONTEXT (webkit_web_context_get_type()) +#define WEBKIT_WEB_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_CONTEXT, WebKitWebContext)) +#define WEBKIT_WEB_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEB_CONTEXT, WebKitWebContextClass)) +#define WEBKIT_IS_WEB_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_CONTEXT)) +#define WEBKIT_IS_WEB_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEB_CONTEXT)) +#define WEBKIT_WEB_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEB_CONTEXT, WebKitWebContextClass)) + +typedef struct _WebKitWebContext WebKitWebContext; +typedef struct _WebKitWebContextClass WebKitWebContextClass; +typedef struct _WebKitWebContextPrivate WebKitWebContextPrivate; + +struct _WebKitWebContext { + GObject parent; + + /*< private >*/ + WebKitWebContextPrivate *priv; +}; + +struct _WebKitWebContextClass { + GObjectClass parent; + + /* Padding for future expansion */ + void (*_webkit_reserved0) (void); + void (*_webkit_reserved1) (void); + void (*_webkit_reserved2) (void); + void (*_webkit_reserved3) (void); +}; + +WK_EXPORT GType +webkit_web_context_get_type (void); + +WK_EXPORT WebKitWebContext * +webkit_web_context_get_default (void); + +G_END_DECLS + +#endif diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/testwebcontext.c b/Source/WebKit2/UIProcess/API/gtk/tests/testwebcontext.c new file mode 100644 index 0000000..1b5257f --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/testwebcontext.c @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2011 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2,1 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 +#include +#include + +static void testWebContextDefault(void) +{ + /* Check there's a single instance of the default web context. */ + g_assert(webkit_web_context_get_default() == webkit_web_context_get_default()); +} + +int main(int argc, char **argv) +{ + g_thread_init(NULL); + gtk_test_init(&argc, &argv, NULL); + + g_test_bug_base("https://bugs.webkit.org/"); + g_test_add_func("/webkit2/webcontext/default_context", + testWebContextDefault); + + return g_test_run(); +} + diff --git a/Source/WebKit2/UIProcess/API/gtk/webkit2.h b/Source/WebKit2/UIProcess/API/gtk/webkit2.h index 08ce3e8..7e1c48c 100644 --- a/Source/WebKit2/UIProcess/API/gtk/webkit2.h +++ b/Source/WebKit2/UIProcess/API/gtk/webkit2.h @@ -20,6 +20,7 @@ #ifndef __WEBKIT2_H__ #define __WEBKIT2_H__ +#include #include #include -- 2.7.4