Bug 1555633 - New URI handling for JS Account based schemes. r=BenB

Creates a new interface for JS Account-based add-ons to implement.
Explicitly proxies calls to the main thread as necessary.
This commit is contained in:
Neil Rashbrook 2019-06-22 00:00:59 +02:00
Родитель 3ca5a8c100
Коммит ed38959ba0
3 изменённых файлов: 45 добавлений и 1 удалений

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

@ -45,6 +45,7 @@ XPIDL_SOURCES += [
'nsIMsgPluggableStore.idl',
'nsIMsgPrintEngine.idl',
'nsIMsgProgress.idl',
'nsIMsgProtocolHandler.idl',
'nsIMsgProtocolInfo.idl',
'nsIMsgPurgeService.idl',
'nsIMsgShutdown.idl',

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

@ -0,0 +1,13 @@
/* -*- Mode: IDL; tab-width: 4; 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 "nsISupports.idl"
interface nsIURI;
[scriptable, uuid(4e9e4a43-343a-4309-a88b-08c5f37f5965)]
interface nsIMsgProtocolHandler : nsISupports {
nsIURI newURI(in AUTF8String aSpec, in string aOriginCharset, in nsIURI aBaseURI);
};

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

@ -7,6 +7,11 @@
#include "nsURLHelper.h"
#include "nsSimpleURI.h"
#include "nsStandardURL.h"
#include "nsThreadUtils.h"
#include "MainThreadUtils.h"
#include "mozilla/SyncRunnable.h"
#include "nsIMsgProtocolHandler.h"
#include "nsIComponentRegistrar.h"
#include "../../local/src/nsPop3Service.h"
#include "../../local/src/nsMailboxService.h"
@ -85,7 +90,32 @@ nsresult NS_NewMailnewsURI(nsIURI** aURI, const nsACString& aSpec,
.Finalize(aURI);
}
// XXX TODO: What about JS Account?
nsCOMPtr<nsIComponentRegistrar> compMgr;
NS_GetComponentRegistrar(getter_AddRefs(compMgr));
if (compMgr) {
nsAutoCString contractID(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX);
contractID += scheme;
bool isRegistered = false;
compMgr->IsContractIDRegistered(contractID.get(), &isRegistered);
if (isRegistered) {
auto NewURI =
[&aSpec, &aCharset, &aBaseURI, aURI, &contractID, &rv ]() -> auto {
nsCOMPtr<nsIMsgProtocolHandler> handler(
do_GetService(contractID.get(), &rv));
if (handler) {
rv = handler->NewURI(aSpec, aCharset, aBaseURI, aURI);
}
};
if (NS_IsMainThread()) {
NewURI();
} else {
nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction("NewURI", NewURI);
mozilla::SyncRunnable::DispatchToThread(
mozilla::GetMainThreadEventTarget(), task);
}
return rv;
}
}
// None of the above, return an error and let M-C handle it.
return NS_ERROR_UNKNOWN_PROTOCOL;