Changeset 98845 in webkit


Ignore:
Timestamp:
Oct 31, 2011 4:45:37 AM (12 years ago)
Author:
Carlos Garcia Campos
Message:

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

Location:
trunk/Source/WebKit2
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r98842 r98845  
     12011-10-31  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Add methods to get/set the settings of a web view to WebKit2 GTK+ API
     4        https://bugs.webkit.org/show_bug.cgi?id=71109
     5
     6        Reviewed by Martin Robinson.
     7
     8        * GNUmakefile.am: Add WebKitSettingsPrivate.h.
     9        * UIProcess/API/gtk/WebKitSettings.cpp:
     10        (webkitSettingsAttachSettingsToPage): Set the preferences of the
     11        given WebKitSettings object to the page group of the given WKPage.
     12        * UIProcess/API/gtk/WebKitSettingsPrivate.h: Added.
     13        * UIProcess/API/gtk/WebKitWebView.cpp:
     14        (webkitWebViewConstructed): Create the default WebKitSettings for
     15        the view.
     16        (webkit_web_view_set_settings):
     17        (webkit_web_view_get_settings):
     18        * UIProcess/API/gtk/WebKitWebView.h:
     19        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt:
     20        * UIProcess/API/gtk/tests/TestWebKitWebView.cpp:
     21        (testWebViewSettings):
     22        (beforeAll):
     23
    1242011-10-31  Carlos Garcia Campos  <cgarcia@igalia.com>
    225
  • trunk/Source/WebKit2/GNUmakefile.am

    r98842 r98845  
    498498        Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp \
    499499        Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h \
     500        Source/WebKit2/UIProcess/API/gtk/WebKitSettingsPrivate.h \
    500501        Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h \
    501502        Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp \
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp

    r98497 r98845  
    3333
    3434#include "WebKitPrivate.h"
    35 #include <WebKit2/WKPreferences.h>
     35#include "WebKitSettingsPrivate.h"
    3636#include <WebKit2/WKRetainPtr.h>
    37 #include <WebKit2/WKType.h>
    3837#include <glib/gi18n-lib.h>
    3938
     
    381380}
    382381
     382void webkitSettingsAttachSettingsToPage(WebKitSettings* settings, WKPageRef wkPage)
     383{
     384    WKPageGroupSetPreferences(WKPageGetPageGroup(wkPage), settings->priv->preferences.get());
     385}
     386
    383387/**
    384388 * webkit_settings_new:
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp

    r98707 r98845  
    2222
    2323#include "WebKitBackForwardListPrivate.h"
     24#include "WebKitSettingsPrivate.h"
    2425#include "WebKitWebContextPrivate.h"
    2526#include "WebKitWebLoaderClient.h"
     
    5556    GRefPtr<WebKitWebLoaderClient> loaderClient;
    5657    GRefPtr<WebKitBackForwardList> backForwardList;
     58    GRefPtr<WebKitSettings> settings;
    5759};
    5860
     
    8284
    8385    priv->backForwardList = adoptGRef(webkitBackForwardListCreate(WKPageGetBackForwardList(toAPI(page))));
     86    priv->settings = adoptGRef(webkit_settings_new());
     87    webkitSettingsAttachSettingsToPage(priv->settings.get(), toAPI(page));
    8488}
    8589
     
    602606    webkitWebViewUpdateURI(webView);
    603607}
     608
     609/**
     610 * webkit_web_view_set_settings:
     611 * @web_view: a #WebKitWebView
     612 * @settings: a #WebKitSettings
     613 *
     614 * Sets the #WebKitSettings to be applied to @web_view. The
     615 * existing #WebKitSettings of @web_view will be replaced by
     616 * @settings. New settings are applied immediately on @web_view.
     617 * The same #WebKitSettings object can be shared
     618 * by multiple #WebKitWebView<!-- -->s.
     619 */
     620void webkit_web_view_set_settings(WebKitWebView* webView, WebKitSettings* settings)
     621{
     622    g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
     623    g_return_if_fail(WEBKIT_IS_SETTINGS(settings));
     624
     625    if (webView->priv->settings == settings)
     626        return;
     627
     628    webView->priv->settings = settings;
     629    webkitSettingsAttachSettingsToPage(settings, toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView))));
     630}
     631
     632/**
     633 * webkit_web_view_get_settings:
     634 * @web_view: a #WebKitWebView
     635 *
     636 * Gets the #WebKitSettings currently applied to @web_view.
     637 * If no other #WebKitSettings have been explicitly applied to
     638 * @web_view with webkit_web_view_set_settings(), the default
     639 * #WebKitSettings will be returned. This method always returns
     640 * a valid #WebKitSettings object.
     641 * To modify any of the @web_view settings, you can either create
     642 * a new #WebKitSettings object with webkit_settings_new(), setting
     643 * the desired preferences, and then replace the existing @web_view
     644 * settings with webkit_web_view_set_settings() or get the existing
     645 * @web_view settings and update it directly. #WebKitSettings objects
     646 * can be shared by multiple #WebKitWebView<!-- -->s, so modifying
     647 * the settings of a #WebKitWebView would affect other
     648 * #WebKitWebView<!-- -->s using the same #WebKitSettings.
     649 *
     650 * Returns: (transfer none): the #WebKitSettings attached to @web_view
     651 */
     652WebKitSettings* webkit_web_view_get_settings(WebKitWebView* webView)
     653{
     654    g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0);
     655
     656    return webView->priv->settings.get();
     657}
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h

    r98707 r98845  
    3232#include <webkit2/WebKitWebContext.h>
    3333#include <webkit2/WebKitWebLoaderClient.h>
     34#include <webkit2/WebKitSettings.h>
    3435#include <webkit2/WebKitWebViewBase.h>
    3536
     
    135136                                              const gchar               *charset);
    136137
     138WEBKIT_API void
     139webkit_web_view_set_settings                 (WebKitWebView             *web_view,
     140                                              WebKitSettings            *settings);
     141
     142WEBKIT_API WebKitSettings *
     143webkit_web_view_get_settings                 (WebKitWebView             *web_view);
     144
    137145G_END_DECLS
    138146
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt

    r98707 r98845  
    6565webkit_web_view_go_to_back_forward_list_item
    6666webkit_web_view_get_uri
     67webkit_web_view_set_settings
     68webkit_web_view_get_settings
    6769
    6870<SUBSECTION Standard>
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp

    r97920 r98845  
    4848}
    4949
     50static void testWebViewSettings(WebViewTest* test, gconstpointer)
     51{
     52    WebKitSettings* defaultSettings = webkit_web_view_get_settings(test->m_webView);
     53    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(defaultSettings));
     54    g_assert(defaultSettings);
     55    g_assert(webkit_settings_get_enable_javascript(defaultSettings));
     56
     57    GRefPtr<WebKitSettings> newSettings = adoptGRef(webkit_settings_new());
     58    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(newSettings.get()));
     59    g_object_set(G_OBJECT(newSettings.get()), "enable-javascript", FALSE, NULL);
     60    webkit_web_view_set_settings(test->m_webView, newSettings.get());
     61
     62    WebKitSettings* settings = webkit_web_view_get_settings(test->m_webView);
     63    g_assert(settings != defaultSettings);
     64    g_assert(!webkit_settings_get_enable_javascript(settings));
     65
     66    GRefPtr<GtkWidget> webView2 = webkit_web_view_new();
     67    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webView2.get()));
     68    webkit_web_view_set_settings(WEBKIT_WEB_VIEW(webView2.get()), settings);
     69    g_assert(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webView2.get())) == settings);
     70
     71    GRefPtr<WebKitSettings> newSettings2 = adoptGRef(webkit_settings_new());
     72    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(newSettings2.get()));
     73    webkit_web_view_set_settings(WEBKIT_WEB_VIEW(webView2.get()), newSettings2.get());
     74    settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webView2.get()));
     75    g_assert(settings == newSettings2.get());
     76    g_assert(webkit_settings_get_enable_javascript(settings));
     77}
     78
    5079void beforeAll()
    5180{
     
    5382    WebViewTest::add("WebKitWebView", "custom-charset", testWebViewCustomCharset);
    5483    Test::add("WebKitWebView", "webviews-share-clients", testWebViewsShareClients);
     84    WebViewTest::add("WebKitWebView", "settings", testWebViewSettings);
    5585}
    5686
Note: See TracChangeset for help on using the changeset viewer.