From f579934db2bf79ffe8572a05afda4ba183198338 Mon Sep 17 00:00:00 2001 From: "scott%scott-macgregor.org" Date: Sat, 22 Jul 2006 01:20:09 +0000 Subject: [PATCH] Bug #345251 --> remove calls to getojbectproperty on a DOM Window as that API is going away. While I'm here, clean up and simplifying nsIMsgStatusFeedback, nsimsgWindow. Combine nsIMsgWindowCommands and nsIMsgPaneController into a single interface. sr=bienvenu --- mail/base/content/FilterListDialog.js | 2 +- mail/base/content/mailWindow.js | 40 ++---- mail/base/content/subscribe.js | 2 +- .../compose/content/MsgComposeCommands.js | 2 +- mail/extensions/newsblog/js/newsblog.js | 2 +- mailnews/base/public/nsIMsgStatusFeedback.idl | 13 +- mailnews/base/public/nsIMsgWindow.idl | 36 ++--- mailnews/base/resources/content/mailWindow.js | 38 ++---- .../base/resources/content/msgSynchronize.js | 2 +- mailnews/base/resources/content/subscribe.js | 2 +- .../search/resources/content/FilterEditor.js | 2 +- .../resources/content/FilterListDialog.js | 2 +- .../search/resources/content/SearchDialog.js | 2 +- mailnews/base/src/nsMessenger.cpp | 129 ++++++++---------- .../base/src/nsMessengerUnixIntegration.cpp | 27 ++-- .../base/src/nsMessengerWinIntegration.cpp | 30 ++-- mailnews/base/src/nsMsgDBView.cpp | 8 +- mailnews/base/src/nsMsgGroupView.cpp | 6 +- mailnews/base/src/nsMsgProgress.cpp | 9 +- mailnews/base/src/nsMsgStatusFeedback.cpp | 48 +++---- mailnews/base/src/nsMsgStatusFeedback.h | 5 +- mailnews/base/src/nsMsgWindow.cpp | 74 ++++------ mailnews/base/src/nsMsgWindow.h | 2 +- .../resources/content/MsgComposeCommands.js | 2 +- mailnews/imap/src/nsImapMailFolder.cpp | 5 +- mailnews/imap/src/nsImapService.cpp | 7 +- mailnews/local/src/nsLocalMailFolder.cpp | 12 +- 27 files changed, 200 insertions(+), 309 deletions(-) diff --git a/mail/base/content/FilterListDialog.js b/mail/base/content/FilterListDialog.js index 9e427acf9bb3..83158a77acff 100644 --- a/mail/base/content/FilterListDialog.js +++ b/mail/base/content/FilterListDialog.js @@ -110,7 +110,7 @@ function onLoad() { gFilterListMsgWindow = Components.classes["@mozilla.org/messenger/msgwindow;1"].createInstance(Components.interfaces.nsIMsgWindow); gFilterListMsgWindow.statusFeedback = gStatusFeedback; - gFilterListMsgWindow.SetDOMWindow(window); + gFilterListMsgWindow.domWindow = window; gFilterBundle = document.getElementById("bundle_filter"); gFilterTree = document.getElementById("filterTree"); diff --git a/mail/base/content/mailWindow.js b/mail/base/content/mailWindow.js index 16eceec3b54f..06609daeddd3 100644 --- a/mail/base/content/mailWindow.js +++ b/mail/base/content/mailWindow.js @@ -52,7 +52,6 @@ var messenger; var pref; var prefServices; var statusFeedback; -var messagePaneController; var msgWindow; var msgComposeService; @@ -157,8 +156,9 @@ function CreateMailWindowGlobals() .getInterface(Components.interfaces.nsIXULWindow) .XULBrowserWindow = window.MsgStatusFeedback; - statusFeedback = Components.classes[statusFeedbackContractID].createInstance(); + statusFeedback = Components.classes[statusFeedbackContractID].createInstance(); statusFeedback = statusFeedback.QueryInterface(Components.interfaces.nsIMsgStatusFeedback); + statusFeedback.setWrappedStatusFeedback(window.MsgStatusFeedback); /* not in use unless we want the lock button back @@ -183,8 +183,6 @@ function CreateMailWindowGlobals() } */ - window.MsgWindowCommands = new nsMsgWindowCommands(); - //Create message window object msgWindow = Components.classes[msgWindowContractID].createInstance(); msgWindow = msgWindow.QueryInterface(Components.interfaces.nsIMsgWindow); @@ -215,10 +213,10 @@ function CreateMailWindowGlobals() function InitMsgWindow() { - msgWindow.messagePaneController = new nsMessagePaneController(); + msgWindow.windowCommands = new nsMsgWindowCommands(); msgWindow.statusFeedback = statusFeedback; msgWindow.msgHeaderSink = messageHeaderSink; - msgWindow.SetDOMWindow(window); + msgWindow.domWindow = window; mailSession.AddMsgWindow(msgWindow); getBrowser().docShell.allowAuth = false; msgWindow.rootDocShell.allowAuth = true; @@ -321,6 +319,7 @@ nsMsgStatusFeedback.prototype = { if (iid.equals(Components.interfaces.nsIMsgStatusFeedback) || iid.equals(Components.interfaces.nsIXULBrowserWindow) || + iid.equals(Components.interfaces.nsISupportsWeakReference) || iid.equals(Components.interfaces.nsISupports)) return this; throw Components.results.NS_NOINTERFACE; @@ -436,10 +435,7 @@ nsMsgStatusFeedback.prototype = this.statusBar.value = percentage; this.statusBar.label = Math.round(percentage) + "%"; } - }, - closeWindow : function(percent) - { - } + } } @@ -456,29 +452,17 @@ nsMsgWindowCommands.prototype = return this; throw Components.results.NS_NOINTERFACE; }, - SelectFolder: function(folderUri) + + selectFolder: function(folderUri) { SelectFolder(folderUri); }, - SelectMessage: function(messageUri) + + selectMessage: function(messageUri) { SelectMessage(messageUri); - } -} - -function nsMessagePaneController() -{ -} - -nsMessagePaneController.prototype = -{ - QueryInterface : function(iid) - { - if (iid.equals(Components.interfaces.nsIMsgMessagePaneController) || - iid.equals(Components.interfaces.nsISupports)) - return this; - throw Components.results.NS_NOINTERFACE; }, + clearMsgPane: function() { if (gDBView) @@ -486,7 +470,7 @@ nsMessagePaneController.prototype = else setTitleFromFolder(null,null); ClearMessagePane(); - } + } } function StopUrls() diff --git a/mail/base/content/subscribe.js b/mail/base/content/subscribe.js index c2bfc69c5a5d..4478f8ee3873 100644 --- a/mail/base/content/subscribe.js +++ b/mail/base/content/subscribe.js @@ -184,7 +184,7 @@ function SubscribeOnLoad() msgWindow = Components.classes[msgWindowContractID].createInstance(Components.interfaces.nsIMsgWindow); msgWindow.statusFeedback = gStatusFeedback; - msgWindow.SetDOMWindow(window); + msgWindow.domWindow = window; msgWindow.rootDocShell.allowAuth = true; // look in arguments[0] for parameters diff --git a/mail/components/compose/content/MsgComposeCommands.js b/mail/components/compose/content/MsgComposeCommands.js index 823a5e442f3d..c8cf3dc3a9d1 100644 --- a/mail/components/compose/content/MsgComposeCommands.js +++ b/mail/components/compose/content/MsgComposeCommands.js @@ -1922,7 +1922,7 @@ function GenericSendMessage( msgType ) progress.registerListener(progressListener); gSendOrSaveOperationInProgress = true; } - msgWindow.SetDOMWindow(window); + msgWindow.domWindow = window; msgWindow.rootDocShell.allowAuth = true; gMsgCompose.SendMsg(msgType, getCurrentIdentity(), currentAccountKey, msgWindow, progress); } diff --git a/mail/extensions/newsblog/js/newsblog.js b/mail/extensions/newsblog/js/newsblog.js index 07edf4f2c364..126f25259ae0 100755 --- a/mail/extensions/newsblog/js/newsblog.js +++ b/mail/extensions/newsblog/js/newsblog.js @@ -468,7 +468,7 @@ var progressNotifier = { // Nice touch: select the folder that now contains the newly subscribed feed...this is particularly nice // if we just finished subscribing to a feed URL that the operating system gave us. - this.mMsgWindow.SelectFolder(feed.folder.URI); + this.mMsgWindow.windowCommands.selectFolder(feed.folder.URI); } else if (feed.folder) feed.folder.setMsgDatabase(null); diff --git a/mailnews/base/public/nsIMsgStatusFeedback.idl b/mailnews/base/public/nsIMsgStatusFeedback.idl index e65abc35cf45..d6fecebde4e3 100644 --- a/mailnews/base/public/nsIMsgStatusFeedback.idl +++ b/mailnews/base/public/nsIMsgStatusFeedback.idl @@ -37,18 +37,15 @@ #include "nsISupports.idl" -interface nsIDocShell; -interface nsIDOMWindow; - -[scriptable, uuid(a0032cf0-49e9-11d3-8d77-00805f8a6617)] +[scriptable, uuid(FD1321EC-C84E-4939-B26B-8CFC676C8333)] interface nsIMsgStatusFeedback : nsISupports { - void showStatusString(in wstring status); void startMeteors(); void stopMeteors(); void showProgress(in long percent); - void setStatusString(in wstring status); // will be displayed until next user action - [noscript] void setDocShell(in nsIDocShell shell, in nsIDOMWindow window); - void closeWindow(); + void setStatusString(in wstring status); // will be displayed until next user action + + /* aStatusFeedback: a wrapped JS status feedback object */ + void setWrappedStatusFeedback(in nsIMsgStatusFeedback aStatusFeedback); }; diff --git a/mailnews/base/public/nsIMsgWindow.idl b/mailnews/base/public/nsIMsgWindow.idl index 3987370df105..7ee882a41d30 100644 --- a/mailnews/base/public/nsIMsgWindow.idl +++ b/mailnews/base/public/nsIMsgWindow.idl @@ -46,25 +46,17 @@ interface nsIMsgHeaderSink; interface nsIPrompt; interface nsIAuthPrompt; -/* - * This interface can be used to set data specific to a window. - */ - -/* nsIMsgMessagePaneController is used to control the visiblity of the message pane - including the header overlay and the body. -*/ - -[scriptable, uuid(923DE63D-EEB9-4574-850B-322C1A4667ED)] -interface nsIMsgMessagePaneController : nsISupports { - void clearMsgPane(); +[scriptable, uuid(0A5C52F3-D1F3-4b6b-AE71-2B95C48BBC6B)] +interface nsIMsgWindowCommands : nsISupports { + void selectFolder(in string folderUri); + void selectMessage(in string messageUri); + void clearMsgPane(); }; - -[scriptable, uuid(BCE0AB71-11FF-428E-9EDC-69ABAD73b697)] +[scriptable, uuid(C4A53DDE-1502-40f1-8D00-71F636D545BE)] interface nsIMsgWindow : nsISupports { - - attribute nsIMsgMessagePaneController messagePaneController; attribute nsIMsgStatusFeedback statusFeedback; + attribute nsIMsgWindowCommands windowCommands; attribute nsIMsgHeaderSink msgHeaderSink; attribute nsITransactionManager transactionManager; attribute nsIMsgFolder openFolder; @@ -81,12 +73,11 @@ interface nsIMsgWindow : nsISupports { there's no convenient place to clear it. */ attribute boolean stopped; - - void SetDOMWindow(in nsIDOMWindowInternal window); + + attribute nsIDOMWindowInternal domWindow; + void StopUrls(); - void SelectFolder(in string folderUri); - void SelectMessage(in string messageUri); /* when the msg window is being unloaded from the content window, * we can use this notification to force a flush on anything the * msg window hangs on too. For some reason xpconnect is still hanging @@ -95,10 +86,3 @@ interface nsIMsgWindow : nsISupports { */ void closeWindow(); }; - -[scriptable, uuid(FAD93C80-1AC6-11d4-A8F6-006097222B83)] -interface nsIMsgWindowCommands : nsISupports { - - void SelectFolder(in string folderUri); - void SelectMessage(in string messageUri); -}; diff --git a/mailnews/base/resources/content/mailWindow.js b/mailnews/base/resources/content/mailWindow.js index 708ad069eb6a..2dff488c49a3 100644 --- a/mailnews/base/resources/content/mailWindow.js +++ b/mailnews/base/resources/content/mailWindow.js @@ -52,7 +52,6 @@ var messenger; var pref; var prefServices; var statusFeedback; -var messagePaneController; var msgWindow; var msgComposeService; @@ -122,8 +121,6 @@ function OnMailWindowUnload() msgDS = accountManagerDataSource.QueryInterface(Components.interfaces.nsIMsgRDFDataSource); msgDS.window = null; - - msgWindow.closeWindow(); } @@ -154,6 +151,7 @@ function CreateMailWindowGlobals() statusFeedback = Components.classes[statusFeedbackContractID].createInstance(); statusFeedback = statusFeedback.QueryInterface(Components.interfaces.nsIMsgStatusFeedback); + statusFeedback.setWrappedStatusFeedback(window.MsgStatusFeedback); /* not in use unless we want the lock button back @@ -207,10 +205,10 @@ function CreateMailWindowGlobals() function InitMsgWindow() { - msgWindow.messagePaneController = new nsMessagePaneController(); + msgWindow.windowCommands = new nsMsgWindowCommands(); msgWindow.statusFeedback = statusFeedback; msgWindow.msgHeaderSink = messageHeaderSink; - msgWindow.SetDOMWindow(window); + msgWindow.domWindow = window; mailSession.AddMsgWindow(msgWindow); var messagepane = document.getElementById("messagepane"); @@ -362,6 +360,7 @@ nsMsgStatusFeedback.prototype = { if (iid.equals(Components.interfaces.nsIMsgStatusFeedback) || iid.equals(Components.interfaces.nsIXULBrowserWindow) || + iid.equals(Components.interfaces.nsISupportsWeakReference) || iid.equals(Components.interfaces.nsISupports)) return this; throw Components.results.NS_NOINTERFACE; @@ -468,10 +467,7 @@ nsMsgStatusFeedback.prototype = this.statusBar.value = percentage; this.statusBar.label = Math.round(percentage) + "%"; } - }, - closeWindow : function(percent) - { - } + } } @@ -488,29 +484,17 @@ nsMsgWindowCommands.prototype = return this; throw Components.results.NS_NOINTERFACE; }, - SelectFolder: function(folderUri) + + selectFolder: function(folderUri) { SelectFolder(folderUri); }, - SelectMessage: function(messageUri) + + selectMessage: function(messageUri) { SelectMessage(messageUri); - } -} - -function nsMessagePaneController() -{ -} - -nsMessagePaneController.prototype = -{ - QueryInterface : function(iid) - { - if (iid.equals(Components.interfaces.nsIMsgMessagePaneController) || - iid.equals(Components.interfaces.nsISupports)) - return this; - throw Components.results.NS_NOINTERFACE; }, + clearMsgPane: function() { if (gDBView) @@ -518,7 +502,7 @@ nsMessagePaneController.prototype = else setTitleFromFolder(null,null); ClearMessagePane(); - } + } } function StopUrls() diff --git a/mailnews/base/resources/content/msgSynchronize.js b/mailnews/base/resources/content/msgSynchronize.js index 659f54a69814..909c8e28078b 100644 --- a/mailnews/base/resources/content/msgSynchronize.js +++ b/mailnews/base/resources/content/msgSynchronize.js @@ -125,7 +125,7 @@ function selectCancelButton() function selectOnLoad() { gMsgWindow = Components.classes[msgWindowContractID].createInstance(Components.interfaces.nsIMsgWindow); - gMsgWindow.SetDOMWindow(window); + gMsgWindow.domWindow = window; gAccountManager = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager); gSynchronizeTree = document.getElementById('synchronizeTree'); diff --git a/mailnews/base/resources/content/subscribe.js b/mailnews/base/resources/content/subscribe.js index bc4c1115c8ca..547bb625d32f 100644 --- a/mailnews/base/resources/content/subscribe.js +++ b/mailnews/base/resources/content/subscribe.js @@ -186,7 +186,7 @@ function SubscribeOnLoad() msgWindow = Components.classes[msgWindowContractID].createInstance(Components.interfaces.nsIMsgWindow); msgWindow.statusFeedback = gStatusFeedback; - msgWindow.SetDOMWindow(window); + msgWindow.domWindow = window; msgWindow.rootDocShell.allowAuth = true; // look in arguments[0] for parameters diff --git a/mailnews/base/search/resources/content/FilterEditor.js b/mailnews/base/search/resources/content/FilterEditor.js index e7e3d171f80d..d7152bcffa2f 100644 --- a/mailnews/base/search/resources/content/FilterEditor.js +++ b/mailnews/base/search/resources/content/FilterEditor.js @@ -408,7 +408,7 @@ function GetFilterEditorMsgWindow() var msgWindowContractID = "@mozilla.org/messenger/msgwindow;1"; var nsIMsgWindow = Components.interfaces.nsIMsgWindow; gFilterEditorMsgWindow = Components.classes[msgWindowContractID].createInstance(nsIMsgWindow); - gFilterEditorMsgWindow.SetDOMWindow(window); + gFilterEditorMsgWindow.domWindow = window; } return gFilterEditorMsgWindow; } diff --git a/mailnews/base/search/resources/content/FilterListDialog.js b/mailnews/base/search/resources/content/FilterListDialog.js index 81497706c1bf..3ffffdbe81b8 100644 --- a/mailnews/base/search/resources/content/FilterListDialog.js +++ b/mailnews/base/search/resources/content/FilterListDialog.js @@ -95,7 +95,7 @@ function onLoad() { gFilterListMsgWindow = Components.classes["@mozilla.org/messenger/msgwindow;1"].createInstance(Components.interfaces.nsIMsgWindow); gFilterListMsgWindow.statusFeedback = gStatusFeedback; - gFilterListMsgWindow.SetDOMWindow(window); + gFilterListMsgWindow.domWindow = window; gFilterBundle = document.getElementById("bundle_filter"); gFilterTree = document.getElementById("filterTree"); diff --git a/mailnews/base/search/resources/content/SearchDialog.js b/mailnews/base/search/resources/content/SearchDialog.js index 4f39e738f5b3..4635ff9bd9e7 100644 --- a/mailnews/base/search/resources/content/SearchDialog.js +++ b/mailnews/base/search/resources/content/SearchDialog.js @@ -318,7 +318,7 @@ function initializeSearchWindowWidgets() msgWindow = Components.classes[msgWindowContractID].createInstance(nsIMsgWindow); msgWindow.statusFeedback = gStatusFeedback; - msgWindow.SetDOMWindow(window); + msgWindow.domWindow = window; // functionality to enable/disable buttons using nsSearchResultsController // depending of whether items are selected in the search results thread pane. diff --git a/mailnews/base/src/nsMessenger.cpp b/mailnews/base/src/nsMessenger.cpp index 0aff917e7a21..01400b002820 100644 --- a/mailnews/base/src/nsMessenger.cpp +++ b/mailnews/base/src/nsMessenger.cpp @@ -107,8 +107,6 @@ #include "nsIMsgIncomingServer.h" #include "nsIMsgMessageService.h" - -#include "nsIMsgStatusFeedback.h" #include "nsMsgRDFUtils.h" #include "nsIMsgHdr.h" @@ -341,83 +339,63 @@ nsMessenger::~nsMessenger() NS_IMPL_ISUPPORTS3(nsMessenger, nsIMessenger, nsIObserver, nsISupportsWeakReference) NS_IMPL_GETSET(nsMessenger, SendingUnsentMsgs, PRBool, mSendingUnsentMsgs) -NS_IMETHODIMP -nsMessenger::SetWindow(nsIDOMWindowInternal *aWin, nsIMsgWindow *aMsgWindow) +NS_IMETHODIMP nsMessenger::SetWindow(nsIDOMWindowInternal *aWin, nsIMsgWindow *aMsgWindow) { - nsCOMPtr pbi = do_GetService(NS_PREFSERVICE_CONTRACTID); + nsresult rv; - if(!aWin) + nsCOMPtr pbi = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + if (aWin) + { + mMsgWindow = aMsgWindow; + mWindow = aWin; + + nsCOMPtr win( do_QueryInterface(aWin) ); + NS_ENSURE_TRUE(win, NS_ERROR_FAILURE); + + nsIDocShell *docShell = win->GetDocShell(); + nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); + NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE); + + nsCOMPtr rootDocShellAsItem; + docShellAsItem->GetSameTypeRootTreeItem(getter_AddRefs(rootDocShellAsItem)); + + nsCOMPtr rootDocShellAsNode(do_QueryInterface(rootDocShellAsItem)); + if (rootDocShellAsNode) + { + nsCOMPtr childAsItem; + rv = rootDocShellAsNode->FindChildWithName(NS_LITERAL_STRING("messagepane").get(), + PR_TRUE, PR_FALSE, nsnull, nsnull, getter_AddRefs(childAsItem)); + + mDocShell = do_QueryInterface(childAsItem); + if (NS_SUCCEEDED(rv) && mDocShell) { + mCurrentDisplayCharset = ""; // Important! Clear out mCurrentDisplayCharset so we reset a default charset on mDocshell the next time we try to load something into it. + + if (aMsgWindow) + { + aMsgWindow->GetTransactionManager(getter_AddRefs(mTxnMgr)); + // Add pref observer + pbi->AddObserver(MAILNEWS_ALLOW_PLUGINS_PREF_NAME, this, PR_TRUE); + SetDisplayProperties(); + } + } + } + + // we don't always have a message pane, like in the addressbook + // so if we don't have a docshell, use the one for the xul window. + // we do this so OpenURL() will work. + if (!mDocShell) + mDocShell = docShell; + } // if aWin + else { // it isn't an error to pass in null for aWin, in fact it means we are shutting // down and we should start cleaning things up... - - if (mMsgWindow) - { - nsCOMPtr aStatusFeedback; - - mMsgWindow->GetStatusFeedback(getter_AddRefs(aStatusFeedback)); - if (aStatusFeedback) - aStatusFeedback->SetDocShell(nsnull, nsnull); - - // Remove pref observer - if (pbi) - pbi->RemoveObserver(MAILNEWS_ALLOW_PLUGINS_PREF_NAME, this); - } - - return NS_OK; + // Remove pref observer + pbi->RemoveObserver(MAILNEWS_ALLOW_PLUGINS_PREF_NAME, this); } - mMsgWindow = aMsgWindow; - - mWindow = aWin; - - nsCOMPtr win( do_QueryInterface(aWin) ); - NS_ENSURE_TRUE(win, NS_ERROR_FAILURE); - - nsIDocShell *docShell = win->GetDocShell(); - nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); - NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE); - - nsCOMPtr rootDocShellAsItem; - docShellAsItem->GetSameTypeRootTreeItem(getter_AddRefs(rootDocShellAsItem)); - - nsCOMPtr rootDocShellAsNode(do_QueryInterface(rootDocShellAsItem)); - - if (rootDocShellAsNode) - { - nsCOMPtr childAsItem; - nsresult rv = rootDocShellAsNode->FindChildWithName(NS_LITERAL_STRING("messagepane").get(), - PR_TRUE, PR_FALSE, nsnull, nsnull, getter_AddRefs(childAsItem)); - - mDocShell = do_QueryInterface(childAsItem); - - if (NS_SUCCEEDED(rv) && mDocShell) { - mCurrentDisplayCharset = ""; // Important! Clear out mCurrentDisplayCharset so we reset a default charset on mDocshell the next time we try to load something into it. - - if (aMsgWindow) - { - nsCOMPtr aStatusFeedback; - - aMsgWindow->GetStatusFeedback(getter_AddRefs(aStatusFeedback)); - if (aStatusFeedback) - aStatusFeedback->SetDocShell(mDocShell, mWindow); - - aMsgWindow->GetTransactionManager(getter_AddRefs(mTxnMgr)); - - // Add pref observer - if (pbi) - pbi->AddObserver(MAILNEWS_ALLOW_PLUGINS_PREF_NAME, this, PR_TRUE); - SetDisplayProperties(); - } - } - } - - // we don't always have a message pane, like in the addressbook - // so if we don't havea docshell, use the one for the xul window. - // we do this so OpenURL() will work. - if (!mDocShell) - mDocShell = docShell; - return NS_OK; } @@ -2672,9 +2650,12 @@ void nsDelAttachListener::SelectNewMessage() if (displayUri.Equals(messageUri)) { mMessageFolder->GenerateMessageURI(mNewMessageKey, getter_Copies(displayUri)); - if (displayUri) + if (displayUri && mMsgWindow) { - mMsgWindow->SelectMessage(displayUri); + nsCOMPtr windowCommands; + mMsgWindow->GetWindowCommands(getter_AddRefs(windowCommands)); + if (windowCommands) + windowCommands->SelectMessage(displayUri); } } mNewMessageKey = PR_UINT32_MAX; diff --git a/mailnews/base/src/nsMessengerUnixIntegration.cpp b/mailnews/base/src/nsMessengerUnixIntegration.cpp index 4ffd9d7431b3..eed042bf33c8 100644 --- a/mailnews/base/src/nsMessengerUnixIntegration.cpp +++ b/mailnews/base/src/nsMessengerUnixIntegration.cpp @@ -81,27 +81,24 @@ static void openMailWindow(const PRUnichar * aMailWindowName, const char * aFolderUri) { - nsCOMPtr mediator ( do_GetService(NS_WINDOWMEDIATOR_CONTRACTID) ); - if (!mediator) + nsCOMPtr mailSession ( do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv)); + if (NS_FAILED(rv)) return; - nsCOMPtr domWindow; - mediator->GetMostRecentWindow(aMailWindowName, getter_AddRefs(domWindow)); - if (domWindow) + nsCOMPtr topMostMsgWindow; + rv = mailSession->GetTopmostMsgWindow(getter_AddRefs(topMostMsgWindow)); + if (topMostMsgWindow) { if (aFolderUri) { - nsCOMPtr piDOMWindow(do_QueryInterface(domWindow)); - if (piDOMWindow) - { - nsCOMPtr xpConnectObj; - piDOMWindow->GetObjectProperty(NS_LITERAL_STRING("MsgWindowCommands").get(), getter_AddRefs(xpConnectObj)); - nsCOMPtr msgWindowCommands = do_QueryInterface(xpConnectObj); - if (msgWindowCommands) - msgWindowCommands->SelectFolder(aFolderUri); - } + nsCOMPtr windowCommands; + topMostMsgWindow->GetWindowCommands(getter_AddRefs(windowCommands)); + if (windowCommands) + windowCommands->SelectFolder(aFolderUri); } - + + nsCOMPtr domWindow; + topMostMsgWindow->GetDomWindow(getter_AddRefs(domWindow)); domWindow->Focus(); } else diff --git a/mailnews/base/src/nsMessengerWinIntegration.cpp b/mailnews/base/src/nsMessengerWinIntegration.cpp index cf19abf5cc13..63d7a203a69b 100644 --- a/mailnews/base/src/nsMessengerWinIntegration.cpp +++ b/mailnews/base/src/nsMessengerWinIntegration.cpp @@ -141,28 +141,26 @@ static void activateWindow( nsIDOMWindowInternal *win ) static void openMailWindow(const PRUnichar * aMailWindowName, const char * aFolderUri) { - nsCOMPtr mediator ( do_GetService(NS_WINDOWMEDIATOR_CONTRACTID) ); - if (!mediator) + nsresult rv; + nsCOMPtr mailSession ( do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv)); + if (NS_FAILED(rv)) return; - nsCOMPtr domWindow; - mediator->GetMostRecentWindow(aMailWindowName, getter_AddRefs(domWindow)); - if (domWindow) + nsCOMPtr topMostMsgWindow; + rv = mailSession->GetTopmostMsgWindow(getter_AddRefs(topMostMsgWindow)); + if (topMostMsgWindow) { if (aFolderUri) { - nsCOMPtr piDOMWindow(do_QueryInterface(domWindow)); - if (piDOMWindow) - { - nsCOMPtr xpConnectObj; - piDOMWindow->GetObjectProperty(NS_LITERAL_STRING("MsgWindowCommands").get(), getter_AddRefs(xpConnectObj)); - nsCOMPtr msgWindowCommands = do_QueryInterface(xpConnectObj); - if (msgWindowCommands) - msgWindowCommands->SelectFolder(aFolderUri); - } + nsCOMPtr windowCommands; + topMostMsgWindow->GetWindowCommands(getter_AddRefs(windowCommands)); + if (windowCommands) + windowCommands->SelectFolder(aFolderUri); } - - activateWindow(domWindow); + nsCOMPtr domWindow; + topMostMsgWindow->GetDomWindow(getter_AddRefs(domWindow)); + if (domWindow) + activateWindow(domWindow); } else { diff --git a/mailnews/base/src/nsMsgDBView.cpp b/mailnews/base/src/nsMsgDBView.cpp index 0ae540e85785..ce7ade5af3be 100644 --- a/mailnews/base/src/nsMsgDBView.cpp +++ b/mailnews/base/src/nsMsgDBView.cpp @@ -1089,9 +1089,11 @@ NS_IMETHODIMP nsMsgDBView::SelectionChanged() m_currentlyDisplayedViewIndex = nsMsgViewIndex_None; // if we used to have one item selected, and now we have more than one, we should clear the message pane. - nsCOMPtr controller; - if ((mNumSelectedRows == 1) && (numSelected > 1) && mMsgWindow && NS_SUCCEEDED(mMsgWindow->GetMessagePaneController(getter_AddRefs(controller))) && controller) { - controller->ClearMsgPane(); + nsCOMPtr windowCommands; + if ((mNumSelectedRows == 1) && (numSelected > 1) && mMsgWindow + && NS_SUCCEEDED(mMsgWindow->GetWindowCommands(getter_AddRefs(windowCommands))) + && windowCommands) { + windowCommands->ClearMsgPane(); } } diff --git a/mailnews/base/src/nsMsgGroupView.cpp b/mailnews/base/src/nsMsgGroupView.cpp index d95fe7e5168b..7c46fadd2030 100755 --- a/mailnews/base/src/nsMsgGroupView.cpp +++ b/mailnews/base/src/nsMsgGroupView.cpp @@ -749,9 +749,9 @@ NS_IMETHODIMP nsMsgGroupView::LoadMessageByViewIndex(nsMsgViewIndex aViewIndex) if (m_flags[aViewIndex] & MSG_VIEW_FLAG_DUMMY) { // if we used to have one item selected, and now we have more than one, we should clear the message pane. - nsCOMPtr controller; - if (mMsgWindow && NS_SUCCEEDED(mMsgWindow->GetMessagePaneController(getter_AddRefs(controller))) && controller) - controller->ClearMsgPane(); + nsCOMPtr windowCommands; + if (mMsgWindow && NS_SUCCEEDED(mMsgWindow->GetWindowCommands(getter_AddRefs(windowCommands))) && windowCommands) + windowCommands->ClearMsgPane(); return NS_OK; } else diff --git a/mailnews/base/src/nsMsgProgress.cpp b/mailnews/base/src/nsMsgProgress.cpp index 494333e2b291..c81573c80fd6 100644 --- a/mailnews/base/src/nsMsgProgress.cpp +++ b/mailnews/base/src/nsMsgProgress.cpp @@ -345,14 +345,7 @@ NS_IMETHODIMP nsMsgProgress::ShowProgress(PRInt32 percent) return NS_ERROR_NOT_IMPLEMENTED; } -/* [noscript] void setDocShell (in nsIDocShell shell, in nsIDOMWindowInternal window); */ -NS_IMETHODIMP nsMsgProgress::SetDocShell(nsIDocShell *shell, nsIDOMWindow *window) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* void closeWindow (); */ -NS_IMETHODIMP nsMsgProgress::CloseWindow() +NS_IMETHODIMP nsMsgProgress::SetWrappedStatusFeedback(nsIMsgStatusFeedback * aJSStatusFeedback) { return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/mailnews/base/src/nsMsgStatusFeedback.cpp b/mailnews/base/src/nsMsgStatusFeedback.cpp index ce69c4031065..b49cbae4c038 100644 --- a/mailnews/base/src/nsMsgStatusFeedback.cpp +++ b/mailnews/base/src/nsMsgStatusFeedback.cpp @@ -40,8 +40,6 @@ #include "nsXPIDLString.h" #include "nsIWebProgress.h" -#include "nsIDOMWindowInternal.h" -#include "nsPIDOMWindow.h" #include "nsIXULBrowserWindow.h" #include "nsMsgStatusFeedback.h" #include "nsIDocumentViewer.h" @@ -232,15 +230,17 @@ nsMsgStatusFeedback::OnSecurityChange(nsIWebProgress *aWebProgress, NS_IMETHODIMP nsMsgStatusFeedback::ShowStatusString(const PRUnichar *status) { - if (mStatusFeedback) - mStatusFeedback->ShowStatusString(status); + nsCOMPtr jsStatusFeedback(do_QueryReferent(mJSStatusFeedbackWeak)); + if (jsStatusFeedback) + jsStatusFeedback->ShowStatusString(status); return NS_OK; } NS_IMETHODIMP nsMsgStatusFeedback::SetStatusString(const PRUnichar *status) { - nsCOMPtr xulBrowserWindow = do_QueryInterface(mStatusFeedback); + nsCOMPtr jsStatusFeedback(do_QueryReferent(mJSStatusFeedbackWeak)); + nsCOMPtr xulBrowserWindow = do_QueryInterface(jsStatusFeedback); if (xulBrowserWindow) xulBrowserWindow->SetJSDefaultStatus(nsDependentString(status)); return NS_OK; @@ -272,48 +272,34 @@ nsMsgStatusFeedback::ShowProgress(PRInt32 percentage) } m_lastProgressTime = nowMS; - - if (mStatusFeedback) - mStatusFeedback->ShowProgress(percentage); + nsCOMPtr jsStatusFeedback(do_QueryReferent(mJSStatusFeedbackWeak)); + if (jsStatusFeedback) + jsStatusFeedback->ShowProgress(percentage); return NS_OK; } NS_IMETHODIMP nsMsgStatusFeedback::StartMeteors() { - if (mStatusFeedback) - mStatusFeedback->StartMeteors(); + nsCOMPtr jsStatusFeedback(do_QueryReferent(mJSStatusFeedbackWeak)); + if (jsStatusFeedback) + jsStatusFeedback->StartMeteors(); return NS_OK; } NS_IMETHODIMP nsMsgStatusFeedback::StopMeteors() { - if (mStatusFeedback) - mStatusFeedback->StopMeteors(); + nsCOMPtr jsStatusFeedback(do_QueryReferent(mJSStatusFeedbackWeak)); + if (jsStatusFeedback) + jsStatusFeedback->StopMeteors(); return NS_OK; } -NS_IMETHODIMP nsMsgStatusFeedback::CloseWindow() +NS_IMETHODIMP nsMsgStatusFeedback::SetWrappedStatusFeedback(nsIMsgStatusFeedback * aJSStatusFeedback) { - mWindow = nsnull; - mStatusFeedback = nsnull; - - return NS_OK; -} - -NS_IMETHODIMP nsMsgStatusFeedback::SetDocShell(nsIDocShell *shell, nsIDOMWindow *aWindow) -{ - - nsCOMPtr piDOMWindow(do_QueryInterface(aWindow)); - if (piDOMWindow) - { - nsCOMPtr xpConnectObj; - piDOMWindow->GetObjectProperty(NS_LITERAL_STRING("MsgStatusFeedback").get(), getter_AddRefs(xpConnectObj)); - mStatusFeedback = do_QueryInterface(xpConnectObj); - } - - mWindow = aWindow; + NS_ENSURE_ARG_POINTER(aJSStatusFeedback); + mJSStatusFeedbackWeak = do_GetWeakReference(aJSStatusFeedback); return NS_OK; } diff --git a/mailnews/base/src/nsMsgStatusFeedback.h b/mailnews/base/src/nsMsgStatusFeedback.h index c00b99e4c637..26e3db371dbe 100644 --- a/mailnews/base/src/nsMsgStatusFeedback.h +++ b/mailnews/base/src/nsMsgStatusFeedback.h @@ -39,7 +39,6 @@ #define _nsMsgStatusFeedback_h #include "nsIWebProgressListener.h" -#include "nsIDOMWindowInternal.h" #include "nsIObserver.h" #include "nsITimer.h" #include "nsCOMPtr.h" @@ -64,18 +63,16 @@ public: NS_DECL_NSIPROGRESSEVENTSINK protected: - nsIDOMWindow *mWindow; PRBool m_meteorsSpinning; PRInt32 m_lastPercent; PRInt64 m_lastProgressTime; - void BeginObserving(); void EndObserving(); // the JS status feedback implementation object...eventually this object // will replace this very C++ class you are looking at. - nsCOMPtr mStatusFeedback; + nsWeakPtr mJSStatusFeedbackWeak; nsCOMPtr mBundle; nsCOMPtr m_msgLoadedAtom; diff --git a/mailnews/base/src/nsMsgWindow.cpp b/mailnews/base/src/nsMsgWindow.cpp index 28491641299e..1e2d9290fef7 100644 --- a/mailnews/base/src/nsMsgWindow.cpp +++ b/mailnews/base/src/nsMsgWindow.cpp @@ -135,19 +135,6 @@ void nsMsgWindow::GetMessageWindowDocShell(nsIDocShell ** aDocShell) NS_IF_ADDREF(*aDocShell); } -/* void SelectFolder (in string folderUri); */ -NS_IMETHODIMP nsMsgWindow::SelectFolder(const char *folderUri) -{ - return mMsgWindowCommands->SelectFolder(folderUri); -} - -/* void SelectMessage (in string messasgeUri); */ -NS_IMETHODIMP nsMsgWindow::SelectMessage(const char *messageUri) -{ - return (mMsgWindowCommands) ? mMsgWindowCommands->SelectMessage(messageUri) - : NS_ERROR_NULL_POINTER;; -} - NS_IMETHODIMP nsMsgWindow::CloseWindow() { nsresult rv = NS_OK; @@ -155,13 +142,8 @@ NS_IMETHODIMP nsMsgWindow::CloseWindow() if (NS_SUCCEEDED(rv)) rv = dispatcher->UnRegisterContentListener(this); - // make sure the status feedback object - // knows the window is going away... - - if (mStatusFeedback) - mStatusFeedback->CloseWindow(); - - mMsgPaneController = nsnull; + mMsgWindowCommands = nsnull; + mStatusFeedback = nsnull; StopUrls(); @@ -187,20 +169,18 @@ NS_IMETHODIMP nsMsgWindow::GetStatusFeedback(nsIMsgStatusFeedback * *aStatusFeed if(!aStatusFeedback) return NS_ERROR_NULL_POINTER; - *aStatusFeedback = mStatusFeedback; - NS_IF_ADDREF(*aStatusFeedback); + NS_IF_ADDREF(*aStatusFeedback = mStatusFeedback); return NS_OK; } NS_IMETHODIMP nsMsgWindow::SetStatusFeedback(nsIMsgStatusFeedback * aStatusFeedback) { + mStatusFeedback = aStatusFeedback; nsCOMPtr messageWindowDocShell; GetMessageWindowDocShell(getter_AddRefs(messageWindowDocShell)); + // register our status feedback object as a web progress listener nsCOMPtr webProgress(do_GetInterface(messageWindowDocShell)); - mStatusFeedback = aStatusFeedback; - - // register our status feedback object if (webProgress && mStatusFeedback && messageWindowDocShell) { nsCOMPtr webProgressListener = do_QueryInterface(mStatusFeedback); @@ -210,18 +190,16 @@ NS_IMETHODIMP nsMsgWindow::SetStatusFeedback(nsIMsgStatusFeedback * aStatusFeedb return NS_OK; } -NS_IMETHODIMP nsMsgWindow::GetMessagePaneController(nsIMsgMessagePaneController * * aMsgPaneController) +NS_IMETHODIMP nsMsgWindow::SetWindowCommands(nsIMsgWindowCommands * aMsgWindowCommands) { - NS_ENSURE_ARG(aMsgPaneController); - - *aMsgPaneController = mMsgPaneController; - NS_IF_ADDREF(*aMsgPaneController); + mMsgWindowCommands = aMsgWindowCommands; return NS_OK; } -NS_IMETHODIMP nsMsgWindow::SetMessagePaneController(nsIMsgMessagePaneController * aMsgPaneController) +NS_IMETHODIMP nsMsgWindow::GetWindowCommands(nsIMsgWindowCommands **aMsgWindowCommands) { - mMsgPaneController = aMsgPaneController; + NS_ENSURE_ARG_POINTER(aMsgWindowCommands); + NS_IF_ADDREF(*aMsgWindowCommands = mMsgWindowCommands); return NS_OK; } @@ -338,12 +316,20 @@ NS_IMETHODIMP nsMsgWindow::SetCharsetOverride(PRBool aCharsetOverride) return NS_OK; } -NS_IMETHODIMP nsMsgWindow::SetDOMWindow(nsIDOMWindowInternal *aWindow) +NS_IMETHODIMP nsMsgWindow::GetDomWindow(nsIDOMWindowInternal **aWindow) { - if (!aWindow) - return NS_ERROR_NULL_POINTER; + NS_ENSURE_ARG_POINTER(aWindow); + if (mDomWindow) + CallQueryReferent(mDomWindow.get(), aWindow); + else + *aWindow = nsnull; + return NS_OK; +} - nsresult rv = NS_OK; +NS_IMETHODIMP nsMsgWindow::SetDomWindow(nsIDOMWindowInternal * aWindow) +{ + NS_ENSURE_ARG_POINTER(aWindow); + mDomWindow = do_GetWeakReference(aWindow); nsCOMPtr win(do_QueryInterface(aWindow)); nsIDocShell *docShell = nsnull; @@ -363,19 +349,9 @@ NS_IMETHODIMP nsMsgWindow::SetDOMWindow(nsIDOMWindowInternal *aWindow) // force ourselves to figure out the message pane nsCOMPtr messageWindowDocShell; GetMessageWindowDocShell(getter_AddRefs(messageWindowDocShell)); - SetStatusFeedback(mStatusFeedback); } - //Get nsIMsgWindowCommands object - nsCOMPtr xpConnectObj; - nsCOMPtr piDOMWindow(do_QueryInterface(aWindow)); - if (piDOMWindow) - { - piDOMWindow->GetObjectProperty(NS_LITERAL_STRING("MsgWindowCommands").get(), getter_AddRefs(xpConnectObj)); - mMsgWindowCommands = do_QueryInterface(xpConnectObj); - } - - return rv; + return NS_OK; } NS_IMETHODIMP nsMsgWindow::StopUrls() @@ -505,8 +481,8 @@ nsMsgWindow::DisplayHTMLInMessagePane(const PRUnichar *title, const PRUnichar *b { nsresult rv; - if (clearMsgHdr && mMsgPaneController) - mMsgPaneController->ClearMsgPane(); + if (clearMsgHdr && mMsgWindowCommands) + mMsgWindowCommands->ClearMsgPane(); nsString htmlStr; htmlStr.Append(NS_LITERAL_STRING("").get()); diff --git a/mailnews/base/src/nsMsgWindow.h b/mailnews/base/src/nsMsgWindow.h index 8fa01d0c159c..82300969215c 100644 --- a/mailnews/base/src/nsMsgWindow.h +++ b/mailnews/base/src/nsMsgWindow.h @@ -67,7 +67,6 @@ public: protected: nsCOMPtr mMsgHeaderSink; nsCOMPtr mStatusFeedback; - nsCOMPtr mMsgPaneController; nsCOMPtr mTransactionManager; nsCOMPtr mOpenFolder; nsCOMPtr mMsgWindowCommands; @@ -75,6 +74,7 @@ protected: // let's not make this a strong ref - we don't own it. nsWeakPtr mRootDocShellWeak; nsWeakPtr mMessageWindowDocShellWeak; + nsWeakPtr mDomWindow; nsCString mMailCharacterSet; PRBool mCharsetOverride; diff --git a/mailnews/compose/resources/content/MsgComposeCommands.js b/mailnews/compose/resources/content/MsgComposeCommands.js index 5429a8fc6df1..a6313c40549b 100644 --- a/mailnews/compose/resources/content/MsgComposeCommands.js +++ b/mailnews/compose/resources/content/MsgComposeCommands.js @@ -1867,7 +1867,7 @@ function GenericSendMessage( msgType ) progress.registerListener(progressListener); gSendOrSaveOperationInProgress = true; } - msgWindow.SetDOMWindow(window); + msgWindow.domWindow = window; msgWindow.rootDocShell.allowAuth = true; gMsgCompose.SendMsg(msgType, getCurrentIdentity(), currentAccountKey, msgWindow, progress); } diff --git a/mailnews/imap/src/nsImapMailFolder.cpp b/mailnews/imap/src/nsImapMailFolder.cpp index e2e5dba43d30..aba0a56571b7 100644 --- a/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mailnews/imap/src/nsImapMailFolder.cpp @@ -5048,7 +5048,10 @@ nsImapMailFolder::OnStopRunningUrl(nsIURI *aUrl, nsresult aExitCode) if (msgFolder) { msgFolder->GetURI(getter_Copies(uri)); - msgWindow->SelectFolder(uri.get()); + nsCOMPtr windowCommands; + msgWindow->GetWindowCommands(getter_AddRefs(windowCommands)); + if (windowCommands) + windowCommands->SelectFolder(uri.get()); } } } diff --git a/mailnews/imap/src/nsImapService.cpp b/mailnews/imap/src/nsImapService.cpp index 5acaa0e28ae0..f4c9c13feeb6 100644 --- a/mailnews/imap/src/nsImapService.cpp +++ b/mailnews/imap/src/nsImapService.cpp @@ -2729,9 +2729,12 @@ NS_IMETHODIMP nsImapService::NewChannel(nsIURI *aURI, nsIChannel **_retval) { nsXPIDLCString uri; rootFolder->GetURI(getter_Copies(uri)); - uri.Append('/'); + uri.Append('/'); uri.Append(fullFolderName); - msgWindow->SelectFolder(uri.get()); + nsCOMPtr windowCommands; + msgWindow->GetWindowCommands(getter_AddRefs(windowCommands)); + if (windowCommands) + windowCommands->SelectFolder(uri.get()); // error out this channel, so it'll stop trying to run the url. *_retval = nsnull; rv = NS_ERROR_FAILURE; diff --git a/mailnews/local/src/nsLocalMailFolder.cpp b/mailnews/local/src/nsLocalMailFolder.cpp index e880e42d1819..216c46aed8dc 100644 --- a/mailnews/local/src/nsLocalMailFolder.cpp +++ b/mailnews/local/src/nsLocalMailFolder.cpp @@ -3133,7 +3133,10 @@ NS_IMETHODIMP nsMsgLocalMailFolder::SelectDownloadMsg() { nsCAutoString newuri; nsBuildLocalMessageURI(mBaseMessageURI, mDownloadSelectKey, newuri); - mDownloadWindow->SelectMessage(newuri.get()); + nsCOMPtr windowCommands; + mDownloadWindow->GetWindowCommands(getter_AddRefs(windowCommands)); + if (windowCommands) + windowCommands->SelectMessage(newuri.get()); mDownloadState = DOWNLOAD_STATE_DIDSEL; } return NS_OK; @@ -3327,9 +3330,12 @@ nsMsgLocalMailFolder::OnStopRunningUrl(nsIURI * aUrl, nsresult aExitCode) if (NS_SUCCEEDED(rv)) { pop3sink->GetMessageUri(getter_Copies(newMessageUri)); - if(msgWindow) + if (msgWindow) { - msgWindow->SelectMessage(newMessageUri); + nsCOMPtr windowCommands; + msgWindow->GetWindowCommands(getter_AddRefs(windowCommands)); + if (windowCommands) + windowCommands->SelectMessage(newMessageUri); } } }