[GTK] Add a GKeyFile especialization to GOwnPtr
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Jan 2012 14:27:24 +0000 (14:27 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Jan 2012 14:27:24 +0000 (14:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=77191

Reviewed by Martin Robinson.

Source/JavaScriptCore:

* wtf/gobject/GOwnPtr.cpp:
(WTF::GKeyFile): Implement freeOwnedGPtr for GKeyFile.
* wtf/gobject/GOwnPtr.h: Add GKeyFile template.
* wtf/gobject/GTypedefs.h: Add forward declaration for GKeyFile.

Source/WebKit2:

* Shared/gtk/ArgumentCodersGtk.cpp:
(CoreIPC::decodeGKeyFile): Use GOwnPtr for GKeyFile.
(CoreIPC::encode): Ditto.
(CoreIPC::decode): Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@106117 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/wtf/gobject/GOwnPtr.cpp
Source/JavaScriptCore/wtf/gobject/GOwnPtr.h
Source/JavaScriptCore/wtf/gobject/GTypedefs.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/gtk/ArgumentCodersGtk.cpp

index f6589eb46d2b358e838c93c895d6bc5f9e56b1a2..af28b77f6dcc7a7b362df44c3384568ad796158a 100644 (file)
@@ -1,3 +1,15 @@
+2012-01-27  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Add a GKeyFile especialization to GOwnPtr
+        https://bugs.webkit.org/show_bug.cgi?id=77191
+
+        Reviewed by Martin Robinson.
+
+        * wtf/gobject/GOwnPtr.cpp:
+        (WTF::GKeyFile): Implement freeOwnedGPtr for GKeyFile.
+        * wtf/gobject/GOwnPtr.h: Add GKeyFile template.
+        * wtf/gobject/GTypedefs.h: Add forward declaration for GKeyFile.
+
 2012-01-25  Yury Semikhatsky  <yurys@chromium.org>
 
         Web Inspector: should be possible to open function declaration from script popover
index 4158689c663a73490676b193bb96686632cfd6c0..c727956cea3132813169e12a7db8fbf9f14c4039 100644 (file)
@@ -55,6 +55,12 @@ template <> void freeOwnedGPtr<GTimer>(GTimer* ptr)
         g_timer_destroy(ptr);
 }
 
+template <> void freeOwnedGPtr<GKeyFile>(GKeyFile* ptr)
+{
+    if (ptr)
+        g_key_file_free(ptr);
+}
+
 } // namespace WTF
 
 #endif // ENABLE(GLIB_SUPPORT)
index 593b838006c9b46c03c1730ddadcd9970deed0c7..221971f97d5d284968f9b41bfa44ab9ea9029665 100644 (file)
@@ -38,6 +38,7 @@ template<> void freeOwnedGPtr<GList>(GList*);
 template<> void freeOwnedGPtr<GPatternSpec>(GPatternSpec*);
 template<> void freeOwnedGPtr<GDir>(GDir*);
 template<> void freeOwnedGPtr<GTimer>(GTimer*);
+template<> void freeOwnedGPtr<GKeyFile>(GKeyFile*);
 
 template <typename T> class GOwnPtr {
     WTF_MAKE_NONCOPYABLE(GOwnPtr);
index 22a0aa260a90e7e4f44dc60b25e52f433fa57963..e2b2ba6b83221632c6cceef3bacfdabe16938fde 100644 (file)
@@ -59,6 +59,7 @@ typedef struct _GSource GSource;
 typedef struct _GVariant GVariant;
 typedef union _GdkEvent GdkEvent;
 typedef struct _GTimer GTimer;
+typedef struct _GKeyFile GKeyFile;
 
 #if USE(CAIRO)
 typedef struct _cairo_surface cairo_surface_t;
index 9a6ffb4c26cf00b464552074b4e68271166255d4..b8d63e9e294e3ce32792354e76aad224598abe39 100644 (file)
@@ -1,3 +1,15 @@
+2012-01-27  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Add a GKeyFile especialization to GOwnPtr
+        https://bugs.webkit.org/show_bug.cgi?id=77191
+
+        Reviewed by Martin Robinson.
+
+        * Shared/gtk/ArgumentCodersGtk.cpp:
+        (CoreIPC::decodeGKeyFile): Use GOwnPtr for GKeyFile.
+        (CoreIPC::encode): Ditto.
+        (CoreIPC::decode): Ditto.
+
 2012-01-27  Kenneth Rohde Christiansen  <kenneth@webkit.org>
 
         [Qt] Fade out tap highlighting when starting to pan
index ad93c554aaf202e6b22669dc2d5dd5aab4b1a474..8b802e9f7517eac91802785ed92ad82415aab647 100644 (file)
@@ -226,21 +226,18 @@ static void encodeGKeyFile(ArgumentEncoder* encoder, GKeyFile* keyFile)
     encoder->encode(dataReference);
 }
 
-static bool decodeGKeyFile(ArgumentDecoder* decoder, GKeyFile** keyFile)
+static bool decodeGKeyFile(ArgumentDecoder* decoder, GOwnPtr<GKeyFile>& keyFile)
 {
     DataReference dataReference;
     if (!decoder->decode(dataReference))
         return false;
 
-    if (!dataReference.size()) {
-        *keyFile = 0;
+    if (!dataReference.size())
         return true;
-    }
 
-    *keyFile = g_key_file_new();
-    if (!g_key_file_load_from_data(*keyFile, reinterpret_cast<const gchar*>(dataReference.data()), dataReference.size(), G_KEY_FILE_NONE, 0)) {
-        g_key_file_free(*keyFile);
-        *keyFile = 0;
+    keyFile.set(g_key_file_new());
+    if (!g_key_file_load_from_data(keyFile.get(), reinterpret_cast<const gchar*>(dataReference.data()), dataReference.size(), G_KEY_FILE_NONE, 0)) {
+        keyFile.clear();
         return false;
     }
 
@@ -249,50 +246,46 @@ static bool decodeGKeyFile(ArgumentDecoder* decoder, GKeyFile** keyFile)
 
 void encode(ArgumentEncoder* encoder, GtkPrintSettings* printSettings)
 {
-    GKeyFile* keyFile = g_key_file_new();
-    gtk_print_settings_to_key_file(printSettings, keyFile, "Print Settings");
-    encodeGKeyFile(encoder, keyFile);
-    g_key_file_free(keyFile);
+    GOwnPtr<GKeyFile> keyFile(g_key_file_new());
+    gtk_print_settings_to_key_file(printSettings, keyFile.get(), "Print Settings");
+    encodeGKeyFile(encoder, keyFile.get());
 }
 
 bool decode(ArgumentDecoder* decoder, GRefPtr<GtkPrintSettings>& printSettings)
 {
-    GKeyFile* keyFile;
-    if (!decodeGKeyFile(decoder, &keyFile))
+    GOwnPtr<GKeyFile> keyFile;
+    if (!decodeGKeyFile(decoder, keyFile))
         return false;
 
     printSettings = adoptGRef(gtk_print_settings_new());
     if (!keyFile)
         return true;
 
-    if (!gtk_print_settings_load_key_file(printSettings.get(), keyFile, "Print Settings", 0))
+    if (!gtk_print_settings_load_key_file(printSettings.get(), keyFile.get(), "Print Settings", 0))
         printSettings = 0;
-    g_key_file_free(keyFile);
 
     return printSettings;
 }
 
 void encode(ArgumentEncoder* encoder, GtkPageSetup* pageSetup)
 {
-    GKeyFile* keyFile = g_key_file_new();
-    gtk_page_setup_to_key_file(pageSetup, keyFile, "Page Setup");
-    encodeGKeyFile(encoder, keyFile);
-    g_key_file_free(keyFile);
+    GOwnPtr<GKeyFile> keyFile(g_key_file_new());
+    gtk_page_setup_to_key_file(pageSetup, keyFile.get(), "Page Setup");
+    encodeGKeyFile(encoder, keyFile.get());
 }
 
 bool decode(ArgumentDecoder* decoder, GRefPtr<GtkPageSetup>& pageSetup)
 {
-    GKeyFile* keyFile;
-    if (!decodeGKeyFile(decoder, &keyFile))
+    GOwnPtr<GKeyFile> keyFile;
+    if (!decodeGKeyFile(decoder, keyFile))
         return false;
 
     pageSetup = adoptGRef(gtk_page_setup_new());
     if (!keyFile)
         return true;
 
-    if (!gtk_page_setup_load_key_file(pageSetup.get(), keyFile, "Page Setup", 0))
+    if (!gtk_page_setup_load_key_file(pageSetup.get(), keyFile.get(), "Page Setup", 0))
         pageSetup = 0;
-    g_key_file_free(keyFile);
 
     return pageSetup;
 }