Bug 1777562 [wpt PR 34663] - [FedCM] Rename FederatedCredential to IdentityCredential...
[gecko.git] / widget / gtk / GRefPtr.h
bloba109abe09064771698a450cb6cf0cd56ea87051f
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef GRefPtr_h_
7 #define GRefPtr_h_
9 // Allows to use RefPtr<T> with various kinds of GObjects
11 #include <gdk/gdk.h>
12 #include <gio/gio.h>
13 #include <gtk/gtk.h>
14 #include "mozilla/RefPtr.h"
16 #ifdef MOZ_ENABLE_DBUS
17 // TODO: Remove this (we should use GDBus instead, which is not deprecated).
18 # include <dbus/dbus-glib.h>
19 #endif
21 namespace mozilla {
23 template <typename T>
24 struct GObjectRefPtrTraits {
25 static void AddRef(T* aObject) { g_object_ref(aObject); }
26 static void Release(T* aObject) { g_object_unref(aObject); }
29 #define GOBJECT_TRAITS(type_) \
30 template <> \
31 struct RefPtrTraits<type_> : public GObjectRefPtrTraits<type_> {};
33 GOBJECT_TRAITS(GtkWidget)
34 GOBJECT_TRAITS(GFile)
35 GOBJECT_TRAITS(GMenu)
36 GOBJECT_TRAITS(GMenuItem)
37 GOBJECT_TRAITS(GSimpleAction)
38 GOBJECT_TRAITS(GSimpleActionGroup)
39 GOBJECT_TRAITS(GDBusProxy)
40 GOBJECT_TRAITS(GAppInfo)
41 GOBJECT_TRAITS(GAppLaunchContext)
42 GOBJECT_TRAITS(GdkDragContext)
43 GOBJECT_TRAITS(GDBusMessage)
44 GOBJECT_TRAITS(GdkPixbuf)
45 GOBJECT_TRAITS(GCancellable)
46 GOBJECT_TRAITS(GUnixFDList)
48 #ifdef MOZ_ENABLE_DBUS
49 GOBJECT_TRAITS(DBusGProxy)
50 #endif
52 #undef GOBJECT_TRAITS
54 template <>
55 struct RefPtrTraits<GVariant> {
56 static void AddRef(GVariant* aVariant) { g_variant_ref(aVariant); }
57 static void Release(GVariant* aVariant) { g_variant_unref(aVariant); }
60 template <>
61 struct RefPtrTraits<GHashTable> {
62 static void AddRef(GHashTable* aObject) { g_hash_table_ref(aObject); }
63 static void Release(GHashTable* aObject) { g_hash_table_unref(aObject); }
66 template <>
67 struct RefPtrTraits<GDBusNodeInfo> {
68 static void AddRef(GDBusNodeInfo* aObject) { g_dbus_node_info_ref(aObject); }
69 static void Release(GDBusNodeInfo* aObject) {
70 g_dbus_node_info_unref(aObject);
74 #ifdef MOZ_ENABLE_DBUS
75 template <>
76 struct RefPtrTraits<DBusGConnection> {
77 static void AddRef(DBusGConnection* aObject) {
78 dbus_g_connection_ref(aObject);
80 static void Release(DBusGConnection* aObject) {
81 dbus_g_connection_unref(aObject);
84 #endif
86 } // namespace mozilla
88 #endif