Bug 1662665 - Merge nsMessengerContentHandler.cpp into MessengerContentHandler.jsm. r=mkmelin

Based on Khushil's patch.

Differential Revision: https://phabricator.services.mozilla.com/D132911
This commit is contained in:
Ping Chen 2021-12-06 03:15:56 +00:00
Родитель e466388114
Коммит 20516fb5db
7 изменённых файлов: 58 добавлений и 132 удалений

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

@ -3,7 +3,11 @@
* 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/. */
var EXPORTED_SYMBOLS = ["MessengerContentHandler", "MidContentHandler"];
var EXPORTED_SYMBOLS = [
"MessengerContentHandler",
"MidContentHandler",
"MessageDisplayContentHandler",
];
var { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
@ -684,3 +688,48 @@ class MidContentHandler {
MailUtils.openMessageByMessageId(request.URI.spec.slice(4));
}
}
/**
* Open a message/rfc822 or eml file in a new msg window.
* @implements {nsIContentHandler}
*/
class MessageDisplayContentHandler {
QueryInterface = ChromeUtils.generateQI(["nsIContentHandler"]);
handleContent(contentType, windowContext, request) {
let channel = request.QueryInterface(Ci.nsIChannel);
if (!channel) {
throw Components.Exception(
"Expecting an nsIChannel",
Cr.NS_ERROR_ILLEGAL_VALUE
);
}
let uri = channel.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
);
}
}

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

@ -52,6 +52,14 @@ Classes = [
'jsm': 'resource:///modules/MessengerContentHandler.jsm',
'constructor': 'MidContentHandler',
},
{
'cid': '{048227f7-852a-473c-b9b5-7748684b57e2}',
'contract_ids': [
'@mozilla.org/uriloader/content-handler;1?type=application/x-message-display',
],
'jsm': 'resource:///modules/MessengerContentHandler.jsm',
'constructor': 'MessageDisplayContentHandler',
},
{
'cid': '{d512ddac-a2c1-11eb-bcbc-0242ac130002}',
'contract_ids': [

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

@ -461,19 +461,6 @@
} \
}
//
// 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
//

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

@ -41,7 +41,6 @@ SOURCES += [
"nsMailDirProvider.cpp",
"nsMessenger.cpp",
"nsMessengerBootstrap.cpp",
"nsMessengerContentHandler.cpp",
"nsMsgAccount.cpp",
"nsMsgAccountManager.cpp",
"nsMsgBiffManager.cpp",

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

@ -1,92 +0,0 @@
/* -*- 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<nsIURI> aUri;
nsCOMPtr<nsIChannel> 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<nsIMsgMailNewsUrl> 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<nsIWindowWatcher> wwatch =
do_GetService("@mozilla.org/embedcomp/window-watcher;1");
if (!wwatch) return NS_ERROR_FAILURE;
nsCOMPtr<mozIDOMWindowProxy> newWindow;
return wwatch->OpenWindow(
0, "chrome://messenger/content/messageWindow.xhtml"_ns, "_blank"_ns,
"all,chrome,dialog=no,status,toolbar"_ns, aURI,
getter_AddRefs(newWindow));
}

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

@ -1,19 +0,0 @@
/* -*- 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);
};

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

@ -90,7 +90,6 @@
#include "nsMailDirProvider.h"
#include "nsCURILoader.h"
#include "nsMessengerContentHandler.h"
#include "nsStopwatch.h"
#include "MailNewsDLF.h"
@ -307,7 +306,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgFolderNotificationService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCidProtocolHandler)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMailDirProvider)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgShutdownService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMessengerContentHandler)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMsgContentPolicy, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsStopwatch)
NS_GENERIC_FACTORY_CONSTRUCTOR(MailNewsDLF)
@ -348,7 +346,6 @@ NS_DEFINE_NAMED_CID(NS_CIDPROTOCOL_CID);
NS_DEFINE_NAMED_CID(NS_MSGTAGSERVICE_CID);
NS_DEFINE_NAMED_CID(NS_MSGFOLDERSERVICE_CID);
NS_DEFINE_NAMED_CID(NS_MSGNOTIFICATIONSERVICE_CID);
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);
@ -702,8 +699,6 @@ const mozilla::Module::CIDEntry kMailNewsCIDs[] = {
{&kNS_MSGFOLDERSERVICE_CID, false, NULL, nsMsgFolderServiceConstructor},
{&kNS_MSGNOTIFICATIONSERVICE_CID, false, NULL,
nsMsgFolderNotificationServiceConstructor},
{&kNS_MESSENGERCONTENTHANDLER_CID, false, NULL,
nsMessengerContentHandlerConstructor},
{&kNS_MSGCONTENTPOLICY_CID, false, NULL, nsMsgContentPolicyConstructor},
{&kNS_MSGSHUTDOWNSERVICE_CID, false, NULL, nsMsgShutdownServiceConstructor},
{&kMAILDIRPROVIDER_CID, false, NULL, nsMailDirProviderConstructor},
@ -891,7 +886,6 @@ const mozilla::Module::ContractIDEntry kMailNewsContracts[] = {
{NS_MSGTAGSERVICE_CONTRACTID, &kNS_MSGTAGSERVICE_CID},
{NS_MSGFOLDERSERVICE_CONTRACTID, &kNS_MSGFOLDERSERVICE_CID},
{NS_MSGNOTIFICATIONSERVICE_CONTRACTID, &kNS_MSGNOTIFICATIONSERVICE_CID},
{NS_MESSENGERCONTENTHANDLER_CONTRACTID, &kNS_MESSENGERCONTENTHANDLER_CID},
{NS_MSGCONTENTPOLICY_CONTRACTID, &kNS_MSGCONTENTPOLICY_CID},
{NS_MSGSHUTDOWNSERVICE_CONTRACTID, &kNS_MSGSHUTDOWNSERVICE_CID},
{NS_MAILDIRPROVIDER_CONTRACTID, &kMAILDIRPROVIDER_CID},