mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 10:00:54 +00:00
Bug 699014 - Toolkit alerts shouldn't be displayed if the user's in a fullscreen app, presentation mode, or in Windows 8 immersive mode. r=bbondy, ui-r=limi
This commit is contained in:
parent
0faf54572f
commit
1e964a8ce4
@ -74,6 +74,33 @@ nsAlertsService::nsAlertsService()
|
||||
nsAlertsService::~nsAlertsService()
|
||||
{}
|
||||
|
||||
bool nsAlertsService::ShouldShowAlert()
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
#ifdef XP_WIN
|
||||
HMODULE shellDLL = ::LoadLibraryW(L"shell32.dll");
|
||||
if (!shellDLL)
|
||||
return result;
|
||||
|
||||
SHQueryUserNotificationStatePtr pSHQueryUserNotificationState =
|
||||
(SHQueryUserNotificationStatePtr) ::GetProcAddress(shellDLL, "SHQueryUserNotificationState");
|
||||
|
||||
if (pSHQueryUserNotificationState) {
|
||||
MOZ_QUERY_USER_NOTIFICATION_STATE qstate;
|
||||
if (SUCCEEDED(pSHQueryUserNotificationState(&qstate))) {
|
||||
if (qstate != QUNS_ACCEPTS_NOTIFICATIONS) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
::FreeLibrary(shellDLL);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const nsAString & aImageUrl, const nsAString & aAlertTitle,
|
||||
const nsAString & aAlertText, bool aAlertTextClickable,
|
||||
const nsAString & aAlertCookie,
|
||||
@ -110,6 +137,13 @@ NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const nsAString & aImageUrl
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (!ShouldShowAlert()) {
|
||||
// Do not display the alert. Instead call alertfinished and get out.
|
||||
if (aAlertListener)
|
||||
aAlertListener->Observe(NULL, "alertfinished", PromiseFlatString(aAlertCookie).get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
|
||||
nsCOMPtr<nsIDOMWindow> newWindow;
|
||||
|
||||
|
@ -42,6 +42,23 @@
|
||||
#include "nsIAlertsService.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#ifdef XP_WIN
|
||||
typedef enum tagMOZ_QUERY_USER_NOTIFICATION_STATE {
|
||||
QUNS_NOT_PRESENT = 1,
|
||||
QUNS_BUSY = 2,
|
||||
QUNS_RUNNING_D3D_FULL_SCREEN = 3,
|
||||
QUNS_PRESENTATION_MODE = 4,
|
||||
QUNS_ACCEPTS_NOTIFICATIONS = 5,
|
||||
QUNS_QUIET_TIME = 6,
|
||||
QUNS_IMMERSIVE = 7
|
||||
} MOZ_QUERY_USER_NOTIFICATION_STATE;
|
||||
|
||||
extern "C" {
|
||||
// This function is Windows Vista or later
|
||||
typedef HRESULT (__stdcall *SHQueryUserNotificationStatePtr)(MOZ_QUERY_USER_NOTIFICATION_STATE *pquns);
|
||||
}
|
||||
#endif // defined(XP_WIN)
|
||||
|
||||
class nsAlertsService : public nsIAlertsService,
|
||||
public nsIAlertsProgressListener
|
||||
{
|
||||
@ -54,6 +71,7 @@ public:
|
||||
virtual ~nsAlertsService();
|
||||
|
||||
protected:
|
||||
bool ShouldShowAlert();
|
||||
};
|
||||
|
||||
#endif /* nsAlertsService_h__ */
|
||||
|
@ -70,6 +70,11 @@ interface nsIAlertsService : nsISupports
|
||||
* topic - "alertfinished" when the alert goes away
|
||||
* "alertclickcallback" when the text is clicked
|
||||
* data - the value of the cookie parameter passed to showAlertNotification.
|
||||
*
|
||||
* @note Depending on current circumstances (if the user's in a fullscreen
|
||||
* application, for instance), the alert might not be displayed at all.
|
||||
* 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,
|
||||
|
Loading…
Reference in New Issue
Block a user