Title: [96136] trunk/Source/WebKit2
Revision
96136
Author
carlo...@webkit.org
Date
2011-09-27 11:32:55 -0700 (Tue, 27 Sep 2011)

Log Message

[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):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (96135 => 96136)


--- trunk/Source/WebKit2/ChangeLog	2011-09-27 18:19:01 UTC (rev 96135)
+++ trunk/Source/WebKit2/ChangeLog	2011-09-27 18:32:55 UTC (rev 96136)
@@ -1,6 +1,40 @@
 2011-09-27  Carlos Garcia Campos  <cgar...@igalia.com>
 
+        [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  <cgar...@igalia.com>
+
+
         [GTK] Add WebKitWebContext to GTK API
         https://bugs.webkit.org/show_bug.cgi?id=67931
 

Modified: trunk/Source/WebKit2/GNUmakefile.am (96135 => 96136)


--- trunk/Source/WebKit2/GNUmakefile.am	2011-09-27 18:19:01 UTC (rev 96135)
+++ trunk/Source/WebKit2/GNUmakefile.am	2011-09-27 18:32:55 UTC (rev 96136)
@@ -453,8 +453,10 @@
 	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 @@
 
 # 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_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

Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h (0 => 96136)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h	2011-09-27 18:32:55 UTC (rev 96136)
@@ -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 <glib.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_PARAM_READABLE (static_cast<GParamFlags>(G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB))
+#define WEBKIT_PARAM_WRITABLE (static_cast<GParamFlags>(G_PARAM_WRITABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB))
+#define WEBKIT_PARAM_READWRITE (static_cast<GParamFlags>(G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB))
+
+G_END_DECLS
+
+#endif // WebKitPrivate_h

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp (96135 => 96136)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp	2011-09-27 18:19:01 UTC (rev 96135)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp	2011-09-27 18:32:55 UTC (rev 96136)
@@ -20,6 +20,7 @@
 #include "config.h"
 #include "WebKitWebContext.h"
 
+#include "WebKitWebContextPrivate.h"
 #include <WebKit2/WKContext.h>
 #include <WebKit2/WKType.h>
 
@@ -74,4 +75,10 @@
     return WEBKIT_WEB_CONTEXT(g_once(&onceInit, createDefaultWebContext, 0));
 }
 
+WKContextRef webkitWebContextGetWKContext(WebKitWebContext* context)
+{
+    g_assert(WEBKIT_IS_WEB_CONTEXT(context));
 
+    return context->priv->context;
+}
+

Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h (0 => 96136)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h	2011-09-27 18:32:55 UTC (rev 96136)
@@ -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 <WebKit2/WebKit2.h>
+
+G_BEGIN_DECLS
+
+WKContextRef webkitWebContextGetWKContext(WebKitWebContext*);
+
+G_END_DECLS
+
+#endif // WebKitWebContextPrivate_h

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp (96135 => 96136)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2011-09-27 18:19:01 UTC (rev 96135)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2011-09-27 18:32:55 UTC (rev 96136)
@@ -21,7 +21,9 @@
 #include "WebKitWebView.h"
 
 #include "NotImplemented.h"
+#include "WebKitWebContextPrivate.h"
 #include "WebKitWebViewBasePrivate.h"
+#include "WebKitPrivate.h"
 #include "WebPageProxy.h"
 #include <WebKit2/WKBase.h>
 #include <WebKit2/WKURL.h>
@@ -29,23 +31,126 @@
 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<GParamFlags>(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)
 {
     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h (96135 => 96136)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h	2011-09-27 18:19:01 UTC (rev 96135)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h	2011-09-27 18:32:55 UTC (rev 96136)
@@ -23,6 +23,7 @@
 #ifndef WebKitWebView_h
 #define WebKitWebView_h
 
+#include <webkit2/WebKitWebContext.h>
 #include <webkit2/WebKitWebViewBase.h>
 
 G_BEGIN_DECLS
@@ -60,20 +61,26 @@
 };
 
 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
 

Added: trunk/Source/WebKit2/UIProcess/API/gtk/tests/testwebview.c (0 => 96136)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/testwebview.c	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/testwebview.c	2011-09-27 18:32:55 UTC (rev 96136)
@@ -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 <glib.h>
+#include <gtk/gtk.h>
+#include <webkit2/webkit2.h>
+
+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();
+}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to