Bug 260865 Remove nsIAlertListener

patch by cst@andrew.cmu.edu r=jag sr=neil
This commit is contained in:
timeless%mozdev.org 2004-10-27 16:20:01 +00:00
Родитель 20aad1878f
Коммит 0d446f7283
7 изменённых файлов: 51 добавлений и 55 удалений

Просмотреть файл

@ -258,7 +258,7 @@ NS_INTERFACE_MAP_BEGIN(nsMessengerWinIntegration)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIMessengerOSIntegration) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIMessengerOSIntegration)
NS_INTERFACE_MAP_ENTRY(nsIMessengerOSIntegration) NS_INTERFACE_MAP_ENTRY(nsIMessengerOSIntegration)
NS_INTERFACE_MAP_ENTRY(nsIFolderListener) NS_INTERFACE_MAP_ENTRY(nsIFolderListener)
NS_INTERFACE_MAP_ENTRY(nsIAlertListener) NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_END NS_INTERFACE_MAP_END
@ -484,20 +484,19 @@ nsresult nsMessengerWinIntegration::ShowAlertMessage(const PRUnichar * aAlertTit
nsCOMPtr<nsIAlertsService> alertsService (do_GetService(NS_ALERTSERVICE_CONTRACTID, &rv)); nsCOMPtr<nsIAlertsService> alertsService (do_GetService(NS_ALERTSERVICE_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv)) if (NS_SUCCEEDED(rv))
{ {
nsCOMPtr<nsIAlertListener> alertListener (do_QueryInterface(NS_STATIC_CAST(nsIMessengerOSIntegration*, this)));
rv = alertsService->ShowAlertNotification(NEW_MAIL_ALERT_ICON, aAlertTitle, aAlertText, PR_TRUE, rv = alertsService->ShowAlertNotification(NEW_MAIL_ALERT_ICON, aAlertTitle, aAlertText, PR_TRUE,
NS_ConvertASCIItoUCS2(aFolderURI).get(), alertListener); NS_ConvertASCIItoUCS2(aFolderURI).get(), this);
mAlertInProgress = PR_TRUE; mAlertInProgress = PR_TRUE;
} }
} }
if (!showAlert || NS_FAILED(rv)) // go straight to showing the system tray icon. if (!showAlert || NS_FAILED(rv)) // go straight to showing the system tray icon.
OnAlertFinished(nsnull); AlertFinished();
return rv; return rv;
} }
NS_IMETHODIMP nsMessengerWinIntegration::OnAlertFinished(const PRUnichar * aAlertCookie) nsresult nsMessengerWinIntegration::AlertFinished()
{ {
// okay we are done showing the alert....now put an icon in the system tray // okay we are done showing the alert....now put an icon in the system tray
if (!mSuppressBiffIcon) if (!mSuppressBiffIcon)
@ -511,7 +510,7 @@ NS_IMETHODIMP nsMessengerWinIntegration::OnAlertFinished(const PRUnichar * aAler
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsMessengerWinIntegration::OnAlertClickCallback(const PRUnichar * aAlertCookie) nsresult nsMessengerWinIntegration::AlertClicked()
{ {
// make sure we don't insert the icon in the system tray since the user clicked on the alert. // make sure we don't insert the icon in the system tray since the user clicked on the alert.
mSuppressBiffIcon = PR_TRUE; mSuppressBiffIcon = PR_TRUE;
@ -524,6 +523,18 @@ NS_IMETHODIMP nsMessengerWinIntegration::OnAlertClickCallback(const PRUnichar *
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsMessengerWinIntegration::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aData)
{
if (strcmp(aTopic, "alertfinished") == 0)
return AlertFinished();
if (strcmp(aTopic, "alertclickcallback") == 0)
return AlertClicked();
return NS_OK;
}
void nsMessengerWinIntegration::FillToolTipInfo() void nsMessengerWinIntegration::FillToolTipInfo()
{ {
// iterate over all the folders in mFoldersWithNewMail // iterate over all the folders in mFoldersWithNewMail

Просмотреть файл

@ -56,6 +56,7 @@
#include "nsIPref.h" #include "nsIPref.h"
#include "nsInt64.h" #include "nsInt64.h"
#include "nsISupportsArray.h" #include "nsISupportsArray.h"
#include "nsIObserver.h"
// this function is exported by shell32.dll version 5.60 or later (Windows XP or greater) // this function is exported by shell32.dll version 5.60 or later (Windows XP or greater)
extern "C" extern "C"
@ -73,7 +74,7 @@ class nsIStringBundle;
class nsMessengerWinIntegration : public nsIMessengerOSIntegration, class nsMessengerWinIntegration : public nsIMessengerOSIntegration,
public nsIFolderListener, public nsIFolderListener,
public nsIAlertListener public nsIObserver
{ {
public: public:
nsMessengerWinIntegration(); nsMessengerWinIntegration();
@ -83,9 +84,11 @@ public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSIMESSENGEROSINTEGRATION NS_DECL_NSIMESSENGEROSINTEGRATION
NS_DECL_NSIFOLDERLISTENER NS_DECL_NSIFOLDERLISTENER
NS_DECL_NSIALERTLISTENER NS_DECL_NSIOBSERVER
private: private:
nsresult AlertFinished();
nsresult AlertClicked();
static NOTIFYICONDATAW mWideBiffIconData; static NOTIFYICONDATAW mWideBiffIconData;
static NOTIFYICONDATA mAsciiBiffIconData; static NOTIFYICONDATA mAsciiBiffIconData;

Просмотреть файл

@ -38,32 +38,27 @@
#include "nsISupports.idl" #include "nsISupports.idl"
#include "nsIObserver.idl"
/* nsIAlertsListener --> when a consumer asks the alerts service to put up an alert, they have the option [scriptable, uuid(3A3C2953-01EE-4D9C-A102-5AA0D7BD444C)]
of passing in an alert listener as well. The alert listener gets notified when the alert has gone away.
*/
[scriptable, uuid(A840623B-5B87-4e99-A74A-9EF0886C11DD)]
interface nsIAlertListener : nsISupports
{
void onAlertFinished(in wstring aAlertCookie);
void onAlertClickCallback(in wstring aAlertCookie); // if the user clicks the link and you wanted to be notified...
};
[scriptable, uuid(7E8B76C6-A70C-4075-81AA-D48B6152E1B4)]
interface nsIAlertsService : nsISupports interface nsIAlertsService : nsISupports
{ {
/* showAlertNotification: shows an animated alert icon /* showAlertNotification: shows an animated alert icon
aImageUrl --> a url identifying an image to put in the alert. aImageUrl --> a url identifying an image to put in the alert.
aAlertTitle --> the title text for the alert (i.e. You have New Mail) aAlertTitle --> the title text for the alert (i.e. You have New Mail)
aAlertText --> the contents of the alert aAlertText --> the contents of the alert
alertTextClickable --> set to true if you wish to be notified if the user attempts to click alertTextClickable --> set to true if you wish to be notified if the user attempts to click
the alert text. Also causes the alert text to look like a link. the alert text. Also causes the alert text to look like a link.
aAlertCookie --> a blind cookie the alert will pass back to the consumer during the alert listener callbacks aAlertCookie --> a blind cookie the alert will pass back to the consumer
during the alert listener callbacks
aAlertListener --> used for callbacks. Subject is null, topic is "alertfinished" when the
alert goes away, or "alertclickcallback" when the text is clicked. Data
is aAlertCookie.
*/ */
void showAlertNotification(in string aImageUrl, in wstring aAlertTitle, void showAlertNotification(in string aImageUrl, in wstring aAlertTitle,
in wstring aAlertText, in boolean alertTextClickable, in wstring aAlertText, in boolean alertTextClickable,
in wstring aAlertCookie, in wstring aAlertCookie,
in nsIAlertListener aAlertListener ); in nsIObserver aAlertListener );
}; };
%{ C++ %{ C++

Просмотреть файл

@ -53,7 +53,7 @@ function prefillAlertInfo()
// arguments[2] --> the alert text // arguments[2] --> the alert text
// arguments[3] --> is the text clickable? // arguments[3] --> is the text clickable?
// arguments[4] --> the alert cookie to be passed back to the listener // arguments[4] --> the alert cookie to be passed back to the listener
// arguments[5] --> an optional callback listener (nsIAlertListener) // arguments[5] --> an optional callback listener (nsIObserver)
document.getElementById('alertImage').setAttribute('src', window.arguments[0]); document.getElementById('alertImage').setAttribute('src', window.arguments[0]);
document.getElementById('alertTitleLabel').setAttribute('value', window.arguments[1]); document.getElementById('alertTitleLabel').setAttribute('value', window.arguments[1]);
@ -65,8 +65,7 @@ function prefillAlertInfo()
document.getElementById('alertTextLabel').setAttribute('clickable', true); document.getElementById('alertTextLabel').setAttribute('clickable', true);
// the 5th argument is optional // the 5th argument is optional
if (window.arguments[5]) gAlertListener = window.arguments[5];
gAlertListener = window.arguments[5].QueryInterface(Components.interfaces.nsIAlertListener);
} }
function onAlertLoad() function onAlertLoad()
@ -117,7 +116,7 @@ function closeAlert()
else else
{ {
if (gAlertListener) if (gAlertListener)
gAlertListener.onAlertFinished(gAlertCookie); gAlertListener.observe(null, "alertfinished", gAlertCookie);
window.close(); window.close();
} }
} }
@ -125,5 +124,5 @@ function closeAlert()
function onAlertClick() function onAlertClick()
{ {
if (gAlertListener && gAlertTextClickable) if (gAlertListener && gAlertTextClickable)
gAlertListener.onAlertClickCallback(gAlertCookie); gAlertListener.observe(null, "alertclickcallback", gAlertCookie);
} }

Просмотреть файл

@ -65,7 +65,7 @@ nsAlertsService::~nsAlertsService()
NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const char * aImageUrl, const PRUnichar * aAlertTitle, NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const char * aImageUrl, const PRUnichar * aAlertTitle,
const PRUnichar * aAlertText, PRBool aAlertTextClickable, const PRUnichar * aAlertText, PRBool aAlertTextClickable,
const PRUnichar * aAlertCookie, const PRUnichar * aAlertCookie,
nsIAlertListener * aAlertListener) nsIObserver * aAlertListener)
{ {
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)); nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
nsCOMPtr<nsIDOMWindow> newWindow; nsCOMPtr<nsIDOMWindow> newWindow;
@ -113,7 +113,7 @@ NS_IMETHODIMP nsAlertsService::ShowAlertNotification(const char * aImageUrl, con
nsCOMPtr<nsISupports> iSupports (do_QueryInterface(aAlertListener)); nsCOMPtr<nsISupports> iSupports (do_QueryInterface(aAlertListener));
ifptr->SetData(iSupports); ifptr->SetData(iSupports);
ifptr->SetDataIID(&NS_GET_IID(nsIAlertListener)); ifptr->SetDataIID(&NS_GET_IID(nsIObserver));
argsArray->AppendElement(ifptr); argsArray->AppendElement(ifptr);
} }

Просмотреть файл

@ -919,7 +919,7 @@ nsDownloadManager::Observe(nsISupports* aSubject, const char* aTopic, const PRUn
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// nsDownload // nsDownload
NS_IMPL_ISUPPORTS5(nsDownload, nsIDownload, nsITransfer, nsIWebProgressListener, nsIObserver, nsIAlertListener) NS_IMPL_ISUPPORTS4(nsDownload, nsIDownload, nsITransfer, nsIWebProgressListener, nsIObserver)
nsDownload::nsDownload(nsDownloadManager* aManager, nsDownload::nsDownload(nsDownloadManager* aManager,
nsIURI* aTarget, nsIURI* aTarget,
@ -982,6 +982,13 @@ nsDownload::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar*
mDownloadManager->CancelDownload(path); mDownloadManager->CancelDownload(path);
// Ignoring return value; this function will get called twice, // Ignoring return value; this function will get called twice,
// and bad things happen if we return a failure code the second time. // and bad things happen if we return a failure code the second time.
return NS_OK;
}
if (strcmp(aTopic, "alertclickcallback") == 0) {
// show the download manager
mDownloadManager->Open(nsnull, this);
return NS_OK;
} }
return NS_OK; return NS_OK;
@ -1269,23 +1276,6 @@ nsDownload::OnSecurityChange(nsIWebProgress *aWebProgress,
return NS_OK; return NS_OK;
} }
///////////////////////////////////////////////////////////////////////////////
// nsIAlertListener
NS_IMETHODIMP
nsDownload::OnAlertFinished(const PRUnichar * aAlertCookie)
{
return NS_OK;
}
NS_IMETHODIMP
nsDownload::OnAlertClickCallback(const PRUnichar * aAlertCookie)
{
// show the download manager
mDownloadManager->Open(nsnull, this);
return NS_OK;
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// nsIDownload // nsIDownload

Просмотреть файл

@ -106,8 +106,7 @@ private:
class nsDownload : public nsIDownload, class nsDownload : public nsIDownload,
public nsIWebProgressListener, public nsIWebProgressListener,
public nsIObserver, public nsIObserver
public nsIAlertListener
{ {
public: public:
NS_DECL_NSIWEBPROGRESSLISTENER NS_DECL_NSIWEBPROGRESSLISTENER
@ -115,7 +114,6 @@ public:
NS_DECL_NSIDOWNLOAD NS_DECL_NSIDOWNLOAD
NS_DECL_NSIOBSERVER NS_DECL_NSIOBSERVER
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSIALERTLISTENER
nsDownload(nsDownloadManager* aManager, nsIURI* aTarget, nsIURI* aSource); nsDownload(nsDownloadManager* aManager, nsIURI* aTarget, nsIURI* aSource);
~nsDownload(); ~nsDownload();