Diff
Modified: trunk/Source/WebKit2/ChangeLog (98844 => 98845)
--- trunk/Source/WebKit2/ChangeLog 2011-10-31 11:23:34 UTC (rev 98844)
+++ trunk/Source/WebKit2/ChangeLog 2011-10-31 11:45:37 UTC (rev 98845)
@@ -1,5 +1,28 @@
2011-10-31 Carlos Garcia Campos <cgar...@igalia.com>
+ [GTK] Add methods to get/set the settings of a web view to WebKit2 GTK+ API
+ https://bugs.webkit.org/show_bug.cgi?id=71109
+
+ Reviewed by Martin Robinson.
+
+ * GNUmakefile.am: Add WebKitSettingsPrivate.h.
+ * UIProcess/API/gtk/WebKitSettings.cpp:
+ (webkitSettingsAttachSettingsToPage): Set the preferences of the
+ given WebKitSettings object to the page group of the given WKPage.
+ * UIProcess/API/gtk/WebKitSettingsPrivate.h: Added.
+ * UIProcess/API/gtk/WebKitWebView.cpp:
+ (webkitWebViewConstructed): Create the default WebKitSettings for
+ the view.
+ (webkit_web_view_set_settings):
+ (webkit_web_view_get_settings):
+ * UIProcess/API/gtk/WebKitWebView.h:
+ * UIProcess/API/gtk/docs/webkit2gtk-sections.txt:
+ * UIProcess/API/gtk/tests/TestWebKitWebView.cpp:
+ (testWebViewSettings):
+ (beforeAll):
+
+2011-10-31 Carlos Garcia Campos <cgar...@igalia.com>
+
Unreviewed. Fix make distcheck build.
* GNUmakefile.am: Remove docs/GNUmakefile.in from EXTRA_DIST,
Modified: trunk/Source/WebKit2/GNUmakefile.am (98844 => 98845)
--- trunk/Source/WebKit2/GNUmakefile.am 2011-10-31 11:23:34 UTC (rev 98844)
+++ trunk/Source/WebKit2/GNUmakefile.am 2011-10-31 11:45:37 UTC (rev 98845)
@@ -497,6 +497,7 @@
Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h \
Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp \
Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h \
+ Source/WebKit2/UIProcess/API/gtk/WebKitSettingsPrivate.h \
Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h \
Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp \
Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h \
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp (98844 => 98845)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp 2011-10-31 11:23:34 UTC (rev 98844)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp 2011-10-31 11:45:37 UTC (rev 98845)
@@ -32,9 +32,8 @@
#include "WebKitSettings.h"
#include "WebKitPrivate.h"
-#include <WebKit2/WKPreferences.h>
+#include "WebKitSettingsPrivate.h"
#include <WebKit2/WKRetainPtr.h>
-#include <WebKit2/WKType.h>
#include <glib/gi18n-lib.h>
struct _WebKitSettingsPrivate {
@@ -380,6 +379,11 @@
priv->preferences = adoptWK(WKPreferencesCreate());
}
+void webkitSettingsAttachSettingsToPage(WebKitSettings* settings, WKPageRef wkPage)
+{
+ WKPageGroupSetPreferences(WKPageGetPageGroup(wkPage), settings->priv->preferences.get());
+}
+
/**
* webkit_settings_new:
*
Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitSettingsPrivate.h (0 => 98845)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitSettingsPrivate.h (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitSettingsPrivate.h 2011-10-31 11:45:37 UTC (rev 98845)
@@ -0,0 +1,34 @@
+/*
+ * 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 WebKitSettingsPrivate_h
+#define WebKitSettingsPrivate_h
+
+#include "WebKitSettings.h"
+#include <WebKit2/WebKit2.h>
+
+void webkitSettingsAttachSettingsToPage(WebKitSettings*, WKPageRef);
+
+#endif // WebKitSettingsPrivate_h
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp (98844 => 98845)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp 2011-10-31 11:23:34 UTC (rev 98844)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp 2011-10-31 11:45:37 UTC (rev 98845)
@@ -21,6 +21,7 @@
#include "WebKitWebView.h"
#include "WebKitBackForwardListPrivate.h"
+#include "WebKitSettingsPrivate.h"
#include "WebKitWebContextPrivate.h"
#include "WebKitWebLoaderClient.h"
#include "WebKitWebLoaderClientPrivate.h"
@@ -54,6 +55,7 @@
GRefPtr<WebKitWebLoaderClient> loaderClient;
GRefPtr<WebKitBackForwardList> backForwardList;
+ GRefPtr<WebKitSettings> settings;
};
G_DEFINE_TYPE(WebKitWebView, webkit_web_view, WEBKIT_TYPE_WEB_VIEW_BASE)
@@ -81,6 +83,8 @@
webkitWebViewSetLoaderClient(webView, defaultLoaderClient.get(), toAPI(page));
priv->backForwardList = adoptGRef(webkitBackForwardListCreate(WKPageGetBackForwardList(toAPI(page))));
+ priv->settings = adoptGRef(webkit_settings_new());
+ webkitSettingsAttachSettingsToPage(priv->settings.get(), toAPI(page));
}
static void webkitWebViewSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec)
@@ -601,3 +605,53 @@
webkitBackForwardListItemGetWKItem(listItem));
webkitWebViewUpdateURI(webView);
}
+
+/**
+ * webkit_web_view_set_settings:
+ * @web_view: a #WebKitWebView
+ * @settings: a #WebKitSettings
+ *
+ * Sets the #WebKitSettings to be applied to @web_view. The
+ * existing #WebKitSettings of @web_view will be replaced by
+ * @settings. New settings are applied immediately on @web_view.
+ * The same #WebKitSettings object can be shared
+ * by multiple #WebKitWebView<!-- -->s.
+ */
+void webkit_web_view_set_settings(WebKitWebView* webView, WebKitSettings* settings)
+{
+ g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
+ g_return_if_fail(WEBKIT_IS_SETTINGS(settings));
+
+ if (webView->priv->settings == settings)
+ return;
+
+ webView->priv->settings = settings;
+ webkitSettingsAttachSettingsToPage(settings, toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView))));
+}
+
+/**
+ * webkit_web_view_get_settings:
+ * @web_view: a #WebKitWebView
+ *
+ * Gets the #WebKitSettings currently applied to @web_view.
+ * If no other #WebKitSettings have been explicitly applied to
+ * @web_view with webkit_web_view_set_settings(), the default
+ * #WebKitSettings will be returned. This method always returns
+ * a valid #WebKitSettings object.
+ * To modify any of the @web_view settings, you can either create
+ * a new #WebKitSettings object with webkit_settings_new(), setting
+ * the desired preferences, and then replace the existing @web_view
+ * settings with webkit_web_view_set_settings() or get the existing
+ * @web_view settings and update it directly. #WebKitSettings objects
+ * can be shared by multiple #WebKitWebView<!-- -->s, so modifying
+ * the settings of a #WebKitWebView would affect other
+ * #WebKitWebView<!-- -->s using the same #WebKitSettings.
+ *
+ * Returns: (transfer none): the #WebKitSettings attached to @web_view
+ */
+WebKitSettings* webkit_web_view_get_settings(WebKitWebView* webView)
+{
+ g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0);
+
+ return webView->priv->settings.get();
+}
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h (98844 => 98845)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h 2011-10-31 11:23:34 UTC (rev 98844)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h 2011-10-31 11:45:37 UTC (rev 98845)
@@ -31,6 +31,7 @@
#include <webkit2/WebKitDefines.h>
#include <webkit2/WebKitWebContext.h>
#include <webkit2/WebKitWebLoaderClient.h>
+#include <webkit2/WebKitSettings.h>
#include <webkit2/WebKitWebViewBase.h>
G_BEGIN_DECLS
@@ -134,6 +135,13 @@
webkit_web_view_set_custom_charset (WebKitWebView *web_view,
const gchar *charset);
+WEBKIT_API void
+webkit_web_view_set_settings (WebKitWebView *web_view,
+ WebKitSettings *settings);
+
+WEBKIT_API WebKitSettings *
+webkit_web_view_get_settings (WebKitWebView *web_view);
+
G_END_DECLS
#endif
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt (98844 => 98845)
--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt 2011-10-31 11:23:34 UTC (rev 98844)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt 2011-10-31 11:45:37 UTC (rev 98845)
@@ -64,6 +64,8 @@
webkit_web_view_get_back_forward_list
webkit_web_view_go_to_back_forward_list_item
webkit_web_view_get_uri
+webkit_web_view_set_settings
+webkit_web_view_get_settings
<SUBSECTION Standard>
WebKitWebViewClass
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp (98844 => 98845)
--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp 2011-10-31 11:23:34 UTC (rev 98844)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp 2011-10-31 11:45:37 UTC (rev 98845)
@@ -47,11 +47,41 @@
g_assert(client1 == client2);
}
+static void testWebViewSettings(WebViewTest* test, gconstpointer)
+{
+ WebKitSettings* defaultSettings = webkit_web_view_get_settings(test->m_webView);
+ test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(defaultSettings));
+ g_assert(defaultSettings);
+ g_assert(webkit_settings_get_enable_javascript(defaultSettings));
+
+ GRefPtr<WebKitSettings> newSettings = adoptGRef(webkit_settings_new());
+ test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(newSettings.get()));
+ g_object_set(G_OBJECT(newSettings.get()), "enable-_javascript_", FALSE, NULL);
+ webkit_web_view_set_settings(test->m_webView, newSettings.get());
+
+ WebKitSettings* settings = webkit_web_view_get_settings(test->m_webView);
+ g_assert(settings != defaultSettings);
+ g_assert(!webkit_settings_get_enable_javascript(settings));
+
+ GRefPtr<GtkWidget> webView2 = webkit_web_view_new();
+ test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webView2.get()));
+ webkit_web_view_set_settings(WEBKIT_WEB_VIEW(webView2.get()), settings);
+ g_assert(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webView2.get())) == settings);
+
+ GRefPtr<WebKitSettings> newSettings2 = adoptGRef(webkit_settings_new());
+ test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(newSettings2.get()));
+ webkit_web_view_set_settings(WEBKIT_WEB_VIEW(webView2.get()), newSettings2.get());
+ settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webView2.get()));
+ g_assert(settings == newSettings2.get());
+ g_assert(webkit_settings_get_enable_javascript(settings));
+}
+
void beforeAll()
{
WebViewTest::add("WebKitWebView", "default-context", testWebViewDefaultContext);
WebViewTest::add("WebKitWebView", "custom-charset", testWebViewCustomCharset);
Test::add("WebKitWebView", "webviews-share-clients", testWebViewsShareClients);
+ WebViewTest::add("WebKitWebView", "settings", testWebViewSettings);
}
void afterAll()