mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-03 10:33:33 +00:00
Bug 904298 - Use CheckPermission to check for the desktop-notification permission. r=sicking
This commit is contained in:
parent
30d37e6394
commit
ccec845618
@ -2833,29 +2833,40 @@ bool
|
||||
ContentParent::RecvShowAlertNotification(const nsString& aImageUrl, const nsString& aTitle,
|
||||
const nsString& aText, const bool& aTextClickable,
|
||||
const nsString& aCookie, const nsString& aName,
|
||||
const nsString& aBidi, const nsString& aLang)
|
||||
const nsString& aBidi, const nsString& aLang,
|
||||
const IPC::Principal& aPrincipal)
|
||||
{
|
||||
if (!AssertAppProcessPermission(this, "desktop-notification")) {
|
||||
return false;
|
||||
#ifdef MOZ_CHILD_PERMISSIONS
|
||||
uint32_t permission = mozilla::CheckPermission(this, aPrincipal,
|
||||
"desktop-notification");
|
||||
if (permission != nsIPermissionManager::ALLOW_ACTION) {
|
||||
return true;
|
||||
}
|
||||
#endif /* MOZ_CHILD_PERMISSIONS */
|
||||
|
||||
nsCOMPtr<nsIAlertsService> sysAlerts(do_GetService(NS_ALERTSERVICE_CONTRACTID));
|
||||
if (sysAlerts) {
|
||||
sysAlerts->ShowAlertNotification(aImageUrl, aTitle, aText, aTextClickable,
|
||||
aCookie, this, aName, aBidi, aLang);
|
||||
aCookie, this, aName, aBidi, aLang, aPrincipal);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentParent::RecvCloseAlert(const nsString& aName)
|
||||
ContentParent::RecvCloseAlert(const nsString& aName,
|
||||
const IPC::Principal& aPrincipal)
|
||||
{
|
||||
if (!AssertAppProcessPermission(this, "desktop-notification")) {
|
||||
return false;
|
||||
#ifdef MOZ_CHILD_PERMISSIONS
|
||||
uint32_t permission = mozilla::CheckPermission(this, aPrincipal,
|
||||
"desktop-notification");
|
||||
if (permission != nsIPermissionManager::ALLOW_ACTION) {
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsIAlertsService> sysAlerts(do_GetService(NS_ALERTSERVICE_CONTRACTID));
|
||||
if (sysAlerts) {
|
||||
sysAlerts->CloseAlert(aName);
|
||||
sysAlerts->CloseAlert(aName, aPrincipal);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -412,9 +412,11 @@ private:
|
||||
virtual bool RecvShowAlertNotification(const nsString& aImageUrl, const nsString& aTitle,
|
||||
const nsString& aText, const bool& aTextClickable,
|
||||
const nsString& aCookie, const nsString& aName,
|
||||
const nsString& aBidi, const nsString& aLang);
|
||||
const nsString& aBidi, const nsString& aLang,
|
||||
const IPC::Principal& aPrincipal);
|
||||
|
||||
virtual bool RecvCloseAlert(const nsString& aName);
|
||||
virtual bool RecvCloseAlert(const nsString& aName,
|
||||
const IPC::Principal& aPrincipal);
|
||||
|
||||
virtual bool RecvLoadURIExternal(const URIParams& uri);
|
||||
|
||||
|
@ -390,9 +390,10 @@ parent:
|
||||
nsString cookie,
|
||||
nsString name,
|
||||
nsString bidi,
|
||||
nsString lang);
|
||||
nsString lang,
|
||||
Principal principal);
|
||||
|
||||
CloseAlert(nsString name);
|
||||
CloseAlert(nsString name, Principal principal);
|
||||
|
||||
PExternalHelperApp(OptionalURIParams uri, nsCString aMimeContentType,
|
||||
nsCString aContentDisposition, bool aForceSave,
|
||||
|
@ -119,13 +119,15 @@ DesktopNotification::PostDesktopNotification()
|
||||
// to nsIObservers, thus cookies must be unique to differentiate observers.
|
||||
nsString uniqueName = NS_LITERAL_STRING("desktop-notification:");
|
||||
uniqueName.AppendInt(sCount++);
|
||||
nsIPrincipal* principal = GetOwner()->GetDoc()->NodePrincipal();
|
||||
return alerts->ShowAlertNotification(mIconURL, mTitle, mDescription,
|
||||
true,
|
||||
uniqueName,
|
||||
mObserver,
|
||||
uniqueName,
|
||||
NS_LITERAL_STRING("auto"),
|
||||
EmptyString());
|
||||
EmptyString(),
|
||||
principal);
|
||||
}
|
||||
|
||||
DesktopNotification::DesktopNotification(const nsAString & title,
|
||||
|
@ -499,6 +499,14 @@ Notification::CreateInternal(nsPIDOMWindow* aWindow,
|
||||
return notification.forget();
|
||||
}
|
||||
|
||||
nsIPrincipal*
|
||||
Notification::GetPrincipal()
|
||||
{
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(GetOwner());
|
||||
NS_ENSURE_TRUE(sop, nullptr);
|
||||
return sop->GetPrincipal();
|
||||
}
|
||||
|
||||
void
|
||||
Notification::ShowInternal()
|
||||
{
|
||||
@ -581,7 +589,8 @@ Notification::ShowInternal()
|
||||
uniqueCookie.AppendInt(sCount++);
|
||||
alertService->ShowAlertNotification(absoluteUrl, mTitle, mBody, true,
|
||||
uniqueCookie, observer, alertName,
|
||||
DirectionToString(mDir), mLang);
|
||||
DirectionToString(mDir), mLang,
|
||||
GetPrincipal());
|
||||
}
|
||||
|
||||
void
|
||||
@ -754,7 +763,7 @@ Notification::CloseInternal()
|
||||
nsString alertName;
|
||||
rv = GetAlertName(alertName);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
alertService->CloseAlert(alertName);
|
||||
alertService->CloseAlert(alertName, GetPrincipal());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,8 @@
|
||||
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
|
||||
class nsIPrincipal;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
@ -146,6 +148,9 @@ protected:
|
||||
bool mIsClosed;
|
||||
|
||||
static uint32_t sCount;
|
||||
|
||||
private:
|
||||
nsIPrincipal* GetPrincipal();
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
@ -4,6 +4,7 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "mozilla/dom/PermissionMessageUtils.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
|
||||
#include "nsAlertsService.h"
|
||||
@ -66,7 +67,8 @@ NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const nsAString & aImageUrl
|
||||
nsIObserver * aAlertListener,
|
||||
const nsAString & aAlertName,
|
||||
const nsAString & aBidi,
|
||||
const nsAString & aLang)
|
||||
const nsAString & aLang,
|
||||
nsIPrincipal * aPrincipal)
|
||||
{
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
||||
ContentChild* cpc = ContentChild::GetSingleton();
|
||||
@ -81,7 +83,8 @@ NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const nsAString & aImageUrl
|
||||
PromiseFlatString(aAlertCookie),
|
||||
PromiseFlatString(aAlertName),
|
||||
PromiseFlatString(aBidi),
|
||||
PromiseFlatString(aLang));
|
||||
PromiseFlatString(aLang),
|
||||
IPC::Principal(aPrincipal));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -96,7 +99,7 @@ NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const nsAString & aImageUrl
|
||||
if (sysAlerts) {
|
||||
return sysAlerts->ShowAlertNotification(aImageUrl, aAlertTitle, aAlertText, aAlertTextClickable,
|
||||
aAlertCookie, aAlertListener, aAlertName,
|
||||
aBidi, aLang);
|
||||
aBidi, aLang, IPC::Principal(aPrincipal));
|
||||
}
|
||||
|
||||
if (!ShouldShowAlert()) {
|
||||
@ -114,11 +117,12 @@ NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const nsAString & aImageUrl
|
||||
#endif // !MOZ_WIDGET_ANDROID
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAlertsService::CloseAlert(const nsAString& aAlertName)
|
||||
NS_IMETHODIMP nsAlertsService::CloseAlert(const nsAString& aAlertName,
|
||||
nsIPrincipal* aPrincipal)
|
||||
{
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
||||
ContentChild* cpc = ContentChild::GetSingleton();
|
||||
cpc->SendCloseAlert(nsAutoString(aAlertName));
|
||||
cpc->SendCloseAlert(nsAutoString(aAlertName), IPC::Principal(aPrincipal));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -130,7 +134,7 @@ NS_IMETHODIMP nsAlertsService::CloseAlert(const nsAString& aAlertName)
|
||||
// Try the system notification service.
|
||||
nsCOMPtr<nsIAlertsService> sysAlerts(do_GetService(NS_SYSTEMALERTSERVICE_CONTRACTID));
|
||||
if (sysAlerts) {
|
||||
return sysAlerts->CloseAlert(aAlertName);
|
||||
return sysAlerts->CloseAlert(aAlertName, nullptr);
|
||||
}
|
||||
|
||||
return mXULAlerts.CloseAlert(aAlertName);
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIObserver.idl"
|
||||
|
||||
interface nsIPrincipal;
|
||||
|
||||
[scriptable, uuid(160e87e1-d57d-456b-b6ea-17826f6ea7a8)]
|
||||
interface nsIAlertsService : nsISupports
|
||||
{
|
||||
@ -55,7 +57,8 @@ interface nsIAlertsService : nsISupports
|
||||
[optional] in nsIObserver alertListener,
|
||||
[optional] in AString name,
|
||||
[optional] in AString dir,
|
||||
[optional] in AString lang);
|
||||
[optional] in AString lang,
|
||||
[optional] in nsIPrincipal principal);
|
||||
|
||||
/**
|
||||
* Close alerts created by the service.
|
||||
@ -64,7 +67,8 @@ interface nsIAlertsService : nsISupports
|
||||
* is provided then only a notification created with
|
||||
* no name (if any) will be closed.
|
||||
*/
|
||||
void closeAlert([optional] in AString name);
|
||||
void closeAlert([optional] in AString name,
|
||||
[optional] in nsIPrincipal principal);
|
||||
};
|
||||
|
||||
[scriptable, uuid(df1bd4b0-3a8c-40e6-806a-203f38b0bd9f)]
|
||||
|
@ -2724,7 +2724,8 @@ nsDownload::SetState(DownloadState aState)
|
||||
NS_LITERAL_STRING(DOWNLOAD_MANAGER_ALERT_ICON), title,
|
||||
message, !removeWhenDone,
|
||||
mPrivate ? NS_LITERAL_STRING("private") : NS_LITERAL_STRING("non-private"),
|
||||
mDownloadManager, EmptyString(), NS_LITERAL_STRING("auto"), EmptyString());
|
||||
mDownloadManager, EmptyString(), NS_LITERAL_STRING("auto"),
|
||||
EmptyString(), nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user