Bug 776134 - Part 2: Make AlertsService remote alerts from content process to chrome process. r=dougt

This commit is contained in:
William Chen 2012-07-26 18:25:02 -04:00
parent e1cec5724c
commit d95a8ff25b
12 changed files with 66 additions and 97 deletions

View File

@ -15,7 +15,7 @@ Cu.import("resource://gre/modules/Services.jsm");
function AlertsService() { }
AlertsService.prototype = {
classID: Components.ID("{5dce03b2-8faa-4b6e-9242-6ddb0411750c}"),
classID: Components.ID("{fe33c107-82a4-41d6-8c64-5353267e04c9}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAlertsService]),
showAlertNotification: function(aImageUrl, aTitle, aText, aTextClickable, aCookie, aAlertListener, aName) {

View File

@ -7,8 +7,8 @@ contract @mozilla.org/b2g-camera-content;1 {eff4231b-abce-4f7f-a40a-d646e8fde3ce
category JavaScript-navigator-property mozCamera @mozilla.org/b2g-camera-content;1
# AlertsService.js
component {5dce03b2-8faa-4b6e-9242-6ddb0411750c} AlertsService.js
contract @mozilla.org/alerts-service;1 {5dce03b2-8faa-4b6e-9242-6ddb0411750c}
component {fe33c107-82a4-41d6-8c64-5353267e04c9} AlertsService.js
contract @mozilla.org/system-alerts-service;1 {fe33c107-82a4-41d6-8c64-5353267e04c9}
# ContentPermissionPrompt.js
component {8c719f03-afe0-4aac-91ff-6c215895d467} ContentPermissionPrompt.js

View File

@ -24,21 +24,21 @@ NS_IMPL_ISUPPORTS1(AlertServiceObserver, nsIObserver)
/* nsDesktopNotification */
/* ------------------------------------------------------------------------ */
void
nsresult
nsDOMDesktopNotification::PostDesktopNotification()
{
nsCOMPtr<nsIAlertsService> alerts = do_GetService("@mozilla.org/alerts-service;1");
if (!alerts)
return;
return NS_ERROR_NOT_IMPLEMENTED;
if (!mObserver)
mObserver = new AlertServiceObserver(this);
alerts->ShowAlertNotification(mIconURL, mTitle, mDescription,
true,
EmptyString(),
mObserver,
EmptyString());
return alerts->ShowAlertNotification(mIconURL, mTitle, mDescription,
true,
EmptyString(),
mObserver,
EmptyString());
}
DOMCI_DATA(DesktopNotification, nsDOMDesktopNotification)
@ -145,14 +145,16 @@ nsDOMDesktopNotification::DispatchNotificationEvent(const nsString& aName)
}
}
void
nsresult
nsDOMDesktopNotification::SetAllow(bool aAllow)
{
mAllow = aAllow;
// if we have called Show() already, lets go ahead and post a notification
if (mShowHasBeenCalled && aAllow)
PostDesktopNotification();
return PostDesktopNotification();
return NS_OK;
}
void
@ -176,8 +178,7 @@ nsDOMDesktopNotification::Show()
if (!mAllow)
return NS_OK;
PostDesktopNotification();
return NS_OK;
return PostDesktopNotification();
}
NS_IMETHODIMP
@ -277,17 +278,17 @@ nsDesktopNotificationRequest::GetElement(nsIDOMElement * *aElement)
NS_IMETHODIMP
nsDesktopNotificationRequest::Cancel()
{
mDesktopNotification->SetAllow(false);
nsresult rv = mDesktopNotification->SetAllow(false);
mDesktopNotification = nullptr;
return NS_OK;
return rv;
}
NS_IMETHODIMP
nsDesktopNotificationRequest::Allow()
{
mDesktopNotification->SetAllow(true);
nsresult rv = mDesktopNotification->SetAllow(true);
mDesktopNotification = nullptr;
return NS_OK;
return rv;
}
NS_IMETHODIMP

View File

@ -87,9 +87,9 @@ public:
* PostDesktopNotification
* Uses alert service to display a notification
*/
void PostDesktopNotification();
nsresult PostDesktopNotification();
void SetAllow(bool aAllow);
nsresult SetAllow(bool aAllow);
/*
* Creates and dispatches a dom event of type aName

View File

@ -17,6 +17,7 @@ endif
PARALLEL_DIRS += \
aboutmemory \
alerts \
apppicker \
commandlines \
console \
@ -51,12 +52,6 @@ PARALLEL_DIRS += \
$(NULL)
endif
ifneq (,$(filter cocoa, $(MOZ_WIDGET_TOOLKIT)))
TOOL_DIRS += alerts
else
PARALLEL_DIRS += alerts
endif
ifdef MOZ_FEEDS
PARALLEL_DIRS += feeds
endif

View File

@ -13,7 +13,6 @@ include $(DEPTH)/config/autoconf.mk
MODULE = alerts
XPIDLSRCS = nsIAlertsService.idl
ifneq (,$(filter $(MOZ_WIDGET_TOOLKIT),windows gtk2 qt android))
LIBRARY_NAME = alerts_s
FORCE_STATIC_LIB = 1
LIBXUL_LIBRARY = 1
@ -21,12 +20,11 @@ CPPSRCS = \
nsAlertsService.cpp \
$(NULL)
LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/components/build/
endif
ifneq (,$(filter cocoa, $(MOZ_WIDGET_TOOLKIT)))
XPIDLSRCS += nsINotificationsList.idl
# mac/growl needs to be first for linking to work!
DIRS += \
TOOL_DIRS += \
mac/growl \
mac \
$(NULL)
@ -34,9 +32,7 @@ endif
TEST_DIRS += test
ifneq (,$(filter $(MOZ_WIDGET_TOOLKIT),windows gtk2 qt android))
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/ipc/chromium/chromium-config.mk
endif
include $(topsrcdir)/config/rules.mk

View File

@ -2,7 +2,7 @@
* 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 "nsAlertsService.h"
#include "nsGrowlAlertsService.h"
#include "nsToolkitCompsCID.h"
#include "mozilla/ModuleUtils.h"
#include "nsCOMPtr.h"
@ -11,16 +11,16 @@
#include "nsICategoryManager.h"
#include "nsMemory.h"
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsAlertsService, Init)
NS_DEFINE_NAMED_CID(NS_ALERTSSERVICE_CID);
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGrowlAlertsService, Init)
NS_DEFINE_NAMED_CID(NS_SYSTEMALERTSSERVICE_CID);
static const mozilla::Module::CIDEntry kAlertsCIDs[] = {
{ &kNS_ALERTSSERVICE_CID, false, NULL, nsAlertsServiceConstructor },
{ &kNS_SYSTEMALERTSSERVICE_CID, false, NULL, nsGrowlAlertsServiceConstructor },
{ NULL }
};
static const mozilla::Module::ContractIDEntry kAlertsContracts[] = {
{ NS_ALERTSERVICE_CONTRACTID, &kNS_ALERTSSERVICE_CID },
{ NS_SYSTEMALERTSERVICE_CONTRACTID, &kNS_SYSTEMALERTSSERVICE_CID },
{ NULL }
};

View File

@ -2,27 +2,27 @@
* 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_
#ifndef nsGrowlAlertsService_h_
#define nsGrowlAlertsService_h_
#include "nsIAlertsService.h"
#include "nsIObserver.h"
struct GrowlDelegateWrapper;
class nsAlertsService : public nsIAlertsService,
public nsIObserver
class nsGrowlAlertsService : public nsIAlertsService,
public nsIObserver
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIALERTSSERVICE
NS_DECL_NSIOBSERVER
nsAlertsService();
nsGrowlAlertsService();
nsresult Init();
private:
GrowlDelegateWrapper* mDelegate;
virtual ~nsAlertsService();
virtual ~nsGrowlAlertsService();
};
#endif // nsAlertsService_h_
#endif // nsGrowlAlertsService_h_

View File

@ -4,7 +4,7 @@
* 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 "nsAlertsService.h"
#include "nsGrowlAlertsService.h"
#include "nsStringAPI.h"
#include "nsAlertsImageLoadListener.h"
#include "nsIURI.h"
@ -97,19 +97,19 @@ DispatchNamedNotification(const nsAString &aName,
}
////////////////////////////////////////////////////////////////////////////////
//// nsAlertsService
//// nsGrowlAlertsService
NS_IMPL_THREADSAFE_ADDREF(nsAlertsService)
NS_IMPL_THREADSAFE_RELEASE(nsAlertsService)
NS_IMPL_THREADSAFE_ADDREF(nsGrowlAlertsService)
NS_IMPL_THREADSAFE_RELEASE(nsGrowlAlertsService)
NS_INTERFACE_MAP_BEGIN(nsAlertsService)
NS_INTERFACE_MAP_BEGIN(nsGrowlAlertsService)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIAlertsService)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsIAlertsService)
NS_INTERFACE_MAP_END_THREADSAFE
nsresult
nsAlertsService::Init()
nsGrowlAlertsService::Init()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
@ -142,9 +142,9 @@ nsAlertsService::Init()
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
nsAlertsService::nsAlertsService() : mDelegate(nullptr) {}
nsGrowlAlertsService::nsGrowlAlertsService() : mDelegate(nullptr) {}
nsAlertsService::~nsAlertsService()
nsGrowlAlertsService::~nsGrowlAlertsService()
{
delete mDelegate;
}
@ -153,13 +153,13 @@ nsAlertsService::~nsAlertsService()
//// nsIAlertsService
NS_IMETHODIMP
nsAlertsService::ShowAlertNotification(const nsAString& aImageUrl,
const nsAString& aAlertTitle,
const nsAString& aAlertText,
bool aAlertClickable,
const nsAString& aAlertCookie,
nsIObserver* aAlertListener,
const nsAString& aAlertName)
nsGrowlAlertsService::ShowAlertNotification(const nsAString& aImageUrl,
const nsAString& aAlertTitle,
const nsAString& aAlertText,
bool aAlertClickable,
const nsAString& aAlertCookie,
nsIObserver* aAlertListener,
const nsAString& aAlertName)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
@ -199,8 +199,8 @@ nsAlertsService::ShowAlertNotification(const nsAString& aImageUrl,
//// nsIObserver
NS_IMETHODIMP
nsAlertsService::Observe(nsISupports* aSubject, const char* aTopic,
const PRUnichar* aData)
nsGrowlAlertsService::Observe(nsISupports* aSubject, const char* aTopic,
const PRUnichar* aData)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;

View File

@ -8,7 +8,7 @@
#include "nsAlertsService.h"
#ifdef ANDROID
#ifdef MOZ_WIDGET_ANDROID
#include "AndroidBridge.h"
#else
@ -24,7 +24,7 @@
#define ALERT_CHROME_URL "chrome://global/content/alerts/alert.xul"
#endif // !ANDROID
#endif // !MOZ_WIDGET_ANDROID
using namespace mozilla;
@ -87,7 +87,7 @@ NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const nsAString & aImageUrl
return NS_OK;
}
#ifdef ANDROID
#ifdef MOZ_WIDGET_ANDROID
mozilla::AndroidBridge::Bridge()->ShowAlertNotification(aImageUrl, aAlertTitle, aAlertText, aAlertCookie,
aAlertListener, aAlertName);
return NS_OK;
@ -109,6 +109,10 @@ NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const nsAString & aImageUrl
return NS_OK;
}
#ifdef XP_MACOSX
return NS_ERROR_NOT_IMPLEMENTED;
#endif
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
nsCOMPtr<nsIDOMWindow> newWindow;
@ -178,7 +182,7 @@ NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const nsAString & aImageUrl
"chrome,dialog=yes,titlebar=no,popup=yes", argsArray,
getter_AddRefs(newWindow));
return rv;
#endif // !ANDROID
#endif // !MOZ_WIDGET_ANDROID
}
NS_IMETHODIMP nsAlertsService::OnProgress(const nsAString & aAlertName,
@ -186,20 +190,20 @@ NS_IMETHODIMP nsAlertsService::OnProgress(const nsAString & aAlertName,
PRInt64 aProgressMax,
const nsAString & aAlertText)
{
#ifdef ANDROID
#ifdef MOZ_WIDGET_ANDROID
mozilla::AndroidBridge::Bridge()->AlertsProgressListener_OnProgress(aAlertName, aProgress, aProgressMax, aAlertText);
return NS_OK;
#else
return NS_ERROR_NOT_IMPLEMENTED;
#endif // !ANDROID
#endif // !MOZ_WIDGET_ANDROID
}
NS_IMETHODIMP nsAlertsService::OnCancel(const nsAString & aAlertName)
{
#ifdef ANDROID
#ifdef MOZ_WIDGET_ANDROID
mozilla::AndroidBridge::Bridge()->AlertsProgressListener_OnCancel(aAlertName);
return NS_OK;
#else
return NS_ERROR_NOT_IMPLEMENTED;
#endif // !ANDROID
#endif // !MOZ_WIDGET_ANDROID
}

View File

@ -18,11 +18,6 @@ IS_COMPONENT = 1
MODULE_NAME = nsToolkitCompsModule
LIBXUL_LIBRARY = 1
ifneq (,$(filter $(MOZ_WIDGET_TOOLKIT),windows gtk2 qt android))
ALERTS_SERVICE=1
DEFINES += -DALERTS_SERVICE
endif
EXPORTS = nsToolkitCompsCID.h
CPPSRCS = nsToolkitCompsModule.cpp
@ -30,6 +25,7 @@ CPPSRCS = nsToolkitCompsModule.cpp
include $(topsrcdir)/config/config.mk
LOCAL_INCLUDES = \
-I$(srcdir)/../alerts \
-I$(srcdir)/../downloads \
-I$(srcdir)/../feeds \
-I$(srcdir)/../find \
@ -41,13 +37,8 @@ LOCAL_INCLUDES = \
-I$(srcdir)/../../xre \
$(NULL)
ifdef ALERTS_SERVICE
LOCAL_INCLUDES += \
-I$(srcdir)/../alerts \
$(NULL)
endif
SHARED_LIBRARY_LIBS = \
../alerts/$(LIB_PREFIX)alerts_s.$(LIB_SUFFIX) \
../find/$(LIB_PREFIX)mozfind_s.$(LIB_SUFFIX) \
../typeaheadfind/$(LIB_PREFIX)fastfind_s.$(LIB_SUFFIX) \
../startup/$(LIB_PREFIX)appstartup_s.$(LIB_SUFFIX) \
@ -65,14 +56,6 @@ LOCAL_INCLUDES += \
endif
endif
ifdef ALERTS_SERVICE
SHARED_LIBRARY_LIBS += ../alerts/$(LIB_PREFIX)alerts_s.$(LIB_SUFFIX)
endif
ifdef ALERTS_SERVICE_MAC
SHARED_LIBRARY_LIBS += ../alerts/mac/$(LIB_PREFIX)alerts_s.$(LIB_SUFFIX)
SHARED_LIBRARY_LIBS += ../alerts/mac/growl/$(LIB_PREFIX)growl_s.$(LIB_SUFFIX)
endif
ifdef MOZ_URL_CLASSIFIER
SHARED_LIBRARY_LIBS += ../url-classifier/$(LIB_PREFIX)urlclassifier_s.$(LIB_SUFFIX)
endif

View File

@ -15,9 +15,7 @@
#include "nsParentalControlsServiceWin.h"
#endif
#ifdef ALERTS_SERVICE
#include "nsAlertsService.h"
#endif
#include "nsDownloadManager.h"
#include "nsDownloadProxy.h"
@ -45,9 +43,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsFindService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsParentalControlsServiceWin)
#endif
#ifdef ALERTS_SERVICE
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAlertsService)
#endif
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsDownloadManager,
nsDownloadManager::GetSingleton)
@ -87,9 +83,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsUpdateProcessor)
NS_DEFINE_NAMED_CID(NS_TOOLKIT_APPSTARTUP_CID);
NS_DEFINE_NAMED_CID(NS_USERINFO_CID);
#ifdef ALERTS_SERVICE
NS_DEFINE_NAMED_CID(NS_ALERTSSERVICE_CID);
#endif
#if defined(XP_WIN) && !defined(MOZ_DISABLE_PARENTAL_CONTROLS)
NS_DEFINE_NAMED_CID(NS_PARENTALCONTROLSSERVICE_CID);
#endif
@ -112,9 +106,7 @@ NS_DEFINE_NAMED_CID(NS_UPDATEPROCESSOR_CID);
static const mozilla::Module::CIDEntry kToolkitCIDs[] = {
{ &kNS_TOOLKIT_APPSTARTUP_CID, false, NULL, nsAppStartupConstructor },
{ &kNS_USERINFO_CID, false, NULL, nsUserInfoConstructor },
#ifdef ALERTS_SERVICE
{ &kNS_ALERTSSERVICE_CID, false, NULL, nsAlertsServiceConstructor },
#endif
#if defined(XP_WIN) && !defined(MOZ_DISABLE_PARENTAL_CONTROLS)
{ &kNS_PARENTALCONTROLSSERVICE_CID, false, NULL, nsParentalControlsServiceWinConstructor },
#endif
@ -139,9 +131,7 @@ static const mozilla::Module::CIDEntry kToolkitCIDs[] = {
static const mozilla::Module::ContractIDEntry kToolkitContracts[] = {
{ NS_APPSTARTUP_CONTRACTID, &kNS_TOOLKIT_APPSTARTUP_CID },
{ NS_USERINFO_CONTRACTID, &kNS_USERINFO_CID },
#ifdef ALERTS_SERVICE
{ NS_ALERTSERVICE_CONTRACTID, &kNS_ALERTSSERVICE_CID },
#endif
#if defined(XP_WIN) && !defined(MOZ_DISABLE_PARENTAL_CONTROLS)
{ NS_PARENTALCONTROLSSERVICE_CONTRACTID, &kNS_PARENTALCONTROLSSERVICE_CID },
#endif