firefox/mozilla-858919.patch
2014-07-30 12:03:59 +02:00

273 lines
9.2 KiB
Diff

# HG changeset patch
# Parent b17cad2d1e5e6bcb5a10096d51d07ea8a79b6921
# User Martin Stransky <stransky@redhat.com>
Bug 858919 - Add support for libnotify calls which was removed for new notification API. r=karlt
diff --git a/toolkit/system/gnome/moz.build b/toolkit/system/gnome/moz.build
--- a/toolkit/system/gnome/moz.build
+++ b/toolkit/system/gnome/moz.build
@@ -1,15 +1,17 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
SOURCES += [
+ 'nsAlertsIconListener.cpp',
+ 'nsAlertsService.cpp',
'nsGnomeModule.cpp',
]
if CONFIG['MOZ_ENABLE_GCONF']:
SOURCES += [
'nsGConfService.cpp',
]
diff --git a/toolkit/system/gnome/nsAlertsIconListener.h b/toolkit/system/gnome/nsAlertsIconListener.h
new file mode 100644
--- /dev/null
+++ b/toolkit/system/gnome/nsAlertsIconListener.h
@@ -0,0 +1,89 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nsAlertsIconListener_h__
+#define nsAlertsIconListener_h__
+
+#include "nsCOMPtr.h"
+#include "imgINotificationObserver.h"
+#include "nsStringAPI.h"
+#include "nsIObserver.h"
+#include "nsWeakReference.h"
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+class imgIRequest;
+
+struct NotifyNotification;
+
+class nsAlertsIconListener : public imgINotificationObserver,
+ public nsIObserver,
+ public nsSupportsWeakReference
+{
+public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_IMGINOTIFICATIONOBSERVER
+ NS_DECL_NSIOBSERVER
+
+ nsAlertsIconListener();
+
+ nsresult InitAlertAsync(const nsAString & aImageUrl,
+ const nsAString & aAlertTitle,
+ const nsAString & aAlertText,
+ bool aAlertTextClickable,
+ const nsAString & aAlertCookie,
+ nsIObserver * aAlertListener);
+
+ void SendCallback();
+ void SendClosed();
+
+protected:
+ virtual ~nsAlertsIconListener();
+
+ nsresult OnStopRequest(imgIRequest* aRequest);
+ nsresult OnStopFrame(imgIRequest* aRequest);
+
+ /**
+ * The only difference between libnotify.so.4 and libnotify.so.1 for these symbols
+ * is that notify_notification_new takes three arguments in libnotify.so.4 and
+ * four in libnotify.so.1.
+ * Passing the fourth argument as NULL is binary compatible.
+ */
+ typedef void (*NotifyActionCallback)(NotifyNotification*, char*, gpointer);
+ typedef bool (*notify_is_initted_t)(void);
+ typedef bool (*notify_init_t)(const char*);
+ typedef GList* (*notify_get_server_caps_t)(void);
+ typedef NotifyNotification* (*notify_notification_new_t)(const char*, const char*, const char*, const char*);
+ typedef bool (*notify_notification_show_t)(void*, char*);
+ typedef void (*notify_notification_set_icon_from_pixbuf_t)(void*, GdkPixbuf*);
+ typedef void (*notify_notification_add_action_t)(void*, const char*, const char*, NotifyActionCallback, gpointer, GFreeFunc);
+
+ nsCOMPtr<imgIRequest> mIconRequest;
+ nsCString mAlertTitle;
+ nsCString mAlertText;
+
+ nsCOMPtr<nsIObserver> mAlertListener;
+ nsString mAlertCookie;
+
+ bool mLoadedFrame;
+ bool mAlertHasAction;
+
+ static void* libNotifyHandle;
+ static bool libNotifyNotAvail;
+ static notify_is_initted_t notify_is_initted;
+ static notify_init_t notify_init;
+ static notify_get_server_caps_t notify_get_server_caps;
+ static notify_notification_new_t notify_notification_new;
+ static notify_notification_show_t notify_notification_show;
+ static notify_notification_set_icon_from_pixbuf_t notify_notification_set_icon_from_pixbuf;
+ static notify_notification_add_action_t notify_notification_add_action;
+ NotifyNotification* mNotification;
+ gulong mClosureHandler;
+
+ nsresult StartRequest(const nsAString & aImageUrl);
+ nsresult ShowAlert(GdkPixbuf* aPixbuf);
+};
+
+#endif
diff --git a/toolkit/system/gnome/nsAlertsService.cpp b/toolkit/system/gnome/nsAlertsService.cpp
new file mode 100644
--- /dev/null
+++ b/toolkit/system/gnome/nsAlertsService.cpp
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode:nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "nsXULAppAPI.h"
+#include "nsAlertsService.h"
+#include "nsAlertsIconListener.h"
+#include "nsAutoPtr.h"
+
+NS_IMPL_ADDREF(nsAlertsService)
+NS_IMPL_RELEASE(nsAlertsService)
+
+NS_INTERFACE_MAP_BEGIN(nsAlertsService)
+ NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIAlertsService)
+ NS_INTERFACE_MAP_ENTRY(nsIAlertsService)
+NS_INTERFACE_MAP_END_THREADSAFE
+
+nsAlertsService::nsAlertsService()
+{
+}
+
+nsAlertsService::~nsAlertsService()
+{}
+
+nsresult
+nsAlertsService::Init()
+{
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const nsAString & aImageUrl, const nsAString & aAlertTitle,
+ const nsAString & aAlertText, bool aAlertTextClickable,
+ const nsAString & aAlertCookie,
+ nsIObserver * aAlertListener,
+ const nsAString & aAlertName,
+ const nsAString & aBidi,
+ const nsAString & aLang,
+ nsIPrincipal * aPrincipal)
+{
+ nsRefPtr<nsAlertsIconListener> alertListener = new nsAlertsIconListener();
+ if (!alertListener)
+ return NS_ERROR_OUT_OF_MEMORY;
+
+ return alertListener->InitAlertAsync(aImageUrl, aAlertTitle, aAlertText, aAlertTextClickable,
+ aAlertCookie, aAlertListener);
+}
+
+NS_IMETHODIMP nsAlertsService::CloseAlert(const nsAString& aAlertName,
+ nsIPrincipal* aPrincipal)
+{
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
diff --git a/toolkit/system/gnome/nsAlertsService.h b/toolkit/system/gnome/nsAlertsService.h
new file mode 100644
--- /dev/null
+++ b/toolkit/system/gnome/nsAlertsService.h
@@ -0,0 +1,27 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nsAlertsService_h__
+#define nsAlertsService_h__
+
+#include "nsIAlertsService.h"
+#include "nsCOMPtr.h"
+
+class nsAlertsService : public nsIAlertsService
+{
+public:
+ NS_DECL_NSIALERTSSERVICE
+ NS_DECL_ISUPPORTS
+
+ nsAlertsService();
+
+ nsresult Init();
+
+protected:
+ virtual ~nsAlertsService();
+
+};
+
+#endif /* nsAlertsService_h__ */
diff --git a/toolkit/system/gnome/nsGnomeModule.cpp b/toolkit/system/gnome/nsGnomeModule.cpp
--- a/toolkit/system/gnome/nsGnomeModule.cpp
+++ b/toolkit/system/gnome/nsGnomeModule.cpp
@@ -17,53 +17,58 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGC
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGnomeVFSService, Init)
#endif
#ifdef MOZ_ENABLE_GIO
#include "nsGIOService.h"
#include "nsGSettingsService.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(nsGIOService)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGSettingsService, Init)
#endif
+#include "nsAlertsService.h"
+NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsAlertsService, Init)
#ifdef MOZ_ENABLE_GCONF
NS_DEFINE_NAMED_CID(NS_GCONFSERVICE_CID);
#endif
#ifdef MOZ_ENABLE_GNOMEVFS
NS_DEFINE_NAMED_CID(NS_GNOMEVFSSERVICE_CID);
#endif
#ifdef MOZ_ENABLE_GIO
NS_DEFINE_NAMED_CID(NS_GIOSERVICE_CID);
NS_DEFINE_NAMED_CID(NS_GSETTINGSSERVICE_CID);
#endif
+NS_DEFINE_NAMED_CID(NS_SYSTEMALERTSSERVICE_CID);
static const mozilla::Module::CIDEntry kGnomeCIDs[] = {
#ifdef MOZ_ENABLE_GCONF
{ &kNS_GCONFSERVICE_CID, false, nullptr, nsGConfServiceConstructor },
#endif
#ifdef MOZ_ENABLE_GNOMEVFS
{ &kNS_GNOMEVFSSERVICE_CID, false, nullptr, nsGnomeVFSServiceConstructor },
#endif
#ifdef MOZ_ENABLE_GIO
{ &kNS_GIOSERVICE_CID, false, nullptr, nsGIOServiceConstructor },
{ &kNS_GSETTINGSSERVICE_CID, false, nullptr, nsGSettingsServiceConstructor },
#endif
+ { &kNS_SYSTEMALERTSSERVICE_CID, false, nullptr, nsAlertsServiceConstructor },
{ nullptr }
};
static const mozilla::Module::ContractIDEntry kGnomeContracts[] = {
#ifdef MOZ_ENABLE_GCONF
{ NS_GCONFSERVICE_CONTRACTID, &kNS_GCONFSERVICE_CID },
#endif
#ifdef MOZ_ENABLE_GNOMEVFS
{ NS_GNOMEVFSSERVICE_CONTRACTID, &kNS_GNOMEVFSSERVICE_CID },
#endif
#ifdef MOZ_ENABLE_GIO
{ NS_GIOSERVICE_CONTRACTID, &kNS_GIOSERVICE_CID },
{ NS_GSETTINGSSERVICE_CONTRACTID, &kNS_GSETTINGSSERVICE_CID },
#endif
+ { NS_SYSTEMALERTSERVICE_CONTRACTID, &kNS_SYSTEMALERTSSERVICE_CID },
{ nullptr }
};
static nsresult
InitGType ()
{
g_type_init();
return NS_OK;