2012-05-21 11:12:37 +00: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/. */
|
2013-04-10 14:20:43 +00:00
|
|
|
#include "mozilla/dom/DesktopNotification.h"
|
2013-04-10 14:20:43 +00:00
|
|
|
#include "mozilla/dom/DesktopNotificationBinding.h"
|
2013-10-11 18:12:13 +00:00
|
|
|
#include "mozilla/dom/AppNotificationServiceOptionsBinding.h"
|
2010-09-13 20:44:53 +00:00
|
|
|
#include "nsContentPermissionHelper.h"
|
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
#include "mozilla/dom/PBrowserChild.h"
|
2013-04-10 15:08:08 +00:00
|
|
|
#include "nsIDOMDesktopNotification.h"
|
2010-09-13 20:44:53 +00:00
|
|
|
#include "TabChild.h"
|
2011-05-25 06:31:59 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-11-29 06:36:15 +00:00
|
|
|
#include "nsGlobalWindow.h"
|
|
|
|
#include "nsIAppsService.h"
|
2013-08-28 04:14:57 +00:00
|
|
|
#include "PCOMContentPermissionRequestChild.h"
|
2013-09-23 21:30:40 +00:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2013-09-10 20:56:05 +00:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2014-02-09 20:34:40 +00:00
|
|
|
#include "PermissionMessageUtils.h"
|
2013-08-28 04:14:57 +00:00
|
|
|
|
2013-04-10 14:20:43 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2010-09-13 20:44:53 +00:00
|
|
|
|
2013-08-28 04:14:57 +00:00
|
|
|
/*
|
|
|
|
* Simple Request
|
|
|
|
*/
|
|
|
|
class DesktopNotificationRequest : public nsIContentPermissionRequest,
|
|
|
|
public nsRunnable,
|
|
|
|
public PCOMContentPermissionRequestChild
|
|
|
|
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSICONTENTPERMISSIONREQUEST
|
|
|
|
|
|
|
|
DesktopNotificationRequest(DesktopNotification* notification)
|
|
|
|
: mDesktopNotification(notification) {}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContentPermissionPrompt> prompt =
|
|
|
|
do_CreateInstance(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID);
|
|
|
|
if (prompt) {
|
|
|
|
prompt->Prompt(this);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
~DesktopNotificationRequest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-09-10 15:41:59 +00:00
|
|
|
virtual bool Recv__delete__(const bool& aAllow,
|
|
|
|
const InfallibleTArray<PermissionChoice>& choices) MOZ_OVERRIDE
|
2013-08-28 04:14:57 +00:00
|
|
|
{
|
2013-09-10 15:41:59 +00:00
|
|
|
MOZ_ASSERT(choices.IsEmpty(), "DesktopNotification doesn't support permission choice");
|
2013-08-28 04:14:57 +00:00
|
|
|
if (aAllow) {
|
2013-09-10 15:41:59 +00:00
|
|
|
(void) Allow(JS::UndefinedHandleValue);
|
2013-08-28 04:14:57 +00:00
|
|
|
} else {
|
|
|
|
(void) Cancel();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
virtual void IPDLRelease() MOZ_OVERRIDE { Release(); }
|
|
|
|
|
|
|
|
nsRefPtr<DesktopNotification> mDesktopNotification;
|
|
|
|
};
|
|
|
|
|
2010-09-10 05:00:14 +00:00
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
/* AlertServiceObserver */
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(AlertServiceObserver, nsIObserver)
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
2013-04-10 14:20:43 +00:00
|
|
|
/* DesktopNotification */
|
2010-09-10 05:00:14 +00:00
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2013-04-10 14:20:43 +00:00
|
|
|
uint32_t DesktopNotification::sCount = 0;
|
2013-03-18 13:24:53 +00:00
|
|
|
|
2012-07-26 22:25:02 +00:00
|
|
|
nsresult
|
2013-04-10 14:20:43 +00:00
|
|
|
DesktopNotification::PostDesktopNotification()
|
2010-09-10 05:00:14 +00:00
|
|
|
{
|
2013-04-10 14:20:43 +00:00
|
|
|
if (!mObserver) {
|
2012-11-29 06:36:15 +00:00
|
|
|
mObserver = new AlertServiceObserver(this);
|
2013-04-10 14:20:43 +00:00
|
|
|
}
|
2012-11-29 06:36:15 +00:00
|
|
|
|
|
|
|
#ifdef MOZ_B2G
|
|
|
|
nsCOMPtr<nsIAppNotificationService> appNotifier =
|
|
|
|
do_GetService("@mozilla.org/system-alerts-service;1");
|
|
|
|
if (appNotifier) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = GetOwner();
|
|
|
|
uint32_t appId = (window.get())->GetDoc()->NodePrincipal()->GetAppId();
|
|
|
|
|
|
|
|
if (appId != nsIScriptSecurityManager::UNKNOWN_APP_ID) {
|
|
|
|
nsCOMPtr<nsIAppsService> appsService = do_GetService("@mozilla.org/AppsService;1");
|
|
|
|
nsString manifestUrl = EmptyString();
|
|
|
|
appsService->GetManifestURLByLocalId(appId, manifestUrl);
|
2013-10-11 18:12:13 +00:00
|
|
|
mozilla::AutoSafeJSContext cx;
|
2013-11-11 08:04:41 +00:00
|
|
|
JS::Rooted<JS::Value> val(cx);
|
2013-10-11 18:12:13 +00:00
|
|
|
AppNotificationServiceOptions ops;
|
|
|
|
ops.mTextClickable = true;
|
|
|
|
ops.mManifestURL = manifestUrl;
|
|
|
|
|
2014-03-29 05:45:10 +00:00
|
|
|
if (!ops.ToObject(cx, &val)) {
|
2013-10-11 18:12:13 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-11-29 06:36:15 +00:00
|
|
|
return appNotifier->ShowAppNotification(mIconURL, mTitle, mDescription,
|
2013-10-11 18:12:13 +00:00
|
|
|
mObserver, val);
|
2012-11-29 06:36:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-09-10 05:00:14 +00:00
|
|
|
nsCOMPtr<nsIAlertsService> alerts = do_GetService("@mozilla.org/alerts-service;1");
|
2013-04-10 14:20:43 +00:00
|
|
|
if (!alerts) {
|
2012-07-26 22:25:02 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2013-04-10 14:20:43 +00:00
|
|
|
}
|
2010-09-10 05:00:14 +00:00
|
|
|
|
2013-03-18 13:24:53 +00:00
|
|
|
// Generate a unique name (which will also be used as a cookie) because
|
|
|
|
// the nsIAlertsService will coalesce notifications with the same name.
|
|
|
|
// In the case of IPC, the parent process will use the cookie to map
|
|
|
|
// to nsIObservers, thus cookies must be unique to differentiate observers.
|
|
|
|
nsString uniqueName = NS_LITERAL_STRING("desktop-notification:");
|
|
|
|
uniqueName.AppendInt(sCount++);
|
2013-11-11 23:56:21 +00:00
|
|
|
nsIPrincipal* principal = GetOwner()->GetDoc()->NodePrincipal();
|
2012-07-26 22:25:02 +00:00
|
|
|
return alerts->ShowAlertNotification(mIconURL, mTitle, mDescription,
|
|
|
|
true,
|
2013-03-18 13:24:53 +00:00
|
|
|
uniqueName,
|
2012-07-26 22:25:02 +00:00
|
|
|
mObserver,
|
2013-03-18 13:24:53 +00:00
|
|
|
uniqueName,
|
2013-03-18 13:24:53 +00:00
|
|
|
NS_LITERAL_STRING("auto"),
|
2013-11-11 23:56:21 +00:00
|
|
|
EmptyString(),
|
|
|
|
principal);
|
2010-09-10 05:00:14 +00:00
|
|
|
}
|
|
|
|
|
2013-04-10 14:20:43 +00:00
|
|
|
DesktopNotification::DesktopNotification(const nsAString & title,
|
|
|
|
const nsAString & description,
|
|
|
|
const nsAString & iconURL,
|
|
|
|
nsPIDOMWindow *aWindow,
|
|
|
|
nsIPrincipal* principal)
|
2014-04-01 06:13:50 +00:00
|
|
|
: DOMEventTargetHelper(aWindow)
|
2014-01-07 02:53:23 +00:00
|
|
|
, mTitle(title)
|
2010-09-10 05:00:14 +00:00
|
|
|
, mDescription(description)
|
|
|
|
, mIconURL(iconURL)
|
2012-07-30 14:58:26 +00:00
|
|
|
, mPrincipal(principal)
|
2011-10-17 14:59:28 +00:00
|
|
|
, mAllow(false)
|
|
|
|
, mShowHasBeenCalled(false)
|
2010-09-10 05:00:14 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
if (Preferences::GetBool("notification.disabled", false)) {
|
2011-01-19 17:38:36 +00:00
|
|
|
return;
|
2011-05-25 06:31:59 +00:00
|
|
|
}
|
2011-01-19 17:38:36 +00:00
|
|
|
|
|
|
|
// If we are in testing mode (running mochitests, for example)
|
|
|
|
// and we are suppose to allow requests, then just post an allow event.
|
2011-09-29 06:19:26 +00:00
|
|
|
if (Preferences::GetBool("notification.prompt.testing", false) &&
|
|
|
|
Preferences::GetBool("notification.prompt.testing.allow", true)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mAllow = true;
|
2011-01-19 17:38:36 +00:00
|
|
|
}
|
2012-11-19 18:27:54 +00:00
|
|
|
}
|
2011-01-19 17:38:36 +00:00
|
|
|
|
2012-11-19 18:27:54 +00:00
|
|
|
void
|
2013-04-10 14:20:43 +00:00
|
|
|
DesktopNotification::Init()
|
2012-11-19 18:27:54 +00:00
|
|
|
{
|
2013-04-10 14:20:43 +00:00
|
|
|
nsRefPtr<DesktopNotificationRequest> request = new DesktopNotificationRequest(this);
|
2011-01-19 17:38:36 +00:00
|
|
|
|
|
|
|
// if we are in the content process, then remote it to the parent.
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
|
|
|
|
// if for some reason mOwner is null, just silently
|
|
|
|
// bail. The user will not see a notification, and that
|
|
|
|
// is fine.
|
2012-03-13 00:56:07 +00:00
|
|
|
if (!GetOwner())
|
2011-01-19 17:38:36 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// because owner implements nsITabChild, we can assume that it is
|
|
|
|
// the one and only TabChild for this docshell.
|
2013-09-12 19:24:11 +00:00
|
|
|
TabChild* child = TabChild::GetFrom(GetOwner()->GetDocShell());
|
2012-07-30 14:58:26 +00:00
|
|
|
|
2011-01-19 17:38:36 +00:00
|
|
|
// Retain a reference so the object isn't deleted without IPDL's knowledge.
|
|
|
|
// Corresponding release occurs in DeallocPContentPermissionRequest.
|
2013-04-10 14:20:43 +00:00
|
|
|
nsRefPtr<DesktopNotificationRequest> copy = request;
|
2011-01-19 17:38:36 +00:00
|
|
|
|
2014-02-09 20:34:40 +00:00
|
|
|
nsTArray<PermissionRequest> permArray;
|
2013-09-10 15:41:59 +00:00
|
|
|
nsTArray<nsString> emptyOptions;
|
2014-02-09 20:34:40 +00:00
|
|
|
permArray.AppendElement(PermissionRequest(
|
|
|
|
NS_LITERAL_CSTRING("desktop-notification"),
|
2013-09-10 15:41:59 +00:00
|
|
|
NS_LITERAL_CSTRING("unused"),
|
|
|
|
emptyOptions));
|
2014-03-15 19:00:15 +00:00
|
|
|
child->SendPContentPermissionRequestConstructor(copy.forget().take(),
|
2014-02-09 20:34:40 +00:00
|
|
|
permArray,
|
2012-11-14 00:06:42 +00:00
|
|
|
IPC::Principal(mPrincipal));
|
2012-07-30 14:58:26 +00:00
|
|
|
|
2011-01-19 17:38:36 +00:00
|
|
|
request->Sendprompt();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise, dispatch it
|
|
|
|
NS_DispatchToMainThread(request);
|
2010-09-10 05:00:14 +00:00
|
|
|
}
|
|
|
|
|
2013-04-10 14:20:43 +00:00
|
|
|
DesktopNotification::~DesktopNotification()
|
2010-09-10 05:00:14 +00:00
|
|
|
{
|
|
|
|
if (mObserver) {
|
|
|
|
mObserver->Disconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-04-10 14:20:43 +00:00
|
|
|
DesktopNotification::DispatchNotificationEvent(const nsString& aName)
|
2010-09-10 05:00:14 +00:00
|
|
|
{
|
|
|
|
if (NS_FAILED(CheckInnerWindowCorrectness())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
2013-03-09 11:34:29 +00:00
|
|
|
nsresult rv = NS_NewDOMEvent(getter_AddRefs(event), this, nullptr, nullptr);
|
2010-09-10 05:00:14 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// it doesn't bubble, and it isn't cancelable
|
2011-10-17 14:59:28 +00:00
|
|
|
rv = event->InitEvent(aName, false, false);
|
2010-09-10 05:00:14 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-06-10 23:44:50 +00:00
|
|
|
event->SetTrusted(true);
|
2012-07-30 14:20:58 +00:00
|
|
|
DispatchDOMEvent(nullptr, event, nullptr, nullptr);
|
2010-09-10 05:00:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-26 22:25:02 +00:00
|
|
|
nsresult
|
2013-04-10 14:20:43 +00:00
|
|
|
DesktopNotification::SetAllow(bool aAllow)
|
2011-01-19 17:38:36 +00:00
|
|
|
{
|
|
|
|
mAllow = aAllow;
|
|
|
|
|
|
|
|
// if we have called Show() already, lets go ahead and post a notification
|
2013-04-10 14:20:43 +00:00
|
|
|
if (mShowHasBeenCalled && aAllow) {
|
2012-07-26 22:25:02 +00:00
|
|
|
return PostDesktopNotification();
|
2013-04-10 14:20:43 +00:00
|
|
|
}
|
2012-07-26 22:25:02 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2011-01-19 17:38:36 +00:00
|
|
|
}
|
|
|
|
|
2010-09-10 05:00:14 +00:00
|
|
|
void
|
2013-04-10 14:20:43 +00:00
|
|
|
DesktopNotification::HandleAlertServiceNotification(const char *aTopic)
|
2010-09-10 05:00:14 +00:00
|
|
|
{
|
2013-04-10 14:20:43 +00:00
|
|
|
if (NS_FAILED(CheckInnerWindowCorrectness())) {
|
2010-09-10 05:00:14 +00:00
|
|
|
return;
|
2013-04-10 14:20:43 +00:00
|
|
|
}
|
2010-09-10 05:00:14 +00:00
|
|
|
|
|
|
|
if (!strcmp("alertclickcallback", aTopic)) {
|
|
|
|
DispatchNotificationEvent(NS_LITERAL_STRING("click"));
|
|
|
|
} else if (!strcmp("alertfinished", aTopic)) {
|
|
|
|
DispatchNotificationEvent(NS_LITERAL_STRING("close"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-10 14:20:43 +00:00
|
|
|
void
|
|
|
|
DesktopNotification::Show(ErrorResult& aRv)
|
2010-09-10 05:00:14 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
mShowHasBeenCalled = true;
|
2010-09-13 20:44:53 +00:00
|
|
|
|
2013-04-10 14:20:43 +00:00
|
|
|
if (!mAllow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aRv = PostDesktopNotification();
|
|
|
|
}
|
2010-09-10 05:00:14 +00:00
|
|
|
|
2013-04-10 14:20:43 +00:00
|
|
|
JSObject*
|
2013-04-25 16:29:54 +00:00
|
|
|
DesktopNotification::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
2013-04-10 14:20:43 +00:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 22:27:17 +00:00
|
|
|
return DesktopNotificationBinding::Wrap(aCx, this);
|
2010-09-10 05:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
2013-04-10 14:20:43 +00:00
|
|
|
/* DesktopNotificationCenter */
|
2010-09-10 05:00:14 +00:00
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2013-04-10 14:20:43 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(DesktopNotificationCenter)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(DesktopNotificationCenter)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(DesktopNotificationCenter)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DesktopNotificationCenter)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2010-09-10 05:00:14 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-04-10 14:20:43 +00:00
|
|
|
already_AddRefed<DesktopNotification>
|
|
|
|
DesktopNotificationCenter::CreateNotification(const nsAString& aTitle,
|
|
|
|
const nsAString& aDescription,
|
|
|
|
const nsAString& aIconURL)
|
2010-09-10 05:00:14 +00:00
|
|
|
{
|
2013-04-10 14:20:43 +00:00
|
|
|
MOZ_ASSERT(mOwner);
|
|
|
|
|
|
|
|
nsRefPtr<DesktopNotification> notification =
|
|
|
|
new DesktopNotification(aTitle,
|
|
|
|
aDescription,
|
|
|
|
aIconURL,
|
|
|
|
mOwner,
|
|
|
|
mPrincipal);
|
2012-11-19 18:27:54 +00:00
|
|
|
notification->Init();
|
2013-04-10 14:20:43 +00:00
|
|
|
return notification.forget();
|
2010-09-10 05:00:14 +00:00
|
|
|
}
|
|
|
|
|
2013-04-10 14:20:43 +00:00
|
|
|
JSObject*
|
2013-04-25 16:29:54 +00:00
|
|
|
DesktopNotificationCenter::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
2013-04-10 14:20:43 +00:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 22:27:17 +00:00
|
|
|
return DesktopNotificationCenterBinding::Wrap(aCx, this);
|
2013-04-10 14:20:43 +00:00
|
|
|
}
|
2010-09-10 05:00:14 +00:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
2013-04-10 14:20:43 +00:00
|
|
|
/* DesktopNotificationRequest */
|
2010-09-10 05:00:14 +00:00
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2013-04-10 14:20:43 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(DesktopNotificationRequest,
|
2010-09-13 19:31:53 +00:00
|
|
|
nsIContentPermissionRequest,
|
2010-09-10 05:00:14 +00:00
|
|
|
nsIRunnable)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-04-10 14:20:43 +00:00
|
|
|
DesktopNotificationRequest::GetPrincipal(nsIPrincipal * *aRequestingPrincipal)
|
2010-09-10 05:00:14 +00:00
|
|
|
{
|
2013-04-10 14:20:43 +00:00
|
|
|
if (!mDesktopNotification) {
|
2010-09-10 05:00:14 +00:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2013-04-10 14:20:43 +00:00
|
|
|
}
|
2010-09-10 05:00:14 +00:00
|
|
|
|
2012-07-30 14:58:26 +00:00
|
|
|
NS_IF_ADDREF(*aRequestingPrincipal = mDesktopNotification->mPrincipal);
|
2010-09-10 05:00:14 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-04-10 14:20:43 +00:00
|
|
|
DesktopNotificationRequest::GetWindow(nsIDOMWindow * *aRequestingWindow)
|
2010-09-10 05:00:14 +00:00
|
|
|
{
|
2013-04-10 14:20:43 +00:00
|
|
|
if (!mDesktopNotification) {
|
2010-09-10 05:00:14 +00:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2013-04-10 14:20:43 +00:00
|
|
|
}
|
2010-09-10 05:00:14 +00:00
|
|
|
|
2013-04-10 14:20:43 +00:00
|
|
|
NS_IF_ADDREF(*aRequestingWindow = mDesktopNotification->GetOwner());
|
2010-09-10 05:00:14 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-13 19:31:53 +00:00
|
|
|
NS_IMETHODIMP
|
2013-04-10 14:20:43 +00:00
|
|
|
DesktopNotificationRequest::GetElement(nsIDOMElement * *aElement)
|
2010-09-13 19:31:53 +00:00
|
|
|
{
|
2013-09-04 15:40:16 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aElement);
|
|
|
|
*aElement = nullptr;
|
|
|
|
return NS_OK;
|
2010-09-13 19:31:53 +00:00
|
|
|
}
|
|
|
|
|
2010-09-10 05:00:14 +00:00
|
|
|
NS_IMETHODIMP
|
2013-04-10 14:20:43 +00:00
|
|
|
DesktopNotificationRequest::Cancel()
|
2010-09-10 05:00:14 +00:00
|
|
|
{
|
2012-07-26 22:25:02 +00:00
|
|
|
nsresult rv = mDesktopNotification->SetAllow(false);
|
2012-07-30 14:20:58 +00:00
|
|
|
mDesktopNotification = nullptr;
|
2012-07-26 22:25:02 +00:00
|
|
|
return rv;
|
2010-09-10 05:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-09-10 15:41:59 +00:00
|
|
|
DesktopNotificationRequest::Allow(JS::HandleValue aChoices)
|
2010-09-10 05:00:14 +00:00
|
|
|
{
|
2013-09-10 15:41:59 +00:00
|
|
|
MOZ_ASSERT(aChoices.isUndefined());
|
2012-07-26 22:25:02 +00:00
|
|
|
nsresult rv = mDesktopNotification->SetAllow(true);
|
2012-07-30 14:20:58 +00:00
|
|
|
mDesktopNotification = nullptr;
|
2012-07-26 22:25:02 +00:00
|
|
|
return rv;
|
2010-09-10 05:00:14 +00:00
|
|
|
}
|
|
|
|
|
2010-09-13 19:31:53 +00:00
|
|
|
NS_IMETHODIMP
|
2014-02-09 20:34:40 +00:00
|
|
|
DesktopNotificationRequest::GetTypes(nsIArray** aTypes)
|
2010-09-13 19:31:53 +00:00
|
|
|
{
|
2013-09-10 15:41:59 +00:00
|
|
|
nsTArray<nsString> emptyOptions;
|
2014-02-09 20:34:40 +00:00
|
|
|
return CreatePermissionArray(NS_LITERAL_CSTRING("desktop-notification"),
|
|
|
|
NS_LITERAL_CSTRING("unused"),
|
2013-09-10 15:41:59 +00:00
|
|
|
emptyOptions,
|
2014-02-09 20:34:40 +00:00
|
|
|
aTypes);
|
2012-11-14 00:06:42 +00:00
|
|
|
}
|
2013-04-10 14:20:43 +00:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|