зеркало из https://github.com/mozilla/gecko-dev.git
Bug 782211 - Part 2: Updated the nsIAlertsService API and its implementation to include support for bidi overrides and a method to close notifications. r=dougt
This commit is contained in:
Родитель
75bb7adc42
Коммит
b382e82e06
|
@ -1508,7 +1508,8 @@ ContentParent::Observe(nsISupports* aSubject,
|
|||
}
|
||||
// listening for alert notifications
|
||||
else if (!strcmp(aTopic, "alertfinished") ||
|
||||
!strcmp(aTopic, "alertclickcallback") ) {
|
||||
!strcmp(aTopic, "alertclickcallback") ||
|
||||
!strcmp(aTopic, "alertshow") ) {
|
||||
if (!SendNotifyAlertsObserver(nsDependentCString(aTopic),
|
||||
nsDependentString(aData)))
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
@ -2242,7 +2243,8 @@ ContentParent::AfterProcessNextEvent(nsIThreadInternal *thread,
|
|||
bool
|
||||
ContentParent::RecvShowAlertNotification(const nsString& aImageUrl, const nsString& aTitle,
|
||||
const nsString& aText, const bool& aTextClickable,
|
||||
const nsString& aCookie, const nsString& aName)
|
||||
const nsString& aCookie, const nsString& aName,
|
||||
const nsString& aBidi, const nsString& aLang)
|
||||
{
|
||||
if (!AssertAppProcessPermission(this, "desktop-notification")) {
|
||||
return false;
|
||||
|
@ -2250,7 +2252,21 @@ ContentParent::RecvShowAlertNotification(const nsString& aImageUrl, const nsStri
|
|||
nsCOMPtr<nsIAlertsService> sysAlerts(do_GetService(NS_ALERTSERVICE_CONTRACTID));
|
||||
if (sysAlerts) {
|
||||
sysAlerts->ShowAlertNotification(aImageUrl, aTitle, aText, aTextClickable,
|
||||
aCookie, this, aName);
|
||||
aCookie, this, aName, aBidi, aLang);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentParent::RecvCloseAlert(const nsString& aName)
|
||||
{
|
||||
if (!AssertAppProcessPermission(this, "desktop-notification")) {
|
||||
return false;
|
||||
}
|
||||
nsCOMPtr<nsIAlertsService> sysAlerts(do_GetService(NS_ALERTSERVICE_CONTRACTID));
|
||||
if (sysAlerts) {
|
||||
sysAlerts->CloseAlert(aName);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -328,7 +328,10 @@ private:
|
|||
|
||||
virtual bool RecvShowAlertNotification(const nsString& aImageUrl, const nsString& aTitle,
|
||||
const nsString& aText, const bool& aTextClickable,
|
||||
const nsString& aCookie, const nsString& aName);
|
||||
const nsString& aCookie, const nsString& aName,
|
||||
const nsString& aBidi, const nsString& aLang);
|
||||
|
||||
virtual bool RecvCloseAlert(const nsString& aName);
|
||||
|
||||
virtual bool RecvLoadURIExternal(const URIParams& uri);
|
||||
|
||||
|
|
|
@ -422,12 +422,16 @@ parent:
|
|||
sync SyncMessage(nsString aMessage, ClonedMessageData aData)
|
||||
returns (nsString[] retval);
|
||||
|
||||
ShowAlertNotification(nsString imageUrl,
|
||||
nsString title,
|
||||
nsString text,
|
||||
ShowAlertNotification(nsString imageUrl,
|
||||
nsString title,
|
||||
nsString text,
|
||||
bool textClickable,
|
||||
nsString cookie,
|
||||
nsString name);
|
||||
nsString name,
|
||||
nsString bidi,
|
||||
nsString lang);
|
||||
|
||||
CloseAlert(nsString name);
|
||||
|
||||
PExternalHelperApp(OptionalURIParams uri, nsCString aMimeContentType,
|
||||
nsCString aContentDisposition, bool aForceSave,
|
||||
|
|
|
@ -60,6 +60,8 @@ nsDOMDesktopNotification::PostDesktopNotification()
|
|||
true,
|
||||
EmptyString(),
|
||||
mObserver,
|
||||
EmptyString(),
|
||||
NS_LITERAL_STRING("auto"),
|
||||
EmptyString());
|
||||
}
|
||||
|
||||
|
|
|
@ -276,7 +276,9 @@ nsMacAlertsService::ShowAlertNotification(const nsAString& aImageUrl,
|
|||
bool aAlertClickable,
|
||||
const nsAString& aAlertCookie,
|
||||
nsIObserver* aAlertListener,
|
||||
const nsAString& aAlertName)
|
||||
const nsAString& aAlertName,
|
||||
const nsAString& aDir,
|
||||
const nsAString& aLang)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
|
@ -321,6 +323,12 @@ nsMacAlertsService::ShowAlertNotification(const nsAString& aImageUrl,
|
|||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacAlertsService::CloseAlert(const nsAString& aName)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// nsIObserver
|
||||
|
||||
|
|
|
@ -70,7 +70,9 @@ NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const nsAString & aImageUrl
|
|||
const nsAString & aAlertText, bool aAlertTextClickable,
|
||||
const nsAString & aAlertCookie,
|
||||
nsIObserver * aAlertListener,
|
||||
const nsAString & aAlertName)
|
||||
const nsAString & aAlertName,
|
||||
const nsAString & aBidi,
|
||||
const nsAString & aLang)
|
||||
{
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
||||
ContentChild* cpc = ContentChild::GetSingleton();
|
||||
|
@ -83,7 +85,9 @@ NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const nsAString & aImageUrl
|
|||
PromiseFlatString(aAlertText),
|
||||
aAlertTextClickable,
|
||||
PromiseFlatString(aAlertCookie),
|
||||
PromiseFlatString(aAlertName));
|
||||
PromiseFlatString(aAlertName),
|
||||
PromiseFlatString(aBidi),
|
||||
PromiseFlatString(aLang));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -98,9 +102,9 @@ NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const nsAString & aImageUrl
|
|||
nsresult rv;
|
||||
if (sysAlerts) {
|
||||
rv = sysAlerts->ShowAlertNotification(aImageUrl, aAlertTitle, aAlertText, aAlertTextClickable,
|
||||
aAlertCookie, aAlertListener, aAlertName);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
return rv;
|
||||
aAlertCookie, aAlertListener, aAlertName,
|
||||
aBidi, aLang);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
if (!ShouldShowAlert()) {
|
||||
|
@ -186,6 +190,35 @@ NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const nsAString & aImageUrl
|
|||
#endif // !MOZ_WIDGET_ANDROID
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAlertsService::CloseAlert(const nsAString& aAlertName)
|
||||
{
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
||||
ContentChild* cpc = ContentChild::GetSingleton();
|
||||
cpc->SendCloseAlert(nsAutoString(aAlertName));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
mozilla::AndroidBridge::Bridge()->CloseNotification(aAlertName);
|
||||
return NS_OK;
|
||||
#else
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
// Try the system notification service.
|
||||
nsCOMPtr<nsIAlertsService> sysAlerts(do_GetService(NS_SYSTEMALERTSERVICE_CONTRACTID));
|
||||
if (sysAlerts) {
|
||||
nsresult rv = sysAlerts->CloseAlert(aAlertName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
#endif // !MOZ_WIDGET_ANDROID
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsAlertsService::OnProgress(const nsAString & aAlertName,
|
||||
int64_t aProgress,
|
||||
int64_t aProgressMax,
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
#include "nsISupports.idl"
|
||||
#include "nsIObserver.idl"
|
||||
|
||||
[scriptable, uuid(e177399e-2e31-4019-aed3-cba63ce9fa99)]
|
||||
[scriptable, uuid(160e87e1-d57d-456b-b6ea-17826f6ea7a8)]
|
||||
interface nsIAlertsService : nsISupports
|
||||
{
|
||||
/**
|
||||
* Displays a sliding notification window.
|
||||
*
|
||||
*
|
||||
* @param imageUrl A URL identifying the image to put in the alert.
|
||||
* @param title The title for the alert.
|
||||
* @param text The contents of the alert.
|
||||
|
@ -27,8 +27,13 @@ interface nsIAlertsService : nsISupports
|
|||
* only used on OS X with Growl and Android.
|
||||
* On OS X with Growl, users can disable notifications
|
||||
* with a given name. On Android the name is hashed
|
||||
* and used as a notification ID.
|
||||
*
|
||||
* and used as a notification ID. Notifications will
|
||||
* replace previous notifications with the same name.
|
||||
* @param dir Bidi override for the title. Valid values are
|
||||
* "auto", "ltr" or "rtl". Only available on supported
|
||||
* platforms.
|
||||
* @param lang Language of title and text of the alert. Only available
|
||||
* on supported platforms.
|
||||
* @throws NS_ERROR_NOT_AVAILABLE If the notification cannot be displayed.
|
||||
*
|
||||
* The following arguments will be passed to the alertListener's observe()
|
||||
|
@ -36,6 +41,7 @@ interface nsIAlertsService : nsISupports
|
|||
* subject - null
|
||||
* topic - "alertfinished" when the alert goes away
|
||||
* "alertclickcallback" when the text is clicked
|
||||
* "alertshow" when the alert is shown
|
||||
* data - the value of the cookie parameter passed to showAlertNotification.
|
||||
*
|
||||
* @note Depending on current circumstances (if the user's in a fullscreen
|
||||
|
@ -43,14 +49,24 @@ interface nsIAlertsService : nsISupports
|
|||
* In that case, if an alert listener is passed in it will receive the
|
||||
* "alertfinished" notification immediately.
|
||||
*/
|
||||
void showAlertNotification(in AString imageUrl,
|
||||
in AString title,
|
||||
in AString text,
|
||||
void showAlertNotification(in AString imageUrl,
|
||||
in AString title,
|
||||
in AString text,
|
||||
[optional] in boolean textClickable,
|
||||
[optional] in AString cookie,
|
||||
[optional] in nsIObserver alertListener,
|
||||
[optional] in AString name);
|
||||
[optional] in AString name,
|
||||
[optional] in AString dir,
|
||||
[optional] in AString lang);
|
||||
|
||||
/**
|
||||
* Close alerts created by the service.
|
||||
*
|
||||
* @param name The name of the notification to close. If no name
|
||||
* is provided then only a notification created with
|
||||
* no name (if any) will be closed.
|
||||
*/
|
||||
void closeAlert([optional] in AString name);
|
||||
};
|
||||
|
||||
[scriptable, uuid(df1bd4b0-3a8c-40e6-806a-203f38b0bd9f)]
|
||||
|
@ -82,3 +98,4 @@ interface nsIAlertsProgressListener : nsISupports
|
|||
*/
|
||||
void onCancel(in AString name);
|
||||
};
|
||||
|
||||
|
|
|
@ -21,14 +21,18 @@
|
|||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
|
||||
var observer = {
|
||||
alertShow: false,
|
||||
observe: function (aSubject, aTopic, aData) {
|
||||
if (aTopic == "alertclickcallback") {
|
||||
todo(false, "Did someone click the notification while running mochitests? (Please don't.)");
|
||||
} else if (aTopic == "alertshow") {
|
||||
ok(!this.alertShow, "Alert should not be shown more than once");
|
||||
this.alertShow = true;
|
||||
} else {
|
||||
is(aTopic, "alertfinished", "Checking the topic for a finished notification");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
is(aData, "foobarcookie", "Checking whether the alert cookie was passed correctly");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -2628,7 +2628,7 @@ 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());
|
||||
mDownloadManager, EmptyString(), NS_LITERAL_STRING("auto"), EmptyString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,9 @@ nsSystemAlertsService::ShowAlertNotification(const nsAString & aImageUrl,
|
|||
bool aAlertTextClickable,
|
||||
const nsAString & aAlertCookie,
|
||||
nsIObserver * aAlertListener,
|
||||
const nsAString & aAlertName)
|
||||
const nsAString & aAlertName,
|
||||
const nsAString & aBidi,
|
||||
const nsAString & aLang)
|
||||
{
|
||||
nsRefPtr<nsAlertsIconListener> alertListener = new nsAlertsIconListener();
|
||||
if (!alertListener)
|
||||
|
@ -43,3 +45,10 @@ nsSystemAlertsService::ShowAlertNotification(const nsAString & aImageUrl,
|
|||
return alertListener->InitAlertAsync(aImageUrl, aAlertTitle, aAlertText, aAlertTextClickable,
|
||||
aAlertCookie, aAlertListener);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemAlertsService::CloseAlert(const nsAString & aAlertName)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче