Bug 840474 - Clicking on new mail notifcation opens two MailNews windows when no MailNews window is open, r=Mnyromyr, a=IanN, a-CLOSED TREE=Callek
authorFrank Wein <mcsmurf@mcsmurf.de>
Sat, 20 Jul 2013 01:41:26 +0200
changeset 15591 56d3f3b988208454b21ccc4fb281bcebbd5e12f4
parent 15588 4b022ddb9be42a08059f5342490157c5d9761726
child 15592 ad06842957a185e296815ca4758399c9de2ffcbf
push id935
push usermcsmurf@mcsmurf.de
push dateMon, 22 Jul 2013 08:20:31 +0000
treeherdercomm-beta@56d3f3b98820 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMnyromyr, IanN, a-CLOSED
bugs840474
Bug 840474 - Clicking on new mail notifcation opens two MailNews windows when no MailNews window is open, r=Mnyromyr, a=IanN, a-CLOSED TREE=Callek
mailnews/base/src/nsMessengerOSXIntegration.h
mailnews/base/src/nsMessengerOSXIntegration.mm
mailnews/base/src/nsMessengerWinIntegration.cpp
mailnews/base/src/nsMessengerWinIntegration.h
suite/mailnews/mailWidgets.xml
--- a/mailnews/base/src/nsMessengerOSXIntegration.h
+++ b/mailnews/base/src/nsMessengerOSXIntegration.h
@@ -39,16 +39,19 @@ public:
   NS_DECL_MOZINEWMAILLISTENER
 
 private:
   nsCOMPtr<nsIAtom> mBiffStateAtom;
   nsCOMPtr<nsIAtom> mNewMailReceivedAtom;
   nsresult ShowAlertMessage(const nsAString& aAlertTitle, const nsAString& aAlertText, const nsACString& aFolderURI);
   nsresult OnAlertFinished();
   nsresult OnAlertClicked(const PRUnichar * aAlertCookie);
+#ifdef MOZ_SUITE
+  nsresult OnAlertClickedSimple();
+#endif
   nsresult GetStringBundle(nsIStringBundle **aBundle);
   void FillToolTipInfo(nsIMsgFolder *aFolder, int32_t aNewCount);
   nsresult GetFirstFolderWithNewMail(nsIMsgFolder* aFolder, nsCString& aFolderURI);
   nsresult BadgeDockIcon();
   nsresult RestoreDockIcon();
   nsresult BounceDockIcon();
   nsresult GetNewMailAuthors(nsIMsgFolder* aFolder, nsString& aAuthors, int32_t aNewCount, int32_t* aNotDisplayed);
 
--- a/mailnews/base/src/nsMessengerOSXIntegration.mm
+++ b/mailnews/base/src/nsMessengerOSXIntegration.mm
@@ -211,16 +211,23 @@ NS_IMETHODIMP
 nsMessengerOSXIntegration::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aData)
 {
   if (!strcmp(aTopic, "alertfinished"))
     return OnAlertFinished();
 
   if (!strcmp(aTopic, "alertclickcallback"))
     return OnAlertClicked(aData);
 
+#ifdef MOZ_SUITE
+  // SeaMonkey does most of the GUI work in JS code when clicking on a mail
+  // notification, so it needs an extra function here 
+  if (!strcmp(aTopic, "alertclicksimplecallback"))
+    return OnAlertClickedSimple();
+#endif
+
   if (!strcmp(aTopic, "mail-startup-done")) {
     nsresult rv;
     nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1", &rv);
     if (NS_SUCCEEDED(rv)) {
       observerService->RemoveObserver(this, "mail-startup-done");
 
       bool chatEnabled = false;
       nsCOMPtr<nsIPrefBranch> pref(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
@@ -443,16 +450,27 @@ nsMessengerOSXIntegration::OnItemIntProp
 
 nsresult
 nsMessengerOSXIntegration::OnAlertClicked(const PRUnichar* aAlertCookie)
 {
   openMailWindow(NS_ConvertUTF16toUTF8(aAlertCookie));
   return NS_OK;
 }
 
+#ifdef MOZ_SUITE
+nsresult
+nsMessengerOSXIntegration::OnAlertClickedSimple()
+{
+  // SeaMonkey only function; only focus the app here, rest of the work will
+  // be done in suite/mailnews/mailWidgets.xml
+  FocusAppNative();
+  return NS_OK;
+}
+#endif
+
 nsresult
 nsMessengerOSXIntegration::OnAlertFinished()
 {
   return NS_OK;
 }
 
 nsresult
 nsMessengerOSXIntegration::BounceDockIcon()
--- a/mailnews/base/src/nsMessengerWinIntegration.cpp
+++ b/mailnews/base/src/nsMessengerWinIntegration.cpp
@@ -632,25 +632,40 @@ nsresult nsMessengerWinIntegration::Aler
   // make sure we don't insert the icon in the system tray since the user clicked on the alert.
   mSuppressBiffIcon = true;
   nsCString folderURI;
   GetFirstFolderWithNewMail(folderURI);
   openMailWindow(folderURI);
   return NS_OK;
 }
 
+#ifdef MOZ_SUITE
+nsresult nsMessengerWinIntegration::AlertClickedSimple()
+{
+  mSuppressBiffIcon = true;
+  return NS_OK;
+}
+#endif MOZ_SUITE
+
 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();
 
+#ifdef MOZ_SUITE
+  // SeaMonkey does most of the GUI work in JS code when clicking on a mail
+  // notification, so it needs an extra function here
+  if (strcmp(aTopic, "alertclicksimplecallback") == 0)
+      return AlertClickedSimple();
+#endif
+
   return NS_OK;
 }
 
 static void EscapeAmpersands(nsString& aToolTip)
 {
   // First, check to see whether we have any ampersands.
   int32_t pos = aToolTip.FindChar('&');
   if (pos == kNotFound)
--- a/mailnews/base/src/nsMessengerWinIntegration.h
+++ b/mailnews/base/src/nsMessengerWinIntegration.h
@@ -59,16 +59,19 @@ public:
   nsresult ShowNewAlertNotification(bool aUserInitiated, const nsString& aAlertTitle, const nsString& aAlertText);
 #ifndef MOZ_THUNDERBIRD
   nsresult ShowAlertMessage(const nsString& aAlertTitle, const nsString& aAlertText, const nsACString& aFolderURI);
 #endif
 
 private:
   nsresult AlertFinished();
   nsresult AlertClicked();
+#ifdef MOZ_SUITE
+  nsresult AlertClickedSimple();
+#endif
 
   void InitializeBiffStatusIcon(); 
   void FillToolTipInfo();
   void GenericShellNotify(DWORD aMessage);
   void DestroyBiffIcon();
 
   nsresult GetFirstFolderWithNewMail(nsACString& aFolderURI);
 
--- a/suite/mailnews/mailWidgets.xml
+++ b/suite/mailnews/mailWidgets.xml
@@ -2064,29 +2064,32 @@
                               getService(Components.interfaces.nsIMsgMailSession);
           var topmostMsgWindow;
           try {
            topmostMsgWindow = mailSession.topmostMsgWindow;
           } catch (ex) {}
 
           if (topmostMsgWindow)
           {
+            // Bring window to the front
+            topmostMsgWindow.domWindow.focus();
+
             try {
               // SelectFolder throws an exception if the folder is not in the current folder view
               mailSession.topmostMsgWindow.windowCommands.selectFolder(this.folderUri);
               mailSession.topmostMsgWindow.windowCommands.selectMessage(this.messageUri);
             } catch (ex) {}
           }
           else
           {
             // open a new window
             var mailWindowService = Components.classes["@mozilla.org/messenger/windowservice;1"].
                                       getService(Components.interfaces.nsIMessengerWindowService);
             mailWindowService.openMessengerWindowWithUri("mail:3pane", this.folderUri, this.msgKey);
           }
 
           if (gAlertListener)
-            gAlertListener.observe(null, "alertclickcallback", "");
+            gAlertListener.observe(null, "alertclicksimplecallback", "");
         ]]>
       </handler>
     </handlers>
   </binding>
 </bindings>