Bug 952453 - Remove mozNotification; r=baku

MozReview-Commit-ID: 5wAa5mYFDq4
This commit is contained in:
Kyle Machulis 2017-12-08 16:58:14 -08:00
Родитель dd34d2a589
Коммит abd8d10b15
20 изменённых файлов: 0 добавлений и 1083 удалений

Просмотреть файл

@ -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',
]

Просмотреть файл

@ -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,16 +0,0 @@
<!DOCTYPE html>
<html>
<head><meta charset=utf-8>
<title>Create a notification</title>
</head>
<body>
<script>
var notification = new Notification("This is a title", {
body: "This is a notification body",
tag: "sometag",
});
</script>
</body>
</html>

Просмотреть файл

@ -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,110 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=782211
-->
<head>
<title>Bug 782211</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.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=782211">Bug 782211</a>
<p id="display"></p>
<iframe name="sameDomain"></iframe>
<iframe name="anotherSameDomain"></iframe>
<iframe name="crossDomain"></iframe>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
<script type="text/javascript">
const MOCK_CID = SpecialPowers.wrap(SpecialPowers.Components).ID("{dbe37e64-d9a3-402c-8d8a-0826c619f7ad}");
const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1";
var mockAlertsService = {
showAlert: function(alert, alertListener) {
notificationsCreated.push(alert.name);
if (notificationsCreated.length == 3) {
checkNotifications();
}
},
showAlertNotification: function(imageUrl, title, text, textClickable,
cookie, alertListener, name, dir,
lang, data) {
this.showAlert({ name: name });
},
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);
var notificationsCreated = [];
function checkNotifications() {
// notifications created by the test1 origin
var test1notifications = [];
// notifications created by the test2 origin
var test2notifications = [];
for (var i = 0; i < notificationsCreated.length; i++) {
var notificationName = notificationsCreated[i];
if (notificationName.indexOf("test1") !== -1) {
test1notifications.push(notificationsCreated[i]);
} else if (notificationName.indexOf("test2") !== -1) {
test2notifications.push(notificationsCreated[i]);
}
}
is(test1notifications.length, 2, "2 notifications should be created by test1.example.org:80 origin.");
is(test1notifications[0], test1notifications[1], "notification names should be identical.");
is(test2notifications.length, 1, "1 notification should be created by test2.example.org:80 origin.");
// Register original alerts service.
SpecialPowers.wrap(SpecialPowers.Components).
manager.QueryInterface(SpecialPowers.Ci.nsIComponentRegistrar).
unregisterFactory(MOCK_CID, mockAlertsService);
SimpleTest.finish();
}
if (window.Notification) {
SimpleTest.waitForExplicitFinish();
function showNotifications() {
SpecialPowers.wrap(SpecialPowers.Components).
manager.QueryInterface(SpecialPowers.Ci.nsIComponentRegistrar).
registerFactory(MOCK_CID, "alerts service", ALERTS_SERVICE_CONTRACT_ID, mockAlertsService);
// Load two frames with the same origin that create notification with the same tag.
// Both pages should generate notifications with the same name, and thus the second
// notification should replace the first.
frames["sameDomain"].location.href = "http://test1.example.org:80/tests/dom/tests/mochitest/notification/create_notification.html";
frames["anotherSameDomain"].location.href = "http://test1.example.org:80/tests/dom/tests/mochitest/notification/create_notification.html";
// Load a frame with a different origin that creates a notification with the same tag.
// The notification name should be different and thus no notifications should be replaced.
frames["crossDomain"].location.href = "http://test2.example.org:80/tests/dom/tests/mochitest/notification/create_notification.html";
}
SpecialPowers.pushPrefEnv({'set': [["notification.prompt.testing", true],
["notification.prompt.testing.allow", true]]},
showNotifications);
} else {
ok(true, "Notifications are not enabled on the platform.");
}
</script>
</body>
</html>

Просмотреть файл

@ -1,85 +0,0 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=874090
-->
<window title="Mozilla Bug 874090" onload="runTests()"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=874090"
target="_blank">Mozilla Bug 874090</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 874090 **/
const MOCK_CID = Components.ID("{2a0f83c4-8818-4914-a184-f1172b4eaaa7}");
const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1";
var mockAlertsService = {
showAlert: function(alert, alertListener) {
ok(true, "System principal was granted permission and is able to call showAlert.");
unregisterMock();
SimpleTest.finish();
},
showAlertNotification: function(imageUrl, title, text, textClickable,
cookie, alertListener, name, dir, lang, data) {
this.showAlert();
},
QueryInterface: function(aIID) {
if (aIID.equals(Components.interfaces.nsISupports) ||
aIID.equals(Components.interfaces.nsIAlertsService)) {
return this;
}
throw Components.results.NS_ERROR_NO_INTERFACE;
},
createInstance: function(aOuter, aIID) {
if (aOuter != null) {
throw Components.results.NS_ERROR_NO_AGGREGATION;
}
return this.QueryInterface(aIID);
}
};
function registerMock() {
Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar).
registerFactory(MOCK_CID, "alerts service", ALERTS_SERVICE_CONTRACT_ID, mockAlertsService);
}
function unregisterMock() {
Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar).
unregisterFactory(MOCK_CID, mockAlertsService);
}
function runTests() {
registerMock();
is(Notification.permission, "granted", "System principal should be automatically granted permission.");
Notification.requestPermission(function(permission) {
is(permission, "granted", "System principal should be granted permission when calling requestPermission.");
if (permission == "granted") {
// Create a notification and make sure that it is able to call into
// the mock alert service to show the notification.
new Notification("Hello");
} else {
unregisterMock();
SimpleTest.finish();
}
});
}
SimpleTest.waitForExplicitFinish();
]]>
</script>
</window>

Просмотреть файл

@ -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',

Просмотреть файл

@ -4978,9 +4978,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,8 +13,6 @@
#include "nsTArray.h"
#include "mozilla/RefPtr.h"
@class mozNotificationCenterDelegate;
#if !defined(MAC_OS_X_VERSION_10_8) || (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_8)
typedef NSInteger NSUserNotificationActivationType;
#endif
@ -45,7 +43,6 @@ protected:
virtual ~OSXNotificationCenter();
private:
mozNotificationCenterDelegate *mDelegate;
nsTArray<RefPtr<OSXNotificationInfo> > mActiveAlerts;
nsTArray<RefPtr<OSXNotificationInfo> > mPendingAlerts;
};

Просмотреть файл

@ -78,69 +78,6 @@ enum {
- (void)_removeDisplayedNotification:(id<FakeNSUserNotification>)notification;
@end
@interface mozNotificationCenterDelegate : NSObject <NSUserNotificationCenterDelegate>
{
OSXNotificationCenter *mOSXNC;
}
- (id)initWithOSXNC:(OSXNotificationCenter*)osxnc;
@end
@implementation mozNotificationCenterDelegate
- (id)initWithOSXNC:(OSXNotificationCenter*)osxnc
{
[super init];
// We should *never* outlive this OSXNotificationCenter.
mOSXNC = osxnc;
return self;
}
- (void)userNotificationCenter:(id<FakeNSUserNotificationCenter>)center
didDeliverNotification:(id<FakeNSUserNotification>)notification
{
}
- (void)userNotificationCenter:(id<FakeNSUserNotificationCenter>)center
didActivateNotification:(id<FakeNSUserNotification>)notification
{
unsigned long long additionalActionIndex = ULLONG_MAX;
if ([notification respondsToSelector:@selector(_alternateActionIndex)]) {
NSNumber *alternateActionIndex = [(NSObject*)notification valueForKey:@"_alternateActionIndex"];
additionalActionIndex = [alternateActionIndex unsignedLongLongValue];
}
mOSXNC->OnActivate([[notification userInfo] valueForKey:@"name"],
notification.activationType,
additionalActionIndex);
}
- (BOOL)userNotificationCenter:(id<FakeNSUserNotificationCenter>)center
shouldPresentNotification:(id<FakeNSUserNotification>)notification
{
return YES;
}
// This is an undocumented method that we need for parity with Safari.
// Apple bug #15440664.
- (void)userNotificationCenter:(id<FakeNSUserNotificationCenter>)center
didRemoveDeliveredNotifications:(NSArray *)notifications
{
for (id<FakeNSUserNotification> notification in notifications) {
NSString *name = [[notification userInfo] valueForKey:@"name"];
mOSXNC->CloseAlertCocoaString(name);
}
}
// This is an undocumented method that we need to be notified if a user clicks the close button.
- (void)userNotificationCenter:(id<FakeNSUserNotificationCenter>)center
didDismissAlert:(id<FakeNSUserNotification>)notification
{
NSString *name = [[notification userInfo] valueForKey:@"name"];
mOSXNC->CloseAlertCocoaString(name);
}
@end
namespace mozilla {
enum {
@ -201,22 +138,10 @@ static id<FakeNSUserNotificationCenter> GetNotificationCenter() {
OSXNotificationCenter::OSXNotificationCenter()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
mDelegate = [[mozNotificationCenterDelegate alloc] initWithOSXNC:this];
GetNotificationCenter().delegate = mDelegate;
NS_OBJC_END_TRY_ABORT_BLOCK;
}
OSXNotificationCenter::~OSXNotificationCenter()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
[GetNotificationCenter() removeAllDeliveredNotifications];
[mDelegate release];
NS_OBJC_END_TRY_ABORT_BLOCK;
}
NS_IMPL_ISUPPORTS(OSXNotificationCenter, nsIAlertsService, nsIAlertsIconData,