2015-05-03 12:32:37 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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/. */
|
2013-04-10 07:20:43 -07:00
|
|
|
#include "mozilla/dom/DesktopNotification.h"
|
2013-04-10 07:20:43 -07:00
|
|
|
#include "mozilla/dom/DesktopNotificationBinding.h"
|
2013-10-11 11:12:13 -07:00
|
|
|
#include "mozilla/dom/AppNotificationServiceOptionsBinding.h"
|
2014-06-11 12:38:55 -07:00
|
|
|
#include "mozilla/dom/ToJSValue.h"
|
2015-12-03 08:27:25 -08:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2010-09-13 13:44:53 -07:00
|
|
|
#include "nsContentPermissionHelper.h"
|
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
#include "mozilla/dom/PBrowserChild.h"
|
2013-04-10 08:08:08 -07:00
|
|
|
#include "nsIDOMDesktopNotification.h"
|
2011-05-24 23:31:59 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-11-28 22:36:15 -08:00
|
|
|
#include "nsGlobalWindow.h"
|
|
|
|
#include "nsIAppsService.h"
|
2013-09-23 14:30:40 -07:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2013-09-10 13:56:05 -07:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2014-02-09 12:34:40 -08:00
|
|
|
#include "PermissionMessageUtils.h"
|
2014-11-28 11:08:29 -08:00
|
|
|
#include "nsILoadContext.h"
|
2013-08-27 21:14:57 -07:00
|
|
|
|
2013-04-10 07:20:43 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2010-09-13 13:44:53 -07:00
|
|
|
|
2013-08-27 21:14:57 -07:00
|
|
|
/*
|
|
|
|
* Simple Request
|
|
|
|
*/
|
2014-08-01 00:22:20 -07:00
|
|
|
class DesktopNotificationRequest : public nsIContentPermissionRequest
|
|
|
|
, public nsRunnable
|
2013-08-27 21:14:57 -07:00
|
|
|
{
|
2014-08-01 00:22:20 -07:00
|
|
|
virtual ~DesktopNotificationRequest()
|
2014-06-23 12:56:07 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-13 18:08:00 -07:00
|
|
|
nsCOMPtr<nsIContentPermissionRequester> mRequester;
|
2013-08-27 21:14:57 -07:00
|
|
|
public:
|
2014-07-14 12:21:34 -07:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2013-08-27 21:14:57 -07:00
|
|
|
NS_DECL_NSICONTENTPERMISSIONREQUEST
|
|
|
|
|
2014-09-01 15:26:43 -07:00
|
|
|
explicit DesktopNotificationRequest(DesktopNotification* aNotification)
|
2015-04-13 18:08:00 -07:00
|
|
|
: mDesktopNotification(aNotification)
|
|
|
|
{
|
|
|
|
mRequester = new nsContentPermissionRequester(mDesktopNotification->GetOwner());
|
|
|
|
}
|
2013-08-27 21:14:57 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
NS_IMETHOD Run() override
|
2013-08-27 21:14:57 -07:00
|
|
|
{
|
2016-01-30 09:05:36 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = mDesktopNotification->GetOwner();
|
2014-08-01 00:22:20 -07:00
|
|
|
nsContentPermissionUtils::AskPermission(this, window);
|
2013-08-27 21:14:57 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<DesktopNotification> mDesktopNotification;
|
2013-08-27 21:14:57 -07:00
|
|
|
};
|
|
|
|
|
2010-09-09 22:00:14 -07:00
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
/* AlertServiceObserver */
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(AlertServiceObserver, nsIObserver)
|
2010-09-09 22:00:14 -07:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
2013-04-10 07:20:43 -07:00
|
|
|
/* DesktopNotification */
|
2010-09-09 22:00:14 -07:00
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2013-04-10 07:20:43 -07:00
|
|
|
uint32_t DesktopNotification::sCount = 0;
|
2013-03-18 06:24:53 -07:00
|
|
|
|
2012-07-26 15:25:02 -07:00
|
|
|
nsresult
|
2013-04-10 07:20:43 -07:00
|
|
|
DesktopNotification::PostDesktopNotification()
|
2010-09-09 22:00:14 -07:00
|
|
|
{
|
2013-04-10 07:20:43 -07:00
|
|
|
if (!mObserver) {
|
2012-11-28 22:36:15 -08:00
|
|
|
mObserver = new AlertServiceObserver(this);
|
2013-04-10 07:20:43 -07:00
|
|
|
}
|
2012-11-28 22:36:15 -08:00
|
|
|
|
|
|
|
#ifdef MOZ_B2G
|
|
|
|
nsCOMPtr<nsIAppNotificationService> appNotifier =
|
|
|
|
do_GetService("@mozilla.org/system-alerts-service;1");
|
|
|
|
if (appNotifier) {
|
2016-01-30 09:05:36 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = GetOwner();
|
2012-11-28 22:36:15 -08:00
|
|
|
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 11:12:13 -07:00
|
|
|
mozilla::AutoSafeJSContext cx;
|
2013-11-11 00:04:41 -08:00
|
|
|
JS::Rooted<JS::Value> val(cx);
|
2013-10-11 11:12:13 -07:00
|
|
|
AppNotificationServiceOptions ops;
|
|
|
|
ops.mTextClickable = true;
|
|
|
|
ops.mManifestURL = manifestUrl;
|
|
|
|
|
2014-06-11 12:38:55 -07:00
|
|
|
if (!ToJSValue(cx, ops, &val)) {
|
2013-10-11 11:12:13 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-11-28 22:36:15 -08:00
|
|
|
return appNotifier->ShowAppNotification(mIconURL, mTitle, mDescription,
|
2013-10-11 11:12:13 -07:00
|
|
|
mObserver, val);
|
2012-11-28 22:36:15 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-09-09 22:00:14 -07:00
|
|
|
nsCOMPtr<nsIAlertsService> alerts = do_GetService("@mozilla.org/alerts-service;1");
|
2013-04-10 07:20:43 -07:00
|
|
|
if (!alerts) {
|
2012-07-26 15:25:02 -07:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2013-04-10 07:20:43 -07:00
|
|
|
}
|
2010-09-09 22:00:14 -07:00
|
|
|
|
2013-03-18 06:24:53 -07: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++);
|
2014-11-28 11:08:29 -08:00
|
|
|
nsCOMPtr<nsIDocument> doc = GetOwner()->GetDoc();
|
|
|
|
nsIPrincipal* principal = doc->NodePrincipal();
|
|
|
|
nsCOMPtr<nsILoadContext> loadContext = doc->GetLoadContext();
|
|
|
|
bool inPrivateBrowsing = loadContext && loadContext->UsePrivateBrowsing();
|
2015-12-03 08:27:25 -08:00
|
|
|
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);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return alerts->ShowAlert(alert, mObserver);
|
2010-09-09 22:00:14 -07:00
|
|
|
}
|
|
|
|
|
2013-04-10 07:20:43 -07:00
|
|
|
DesktopNotification::DesktopNotification(const nsAString & title,
|
|
|
|
const nsAString & description,
|
|
|
|
const nsAString & iconURL,
|
2016-01-30 09:05:36 -08:00
|
|
|
nsPIDOMWindowInner* aWindow,
|
2013-04-10 07:20:43 -07:00
|
|
|
nsIPrincipal* principal)
|
2014-03-31 23:13:50 -07:00
|
|
|
: DOMEventTargetHelper(aWindow)
|
2014-01-06 18:53:23 -08:00
|
|
|
, mTitle(title)
|
2010-09-09 22:00:14 -07:00
|
|
|
, mDescription(description)
|
|
|
|
, mIconURL(iconURL)
|
2012-07-30 07:58:26 -07:00
|
|
|
, mPrincipal(principal)
|
2011-10-17 07:59:28 -07:00
|
|
|
, mAllow(false)
|
|
|
|
, mShowHasBeenCalled(false)
|
2010-09-09 22:00:14 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
if (Preferences::GetBool("notification.disabled", false)) {
|
2011-01-19 09:38:36 -08:00
|
|
|
return;
|
2011-05-24 23:31:59 -07:00
|
|
|
}
|
2011-01-19 09:38:36 -08: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-28 23:19:26 -07:00
|
|
|
if (Preferences::GetBool("notification.prompt.testing", false) &&
|
|
|
|
Preferences::GetBool("notification.prompt.testing.allow", true)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mAllow = true;
|
2011-01-19 09:38:36 -08:00
|
|
|
}
|
2012-11-19 10:27:54 -08:00
|
|
|
}
|
2011-01-19 09:38:36 -08:00
|
|
|
|
2012-11-19 10:27:54 -08:00
|
|
|
void
|
2013-04-10 07:20:43 -07:00
|
|
|
DesktopNotification::Init()
|
2012-11-19 10:27:54 -08:00
|
|
|
{
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<DesktopNotificationRequest> request = new DesktopNotificationRequest(this);
|
2011-01-19 09:38:36 -08:00
|
|
|
|
|
|
|
NS_DispatchToMainThread(request);
|
2010-09-09 22:00:14 -07:00
|
|
|
}
|
|
|
|
|
2013-04-10 07:20:43 -07:00
|
|
|
DesktopNotification::~DesktopNotification()
|
2010-09-09 22:00:14 -07:00
|
|
|
{
|
|
|
|
if (mObserver) {
|
|
|
|
mObserver->Disconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-04-10 07:20:43 -07:00
|
|
|
DesktopNotification::DispatchNotificationEvent(const nsString& aName)
|
2010-09-09 22:00:14 -07:00
|
|
|
{
|
|
|
|
if (NS_FAILED(CheckInnerWindowCorrectness())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<Event> event = NS_NewDOMEvent(this, nullptr, nullptr);
|
2015-08-12 04:39:31 -07:00
|
|
|
// it doesn't bubble, and it isn't cancelable
|
2015-11-12 16:09:42 -08:00
|
|
|
event->InitEvent(aName, false, false);
|
2015-08-12 04:39:31 -07:00
|
|
|
event->SetTrusted(true);
|
|
|
|
DispatchDOMEvent(nullptr, event, nullptr, nullptr);
|
2010-09-09 22:00:14 -07:00
|
|
|
}
|
|
|
|
|
2012-07-26 15:25:02 -07:00
|
|
|
nsresult
|
2013-04-10 07:20:43 -07:00
|
|
|
DesktopNotification::SetAllow(bool aAllow)
|
2011-01-19 09:38:36 -08:00
|
|
|
{
|
|
|
|
mAllow = aAllow;
|
|
|
|
|
|
|
|
// if we have called Show() already, lets go ahead and post a notification
|
2013-04-10 07:20:43 -07:00
|
|
|
if (mShowHasBeenCalled && aAllow) {
|
2012-07-26 15:25:02 -07:00
|
|
|
return PostDesktopNotification();
|
2013-04-10 07:20:43 -07:00
|
|
|
}
|
2012-07-26 15:25:02 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
2011-01-19 09:38:36 -08:00
|
|
|
}
|
|
|
|
|
2010-09-09 22:00:14 -07:00
|
|
|
void
|
2013-04-10 07:20:43 -07:00
|
|
|
DesktopNotification::HandleAlertServiceNotification(const char *aTopic)
|
2010-09-09 22:00:14 -07:00
|
|
|
{
|
2013-04-10 07:20:43 -07:00
|
|
|
if (NS_FAILED(CheckInnerWindowCorrectness())) {
|
2010-09-09 22:00:14 -07:00
|
|
|
return;
|
2013-04-10 07:20:43 -07:00
|
|
|
}
|
2010-09-09 22:00:14 -07:00
|
|
|
|
|
|
|
if (!strcmp("alertclickcallback", aTopic)) {
|
|
|
|
DispatchNotificationEvent(NS_LITERAL_STRING("click"));
|
|
|
|
} else if (!strcmp("alertfinished", aTopic)) {
|
|
|
|
DispatchNotificationEvent(NS_LITERAL_STRING("close"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-10 07:20:43 -07:00
|
|
|
void
|
|
|
|
DesktopNotification::Show(ErrorResult& aRv)
|
2010-09-09 22:00:14 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
mShowHasBeenCalled = true;
|
2010-09-13 13:44:53 -07:00
|
|
|
|
2013-04-10 07:20:43 -07:00
|
|
|
if (!mAllow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aRv = PostDesktopNotification();
|
|
|
|
}
|
2010-09-09 22:00:14 -07:00
|
|
|
|
2013-04-10 07:20:43 -07:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
DesktopNotification::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-04-10 07:20:43 -07:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
return DesktopNotificationBinding::Wrap(aCx, this, aGivenProto);
|
2010-09-09 22:00:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
2013-04-10 07:20:43 -07:00
|
|
|
/* DesktopNotificationCenter */
|
2010-09-09 22:00:14 -07:00
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2013-04-10 07:20:43 -07: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-09 22:00:14 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-04-10 07:20:43 -07:00
|
|
|
already_AddRefed<DesktopNotification>
|
|
|
|
DesktopNotificationCenter::CreateNotification(const nsAString& aTitle,
|
|
|
|
const nsAString& aDescription,
|
|
|
|
const nsAString& aIconURL)
|
2010-09-09 22:00:14 -07:00
|
|
|
{
|
2013-04-10 07:20:43 -07:00
|
|
|
MOZ_ASSERT(mOwner);
|
|
|
|
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<DesktopNotification> notification =
|
2013-04-10 07:20:43 -07:00
|
|
|
new DesktopNotification(aTitle,
|
|
|
|
aDescription,
|
|
|
|
aIconURL,
|
|
|
|
mOwner,
|
|
|
|
mPrincipal);
|
2012-11-19 10:27:54 -08:00
|
|
|
notification->Init();
|
2013-04-10 07:20:43 -07:00
|
|
|
return notification.forget();
|
2010-09-09 22:00:14 -07:00
|
|
|
}
|
|
|
|
|
2013-04-10 07:20:43 -07:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
DesktopNotificationCenter::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-04-10 07:20:43 -07:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
return DesktopNotificationCenterBinding::Wrap(aCx, this, aGivenProto);
|
2013-04-10 07:20:43 -07:00
|
|
|
}
|
2010-09-09 22:00:14 -07:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
2013-04-10 07:20:43 -07:00
|
|
|
/* DesktopNotificationRequest */
|
2010-09-09 22:00:14 -07:00
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2014-07-14 12:21:34 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(DesktopNotificationRequest, nsRunnable,
|
2014-08-01 00:22:20 -07:00
|
|
|
nsIContentPermissionRequest)
|
2010-09-09 22:00:14 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-04-10 07:20:43 -07:00
|
|
|
DesktopNotificationRequest::GetPrincipal(nsIPrincipal * *aRequestingPrincipal)
|
2010-09-09 22:00:14 -07:00
|
|
|
{
|
2013-04-10 07:20:43 -07:00
|
|
|
if (!mDesktopNotification) {
|
2010-09-09 22:00:14 -07:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2013-04-10 07:20:43 -07:00
|
|
|
}
|
2010-09-09 22:00:14 -07:00
|
|
|
|
2012-07-30 07:58:26 -07:00
|
|
|
NS_IF_ADDREF(*aRequestingPrincipal = mDesktopNotification->mPrincipal);
|
2010-09-09 22:00:14 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-01-30 09:05:36 -08:00
|
|
|
DesktopNotificationRequest::GetWindow(mozIDOMWindow** aRequestingWindow)
|
2010-09-09 22:00:14 -07:00
|
|
|
{
|
2013-04-10 07:20:43 -07:00
|
|
|
if (!mDesktopNotification) {
|
2010-09-09 22:00:14 -07:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2013-04-10 07:20:43 -07:00
|
|
|
}
|
2010-09-09 22:00:14 -07:00
|
|
|
|
2013-04-10 07:20:43 -07:00
|
|
|
NS_IF_ADDREF(*aRequestingWindow = mDesktopNotification->GetOwner());
|
2010-09-09 22:00:14 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-13 12:31:53 -07:00
|
|
|
NS_IMETHODIMP
|
2013-04-10 07:20:43 -07:00
|
|
|
DesktopNotificationRequest::GetElement(nsIDOMElement * *aElement)
|
2010-09-13 12:31:53 -07:00
|
|
|
{
|
2013-09-04 08:40:16 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aElement);
|
|
|
|
*aElement = nullptr;
|
|
|
|
return NS_OK;
|
2010-09-13 12:31:53 -07:00
|
|
|
}
|
|
|
|
|
2010-09-09 22:00:14 -07:00
|
|
|
NS_IMETHODIMP
|
2013-04-10 07:20:43 -07:00
|
|
|
DesktopNotificationRequest::Cancel()
|
2010-09-09 22:00:14 -07:00
|
|
|
{
|
2012-07-26 15:25:02 -07:00
|
|
|
nsresult rv = mDesktopNotification->SetAllow(false);
|
2012-07-30 07:20:58 -07:00
|
|
|
mDesktopNotification = nullptr;
|
2012-07-26 15:25:02 -07:00
|
|
|
return rv;
|
2010-09-09 22:00:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-09-10 08:41:59 -07:00
|
|
|
DesktopNotificationRequest::Allow(JS::HandleValue aChoices)
|
2010-09-09 22:00:14 -07:00
|
|
|
{
|
2013-09-10 08:41:59 -07:00
|
|
|
MOZ_ASSERT(aChoices.isUndefined());
|
2012-07-26 15:25:02 -07:00
|
|
|
nsresult rv = mDesktopNotification->SetAllow(true);
|
2012-07-30 07:20:58 -07:00
|
|
|
mDesktopNotification = nullptr;
|
2012-07-26 15:25:02 -07:00
|
|
|
return rv;
|
2010-09-09 22:00:14 -07:00
|
|
|
}
|
|
|
|
|
2015-04-13 18:08:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DesktopNotificationRequest::GetRequester(nsIContentPermissionRequester** aRequester)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRequester);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContentPermissionRequester> requester = mRequester;
|
|
|
|
requester.forget(aRequester);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-13 12:31:53 -07:00
|
|
|
NS_IMETHODIMP
|
2014-02-09 12:34:40 -08:00
|
|
|
DesktopNotificationRequest::GetTypes(nsIArray** aTypes)
|
2010-09-13 12:31:53 -07:00
|
|
|
{
|
2013-09-10 08:41:59 -07:00
|
|
|
nsTArray<nsString> emptyOptions;
|
2014-08-01 00:22:20 -07:00
|
|
|
return nsContentPermissionUtils::CreatePermissionArray(NS_LITERAL_CSTRING("desktop-notification"),
|
|
|
|
NS_LITERAL_CSTRING("unused"),
|
|
|
|
emptyOptions,
|
|
|
|
aTypes);
|
2012-11-13 16:06:42 -08:00
|
|
|
}
|
2013-04-10 07:20:43 -07:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|