From ec05a62f84c886eb96796e83f666e5b8e2de7739 Mon Sep 17 00:00:00 2001 From: Kit Cambridge Date: Thu, 22 Oct 2015 15:10:14 -0600 Subject: [PATCH] Bug 1212129 - e10s support for disabling site notifications. r=wchen --HG-- extra : commitid : DPxANWhtVhu extra : rebase_source : ba1b2c4cc9a93f7acbc4b68936b808dfc3552294 --- browser/base/content/test/alerts/browser.ini | 2 +- dom/ipc/ContentParent.cpp | 19 +++++++++++++- dom/ipc/ContentParent.h | 2 ++ dom/ipc/PContent.ipdl | 2 ++ dom/ipc/StructuredCloneData.cpp | 3 ++- dom/ipc/TabParent.cpp | 2 ++ dom/ipc/nsIContentParent.cpp | 1 + dom/notification/Notification.cpp | 27 ++++++++++++++++---- dom/notification/Notification.h | 2 ++ 9 files changed, 52 insertions(+), 8 deletions(-) diff --git a/browser/base/content/test/alerts/browser.ini b/browser/base/content/test/alerts/browser.ini index 7fd34c951136..70c3bec77be2 100644 --- a/browser/base/content/test/alerts/browser.ini +++ b/browser/base/content/test/alerts/browser.ini @@ -5,6 +5,6 @@ support-files = [browser_notification_do_not_disturb.js] [browser_notification_open_settings.js] [browser_notification_remove_permission.js] -skip-if = e10s + [browser_notification_tab_switching.js] skip-if = buildapp == 'mulet' || e10s # Bug 1100662 - content access causing uncaught exception - Error: cannot ipc non-cpow object at chrome://mochitests/content/browser/browser/base/content/test/general/browser_notification_tab_switching.js:32 (or in RemoteAddonsChild.jsm) diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index d708b2db7444..207c0853cce7 100755 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -47,6 +47,7 @@ #ifdef MOZ_EME #include "mozilla/dom/MediaKeySystemAccess.h" #endif +#include "mozilla/dom/Notification.h" #include "mozilla/dom/NuwaParent.h" #include "mozilla/dom/PContentBridgeParent.h" #include "mozilla/dom/PContentPermissionRequestParent.h" @@ -3181,7 +3182,8 @@ ContentParent::Observe(nsISupports* aSubject, // listening for alert notifications else if (!strcmp(aTopic, "alertfinished") || !strcmp(aTopic, "alertclickcallback") || - !strcmp(aTopic, "alertshow") ) { + !strcmp(aTopic, "alertshow") || + !strcmp(aTopic, "alertdisablecallback")) { if (!SendNotifyAlertsObserver(nsDependentCString(aTopic), nsDependentString(aData))) return NS_ERROR_NOT_AVAILABLE; @@ -4316,6 +4318,21 @@ ContentParent::RecvCloseAlert(const nsString& aName, return true; } +bool +ContentParent::RecvDisableNotifications(const IPC::Principal& aPrincipal) +{ +#ifdef MOZ_CHILD_PERMISSIONS + uint32_t permission = mozilla::CheckPermission(this, aPrincipal, + "desktop-notification"); + if (permission != nsIPermissionManager::ALLOW_ACTION) { + return true; + } +#endif + + unused << Notification::RemovePermission(aPrincipal); + return true; +} + bool ContentParent::RecvSyncMessage(const nsString& aMsg, const ClonedMessageData& aData, diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index 08faa49491e0..8a51f6090e3c 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -767,6 +767,8 @@ private: virtual bool RecvCloseAlert(const nsString& aName, const IPC::Principal& aPrincipal) override; + virtual bool RecvDisableNotifications(const IPC::Principal& aPrincipal) override; + virtual bool RecvLoadURIExternal(const URIParams& uri) override; virtual bool RecvSyncMessage(const nsString& aMsg, diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index 8a923e80cd42..2bf8ce5eb582 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -842,6 +842,8 @@ parent: CloseAlert(nsString name, Principal principal); + DisableNotifications(Principal principal); + PPSMContentDownloader(uint32_t aCertType); PExternalHelperApp(OptionalURIParams uri, diff --git a/dom/ipc/StructuredCloneData.cpp b/dom/ipc/StructuredCloneData.cpp index 163ab385d013..10919290bf64 100644 --- a/dom/ipc/StructuredCloneData.cpp +++ b/dom/ipc/StructuredCloneData.cpp @@ -10,6 +10,7 @@ #include "nsIMutable.h" #include "nsIXPConnect.h" +#include "ipc/IPCMessageUtils.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/BlobBinding.h" #include "mozilla/dom/File.h" @@ -81,7 +82,7 @@ StructuredCloneData::Write(JSContext* aCx, } void -StructuredCloneData::WriteIPCParams(Message* aMsg) const +StructuredCloneData::WriteIPCParams(IPC::Message* aMsg) const { WriteParam(aMsg, DataLength()); diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index fc09609b4aff..068765bc22eb 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -16,8 +16,10 @@ #include "nsAccessibilityService.h" #endif #include "mozilla/BrowserElementParent.h" +#include "mozilla/dom/ContentBridgeParent.h" #include "mozilla/dom/ContentParent.h" #include "mozilla/dom/DataTransfer.h" +#include "mozilla/dom/Event.h" #include "mozilla/dom/indexedDB/ActorsParent.h" #include "mozilla/plugins/PluginWidgetParent.h" #include "mozilla/EventStateManager.h" diff --git a/dom/ipc/nsIContentParent.cpp b/dom/ipc/nsIContentParent.cpp index c1b3fe84b4f3..bbf8f931cd99 100644 --- a/dom/ipc/nsIContentParent.cpp +++ b/dom/ipc/nsIContentParent.cpp @@ -20,6 +20,7 @@ #include "mozilla/unused.h" #include "nsFrameMessageManager.h" +#include "nsIWebBrowserChrome.h" #include "nsPrintfCString.h" #include "xpcpublic.h" diff --git a/dom/notification/Notification.cpp b/dom/notification/Notification.cpp index cf980139fbdc..f33ad472e09c 100644 --- a/dom/notification/Notification.cpp +++ b/dom/notification/Notification.cpp @@ -14,6 +14,7 @@ #include "mozilla/dom/AppNotificationServiceOptionsBinding.h" #include "mozilla/dom/BindingUtils.h" +#include "mozilla/dom/ContentChild.h" #include "mozilla/dom/NotificationEvent.h" #include "mozilla/dom/PermissionMessageUtils.h" #include "mozilla/dom/Promise.h" @@ -40,6 +41,7 @@ #include "nsServiceManagerUtils.h" #include "nsStructuredCloneContainer.h" #include "nsToolkitCompsCID.h" +#include "nsXULAppAPI.h" #include "ServiceWorkerManager.h" #include "WorkerPrivate.h" #include "WorkerRunnable.h" @@ -1154,12 +1156,14 @@ NotificationObserver::Observe(nsISupports* aSubject, const char* aTopic, AssertIsOnMainThread(); if (!strcmp("alertdisablecallback", aTopic)) { - nsCOMPtr permissionManager = - mozilla::services::GetPermissionManager(); - if (!permissionManager) { - return NS_ERROR_FAILURE; + if (XRE_IsParentProcess()) { + return Notification::RemovePermission(mPrincipal); } - permissionManager->RemoveFromPrincipal(mPrincipal, "desktop-notification"); + // Permissions can't be removed from the content process. Send a message + // to the parent; `ContentParent::RecvDisableNotifications` will call + // `RemovePermission`. + ContentChild::GetSingleton()->SendDisableNotifications( + IPC::Principal(mPrincipal)); return NS_OK; } else if (!strcmp("alertsettingscallback", aTopic)) { nsCOMPtr obs = mozilla::services::GetObserverService(); @@ -2411,6 +2415,19 @@ Notification::CreateAndShow(nsIGlobalObject* aGlobal, return notification.forget(); } +/* static */ nsresult +Notification::RemovePermission(nsIPrincipal* aPrincipal) +{ + MOZ_ASSERT(XRE_IsParentProcess()); + nsCOMPtr permissionManager = + mozilla::services::GetPermissionManager(); + if (!permissionManager) { + return NS_ERROR_FAILURE; + } + permissionManager->RemoveFromPrincipal(aPrincipal, "desktop-notification"); + return NS_OK; +} + } // namespace dom } // namespace mozilla diff --git a/dom/notification/Notification.h b/dom/notification/Notification.h index 7ae08656847f..cdc441979d32 100644 --- a/dom/notification/Notification.h +++ b/dom/notification/Notification.h @@ -275,6 +275,8 @@ public: bool DispatchClickEvent(); bool DispatchNotificationClickEvent(); + + static nsresult RemovePermission(nsIPrincipal* aPrincipal); protected: Notification(nsIGlobalObject* aGlobal, const nsAString& aID, const nsAString& aTitle, const nsAString& aBody,