From b9e48a04a76b7fdbd9ed033620362b26eadbe7b9 Mon Sep 17 00:00:00 2001 From: Geoff Lankow Date: Wed, 18 Nov 2020 14:23:28 +1300 Subject: [PATCH] Backed out changeset 8587f3e2dbbf (bug 1662665) for breaking tests. --HG-- extra : rebase_source : 6a54710b5597914738e13abd9c420d92b52bee67 extra : histedit_source : cc6f9da408f138ed3948a5a2783ab3b35e1f6b3a --- mail/components/MessengerContentHandler.jsm | 34 +------ .../compose/content/MsgComposeCommands.js | 36 +------- mailnews/base/public/nsMsgBaseCID.h | 13 +++ mailnews/base/src/moz.build | 1 + .../base/src/nsMessengerContentHandler.cpp | 92 +++++++++++++++++++ mailnews/base/src/nsMessengerContentHandler.h | 19 ++++ mailnews/build/nsMailModule.cpp | 6 ++ 7 files changed, 139 insertions(+), 62 deletions(-) create mode 100644 mailnews/base/src/nsMessengerContentHandler.cpp create mode 100644 mailnews/base/src/nsMessengerContentHandler.h diff --git a/mail/components/MessengerContentHandler.jsm b/mail/components/MessengerContentHandler.jsm index 63cf9dd73a..ed9c3cdf95 100644 --- a/mail/components/MessengerContentHandler.jsm +++ b/mail/components/MessengerContentHandler.jsm @@ -109,38 +109,12 @@ function openURI(uri) { loadgroup.groupObserver = loadlistener; - /** - * @implements {nsIURIContentListener} - */ var listener = { doContent(ctype, preferred, request, handler) { - let uri = request.URI; - let mailnewsurl = ""; - try { - mailnewsurl = uri.QueryInterface(Ci.nsIMsgMailNewsUrl); - } catch (e) {} - if (mailnewsurl) { - let queryPart = mailnewsurl.query.replace( - "type=message/rfc822", - "type=application/x-message-display" - ); - uri = mailnewsurl - .mutate() - .setQuery(queryPart) - .finalize(); - } else if (uri.scheme == "file") { - uri = uri - .mutate() - .setQuery("type=application/x-message-display") - .finalize(); - } - Services.ww.openWindow( - null, - "chrome://messenger/content/messageWindow.xhtml", - "_blank", - "all,chrome,dialog=no,status,toolbar", - uri - ); + var newHandler = Cc[ + "@mozilla.org/uriloader/content-handler;1?type=application/x-message-display" + ].createInstance(Ci.nsIContentHandler); + newHandler.handleContent("application/x-message-display", this, request); return true; }, isPreferred(ctype, desired) { diff --git a/mail/components/compose/content/MsgComposeCommands.js b/mail/components/compose/content/MsgComposeCommands.js index a7108b750b..b4ae254faf 100644 --- a/mail/components/compose/content/MsgComposeCommands.js +++ b/mail/components/compose/content/MsgComposeCommands.js @@ -6903,11 +6903,6 @@ function OpenSelectedAttachment() { } // if one attachment selected } -/** - * @implements {nsIURIContentListener} - * - * @see {MessengerContentHandler} - */ function nsAttachmentOpener() {} nsAttachmentOpener.prototype = { @@ -6924,33 +6919,10 @@ nsAttachmentOpener.prototype = { .setQuery(newQuery) .finalize(); } - let uri = request.URI; - let mailnewsurl = ""; - try { - mailnewsurl = uri.QueryInterface(Ci.nsIMsgMailNewsUrl); - } catch (e) {} - if (mailnewsurl) { - let queryPart = mailnewsurl.query.replace( - "type=message/rfc822", - "type=application/x-message-display" - ); - uri = mailnewsurl - .mutate() - .setQuery(queryPart) - .finalize(); - } else if (uri.scheme == "file") { - uri = uri - .mutate() - .setQuery("type=application/x-message-display") - .finalize(); - } - Services.ww.openWindow( - null, - "chrome://messenger/content/messageWindow.xhtml", - "_blank", - "all,chrome,dialog=no,status,toolbar", - uri - ); + let newHandler = Cc[ + "@mozilla.org/uriloader/content-handler;1?type=application/x-message-display" + ].createInstance(Ci.nsIContentHandler); + newHandler.handleContent("application/x-message-display", this, request); return true; }, diff --git a/mailnews/base/public/nsMsgBaseCID.h b/mailnews/base/public/nsMsgBaseCID.h index 56618ce472..e57ac71696 100644 --- a/mailnews/base/public/nsMsgBaseCID.h +++ b/mailnews/base/public/nsMsgBaseCID.h @@ -485,6 +485,19 @@ } \ } +// +// nsMessengerContentHandler +// +#define NS_MESSENGERCONTENTHANDLER_CID \ + { \ + 0x57e1bcbb, 0x1fba, 0x47e7, { \ + 0xb9, 0x6b, 0xf5, 0x9e, 0x39, 0x24, 0x73, 0xb0 \ + } \ + } + +#define NS_MESSENGERCONTENTHANDLER_CONTRACTID \ + NS_CONTENT_HANDLER_CONTRACTID_PREFIX "application/x-message-display" + // // nsMsgShutdownService // diff --git a/mailnews/base/src/moz.build b/mailnews/base/src/moz.build index fd33ee61e7..33c797b1d1 100644 --- a/mailnews/base/src/moz.build +++ b/mailnews/base/src/moz.build @@ -37,6 +37,7 @@ SOURCES += [ "nsMailDirProvider.cpp", "nsMessenger.cpp", "nsMessengerBootstrap.cpp", + "nsMessengerContentHandler.cpp", "nsMsgAccount.cpp", "nsMsgAccountManager.cpp", "nsMsgBiffManager.cpp", diff --git a/mailnews/base/src/nsMessengerContentHandler.cpp b/mailnews/base/src/nsMessengerContentHandler.cpp new file mode 100644 index 0000000000..4b0da42b78 --- /dev/null +++ b/mailnews/base/src/nsMessengerContentHandler.cpp @@ -0,0 +1,92 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsMessengerContentHandler.h" +#include "nsIChannel.h" +#include "nsPIDOMWindow.h" +#include "nsIServiceManager.h" +#include "nsIWindowWatcher.h" +#include "nsIDocShell.h" +#include "nsIWebNavigation.h" +#include "nsString.h" +#include "nsMsgBaseCID.h" +#include "plstr.h" +#include "nsIMsgMailNewsUrl.h" +#include "nsServiceManagerUtils.h" +#include "nsIURIMutator.h" + +nsMessengerContentHandler::nsMessengerContentHandler() {} + +/* the following macro actually implement addref, release and query interface + * for our component. */ +NS_IMPL_ISUPPORTS(nsMessengerContentHandler, nsIContentHandler) + +nsMessengerContentHandler::~nsMessengerContentHandler() {} + +NS_IMETHODIMP nsMessengerContentHandler::HandleContent( + const char* aContentType, nsIInterfaceRequestor* aWindowContext, + nsIRequest* request) { + nsresult rv = NS_OK; + if (!request) return NS_ERROR_NULL_POINTER; + + // First of all, get the content type and make sure it is a content type we + // know how to handle! + if (PL_strcasecmp(aContentType, "application/x-message-display") == 0) { + nsCOMPtr aUri; + nsCOMPtr aChannel = do_QueryInterface(request); + if (!aChannel) return NS_ERROR_FAILURE; + + rv = aChannel->GetURI(getter_AddRefs(aUri)); + if (aUri) { + rv = request->Cancel(NS_ERROR_ABORT); + if (NS_SUCCEEDED(rv)) { + nsCOMPtr mailnewsurl = do_QueryInterface(aUri); + if (mailnewsurl) { + nsAutoCString queryPart; + mailnewsurl->GetQuery(queryPart); + queryPart.Replace(queryPart.Find("type=message/rfc822"), + sizeof("type=message/rfc822") - 1, + "type=application/x-message-display"); + // Don't mutate/clone here. + rv = mailnewsurl->SetQueryInternal(queryPart); + NS_ENSURE_SUCCESS(rv, rv); + rv = OpenWindow(aUri); + } else { + // Not an nsIMsgMailNewsUrl, so maybe a file URL, like opening a + // message attachment (.eml file in a temp directory). + nsAutoCString scheme; + rv = aUri->GetScheme(scheme); + NS_ENSURE_SUCCESS(rv, rv); + if (scheme.Equals("file")) { + // Add a special bit like in MsgOpenFromFile(). + rv = NS_MutateURI(aUri) + .SetQuery("type=application/x-message-display"_ns) + .Finalize(aUri); + NS_ENSURE_SUCCESS(rv, rv); + } + rv = OpenWindow(aUri); + } + } + } + } + + return rv; +} + +// Utility function to open a message display window and and load the message in +// it. +nsresult nsMessengerContentHandler::OpenWindow(nsIURI* aURI) { + NS_ENSURE_ARG_POINTER(aURI); + + nsCOMPtr wwatch = + do_GetService("@mozilla.org/embedcomp/window-watcher;1"); + if (!wwatch) return NS_ERROR_FAILURE; + + nsCOMPtr newWindow; + return wwatch->OpenWindow( + 0, "chrome://messenger/content/messageWindow.xhtml"_ns, "_blank"_ns, + "all,chrome,dialog=no,status,toolbar"_ns, aURI, + getter_AddRefs(newWindow)); +} diff --git a/mailnews/base/src/nsMessengerContentHandler.h b/mailnews/base/src/nsMessengerContentHandler.h new file mode 100644 index 0000000000..8bf95b5230 --- /dev/null +++ b/mailnews/base/src/nsMessengerContentHandler.h @@ -0,0 +1,19 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsIContentHandler.h" +#include "nsIURI.h" + +class nsMessengerContentHandler : public nsIContentHandler { + public: + nsMessengerContentHandler(); + + NS_DECL_ISUPPORTS + NS_DECL_NSICONTENTHANDLER + + private: + virtual ~nsMessengerContentHandler(); + nsresult OpenWindow(nsIURI* aURI); +}; diff --git a/mailnews/build/nsMailModule.cpp b/mailnews/build/nsMailModule.cpp index 8d2bd49fa7..3dc68e8e6e 100644 --- a/mailnews/build/nsMailModule.cpp +++ b/mailnews/build/nsMailModule.cpp @@ -103,6 +103,7 @@ # include "nsMessengerUnixIntegration.h" #endif #include "nsCURILoader.h" +#include "nsMessengerContentHandler.h" #include "nsStopwatch.h" #include "MailNewsDLF.h" @@ -351,6 +352,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMessengerOSXIntegration, Init) #if defined(MOZ_WIDGET_GTK) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMessengerUnixIntegration, Init) #endif +NS_GENERIC_FACTORY_CONSTRUCTOR(nsMessengerContentHandler) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMsgContentPolicy, Init) NS_GENERIC_FACTORY_CONSTRUCTOR(nsStopwatch) NS_GENERIC_FACTORY_CONSTRUCTOR(MailNewsDLF) @@ -404,6 +406,7 @@ NS_DEFINE_NAMED_CID(NS_MESSENGEROSXINTEGRATION_CID); #if defined(MOZ_WIDGET_GTK) NS_DEFINE_NAMED_CID(NS_MESSENGERUNIXINTEGRATION_CID); #endif +NS_DEFINE_NAMED_CID(NS_MESSENGERCONTENTHANDLER_CID); NS_DEFINE_NAMED_CID(NS_MSGCONTENTPOLICY_CID); NS_DEFINE_NAMED_CID(NS_MSGSHUTDOWNSERVICE_CID); NS_DEFINE_NAMED_CID(MAILDIRPROVIDER_CID); @@ -808,6 +811,8 @@ const mozilla::Module::CIDEntry kMailNewsCIDs[] = { {&kNS_MESSENGERUNIXINTEGRATION_CID, false, NULL, nsMessengerUnixIntegrationConstructor}, #endif + {&kNS_MESSENGERCONTENTHANDLER_CID, false, NULL, + nsMessengerContentHandlerConstructor}, {&kNS_MSGCONTENTPOLICY_CID, false, NULL, nsMsgContentPolicyConstructor}, {&kNS_MSGSHUTDOWNSERVICE_CID, false, NULL, nsMsgShutdownServiceConstructor}, {&kMAILDIRPROVIDER_CID, false, NULL, nsMailDirProviderConstructor}, @@ -1032,6 +1037,7 @@ const mozilla::Module::ContractIDEntry kMailNewsContracts[] = { #if defined(MOZ_WIDGET_GTK) {NS_MESSENGEROSINTEGRATION_CONTRACTID, &kNS_MESSENGERUNIXINTEGRATION_CID}, #endif + {NS_MESSENGERCONTENTHANDLER_CONTRACTID, &kNS_MESSENGERCONTENTHANDLER_CID}, {NS_MSGCONTENTPOLICY_CONTRACTID, &kNS_MSGCONTENTPOLICY_CID}, {NS_MSGSHUTDOWNSERVICE_CONTRACTID, &kNS_MSGSHUTDOWNSERVICE_CID}, {NS_MAILDIRPROVIDER_CONTRACTID, &kMAILDIRPROVIDER_CID},