зеркало из https://github.com/mozilla/gecko-dev.git
Bug 952453 - Remove mozNotification API; r=mattn r=baku
MozReview-Commit-ID: 3TMxnPRSh1j --HG-- rename : dom/tests/mochitest/notification/desktop-notification/test_system_principal.xul => dom/notification/test/chrome/test_notification_system_principal.xul rename : dom/tests/mochitest/notification/desktop-notification/create_notification.html => dom/notification/test/mochitest/create_notification.html rename : dom/tests/mochitest/notification/desktop-notification/test_notification_tag.html => dom/notification/test/mochitest/test_notification_tag.html
This commit is contained in:
Родитель
251971ad8e
Коммит
5cd6c64525
|
@ -13,7 +13,6 @@
|
|||
#include "nsMimeTypeArray.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/dom/BodyExtractor.h"
|
||||
#include "mozilla/dom/DesktopNotification.h"
|
||||
#include "mozilla/dom/FetchBinding.h"
|
||||
#include "mozilla/dom/File.h"
|
||||
#include "nsGeolocation.h"
|
||||
|
@ -195,7 +194,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator)
|
|||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPlugins)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPermissions)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGeolocation)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNotification)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBatteryManager)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBatteryPromise)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConnection)
|
||||
|
@ -238,11 +236,6 @@ Navigator::Invalidate()
|
|||
mGeolocation = nullptr;
|
||||
}
|
||||
|
||||
if (mNotification) {
|
||||
mNotification->Shutdown();
|
||||
mNotification = nullptr;
|
||||
}
|
||||
|
||||
if (mBatteryManager) {
|
||||
mBatteryManager->Shutdown();
|
||||
mBatteryManager = nullptr;
|
||||
|
@ -1316,22 +1309,6 @@ Navigator::MozGetUserMediaDevices(const MediaStreamConstraints& aConstraints,
|
|||
aInnerWindowID, aCallID);
|
||||
}
|
||||
|
||||
DesktopNotificationCenter*
|
||||
Navigator::GetMozNotification(ErrorResult& aRv)
|
||||
{
|
||||
if (mNotification) {
|
||||
return mNotification;
|
||||
}
|
||||
|
||||
if (!mWindow || !mWindow->GetDocShell()) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
mNotification = new DesktopNotificationCenter(mWindow);
|
||||
return mNotification;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// Navigator::nsINavigatorBattery
|
||||
//*****************************************************************************
|
||||
|
|
|
@ -59,7 +59,6 @@ class BatteryManager;
|
|||
|
||||
class Promise;
|
||||
|
||||
class DesktopNotificationCenter;
|
||||
class MozIdleObserver;
|
||||
class Gamepad;
|
||||
class GamepadServiceTest;
|
||||
|
@ -178,7 +177,6 @@ public:
|
|||
void AddIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
|
||||
void RemoveIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
|
||||
|
||||
DesktopNotificationCenter* GetMozNotification(ErrorResult& aRv);
|
||||
already_AddRefed<LegacyMozTCPSocket> MozTCPSocket();
|
||||
network::Connection* GetConnection(ErrorResult& aRv);
|
||||
MediaDevices* GetMediaDevices(ErrorResult& aRv);
|
||||
|
@ -275,7 +273,6 @@ private:
|
|||
RefPtr<nsPluginArray> mPlugins;
|
||||
RefPtr<Permissions> mPermissions;
|
||||
RefPtr<Geolocation> mGeolocation;
|
||||
RefPtr<DesktopNotificationCenter> mNotification;
|
||||
RefPtr<battery::BatteryManager> mBatteryManager;
|
||||
RefPtr<Promise> mBatteryPromise;
|
||||
RefPtr<network::Connection> mConnection;
|
||||
|
|
|
@ -1,332 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 "mozilla/dom/DesktopNotification.h"
|
||||
#include "mozilla/dom/DesktopNotificationBinding.h"
|
||||
#include "mozilla/dom/AppNotificationServiceOptionsBinding.h"
|
||||
#include "mozilla/dom/ToJSValue.h"
|
||||
#include "mozilla/EventStateManager.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsContentPermissionHelper.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
#include "mozilla/dom/PBrowserChild.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "nsGlobalWindow.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "PermissionMessageUtils.h"
|
||||
#include "nsILoadContext.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
/*
|
||||
* Simple Request
|
||||
*/
|
||||
class DesktopNotificationRequest : public nsIContentPermissionRequest
|
||||
, public Runnable
|
||||
{
|
||||
virtual ~DesktopNotificationRequest()
|
||||
{
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIContentPermissionRequester> mRequester;
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSICONTENTPERMISSIONREQUEST
|
||||
|
||||
explicit DesktopNotificationRequest(DesktopNotification* aNotification)
|
||||
: Runnable("dom::DesktopNotificationRequest")
|
||||
, mDesktopNotification(aNotification)
|
||||
{
|
||||
mRequester = new nsContentPermissionRequester(mDesktopNotification->GetOwner());
|
||||
}
|
||||
|
||||
NS_IMETHOD Run() override
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = mDesktopNotification->GetOwner();
|
||||
nsContentPermissionUtils::AskPermission(this, window);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
RefPtr<DesktopNotification> mDesktopNotification;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* AlertServiceObserver */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
NS_IMPL_ISUPPORTS(AlertServiceObserver, nsIObserver)
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* DesktopNotification */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
uint32_t DesktopNotification::sCount = 0;
|
||||
|
||||
nsresult
|
||||
DesktopNotification::PostDesktopNotification()
|
||||
{
|
||||
if (!mObserver) {
|
||||
mObserver = new AlertServiceObserver(this);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIAlertsService> alerts = do_GetService("@mozilla.org/alerts-service;1");
|
||||
if (!alerts) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// 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++);
|
||||
nsCOMPtr<nsPIDOMWindowInner> owner = GetOwner();
|
||||
if (!owner) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
nsCOMPtr<nsIDocument> doc = owner->GetDoc();
|
||||
nsIPrincipal* principal = doc->NodePrincipal();
|
||||
nsCOMPtr<nsILoadContext> loadContext = doc->GetLoadContext();
|
||||
bool inPrivateBrowsing = loadContext && loadContext->UsePrivateBrowsing();
|
||||
nsCOMPtr<nsIAlertNotification> alert =
|
||||
do_CreateInstance(ALERT_NOTIFICATION_CONTRACTID);
|
||||
NS_ENSURE_TRUE(alert, NS_ERROR_FAILURE);
|
||||
nsresult rv = alert->Init(uniqueName, mIconURL, mTitle,
|
||||
mDescription,
|
||||
true,
|
||||
uniqueName,
|
||||
NS_LITERAL_STRING("auto"),
|
||||
EmptyString(),
|
||||
EmptyString(),
|
||||
principal,
|
||||
inPrivateBrowsing,
|
||||
false /* requireInteraction */);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return alerts->ShowAlert(alert, mObserver);
|
||||
}
|
||||
|
||||
DesktopNotification::DesktopNotification(const nsAString & title,
|
||||
const nsAString & description,
|
||||
const nsAString & iconURL,
|
||||
nsPIDOMWindowInner* aWindow,
|
||||
bool aIsHandlingUserInput,
|
||||
nsIPrincipal* principal)
|
||||
: DOMEventTargetHelper(aWindow)
|
||||
, mTitle(title)
|
||||
, mDescription(description)
|
||||
, mIconURL(iconURL)
|
||||
, mPrincipal(principal)
|
||||
, mIsHandlingUserInput(aIsHandlingUserInput)
|
||||
, mAllow(false)
|
||||
, mShowHasBeenCalled(false)
|
||||
{
|
||||
if (Preferences::GetBool("notification.disabled", false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we are in testing mode (running mochitests, for example)
|
||||
// and we are suppose to allow requests, then just post an allow event.
|
||||
if (Preferences::GetBool("notification.prompt.testing", false) &&
|
||||
Preferences::GetBool("notification.prompt.testing.allow", true)) {
|
||||
mAllow = true;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DesktopNotification::Init()
|
||||
{
|
||||
RefPtr<DesktopNotificationRequest> request = new DesktopNotificationRequest(this);
|
||||
|
||||
NS_DispatchToMainThread(request);
|
||||
}
|
||||
|
||||
DesktopNotification::~DesktopNotification()
|
||||
{
|
||||
if (mObserver) {
|
||||
mObserver->Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DesktopNotification::DispatchNotificationEvent(const nsString& aName)
|
||||
{
|
||||
if (NS_FAILED(CheckInnerWindowCorrectness())) {
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<Event> event = NS_NewDOMEvent(this, nullptr, nullptr);
|
||||
// it doesn't bubble, and it isn't cancelable
|
||||
event->InitEvent(aName, false, false);
|
||||
event->SetTrusted(true);
|
||||
bool dummy;
|
||||
DispatchEvent(event, &dummy);
|
||||
}
|
||||
|
||||
nsresult
|
||||
DesktopNotification::SetAllow(bool aAllow)
|
||||
{
|
||||
mAllow = aAllow;
|
||||
|
||||
// if we have called Show() already, lets go ahead and post a notification
|
||||
if (mShowHasBeenCalled && aAllow) {
|
||||
return PostDesktopNotification();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
DesktopNotification::HandleAlertServiceNotification(const char *aTopic)
|
||||
{
|
||||
if (NS_FAILED(CheckInnerWindowCorrectness())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!strcmp("alertclickcallback", aTopic)) {
|
||||
DispatchNotificationEvent(NS_LITERAL_STRING("click"));
|
||||
} else if (!strcmp("alertfinished", aTopic)) {
|
||||
DispatchNotificationEvent(NS_LITERAL_STRING("close"));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DesktopNotification::Show(ErrorResult& aRv)
|
||||
{
|
||||
mShowHasBeenCalled = true;
|
||||
|
||||
if (!mAllow) {
|
||||
return;
|
||||
}
|
||||
|
||||
aRv = PostDesktopNotification();
|
||||
}
|
||||
|
||||
JSObject*
|
||||
DesktopNotification::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return DesktopNotificationBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* DesktopNotificationCenter */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
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)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
already_AddRefed<DesktopNotification>
|
||||
DesktopNotificationCenter::CreateNotification(const nsAString& aTitle,
|
||||
const nsAString& aDescription,
|
||||
const nsAString& aIconURL)
|
||||
{
|
||||
MOZ_ASSERT(mOwner);
|
||||
|
||||
RefPtr<DesktopNotification> notification =
|
||||
new DesktopNotification(aTitle,
|
||||
aDescription,
|
||||
aIconURL,
|
||||
mOwner,
|
||||
EventStateManager::IsHandlingUserInput(),
|
||||
mPrincipal);
|
||||
notification->Init();
|
||||
return notification.forget();
|
||||
}
|
||||
|
||||
JSObject*
|
||||
DesktopNotificationCenter::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return DesktopNotificationCenterBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* DesktopNotificationRequest */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED(DesktopNotificationRequest, Runnable,
|
||||
nsIContentPermissionRequest)
|
||||
|
||||
NS_IMETHODIMP
|
||||
DesktopNotificationRequest::GetPrincipal(nsIPrincipal * *aRequestingPrincipal)
|
||||
{
|
||||
if (!mDesktopNotification) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
NS_IF_ADDREF(*aRequestingPrincipal = mDesktopNotification->mPrincipal);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DesktopNotificationRequest::GetWindow(mozIDOMWindow** aRequestingWindow)
|
||||
{
|
||||
if (!mDesktopNotification) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
NS_IF_ADDREF(*aRequestingWindow = mDesktopNotification->GetOwner());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DesktopNotificationRequest::GetElement(nsIDOMElement * *aElement)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aElement);
|
||||
*aElement = nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DesktopNotificationRequest::GetIsHandlingUserInput(bool *aIsHandlingUserInput)
|
||||
{
|
||||
*aIsHandlingUserInput = mDesktopNotification->mIsHandlingUserInput;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DesktopNotificationRequest::Cancel()
|
||||
{
|
||||
nsresult rv = mDesktopNotification->SetAllow(false);
|
||||
mDesktopNotification = nullptr;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DesktopNotificationRequest::Allow(JS::HandleValue aChoices)
|
||||
{
|
||||
MOZ_ASSERT(aChoices.isUndefined());
|
||||
nsresult rv = mDesktopNotification->SetAllow(true);
|
||||
mDesktopNotification = nullptr;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DesktopNotificationRequest::GetRequester(nsIContentPermissionRequester** aRequester)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aRequester);
|
||||
|
||||
nsCOMPtr<nsIContentPermissionRequester> requester = mRequester;
|
||||
requester.forget(aRequester);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DesktopNotificationRequest::GetTypes(nsIArray** aTypes)
|
||||
{
|
||||
nsTArray<nsString> emptyOptions;
|
||||
return nsContentPermissionUtils::CreatePermissionArray(NS_LITERAL_CSTRING("desktop-notification"),
|
||||
NS_LITERAL_CSTRING("unused"),
|
||||
emptyOptions,
|
||||
aTypes);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
|
@ -1,178 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 mozilla_dom_DesktopNotification_h
|
||||
#define mozilla_dom_DesktopNotification_h
|
||||
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsIAlertsService.h"
|
||||
#include "nsIContentPermissionPrompt.h"
|
||||
|
||||
#include "nsIObserver.h"
|
||||
#include "nsString.h"
|
||||
#include "nsWeakPtr.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIScriptObjectPrincipal.h"
|
||||
|
||||
#include "nsIDOMEvent.h"
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/DOMEventTargetHelper.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class AlertServiceObserver;
|
||||
class DesktopNotification;
|
||||
|
||||
/*
|
||||
* DesktopNotificationCenter
|
||||
* Object hangs off of the navigator object and hands out DesktopNotification objects
|
||||
*/
|
||||
class DesktopNotificationCenter final : public nsISupports,
|
||||
public nsWrapperCache
|
||||
{
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DesktopNotificationCenter)
|
||||
|
||||
explicit DesktopNotificationCenter(nsPIDOMWindowInner* aWindow)
|
||||
{
|
||||
MOZ_ASSERT(aWindow);
|
||||
mOwner = aWindow;
|
||||
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(aWindow);
|
||||
MOZ_ASSERT(sop);
|
||||
|
||||
mPrincipal = sop->GetPrincipal();
|
||||
MOZ_ASSERT(mPrincipal);
|
||||
}
|
||||
|
||||
void Shutdown() {
|
||||
mOwner = nullptr;
|
||||
}
|
||||
|
||||
nsPIDOMWindowInner* GetParentObject() const
|
||||
{
|
||||
return mOwner;
|
||||
}
|
||||
|
||||
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
already_AddRefed<DesktopNotification>
|
||||
CreateNotification(const nsAString& title,
|
||||
const nsAString& description,
|
||||
const nsAString& iconURL);
|
||||
|
||||
private:
|
||||
virtual ~DesktopNotificationCenter()
|
||||
{
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowInner> mOwner;
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
};
|
||||
|
||||
class DesktopNotificationRequest;
|
||||
|
||||
class DesktopNotification final : public DOMEventTargetHelper
|
||||
{
|
||||
friend class DesktopNotificationRequest;
|
||||
|
||||
public:
|
||||
|
||||
DesktopNotification(const nsAString& aTitle,
|
||||
const nsAString& aDescription,
|
||||
const nsAString& aIconURL,
|
||||
nsPIDOMWindowInner* aWindow,
|
||||
bool aIsHandlingUserInput,
|
||||
nsIPrincipal* principal);
|
||||
|
||||
virtual ~DesktopNotification();
|
||||
|
||||
void Init();
|
||||
|
||||
/*
|
||||
* PostDesktopNotification
|
||||
* Uses alert service to display a notification
|
||||
*/
|
||||
nsresult PostDesktopNotification();
|
||||
|
||||
nsresult SetAllow(bool aAllow);
|
||||
|
||||
/*
|
||||
* Creates and dispatches a dom event of type aName
|
||||
*/
|
||||
void DispatchNotificationEvent(const nsString& aName);
|
||||
|
||||
void HandleAlertServiceNotification(const char *aTopic);
|
||||
|
||||
// WebIDL
|
||||
|
||||
nsPIDOMWindowInner* GetParentObject() const
|
||||
{
|
||||
return GetOwner();
|
||||
}
|
||||
|
||||
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
void Show(ErrorResult& aRv);
|
||||
|
||||
IMPL_EVENT_HANDLER(click)
|
||||
IMPL_EVENT_HANDLER(close)
|
||||
|
||||
protected:
|
||||
|
||||
nsString mTitle;
|
||||
nsString mDescription;
|
||||
nsString mIconURL;
|
||||
|
||||
RefPtr<AlertServiceObserver> mObserver;
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
bool mIsHandlingUserInput;
|
||||
bool mAllow;
|
||||
bool mShowHasBeenCalled;
|
||||
|
||||
static uint32_t sCount;
|
||||
};
|
||||
|
||||
class AlertServiceObserver: public nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
explicit AlertServiceObserver(DesktopNotification* notification)
|
||||
: mNotification(notification) {}
|
||||
|
||||
void Disconnect() { mNotification = nullptr; }
|
||||
|
||||
NS_IMETHOD
|
||||
Observe(nsISupports* aSubject,
|
||||
const char* aTopic,
|
||||
const char16_t* aData) override
|
||||
{
|
||||
|
||||
// forward to parent
|
||||
if (mNotification) {
|
||||
mNotification->HandleAlertServiceNotification(aTopic);
|
||||
}
|
||||
return NS_OK;
|
||||
};
|
||||
|
||||
private:
|
||||
virtual ~AlertServiceObserver() {}
|
||||
|
||||
DesktopNotification* mNotification;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* mozilla_dom_DesktopNotification_h */
|
|
@ -17,13 +17,11 @@ EXTRA_JS_MODULES += [
|
|||
]
|
||||
|
||||
EXPORTS.mozilla.dom += [
|
||||
'DesktopNotification.h',
|
||||
'Notification.h',
|
||||
'NotificationEvent.h',
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'DesktopNotification.cpp',
|
||||
'Notification.cpp',
|
||||
'NotificationEvent.cpp',
|
||||
]
|
||||
|
@ -40,6 +38,8 @@ LOCAL_INCLUDES += [
|
|||
BROWSER_CHROME_MANIFESTS += ['test/browser/browser.ini']
|
||||
XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini']
|
||||
MOCHITEST_MANIFESTS += ['test/mochitest/mochitest.ini']
|
||||
MOCHITEST_CHROME_MANIFESTS += ['test/chrome/chrome.ini']
|
||||
|
||||
|
||||
if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
|
||||
CXXFLAGS += ['-Wno-error=shadow']
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
[test_notification_system_principal.xul]
|
|
@ -1,6 +1,7 @@
|
|||
[DEFAULT]
|
||||
|
||||
support-files =
|
||||
create_notification.html
|
||||
MockServices.js
|
||||
NotificationTest.js
|
||||
|
||||
|
@ -8,3 +9,4 @@ support-files =
|
|||
[test_notification_storage.html]
|
||||
[test_bug931307.html]
|
||||
skip-if = (os == 'android') # Bug 1258975 on android.
|
||||
[test_notification_tag.html]
|
|
@ -270,10 +270,6 @@ var interfaceNamesInGlobalScope =
|
|||
"DataTransferItemList",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"DelayNode",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"DesktopNotification",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"DesktopNotificationCenter",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"DeviceLightEvent",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
# -*- Mode: python; 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/.
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
const MOCK_ALERTS_CID = SpecialPowers.wrap(SpecialPowers.Components).ID("{48068bc2-40ab-4904-8afd-4cdfb3a385f3}");
|
||||
const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1";
|
||||
|
||||
const MOCK_SYSTEM_ALERTS_CID = SpecialPowers.wrap(SpecialPowers.Components).ID("{e86d888c-e41b-4b78-9104-2f2742a532de}");
|
||||
const SYSTEM_ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/system-alerts-service;1";
|
||||
|
||||
var registrar = SpecialPowers.wrap(SpecialPowers.Components).manager.
|
||||
QueryInterface(SpecialPowers.Ci.nsIComponentRegistrar);
|
||||
|
||||
var mockAlertsService = {
|
||||
showAlert: function(alert, alertListener) {
|
||||
// probably should do this async....
|
||||
SpecialPowers.wrap(alertListener).observe(null, "alertshow", alert.cookie);
|
||||
|
||||
if (SpecialPowers.getBoolPref("notification.prompt.testing.click_on_notification") == true) {
|
||||
SpecialPowers.wrap(alertListener).observe(null, "alertclickcallback", alert.cookie);
|
||||
}
|
||||
|
||||
SpecialPowers.wrap(alertListener).observe(null, "alertfinished", alert.cookie);
|
||||
},
|
||||
|
||||
showAlertNotification: function(imageUrl, title, text, textClickable,
|
||||
cookie, alertListener, name, bidi,
|
||||
lang, data) {
|
||||
return this.showAlert({
|
||||
cookie: cookie
|
||||
}, alertListener);
|
||||
},
|
||||
|
||||
QueryInterface: function(aIID) {
|
||||
if (SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsISupports) ||
|
||||
SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsIAlertsService)) {
|
||||
return this;
|
||||
}
|
||||
throw SpecialPowers.Components.results.NS_ERROR_NO_INTERFACE;
|
||||
},
|
||||
|
||||
createInstance: function(aOuter, aIID) {
|
||||
if (aOuter != null) {
|
||||
throw SpecialPowers.Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
return this.QueryInterface(aIID);
|
||||
}
|
||||
};
|
||||
mockAlertsService = SpecialPowers.wrapCallbackObject(mockAlertsService);
|
||||
|
||||
function setup_notifications(allowPrompt, forceClick, callback) {
|
||||
SpecialPowers.pushPrefEnv({'set': [["notification.prompt.testing", true],
|
||||
["notification.prompt.testing.allow", allowPrompt],
|
||||
["notification.prompt.testing.click_on_notification", forceClick]]},
|
||||
callback);
|
||||
|
||||
registrar.registerFactory(MOCK_SYSTEM_ALERTS_CID, "system alerts service",
|
||||
SYSTEM_ALERTS_SERVICE_CONTRACT_ID,
|
||||
mockAlertsService);
|
||||
|
||||
registrar.registerFactory(MOCK_ALERTS_CID, "alerts service",
|
||||
ALERTS_SERVICE_CONTRACT_ID,
|
||||
mockAlertsService);
|
||||
}
|
||||
|
||||
function reset_notifications() {
|
||||
registrar.unregisterFactory(MOCK_SYSTEM_ALERTS_CID, mockAlertsService);
|
||||
registrar.unregisterFactory(MOCK_ALERTS_CID, mockAlertsService);
|
||||
}
|
||||
|
||||
function is_feature_enabled() {
|
||||
return navigator.mozNotification && SpecialPowers.getBoolPref("notification.feature.enabled");
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=573588
|
||||
-->
|
||||
<head>
|
||||
<title>Basic functional test</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="notification_common.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=573588">Basic property tests</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
<script type="text/javascript">
|
||||
if (is_feature_enabled()) {
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function showNotifications() {
|
||||
ok(navigator.mozNotification, "test for notification.");
|
||||
|
||||
var notification = navigator.mozNotification.createNotification("test", "test");
|
||||
ok(notification, "test to ensure we can create a notification");
|
||||
|
||||
notification.onclose = function() {
|
||||
ok(true, "notification was display and is now closing");
|
||||
reset_notifications();
|
||||
SimpleTest.finish();
|
||||
};
|
||||
|
||||
notification.onclick = function() {
|
||||
ok(false, "Click should not have been called.");
|
||||
reset_notifications();
|
||||
SimpleTest.finish();
|
||||
};
|
||||
|
||||
notification.show();
|
||||
}
|
||||
|
||||
setup_notifications(true, false, showNotifications);
|
||||
} else {
|
||||
ok(true, "Desktop notifications not enabled.");
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,53 +0,0 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=573588
|
||||
-->
|
||||
<head>
|
||||
<title>Basic functional test</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="notification_common.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=573588">Basic property tests</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
<script type="text/javascript">
|
||||
if (is_feature_enabled()) {
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var click_was_called = false;
|
||||
|
||||
function showNotifications() {
|
||||
ok(navigator.mozNotification, "test for notification.");
|
||||
|
||||
var notification = navigator.mozNotification.createNotification("test", "test");
|
||||
ok(notification, "test to ensure we can create a notification");
|
||||
|
||||
notification.onclose = function() {
|
||||
ok(true, "notification was display and is now closing");
|
||||
ok(click_was_called, "was notification clicked?");
|
||||
|
||||
reset_notifications();
|
||||
SimpleTest.finish();
|
||||
};
|
||||
|
||||
notification.onclick = function() {
|
||||
ok(true, "Click was called. Good.");
|
||||
click_was_called = true;
|
||||
};
|
||||
|
||||
notification.show();
|
||||
}
|
||||
|
||||
setup_notifications(true, true, showNotifications);
|
||||
} else {
|
||||
ok(true, "Desktop notifications not enabled.");
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,34 +0,0 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=605309
|
||||
-->
|
||||
<head>
|
||||
<title>Test for leak when window closes</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="notification_common.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
|
||||
<script>
|
||||
if (is_feature_enabled()) {
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function boom()
|
||||
{
|
||||
document.documentElement.focus();
|
||||
var x = navigator.mozNotification;
|
||||
document.documentElement.addEventListener('', function(){x});
|
||||
ok(true, "load callback called");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
window.addEventListener("load", boom);
|
||||
} else {
|
||||
ok(true, "Desktop notifications not enabled.");
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<p> I like to write tests </p>
|
||||
</body>
|
||||
</html>
|
|
@ -1,26 +0,0 @@
|
|||
/* -*- Mode: IDL; 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/.
|
||||
*/
|
||||
|
||||
interface MozObserver;
|
||||
|
||||
[HeaderFile="mozilla/dom/DesktopNotification.h"]
|
||||
interface DesktopNotificationCenter
|
||||
{
|
||||
[NewObject]
|
||||
DesktopNotification createNotification(DOMString title,
|
||||
DOMString description,
|
||||
optional DOMString iconURL = "");
|
||||
};
|
||||
|
||||
interface DesktopNotification : EventTarget
|
||||
{
|
||||
[Throws]
|
||||
void show();
|
||||
|
||||
attribute EventHandler onclick;
|
||||
|
||||
attribute EventHandler onclose;
|
||||
};
|
|
@ -200,12 +200,6 @@ partial interface Navigator {
|
|||
void removeIdleObserver(MozIdleObserver aIdleObserver);
|
||||
};
|
||||
|
||||
// nsIDOMNavigatorDesktopNotification
|
||||
partial interface Navigator {
|
||||
[Throws, Pref="notification.feature.enabled", UnsafeInPrerendering]
|
||||
readonly attribute DesktopNotificationCenter mozNotification;
|
||||
};
|
||||
|
||||
// NetworkInformation
|
||||
partial interface Navigator {
|
||||
[Throws, Pref="dom.netinfo.enabled"]
|
||||
|
|
|
@ -97,9 +97,6 @@ with Files("DelayNode.webidl"):
|
|||
with Files("DynamicsCompressorNode.webidl"):
|
||||
BUG_COMPONENT = ("Core", "Web Audio")
|
||||
|
||||
with Files("DesktopNotification.webidl"):
|
||||
BUG_COMPONENT = ("Toolkit", "Notifications and Alerts")
|
||||
|
||||
with Files("FakePluginTagInit.webidl"):
|
||||
BUG_COMPONENT = ("Core", "Plug-ins")
|
||||
|
||||
|
@ -478,7 +475,6 @@ WEBIDL_FILES = [
|
|||
'DecoderDoctorNotification.webidl',
|
||||
'DedicatedWorkerGlobalScope.webidl',
|
||||
'DelayNode.webidl',
|
||||
'DesktopNotification.webidl',
|
||||
'DeviceMotionEvent.webidl',
|
||||
'Directory.webidl',
|
||||
'Document.webidl',
|
||||
|
|
|
@ -5026,9 +5026,6 @@ pref("extensions.webcompat-reporter.enabled", false);
|
|||
pref("network.buffer.cache.count", 24);
|
||||
pref("network.buffer.cache.size", 32768);
|
||||
|
||||
// Desktop Notification
|
||||
pref("notification.feature.enabled", false);
|
||||
|
||||
// Web Notification
|
||||
pref("dom.webnotifications.enabled", true);
|
||||
pref("dom.webnotifications.serviceworker.enabled", true);
|
||||
|
|
|
@ -13,6 +13,11 @@
|
|||
#include "nsTArray.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
|
||||
// mozNotificationCenterDelegate is used to access the macOS notification
|
||||
// center. It is not related to the DesktopNotificationCenter object, which was
|
||||
// removed in bug 952453. While there are no direct references to this class
|
||||
// elsewhere, removing this will cause push notifications on macOS to stop
|
||||
// working.
|
||||
@class mozNotificationCenterDelegate;
|
||||
|
||||
#if !defined(MAC_OS_X_VERSION_10_8) || (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_8)
|
||||
|
|
Загрузка…
Ссылка в новой задаче