Changeset 65255 in webkit


Ignore:
Timestamp:
Aug 12, 2010 10:33:35 AM (14 years ago)
Author:
kov@webkit.org
Message:

2010-08-12 Gustavo Noronha Silva <gustavo.noronha@collabora.co.uk>

Reviewed by Martin Robinson.

[GTK] Use GSettings to save/restore Web Inspector settings
https://bugs.webkit.org/show_bug.cgi?id=43512

  • GNUmakefile.am: GSettings rules.
  • configure.ac: GSettings infrastructure, and check if we should use it by looking for an appropriate version of GIO.

JavaScriptCore

2010-08-12 Gustavo Noronha Silva <gustavo.noronha@collabora.co.uk>

Reviewed by Martin Robinson.

[GTK] Use GSettings to save/restore Web Inspector settings
https://bugs.webkit.org/show_bug.cgi?id=43512

  • wtf/gobject/GRefPtr.cpp: Added support for GVariant, used by our GSettings support. (WTF::refGPtr): (WTF::derefGPtr):
  • wtf/gobject/GRefPtr.h:

WebKit/gtk

2010-08-12 Gustavo Noronha Silva <gustavo.noronha@collabora.co.uk>

Reviewed by Martin Robinson.

[GTK] Use GSettings to save/restore Web Inspector settings
https://bugs.webkit.org/show_bug.cgi?id=43512

Use GSettings to save/restore settings used by the Web Inspector.
A few helper functions were added to have settings that use
boolean values be actual booleans, and also to conform with the
GSettings naming requirements for keys.

  • WebCoreSupport/InspectorClientGtk.cpp: (WebKit::toGSettingName): (WebKit::truthStringFromVariant): (WebKit::variantFromTruthString): (WebKit::InspectorClient::populateSetting): (WebKit::InspectorClient::storeSetting):
  • org.webkit.gtk.gschema.xml: Added.
  • webkit/webkitprivate.cpp: (inspectorGSettings): (webkit_init):
  • webkit/webkitprivate.h:
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r65253 r65255  
     12010-08-12  Gustavo Noronha Silva  <gustavo.noronha@collabora.co.uk>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [GTK] Use GSettings to save/restore Web Inspector settings
     6        https://bugs.webkit.org/show_bug.cgi?id=43512
     7
     8        * GNUmakefile.am: GSettings rules.
     9        * configure.ac: GSettings infrastructure, and check if we should
     10        use it by looking for an appropriate version of GIO.
     11
    1122010-08-12  Rafael Antognolli  <antognolli@profusion.mobi>
    213
  • trunk/GNUmakefile.am

    r64760 r65255  
    925925        && rm -f xgen-gtc
    926926
     927# GSettings
     928if USE_GSETTINGS
     929gsettings_SCHEMAS = $(top_builddir)/WebKit/gtk/org.webkitgtk-@WEBKITGTK_API_VERSION@.gschema.xml
     930
     931@GSETTINGS_RULES@
     932endif
     933
    927934# Files that will be distributed
    928935EXTRA_DIST += \
     
    941948        $(srcdir)/WebKit/gtk/resources/* \
    942949        $(srcdir)/WebKit/gtk/tests/resources/* \
    943         $(srcdir)/WebKit/gtk/tests/test_utils.h
     950        $(srcdir)/WebKit/gtk/tests/test_utils.h \
     951        $(srcdir)/WebKit/gtk/org.webkitgtk.gschema.xml.in
    944952
    945953# extra resource files
     
    11461154        $(top_builddir)/WebKit/gtk/docs/GNUmakefile \
    11471155        $(top_builddir)/WebKit/gtk/@WEBKITGTK_PC_NAME@-@WEBKITGTK_API_VERSION@.pc \
    1148         $(top_builddir)/WebKit/gtk/webkit/webkitversion.h
     1156        $(top_builddir)/WebKit/gtk/webkit/webkitversion.h \
     1157        $(top_builddir)/WebKit/gtk/org.webkitgtk-@WEBKITGTK_API_VERSION@.gschema.xml
    11491158
    11501159MAINTAINERCLEANFILES += \
  • trunk/JavaScriptCore/ChangeLog

    r65242 r65255  
     12010-08-12  Gustavo Noronha Silva  <gustavo.noronha@collabora.co.uk>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [GTK] Use GSettings to save/restore Web Inspector settings
     6        https://bugs.webkit.org/show_bug.cgi?id=43512
     7
     8        * wtf/gobject/GRefPtr.cpp: Added support for GVariant, used by our
     9        GSettings support.
     10        (WTF::refGPtr):
     11        (WTF::derefGPtr):
     12        * wtf/gobject/GRefPtr.h:
     13
    1142010-08-12  Gabor Loki  <loki@webkit.org>
    215
  • trunk/JavaScriptCore/wtf/gobject/GRefPtr.cpp

    r55149 r65255  
    3636}
    3737
     38#if GLIB_CHECK_VERSION(2, 24, 0)
     39template <> GVariant* refGPtr(GVariant* ptr)
     40{
     41    if (ptr)
     42        g_variant_ref(ptr);
     43    return ptr;
     44}
     45
     46template <> void derefGPtr(GVariant* ptr)
     47{
     48    g_variant_unref(ptr);
     49}
     50#endif
     51
    3852} // namespace WTF
  • trunk/JavaScriptCore/wtf/gobject/GRefPtr.h

    r62674 r65255  
    2626#include "AlwaysInline.h"
    2727#include <algorithm>
    28 
    29 typedef struct _GHashTable GHashTable;
    30 typedef void* gpointer;
    31 extern "C" void g_object_unref(gpointer object);
    32 extern "C" gpointer  g_object_ref_sink(gpointer object);
     28#include <glib.h>
    3329
    3430namespace WTF {
     
    4137template <> GHashTable* refGPtr(GHashTable* ptr);
    4238template <> void derefGPtr(GHashTable* ptr);
     39
     40#if GLIB_CHECK_VERSION(2, 24, 0)
     41template <> GVariant* refGPtr(GVariant* ptr);
     42template <> void derefGPtr(GVariant* ptr);
     43#endif
    4344
    4445template <typename T> class GRefPtr {
  • trunk/WebKit/gtk/ChangeLog

    r65209 r65255  
     12010-08-12  Gustavo Noronha Silva  <gustavo.noronha@collabora.co.uk>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [GTK] Use GSettings to save/restore Web Inspector settings
     6        https://bugs.webkit.org/show_bug.cgi?id=43512
     7
     8        Use GSettings to save/restore settings used by the Web Inspector.
     9        A few helper functions were added to have settings that use
     10        boolean values be actual booleans, and also to conform with the
     11        GSettings naming requirements for keys.
     12
     13        * WebCoreSupport/InspectorClientGtk.cpp:
     14        (WebKit::toGSettingName):
     15        (WebKit::truthStringFromVariant):
     16        (WebKit::variantFromTruthString):
     17        (WebKit::InspectorClient::populateSetting):
     18        (WebKit::InspectorClient::storeSetting):
     19        * org.webkit.gtk.gschema.xml: Added.
     20        * webkit/webkitprivate.cpp:
     21        (inspectorGSettings):
     22        (webkit_init):
     23        * webkit/webkitprivate.h:
     24
    1252010-08-11  Joone Hur  <joone@kldp.org>
    226
  • trunk/WebKit/gtk/WebCoreSupport/InspectorClientGtk.cpp

    r64865 r65255  
    11/*
    22 * Copyright (C) 2008 Gustavo Noronha Silva
     3 * Copyright (C) 2010 Collabora Ltd.
    34 *
    45 *  This library is free software; you can redistribute it and/or
     
    119120}
    120121
     122#if HAVE_GSETTINGS
     123static String toGSettingName(String inspectorSettingName)
     124{
     125    if (inspectorSettingName == "resourceTrackingEnabled")
     126        return String("resource-tracking-enabled");
     127
     128    if (inspectorSettingName == "xhrMonitor")
     129        return String("xhr-monitor-enabled");
     130
     131    if (inspectorSettingName == "frontendSettings")
     132        return String("frontend-settings");
     133
     134    if (inspectorSettingName == "debuggerEnabled")
     135        return String("debugger-enabled");
     136
     137    if (inspectorSettingName == "profilerEnabled")
     138        return String("profiler-enabled");
     139
     140    return inspectorSettingName;
     141}
     142
     143static String truthStringFromVariant(GVariant* variant)
     144{
     145    if (g_variant_get_boolean(variant))
     146        return String("true");
     147
     148    return String("false");
     149}
     150
     151static GVariant* variantFromTruthString(const String& truth)
     152{
     153    if (truth == "true")
     154        return g_variant_new_boolean(TRUE);
     155
     156    return g_variant_new_boolean(FALSE);
     157}
     158
     159static bool shouldIgnoreSetting(const String& key)
     160{
     161    // Ignore this setting for now, it doesn't seem to be used for
     162    // anything right now.
     163    if (key == "lastActivePanel")
     164        return true;
     165
     166    // GSettings considers trying to fetch or set a setting that is
     167    // not backed by a schema as programmer error, and aborts the
     168    // program's execution. We check here to avoid having an unhandled
     169    // setting as a fatal error.
     170    if (key == "resourceTrackingEnabled" || key == "xhrMonitor"
     171        || key == "frontendSettings" || key == "debuggerEnabled"
     172        || key == "profilerEnabled")
     173        return false;
     174
     175    LOG_VERBOSE(NotYetImplemented, "Unknown key ignored: %s", key.ascii().data());
     176    return true;
     177}
     178
    121179void InspectorClient::populateSetting(const String& key, String* value)
    122180{
     181    if (shouldIgnoreSetting(key))
     182        return;
     183
     184    GSettings* settings = inspectorGSettings();
     185    if (!settings)
     186        return;
     187
     188    GRefPtr<GVariant> variant = adoptGRef(g_settings_get_value(settings, toGSettingName(key).utf8().data()));
     189
     190    if (key == "resourceTrackingEnabled" || key == "xhrMonitor"
     191        || key == "debuggerEnabled" || key == "profilerEnabled")
     192        *value = truthStringFromVariant(variant.get());
     193    else if (key == "frontendSettings")
     194        *value = String(g_variant_get_string(variant.get(), 0));
     195}
     196
     197void InspectorClient::storeSetting(const String& key, const String& value)
     198{
     199    if (shouldIgnoreSetting(key))
     200        return;
     201
     202    GSettings* settings = inspectorGSettings();
     203    if (!settings)
     204        return;
     205
     206    GRefPtr<GVariant> variant(0);
     207
     208    // Set the key with the appropriate type, and also avoid setting
     209    // unknown keys to avoid aborting the execution.
     210    if (key == "resourceTrackingEnabled" || key == "xhrMonitor"
     211        || key == "debuggerEnabled" || key == "profilerEnabled")
     212        variant = adoptGRef(variantFromTruthString(value));
     213    else if (key == "frontendSettings")
     214        variant = adoptGRef(g_variant_new_string(value.utf8().data()));
     215
     216    if (!variant)
     217        return;
     218
     219    g_settings_set_value(settings, toGSettingName(key).utf8().data(), variant.get());
     220}
     221#else
     222void InspectorClient::populateSetting(const String&, String*)
     223{
    123224    notImplemented();
    124225}
    125226
    126 void InspectorClient::storeSetting(const String& key, const String& value)
     227void InspectorClient::storeSetting(const String&, const String&)
    127228{
    128229    notImplemented();
    129230}
     231#endif // HAVE_GSETTINGS
    130232
    131233bool InspectorClient::sendMessageToFrontend(const String& message)
  • trunk/WebKit/gtk/webkit/webkitprivate.cpp

    r60841 r65255  
    4545#include "webkitnetworkresponse.h"
    4646#include "webkitsoupauthdialog.h"
     47#include "webkitversion.h"
    4748#include <libintl.h>
    4849#include <runtime/InitializeThreading.h>
     
    215216}
    216217
     218#if HAVE_GSETTINGS
     219static bool isSchemaAvailable(char* schemaID)
     220{
     221    const char* const* availableSchemas = g_settings_list_schemas();
     222    char* const* iter = const_cast<char* const*>(availableSchemas);
     223
     224    while (*iter) {
     225        if (g_str_equal(schemaID, *iter))
     226            return true;
     227        iter++;
     228    }
     229
     230    return false;
     231}
     232
     233GSettings* inspectorGSettings()
     234{
     235    static GSettings* settings = 0;
     236
     237    if (settings)
     238        return settings;
     239
     240    GOwnPtr<gchar> schemaID(g_strdup_printf("org.webkitgtk-%.1f.inspector", WEBKITGTK_API_VERSION));
     241
     242    // Unfortunately GSettings will abort the process execution if the
     243    // schema is not installed, which is the case for when running
     244    // tests, or even the introspection dump at build time, so check
     245    // if we have the schema before trying to initialize it.
     246    if (!isSchemaAvailable(schemaID.get())) {
     247        g_warning("GSettings schema not found - settings will not be used or saved.");
     248        return 0;
     249    }
     250
     251    settings = g_settings_new(schemaID.get());
     252
     253    return settings;
     254}
     255#endif
     256
    217257void webkit_init()
    218258{
     
    239279    webkit_set_cache_model(WEBKIT_CACHE_MODEL_WEB_BROWSER);
    240280
     281#if HAVE_GSETTINGS
     282    // Initialize settings variables here to make sure this happens in
     283    // the main thread.
     284    inspectorGSettings();
     285#endif
     286
    241287#if ENABLE(DATABASE)
    242288    gchar* databaseDirectory = g_build_filename(g_get_user_data_dir(), "webkit", "databases", NULL);
  • trunk/WebKit/gtk/webkit/webkitprivate.h

    r65107 r65255  
    121121    void webkit_init();
    122122
     123#if HAVE_GSETTINGS
     124    GSettings* inspectorGSettings();
     125#endif
     126
    123127#define WEBKIT_PARAM_READABLE ((GParamFlags)(G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB))
    124128#define WEBKIT_PARAM_READWRITE ((GParamFlags)(G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB))
  • trunk/configure.ac

    r64763 r65255  
    261261WEBKIT_CHECK_DEPENDENCIES([glib unicode])
    262262
     263# Check if we can use GSettings
     264PKG_CHECK_MODULES([GSETTINGS],
     265                  [gio-2.0 >= 2.25.0],
     266                  [have_gsettings=yes],
     267                  [have_gsettings=no])
     268if test "$have_gsettings" = "yes"; then
     269   AC_DEFINE([HAVE_GSETTINGS], 1, [Whether we can use GSettings])
     270fi
     271
    263272GETTEXT_PACKAGE=$PACKAGE-$GTK_API_VERSION
    264273AC_SUBST(GETTEXT_PACKAGE)
     
    826835fi
    827836
     837# GSettings
     838GLIB_GSETTINGS
     839
    828840# check if gstreamer is available
    829841if test "$enable_video" = "yes"; then
     
    874886AM_CONDITIONAL([USE_FREETYPE], [test "$with_font_backend" = "freetype"])
    875887AM_CONDITIONAL([USE_PANGO], [test "$with_font_backend" = "pango"])
     888
     889# GLib/GIO feature conditionals
     890AM_CONDITIONAL([USE_GSETTINGS], [test "$have_gsettings" = "yes"])
    876891
    877892# WebKit feature conditionals
     
    935950AC_CONFIG_FILES([
    936951WebKit/gtk/${WEBKITGTK_PC_NAME}-${WEBKITGTK_API_VERSION}.pc:WebKit/gtk/webkit.pc.in
    937 WebKit/gtk/JSCore-${WEBKITGTK_API_VERSION}.gir:WebKit/gtk/JSCore.gir.in]
     952WebKit/gtk/JSCore-${WEBKITGTK_API_VERSION}.gir:WebKit/gtk/JSCore.gir.in
     953WebKit/gtk/org.webkitgtk-${WEBKITGTK_API_VERSION}.gschema.xml:WebKit/gtk/org.webkitgtk.gschema.xml.in
     954]
    938955,[WEBKITGTK_API_VERSION=$WEBKITGTK_API_VERSION,WEBKITGTK_PC_NAME=$WEBKITGTK_PC_NAME]
    939956)
Note: See TracChangeset for help on using the changeset viewer.