2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2010-09-09 22:00:14 -07:00
|
|
|
|
|
|
|
#ifndef nsDesktopNotification_h
|
|
|
|
#define nsDesktopNotification_h
|
|
|
|
|
2010-09-13 13:44:53 -07:00
|
|
|
#include "PCOMContentPermissionRequestChild.h"
|
|
|
|
|
2011-10-03 12:11:31 -07:00
|
|
|
#include "nsDOMClassInfoID.h"
|
|
|
|
#include "nsIPrincipal.h"
|
2010-09-09 22:00:14 -07:00
|
|
|
#include "nsIJSContextStack.h"
|
|
|
|
|
|
|
|
#include "nsIAlertsService.h"
|
|
|
|
|
|
|
|
#include "nsIDOMDesktopNotification.h"
|
|
|
|
#include "nsIDOMEventTarget.h"
|
2010-09-13 12:31:53 -07:00
|
|
|
#include "nsIContentPermissionPrompt.h"
|
2010-09-09 22:00:14 -07:00
|
|
|
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsWeakPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
|
|
|
|
#include "nsDOMEventTargetHelper.h"
|
2012-06-10 16:44:50 -07:00
|
|
|
#include "nsIDOMEvent.h"
|
2011-07-20 12:18:54 -07:00
|
|
|
#include "nsIDocument.h"
|
2010-09-09 22:00:14 -07:00
|
|
|
|
|
|
|
class AlertServiceObserver;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nsDesktopNotificationCenter
|
|
|
|
* Object hangs off of the navigator object and hands out nsDOMDesktopNotification objects
|
|
|
|
*/
|
|
|
|
class nsDesktopNotificationCenter : public nsIDOMDesktopNotificationCenter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMDESKTOPNOTIFICATIONCENTER
|
|
|
|
|
2012-03-12 17:56:07 -07:00
|
|
|
nsDesktopNotificationCenter(nsPIDOMWindow *aWindow)
|
2010-09-09 22:00:14 -07:00
|
|
|
{
|
|
|
|
mOwner = aWindow;
|
|
|
|
|
|
|
|
// Grab the uri of the document
|
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc;
|
|
|
|
mOwner->GetDocument(getter_AddRefs(domdoc));
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
|
2012-07-30 07:58:26 -07:00
|
|
|
mPrincipal = doc->NodePrincipal();
|
2010-09-09 22:00:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~nsDesktopNotificationCenter()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-10-18 18:54:00 -07:00
|
|
|
void Shutdown() {
|
2012-07-30 07:20:58 -07:00
|
|
|
mOwner = nullptr;
|
2010-10-18 18:54:00 -07:00
|
|
|
}
|
|
|
|
|
2010-09-09 22:00:14 -07:00
|
|
|
private:
|
|
|
|
nsCOMPtr<nsPIDOMWindow> mOwner;
|
2012-07-30 07:58:26 -07:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2010-09-09 22:00:14 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class nsDOMDesktopNotification : public nsDOMEventTargetHelper,
|
|
|
|
public nsIDOMDesktopNotification
|
|
|
|
{
|
|
|
|
friend class nsDesktopNotificationRequest;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSIDOMDESKTOPNOTIFICATION
|
|
|
|
|
|
|
|
nsDOMDesktopNotification(const nsAString & title,
|
|
|
|
const nsAString & description,
|
|
|
|
const nsAString & iconURL,
|
|
|
|
nsPIDOMWindow *aWindow,
|
2012-07-30 07:58:26 -07:00
|
|
|
nsIPrincipal* principal);
|
2010-09-09 22:00:14 -07:00
|
|
|
|
|
|
|
virtual ~nsDOMDesktopNotification();
|
|
|
|
|
2012-11-19 10:27:54 -08:00
|
|
|
void Init();
|
|
|
|
|
2010-09-09 22:00:14 -07:00
|
|
|
/*
|
|
|
|
* PostDesktopNotification
|
|
|
|
* Uses alert service to display a notification
|
|
|
|
*/
|
2012-07-26 15:25:02 -07:00
|
|
|
nsresult PostDesktopNotification();
|
2010-09-09 22:00:14 -07:00
|
|
|
|
2012-07-26 15:25:02 -07:00
|
|
|
nsresult SetAllow(bool aAllow);
|
2011-01-19 09:38:36 -08:00
|
|
|
|
2010-09-09 22:00:14 -07:00
|
|
|
/*
|
|
|
|
* Creates and dispatches a dom event of type aName
|
|
|
|
*/
|
|
|
|
void DispatchNotificationEvent(const nsString& aName);
|
|
|
|
|
|
|
|
void HandleAlertServiceNotification(const char *aTopic);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
nsString mTitle;
|
|
|
|
nsString mDescription;
|
|
|
|
nsString mIconURL;
|
|
|
|
|
|
|
|
nsRefPtr<AlertServiceObserver> mObserver;
|
2012-07-30 07:58:26 -07:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mAllow;
|
|
|
|
bool mShowHasBeenCalled;
|
2010-09-09 22:00:14 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simple Request
|
|
|
|
*/
|
2010-09-13 12:31:53 -07:00
|
|
|
class nsDesktopNotificationRequest : public nsIContentPermissionRequest,
|
2011-04-02 19:14:00 -07:00
|
|
|
public nsRunnable,
|
|
|
|
public PCOMContentPermissionRequestChild
|
2010-09-13 13:44:53 -07:00
|
|
|
|
2010-09-09 22:00:14 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2010-09-13 12:31:53 -07:00
|
|
|
NS_DECL_NSICONTENTPERMISSIONREQUEST
|
2010-09-09 22:00:14 -07:00
|
|
|
|
|
|
|
nsDesktopNotificationRequest(nsDOMDesktopNotification* notification)
|
|
|
|
: mDesktopNotification(notification) {}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
2010-09-13 12:31:53 -07:00
|
|
|
nsCOMPtr<nsIContentPermissionPrompt> prompt =
|
2012-10-31 10:06:42 -07:00
|
|
|
do_CreateInstance(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID);
|
2010-09-09 22:00:14 -07:00
|
|
|
if (prompt) {
|
|
|
|
prompt->Prompt(this);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
~nsDesktopNotificationRequest()
|
2010-09-13 13:44:53 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Recv__delete__(const bool& allow)
|
2010-09-09 22:00:14 -07:00
|
|
|
{
|
2010-09-13 13:44:53 -07:00
|
|
|
if (allow)
|
|
|
|
(void) Allow();
|
|
|
|
else
|
|
|
|
(void) Cancel();
|
|
|
|
return true;
|
2010-09-09 22:00:14 -07:00
|
|
|
}
|
2010-09-13 13:44:53 -07:00
|
|
|
void IPDLRelease() { Release(); }
|
2010-09-09 22:00:14 -07:00
|
|
|
|
|
|
|
nsRefPtr<nsDOMDesktopNotification> mDesktopNotification;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AlertServiceObserver: public nsIObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
AlertServiceObserver(nsDOMDesktopNotification* notification)
|
|
|
|
: mNotification(notification) {}
|
|
|
|
|
|
|
|
virtual ~AlertServiceObserver() {}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
void Disconnect() { mNotification = nullptr; }
|
2010-09-09 22:00:14 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Observe(nsISupports *aSubject,
|
|
|
|
const char *aTopic,
|
|
|
|
const PRUnichar *aData)
|
|
|
|
{
|
|
|
|
// forward to parent
|
|
|
|
if (mNotification)
|
|
|
|
mNotification->HandleAlertServiceNotification(aTopic);
|
|
|
|
return NS_OK;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsDOMDesktopNotification* mNotification;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsDesktopNotification_h */
|