From 26674bdc108ff9bc4bfd164cb2ed0d78c3c82c55 Mon Sep 17 00:00:00 2001 From: "carlosgc@webkit.org" Date: Tue, 27 Sep 2011 18:32:55 +0000 Subject: [PATCH] [GTK] Use WebKitWebContext in WebKitWebView https://bugs.webkit.org/show_bug.cgi?id=67990 Reviewed by Martin Robinson. Use webkit_web_context_get_default() instead of WKContextGetSharedProcessContext() and add API to create a view with a given web context and to return the current context associated to the view. * GNUmakefile.am: Add new files to compilation. * UIProcess/API/gtk/WebKitPrivate.h: Added. * UIProcess/API/gtk/WebKitWebContext.cpp: (webkitWebContextGetWKContext): Private API to get the WKContext wrapped by the WebKitWebContext. * UIProcess/API/gtk/WebKitWebContextPrivate.h: Added. * UIProcess/API/gtk/WebKitWebView.cpp: (webkitWebViewConstructed): Create the webpage using the web context of the view. (webkitWebViewSetProperty): (webkitWebViewGetProperty): (webkit_web_view_init): (webkit_web_view_class_init): (webkit_web_view_new): Create a new view with the default context. (webkit_web_view_new_with_context): Create a new view with the given context. (webkit_web_view_get_context): Return the context. * UIProcess/API/gtk/WebKitWebView.h: * UIProcess/API/gtk/tests/testwebview.c: Added. (testWebViewDefaultContext): (main): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96136 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebKit2/ChangeLog | 34 +++++++ Source/WebKit2/GNUmakefile.am | 10 +- Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h | 39 ++++++++ .../WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp | 7 ++ .../UIProcess/API/gtk/WebKitWebContextPrivate.h | 38 +++++++ Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp | 109 ++++++++++++++++++++- Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h | 19 ++-- .../WebKit2/UIProcess/API/gtk/tests/testwebview.c | 42 ++++++++ 8 files changed, 289 insertions(+), 9 deletions(-) create mode 100644 Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h create mode 100644 Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h create mode 100644 Source/WebKit2/UIProcess/API/gtk/tests/testwebview.c diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog index 0fd7afa..0dab620 100644 --- a/Source/WebKit2/ChangeLog +++ b/Source/WebKit2/ChangeLog @@ -1,5 +1,39 @@ 2011-09-27 Carlos Garcia Campos + [GTK] Use WebKitWebContext in WebKitWebView + https://bugs.webkit.org/show_bug.cgi?id=67990 + + Reviewed by Martin Robinson. + + Use webkit_web_context_get_default() instead of + WKContextGetSharedProcessContext() and add API to create a view + with a given web context and to return the current context + associated to the view. + + * GNUmakefile.am: Add new files to compilation. + * UIProcess/API/gtk/WebKitPrivate.h: Added. + * UIProcess/API/gtk/WebKitWebContext.cpp: + (webkitWebContextGetWKContext): Private API to get the WKContext + wrapped by the WebKitWebContext. + * UIProcess/API/gtk/WebKitWebContextPrivate.h: Added. + * UIProcess/API/gtk/WebKitWebView.cpp: + (webkitWebViewConstructed): Create the webpage using the web + context of the view. + (webkitWebViewSetProperty): + (webkitWebViewGetProperty): + (webkit_web_view_init): + (webkit_web_view_class_init): + (webkit_web_view_new): Create a new view with the default context. + (webkit_web_view_new_with_context): Create a new view with the + given context. + (webkit_web_view_get_context): Return the context. + * UIProcess/API/gtk/WebKitWebView.h: + * UIProcess/API/gtk/tests/testwebview.c: Added. + (testWebViewDefaultContext): + (main): + +2011-09-27 Carlos Garcia Campos + [GTK] Add WebKitWebContext to GTK API https://bugs.webkit.org/show_bug.cgi?id=67931 diff --git a/Source/WebKit2/GNUmakefile.am b/Source/WebKit2/GNUmakefile.am index 9f31ab2..c400495 100644 --- a/Source/WebKit2/GNUmakefile.am +++ b/Source/WebKit2/GNUmakefile.am @@ -453,8 +453,10 @@ 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/WebKitPrivate.h \ Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h \ Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp \ + Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h \ Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h \ Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp \ Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.h \ @@ -987,7 +989,8 @@ DISTCLEANFILES += \ # Unit tests TEST_PROGS += \ - Programs/unittests/webkit2/testwebcontext + Programs/unittests/webkit2/testwebcontext \ + Programs/unittests/webkit2/testwebview noinst_PROGRAMS += $(TEST_PROGS) webkit2_tests_cflags = \ @@ -1018,6 +1021,11 @@ Programs_unittests_webkit2_testwebcontext_CFLAGS = $(webkit2_tests_cflags) Programs_unittests_webkit2_testwebcontext_LDADD = $(webkit2_tests_ldadd) Programs_unittests_webkit2_testwebcontext_LDFLAGS = $(webkit2_tests_ldflags) +Programs_unittests_webkit2_testwebview_SOURCES = Source/WebKit2/UIProcess/API/gtk/tests/testwebview.c +Programs_unittests_webkit2_testwebview_CFLAGS = $(webkit2_tests_cflags) +Programs_unittests_webkit2_testwebview_LDADD = $(webkit2_tests_ldadd) +Programs_unittests_webkit2_testwebview_LDFLAGS = $(webkit2_tests_ldflags) + # WebKitWebProcess libexec_PROGRAMS += \ Programs/WebKitWebProcess diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h new file mode 100644 index 0000000..a102e61 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2011 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebKitPrivate_h +#define WebKitPrivate_h + +#include + +G_BEGIN_DECLS + +#define WEBKIT_PARAM_READABLE (static_cast(G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB)) +#define WEBKIT_PARAM_WRITABLE (static_cast(G_PARAM_WRITABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB)) +#define WEBKIT_PARAM_READWRITE (static_cast(G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB)) + +G_END_DECLS + +#endif // WebKitPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp index 88a09a2..a00db49 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp @@ -20,6 +20,7 @@ #include "config.h" #include "WebKitWebContext.h" +#include "WebKitWebContextPrivate.h" #include #include @@ -74,4 +75,10 @@ WebKitWebContext* webkit_web_context_get_default(void) return WEBKIT_WEB_CONTEXT(g_once(&onceInit, createDefaultWebContext, 0)); } +WKContextRef webkitWebContextGetWKContext(WebKitWebContext* context) +{ + g_assert(WEBKIT_IS_WEB_CONTEXT(context)); + + return context->priv->context; +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h new file mode 100644 index 0000000..86d7dec --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WebKitWebContextPrivate_h +#define WebKitWebContextPrivate_h + +#include "WebKitWebContext.h" +#include + +G_BEGIN_DECLS + +WKContextRef webkitWebContextGetWKContext(WebKitWebContext*); + +G_END_DECLS + +#endif // WebKitWebContextPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp index 73079ba..ad7db5e 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp @@ -21,7 +21,9 @@ #include "WebKitWebView.h" #include "NotImplemented.h" +#include "WebKitWebContextPrivate.h" #include "WebKitWebViewBasePrivate.h" +#include "WebKitPrivate.h" #include "WebPageProxy.h" #include #include @@ -29,21 +31,124 @@ using namespace WebKit; using namespace WebCore; +enum { + PROP_0, + + PROP_WEB_CONTEXT +}; + +struct _WebKitWebViewPrivate { + WebKitWebContext* context; +}; + G_DEFINE_TYPE(WebKitWebView, webkit_web_view, WEBKIT_TYPE_WEB_VIEW_BASE) +static void webkitWebViewConstructed(GObject* object) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(object); + + webkitWebViewBaseCreateWebPage(WEBKIT_WEB_VIEW_BASE(webView), + webkitWebContextGetWKContext(webView->priv->context), 0); +} + +static void webkitWebViewSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(object); + + switch (propId) { + case PROP_WEB_CONTEXT: + webView->priv->context = WEBKIT_WEB_CONTEXT(g_value_get_object(value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); + } +} + +static void webkitWebViewGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(object); + + switch (propId) { + case PROP_WEB_CONTEXT: + g_value_take_object(value, webView->priv->context); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); + } +} + static void webkit_web_view_init(WebKitWebView* webView) { - webkitWebViewBaseCreateWebPage(WEBKIT_WEB_VIEW_BASE(webView), WKContextGetSharedProcessContext(), 0); + webView->priv = G_TYPE_INSTANCE_GET_PRIVATE(webView, WEBKIT_TYPE_WEB_VIEW, WebKitWebViewPrivate); } static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) { + GObjectClass* gObjectClass = G_OBJECT_CLASS(webViewClass); + + gObjectClass->constructed = webkitWebViewConstructed; + gObjectClass->set_property = webkitWebViewSetProperty; + gObjectClass->get_property = webkitWebViewGetProperty; + + g_type_class_add_private(webViewClass, sizeof(WebKitWebViewPrivate)); + + /** + * WebKitWebView:web-context: + * + * The #WebKitWebContext of the view. + */ + g_object_class_install_property(gObjectClass, + PROP_WEB_CONTEXT, + g_param_spec_object("web-context", + "Web Context", + "The web context for the view", + WEBKIT_TYPE_WEB_CONTEXT, + static_cast(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); } // Public API. + +/** + * webkit_web_view_new: + * + * Creates a new #WebKitWebView with the default #WebKitWebContext. + * See also webkit_web_view_new_with_context(). + * + * Returns: The newly created #WebKitWebView widget + */ GtkWidget* webkit_web_view_new() { - return GTK_WIDGET(WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW, NULL))); + return webkit_web_view_new_with_context(webkit_web_context_get_default()); +} + +/** + * webkit_web_view_new_with_context: + * @context: the #WebKitWebContext to be used by the #WebKitWebView + * + * Creates a new #WebKitWebView with the given #WebKitWebContext. + * + * Returns: The newly created #WebKitWebView widget + */ +GtkWidget* webkit_web_view_new_with_context(WebKitWebContext* context) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0); + + return GTK_WIDGET(g_object_new(WEBKIT_TYPE_WEB_VIEW, "web-context", context, NULL)); +} + +/** + * webkit_web_view_get_context: + * @web_view: a #WebKitWebView + * + * Gets the web context of @web_view. + * + * Returns: (transfer-none): the #WebKitWebContext of the view + */ +WebKitWebContext* webkit_web_view_get_context(WebKitWebView *webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); + + return webView->priv->context; } void webkit_web_view_load_uri(WebKitWebView* webView, const gchar* uri) diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h index 8eac614..305bc56 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h @@ -23,6 +23,7 @@ #ifndef WebKitWebView_h #define WebKitWebView_h +#include #include G_BEGIN_DECLS @@ -60,20 +61,26 @@ struct _WebKitWebViewClass { }; WK_EXPORT GType -webkit_web_view_get_type (void); +webkit_web_view_get_type (void); WK_EXPORT GtkWidget * -webkit_web_view_new (void); +webkit_web_view_new (void); + +WK_EXPORT GtkWidget * +webkit_web_view_new_with_context (WebKitWebContext *context); + +WK_EXPORT WebKitWebContext * +webkit_web_view_get_context (WebKitWebView *web_view); WK_EXPORT void -webkit_web_view_load_uri (WebKitWebView *webView, - const gchar *uri); +webkit_web_view_load_uri (WebKitWebView *webView, + const gchar *uri); WK_EXPORT void -webkit_web_view_go_back (WebKitWebView *webView); +webkit_web_view_go_back (WebKitWebView *webView); WK_EXPORT void -webkit_web_view_go_forward (WebKitWebView *webView); +webkit_web_view_go_forward (WebKitWebView *webView); G_END_DECLS diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/testwebview.c b/Source/WebKit2/UIProcess/API/gtk/tests/testwebview.c new file mode 100644 index 0000000..fe47c30 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/testwebview.c @@ -0,0 +1,42 @@ +/* + * 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 testWebViewDefaultContext(void) +{ + WebKitWebView *view = WEBKIT_WEB_VIEW(webkit_web_view_new()); + g_object_ref_sink(view); + g_assert(webkit_web_view_get_context(view) == webkit_web_context_get_default()); + g_object_unref(view); +} + +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/webview/default_context", + testWebViewDefaultContext); + + return g_test_run(); +} -- 2.7.4