зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1366511: Part 3 - Add mozilla::ToResult() to convert other result types to equivalent Result. r=nbp,ehsan
Also adds a mozilla/ResultExtensions.h header to define the appropriate conversion functions for nsresult and PRResult. This is in a separate header since those types are not available in Spidermonkey, and this is the pattern other *Extensions.h headers follow. Also removes equivalent NS_TRY macros and WrapNSResult inlines that served the same purpose in existing code, and are no longer necessary. MozReview-Commit-ID: A85PCAeyWhx --HG-- extra : rebase_source : a5988ff770888f901dd0798e7717bcf6254460cd
This commit is contained in:
Родитель
c9899cb3fa
Коммит
6bad4f8ef7
|
@ -45,7 +45,7 @@ AutoMemMap::init(nsIFile* file, int flags, int mode, PRFileMapProtect prot)
|
|||
{
|
||||
MOZ_ASSERT(!fd);
|
||||
|
||||
NS_TRY(file->OpenNSPRFileDesc(flags, mode, &fd.rwget()));
|
||||
MOZ_TRY(file->OpenNSPRFileDesc(flags, mode, &fd.rwget()));
|
||||
|
||||
return initInternal(prot);
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ AutoMemMap::initInternal(PRFileMapProtect prot)
|
|||
MOZ_ASSERT(!addr);
|
||||
|
||||
PRFileInfo64 fileInfo;
|
||||
NS_TRY(PR_GetOpenFileInfo64(fd.get(), &fileInfo));
|
||||
MOZ_TRY(PR_GetOpenFileInfo64(fd.get(), &fileInfo));
|
||||
|
||||
if (fileInfo.size > UINT32_MAX)
|
||||
return Err(NS_ERROR_INVALID_ARG);
|
||||
|
|
|
@ -30,26 +30,6 @@ struct MOZ_RAII AutoSafeJSAPI : public AutoJSAPI
|
|||
AutoSafeJSAPI() { Init(); }
|
||||
};
|
||||
|
||||
static inline Result<Ok, nsresult>
|
||||
WrapNSResult(PRStatus aRv)
|
||||
{
|
||||
if (aRv != PR_SUCCESS) {
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
static inline Result<Ok, nsresult>
|
||||
WrapNSResult(nsresult aRv)
|
||||
{
|
||||
if (NS_FAILED(aRv)) {
|
||||
return Err(aRv);
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
#define NS_TRY(expr) MOZ_TRY(WrapNSResult(expr))
|
||||
|
||||
|
||||
class OutputBuffer
|
||||
{
|
||||
|
|
|
@ -362,12 +362,12 @@ Result<nsCOMPtr<nsIFile>, nsresult>
|
|||
ScriptPreloader::GetCacheFile(const nsAString& suffix)
|
||||
{
|
||||
nsCOMPtr<nsIFile> cacheFile;
|
||||
NS_TRY(mProfD->Clone(getter_AddRefs(cacheFile)));
|
||||
MOZ_TRY(mProfD->Clone(getter_AddRefs(cacheFile)));
|
||||
|
||||
NS_TRY(cacheFile->AppendNative(NS_LITERAL_CSTRING("startupCache")));
|
||||
MOZ_TRY(cacheFile->AppendNative(NS_LITERAL_CSTRING("startupCache")));
|
||||
Unused << cacheFile->Create(nsIFile::DIRECTORY_TYPE, 0777);
|
||||
|
||||
NS_TRY(cacheFile->Append(mBaseName + suffix));
|
||||
MOZ_TRY(cacheFile->Append(mBaseName + suffix));
|
||||
|
||||
return Move(cacheFile);
|
||||
}
|
||||
|
@ -377,18 +377,18 @@ static const uint8_t MAGIC[] = "mozXDRcachev001";
|
|||
Result<Ok, nsresult>
|
||||
ScriptPreloader::OpenCache()
|
||||
{
|
||||
NS_TRY(NS_GetSpecialDirectory("ProfLDS", getter_AddRefs(mProfD)));
|
||||
MOZ_TRY(NS_GetSpecialDirectory("ProfLDS", getter_AddRefs(mProfD)));
|
||||
|
||||
nsCOMPtr<nsIFile> cacheFile;
|
||||
MOZ_TRY_VAR(cacheFile, GetCacheFile(NS_LITERAL_STRING(".bin")));
|
||||
|
||||
bool exists;
|
||||
NS_TRY(cacheFile->Exists(&exists));
|
||||
MOZ_TRY(cacheFile->Exists(&exists));
|
||||
if (exists) {
|
||||
NS_TRY(cacheFile->MoveTo(nullptr, mBaseName + NS_LITERAL_STRING("-current.bin")));
|
||||
MOZ_TRY(cacheFile->MoveTo(nullptr, mBaseName + NS_LITERAL_STRING("-current.bin")));
|
||||
} else {
|
||||
NS_TRY(cacheFile->SetLeafName(mBaseName + NS_LITERAL_STRING("-current.bin")));
|
||||
NS_TRY(cacheFile->Exists(&exists));
|
||||
MOZ_TRY(cacheFile->SetLeafName(mBaseName + NS_LITERAL_STRING("-current.bin")));
|
||||
MOZ_TRY(cacheFile->Exists(&exists));
|
||||
if (!exists) {
|
||||
return Err(NS_ERROR_FILE_NOT_FOUND);
|
||||
}
|
||||
|
@ -627,14 +627,14 @@ ScriptPreloader::WriteCache()
|
|||
MOZ_TRY_VAR(cacheFile, GetCacheFile(NS_LITERAL_STRING("-new.bin")));
|
||||
|
||||
bool exists;
|
||||
NS_TRY(cacheFile->Exists(&exists));
|
||||
MOZ_TRY(cacheFile->Exists(&exists));
|
||||
if (exists) {
|
||||
NS_TRY(cacheFile->Remove(false));
|
||||
MOZ_TRY(cacheFile->Remove(false));
|
||||
}
|
||||
|
||||
{
|
||||
AutoFDClose fd;
|
||||
NS_TRY(cacheFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE, 0644, &fd.rwget()));
|
||||
MOZ_TRY(cacheFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE, 0644, &fd.rwget()));
|
||||
|
||||
// We also need to hold mMonitor while we're touching scripts in
|
||||
// mScripts, or they may be freed before we're done with them.
|
||||
|
@ -675,7 +675,7 @@ ScriptPreloader::WriteCache()
|
|||
}
|
||||
}
|
||||
|
||||
NS_TRY(cacheFile->MoveTo(nullptr, mBaseName + NS_LITERAL_STRING(".bin")));
|
||||
MOZ_TRY(cacheFile->MoveTo(nullptr, mBaseName + NS_LITERAL_STRING(".bin")));
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
|
|
@ -260,6 +260,14 @@ struct IsResult<Result<V, E>> : TrueType { };
|
|||
|
||||
} // namespace detail
|
||||
|
||||
template <typename V, typename E>
|
||||
auto
|
||||
ToResult(Result<V, E>&& aValue)
|
||||
-> decltype(Forward<Result<V, E>>(aValue))
|
||||
{
|
||||
return Forward<Result<V, E>>(aValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Result<V, E> represents the outcome of an operation that can either succeed
|
||||
* or fail. It contains either a success value of type V or an error value of
|
||||
|
@ -442,7 +450,7 @@ Err(E&& aErrorValue)
|
|||
*/
|
||||
#define MOZ_TRY(expr) \
|
||||
do { \
|
||||
auto mozTryTempResult_ = (expr); \
|
||||
auto mozTryTempResult_ = ::mozilla::ToResult(expr); \
|
||||
if (mozTryTempResult_.isErr()) { \
|
||||
return ::mozilla::Err(mozTryTempResult_.unwrapErr()); \
|
||||
} \
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "nscore.h"
|
||||
#include "prtypes.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
|
@ -32,6 +33,33 @@ public:
|
|||
operator nsresult() { return mErrorValue; }
|
||||
};
|
||||
|
||||
// Allow MOZ_TRY to handle `PRStatus` values.
|
||||
inline Result<Ok, nsresult> ToResult(PRStatus aValue);
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#include "mozilla/Result.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
inline Result<Ok, nsresult>
|
||||
ToResult(nsresult aValue)
|
||||
{
|
||||
if (NS_FAILED(aValue)) {
|
||||
return Err(aValue);
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
inline Result<Ok, nsresult>
|
||||
ToResult(PRStatus aValue)
|
||||
{
|
||||
if (aValue == PR_SUCCESS) {
|
||||
return Ok();
|
||||
}
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_ResultExtensions_h
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "mozilla/ipc/URIUtils.h"
|
||||
#include "mozilla/net/NeckoChild.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/ResultExtensions.h"
|
||||
|
||||
#include "FileDescriptor.h"
|
||||
#include "FileDescriptorFile.h"
|
||||
|
@ -62,26 +63,6 @@ LazyLogModule gExtProtocolLog("ExtProtocol");
|
|||
|
||||
StaticRefPtr<ExtensionProtocolHandler> ExtensionProtocolHandler::sSingleton;
|
||||
|
||||
static inline Result<Ok, nsresult>
|
||||
WrapNSResult(PRStatus aRv)
|
||||
{
|
||||
if (aRv != PR_SUCCESS) {
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
static inline Result<Ok, nsresult>
|
||||
WrapNSResult(nsresult aRv)
|
||||
{
|
||||
if (NS_FAILED(aRv)) {
|
||||
return Err(aRv);
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
#define NS_TRY(expr) MOZ_TRY(WrapNSResult(expr))
|
||||
|
||||
/**
|
||||
* Helper class used with SimpleChannel to asynchronously obtain an input
|
||||
* stream or file descriptor from the parent for a remote moz-extension load
|
||||
|
@ -449,21 +430,21 @@ ExtensionProtocolHandler::SubstituteRemoteChannel(nsIURI* aURI,
|
|||
nsIChannel** aRetVal)
|
||||
{
|
||||
MOZ_ASSERT(IsNeckoChild());
|
||||
NS_TRY(aURI ? NS_OK : NS_ERROR_INVALID_ARG);
|
||||
NS_TRY(aLoadInfo ? NS_OK : NS_ERROR_INVALID_ARG);
|
||||
MOZ_TRY(aURI ? NS_OK : NS_ERROR_INVALID_ARG);
|
||||
MOZ_TRY(aLoadInfo ? NS_OK : NS_ERROR_INVALID_ARG);
|
||||
|
||||
nsAutoCString unResolvedSpec;
|
||||
NS_TRY(aURI->GetSpec(unResolvedSpec));
|
||||
MOZ_TRY(aURI->GetSpec(unResolvedSpec));
|
||||
|
||||
nsAutoCString resolvedSpec;
|
||||
NS_TRY(ResolveURI(aURI, resolvedSpec));
|
||||
MOZ_TRY(ResolveURI(aURI, resolvedSpec));
|
||||
|
||||
// Use the target URI scheme to determine if this is a packed or unpacked
|
||||
// extension URI. For unpacked extensions, we'll request an input stream
|
||||
// from the parent. For a packed extension, we'll request a file descriptor
|
||||
// for the JAR file.
|
||||
nsAutoCString scheme;
|
||||
NS_TRY(net_ExtractURLScheme(resolvedSpec, scheme));
|
||||
MOZ_TRY(net_ExtractURLScheme(resolvedSpec, scheme));
|
||||
|
||||
if (scheme.EqualsLiteral("file")) {
|
||||
// Unpacked extension
|
||||
|
@ -511,21 +492,21 @@ ExtensionProtocolHandler::SubstituteChannel(nsIURI* aURI,
|
|||
nsresult rv;
|
||||
nsCOMPtr<nsIStreamConverterService> convService =
|
||||
do_GetService(NS_STREAMCONVERTERSERVICE_CONTRACTID, &rv);
|
||||
NS_TRY(rv);
|
||||
MOZ_TRY(rv);
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_TRY(channel->GetURI(getter_AddRefs(uri)));
|
||||
MOZ_TRY(channel->GetURI(getter_AddRefs(uri)));
|
||||
|
||||
const char* kFromType = "application/vnd.mozilla.webext.unlocalized";
|
||||
const char* kToType = "text/css";
|
||||
|
||||
nsCOMPtr<nsIStreamListener> converter;
|
||||
NS_TRY(convService->AsyncConvertData(kFromType, kToType, listener,
|
||||
MOZ_TRY(convService->AsyncConvertData(kFromType, kToType, listener,
|
||||
uri, getter_AddRefs(converter)));
|
||||
if (haveLoadInfo) {
|
||||
NS_TRY(origChannel->AsyncOpen2(converter));
|
||||
MOZ_TRY(origChannel->AsyncOpen2(converter));
|
||||
} else {
|
||||
NS_TRY(origChannel->AsyncOpen(converter, nullptr));
|
||||
MOZ_TRY(origChannel->AsyncOpen(converter, nullptr));
|
||||
}
|
||||
|
||||
return RequestOrReason(origChannel);
|
||||
|
@ -596,7 +577,7 @@ ExtensionProtocolHandler::DevRepoContains(nsIFile* aRequestedFile,
|
|||
// On the first invocation, set mDevRepo
|
||||
if (!mAlreadyCheckedDevRepo) {
|
||||
mAlreadyCheckedDevRepo = true;
|
||||
NS_TRY(mozilla::GetRepoDir(getter_AddRefs(mDevRepo)));
|
||||
MOZ_TRY(mozilla::GetRepoDir(getter_AddRefs(mDevRepo)));
|
||||
if (MOZ_LOG_TEST(gExtProtocolLog, LogLevel::Debug)) {
|
||||
nsAutoCString repoPath;
|
||||
Unused << mDevRepo->GetNativePath(repoPath);
|
||||
|
@ -605,7 +586,7 @@ ExtensionProtocolHandler::DevRepoContains(nsIFile* aRequestedFile,
|
|||
}
|
||||
|
||||
if (mDevRepo) {
|
||||
NS_TRY(mDevRepo->Contains(aRequestedFile, aResult));
|
||||
MOZ_TRY(mDevRepo->Contains(aRequestedFile, aResult));
|
||||
}
|
||||
|
||||
return Ok();
|
||||
|
@ -625,7 +606,7 @@ ExtensionProtocolHandler::AppDirContains(nsIFile* aExtensionDir,
|
|||
// On the first invocation, set mAppDir
|
||||
if (!mAlreadyCheckedAppDir) {
|
||||
mAlreadyCheckedAppDir = true;
|
||||
NS_TRY(NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(mAppDir)));
|
||||
MOZ_TRY(NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(mAppDir)));
|
||||
if (MOZ_LOG_TEST(gExtProtocolLog, LogLevel::Debug)) {
|
||||
nsAutoCString appDirPath;
|
||||
Unused << mAppDir->GetNativePath(appDirPath);
|
||||
|
@ -634,7 +615,7 @@ ExtensionProtocolHandler::AppDirContains(nsIFile* aExtensionDir,
|
|||
}
|
||||
|
||||
if (mAppDir) {
|
||||
NS_TRY(mAppDir->Contains(aExtensionDir, aResult));
|
||||
MOZ_TRY(mAppDir->Contains(aExtensionDir, aResult));
|
||||
}
|
||||
|
||||
return Ok();
|
||||
|
@ -660,8 +641,8 @@ Result<nsCOMPtr<nsIInputStream>, nsresult>
|
|||
ExtensionProtocolHandler::NewStream(nsIURI* aChildURI, bool* aTerminateSender)
|
||||
{
|
||||
MOZ_ASSERT(!IsNeckoChild());
|
||||
NS_TRY(aChildURI ? NS_OK : NS_ERROR_INVALID_ARG);
|
||||
NS_TRY(aTerminateSender ? NS_OK : NS_ERROR_INVALID_ARG);
|
||||
MOZ_TRY(aChildURI ? NS_OK : NS_ERROR_INVALID_ARG);
|
||||
MOZ_TRY(aTerminateSender ? NS_OK : NS_ERROR_INVALID_ARG);
|
||||
|
||||
*aTerminateSender = true;
|
||||
nsresult rv;
|
||||
|
@ -688,21 +669,21 @@ ExtensionProtocolHandler::NewStream(nsIURI* aChildURI, bool* aTerminateSender)
|
|||
*/
|
||||
|
||||
nsAutoCString host;
|
||||
NS_TRY(aChildURI->GetAsciiHost(host));
|
||||
MOZ_TRY(aChildURI->GetAsciiHost(host));
|
||||
|
||||
// Lookup the directory this host string resolves to
|
||||
nsCOMPtr<nsIURI> baseURI;
|
||||
NS_TRY(GetSubstitution(host, getter_AddRefs(baseURI)));
|
||||
MOZ_TRY(GetSubstitution(host, getter_AddRefs(baseURI)));
|
||||
|
||||
// The result should be a file URL for the extension base dir
|
||||
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(baseURI, &rv);
|
||||
NS_TRY(rv);
|
||||
MOZ_TRY(rv);
|
||||
|
||||
nsCOMPtr<nsIFile> extensionDir;
|
||||
NS_TRY(fileURL->GetFile(getter_AddRefs(extensionDir)));
|
||||
MOZ_TRY(fileURL->GetFile(getter_AddRefs(extensionDir)));
|
||||
|
||||
bool isDirectory = false;
|
||||
NS_TRY(extensionDir->IsDirectory(&isDirectory));
|
||||
MOZ_TRY(extensionDir->IsDirectory(&isDirectory));
|
||||
if (!isDirectory) {
|
||||
// The host should map to a directory for unpacked extensions
|
||||
return Err(NS_ERROR_FILE_NOT_DIRECTORY);
|
||||
|
@ -713,38 +694,38 @@ ExtensionProtocolHandler::NewStream(nsIURI* aChildURI, bool* aTerminateSender)
|
|||
// file channel because we only request remote streams for unpacked
|
||||
// extension resource loads where the URI resolves to a file.
|
||||
nsAutoCString resolvedSpec;
|
||||
NS_TRY(ResolveURI(aChildURI, resolvedSpec));
|
||||
MOZ_TRY(ResolveURI(aChildURI, resolvedSpec));
|
||||
|
||||
nsAutoCString resolvedScheme;
|
||||
NS_TRY(net_ExtractURLScheme(resolvedSpec, resolvedScheme));
|
||||
MOZ_TRY(net_ExtractURLScheme(resolvedSpec, resolvedScheme));
|
||||
if (!resolvedScheme.EqualsLiteral("file")) {
|
||||
return Err(NS_ERROR_UNEXPECTED);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
|
||||
NS_TRY(rv);
|
||||
MOZ_TRY(rv);
|
||||
|
||||
nsCOMPtr<nsIURI> resolvedURI;
|
||||
NS_TRY(ioService->NewURI(resolvedSpec,
|
||||
nullptr,
|
||||
nullptr,
|
||||
getter_AddRefs(resolvedURI)));
|
||||
MOZ_TRY(ioService->NewURI(resolvedSpec,
|
||||
nullptr,
|
||||
nullptr,
|
||||
getter_AddRefs(resolvedURI)));
|
||||
|
||||
// We use the system principal to get a file channel for the request,
|
||||
// but only after we've checked (above) that the child URI is of
|
||||
// moz-extension scheme and that the URI host maps to a directory.
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
NS_TRY(NS_NewChannel(getter_AddRefs(channel),
|
||||
resolvedURI,
|
||||
nsContentUtils::GetSystemPrincipal(),
|
||||
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
|
||||
nsIContentPolicy::TYPE_OTHER));
|
||||
MOZ_TRY(NS_NewChannel(getter_AddRefs(channel),
|
||||
resolvedURI,
|
||||
nsContentUtils::GetSystemPrincipal(),
|
||||
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
|
||||
nsIContentPolicy::TYPE_OTHER));
|
||||
|
||||
nsCOMPtr<nsIFileChannel> fileChannel = do_QueryInterface(channel, &rv);
|
||||
NS_TRY(rv);
|
||||
MOZ_TRY(rv);
|
||||
|
||||
nsCOMPtr<nsIFile> requestedFile;
|
||||
NS_TRY(fileChannel->GetFile(getter_AddRefs(requestedFile)));
|
||||
MOZ_TRY(fileChannel->GetFile(getter_AddRefs(requestedFile)));
|
||||
|
||||
/*
|
||||
* Make sure the file we resolved to is within the extension directory.
|
||||
|
@ -752,8 +733,8 @@ ExtensionProtocolHandler::NewStream(nsIURI* aChildURI, bool* aTerminateSender)
|
|||
|
||||
// Normalize paths for sane comparisons. nsIFile::Contains depends on
|
||||
// it for reliable subpath checks.
|
||||
NS_TRY(extensionDir->Normalize());
|
||||
NS_TRY(requestedFile->Normalize());
|
||||
MOZ_TRY(extensionDir->Normalize());
|
||||
MOZ_TRY(requestedFile->Normalize());
|
||||
#if defined(XP_WIN)
|
||||
if (!widget::WinUtils::ResolveJunctionPointsAndSymLinks(extensionDir) ||
|
||||
!widget::WinUtils::ResolveJunctionPointsAndSymLinks(requestedFile)) {
|
||||
|
@ -762,7 +743,7 @@ ExtensionProtocolHandler::NewStream(nsIURI* aChildURI, bool* aTerminateSender)
|
|||
#endif
|
||||
|
||||
bool isResourceFromExtensionDir = false;
|
||||
NS_TRY(extensionDir->Contains(requestedFile, &isResourceFromExtensionDir));
|
||||
MOZ_TRY(extensionDir->Contains(requestedFile, &isResourceFromExtensionDir));
|
||||
if (!isResourceFromExtensionDir) {
|
||||
bool isAllowed = false;
|
||||
MOZ_TRY(AllowExternalResource(extensionDir, requestedFile, &isAllowed));
|
||||
|
@ -773,11 +754,11 @@ ExtensionProtocolHandler::NewStream(nsIURI* aChildURI, bool* aTerminateSender)
|
|||
}
|
||||
|
||||
nsCOMPtr<nsIInputStream> inputStream;
|
||||
NS_TRY(NS_NewLocalFileInputStream(getter_AddRefs(inputStream),
|
||||
requestedFile,
|
||||
PR_RDONLY,
|
||||
-1,
|
||||
nsIFileInputStream::DEFER_OPEN));
|
||||
MOZ_TRY(NS_NewLocalFileInputStream(getter_AddRefs(inputStream),
|
||||
requestedFile,
|
||||
PR_RDONLY,
|
||||
-1,
|
||||
nsIFileInputStream::DEFER_OPEN));
|
||||
|
||||
return inputStream;
|
||||
}
|
||||
|
@ -788,8 +769,8 @@ ExtensionProtocolHandler::NewFD(nsIURI* aChildURI,
|
|||
NeckoParent::GetExtensionFDResolver& aResolve)
|
||||
{
|
||||
MOZ_ASSERT(!IsNeckoChild());
|
||||
NS_TRY(aChildURI ? NS_OK : NS_ERROR_INVALID_ARG);
|
||||
NS_TRY(aTerminateSender ? NS_OK : NS_ERROR_INVALID_ARG);
|
||||
MOZ_TRY(aChildURI ? NS_OK : NS_ERROR_INVALID_ARG);
|
||||
MOZ_TRY(aTerminateSender ? NS_OK : NS_ERROR_INVALID_ARG);
|
||||
|
||||
*aTerminateSender = true;
|
||||
nsresult rv;
|
||||
|
@ -806,24 +787,24 @@ ExtensionProtocolHandler::NewFD(nsIURI* aChildURI,
|
|||
*aTerminateSender = false;
|
||||
|
||||
nsAutoCString host;
|
||||
NS_TRY(aChildURI->GetAsciiHost(host));
|
||||
MOZ_TRY(aChildURI->GetAsciiHost(host));
|
||||
|
||||
// We expect the host string to map to a JAR file because the URI
|
||||
// should refer to a web accessible resource for an enabled extension.
|
||||
nsCOMPtr<nsIURI> subURI;
|
||||
NS_TRY(GetSubstitution(host, getter_AddRefs(subURI)));
|
||||
MOZ_TRY(GetSubstitution(host, getter_AddRefs(subURI)));
|
||||
|
||||
nsCOMPtr<nsIJARURI> jarURI = do_QueryInterface(subURI, &rv);
|
||||
NS_TRY(rv);
|
||||
MOZ_TRY(rv);
|
||||
|
||||
nsCOMPtr<nsIURI> innerFileURI;
|
||||
NS_TRY(jarURI->GetJARFile(getter_AddRefs(innerFileURI)));
|
||||
MOZ_TRY(jarURI->GetJARFile(getter_AddRefs(innerFileURI)));
|
||||
|
||||
nsCOMPtr<nsIFileURL> innerFileURL = do_QueryInterface(innerFileURI, &rv);
|
||||
NS_TRY(rv);
|
||||
MOZ_TRY(rv);
|
||||
|
||||
nsCOMPtr<nsIFile> jarFile;
|
||||
NS_TRY(innerFileURL->GetFile(getter_AddRefs(jarFile)));
|
||||
MOZ_TRY(innerFileURL->GetFile(getter_AddRefs(jarFile)));
|
||||
|
||||
if (!mFileOpenerThread) {
|
||||
mFileOpenerThread =
|
||||
|
@ -838,7 +819,7 @@ ExtensionProtocolHandler::NewFD(nsIURI* aChildURI,
|
|||
mozilla::NewRunnableMethod("ExtensionJarFileOpener",
|
||||
fileOpener, &ExtensionJARFileOpener::OpenFile);
|
||||
|
||||
NS_TRY(mFileOpenerThread->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL));
|
||||
MOZ_TRY(mFileOpenerThread->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL));
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
@ -892,13 +873,13 @@ LogCacheCheck(const nsIJARChannel* aJarChannel,
|
|||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIURI> innerFileURI;
|
||||
NS_TRY(aJarURI->GetJARFile(getter_AddRefs(innerFileURI)));
|
||||
MOZ_TRY(aJarURI->GetJARFile(getter_AddRefs(innerFileURI)));
|
||||
|
||||
nsCOMPtr<nsIFileURL> innerFileURL = do_QueryInterface(innerFileURI, &rv);
|
||||
NS_TRY(rv);
|
||||
MOZ_TRY(rv);
|
||||
|
||||
nsCOMPtr<nsIFile> jarFile;
|
||||
NS_TRY(innerFileURL->GetFile(getter_AddRefs(jarFile)));
|
||||
MOZ_TRY(innerFileURL->GetFile(getter_AddRefs(jarFile)));
|
||||
|
||||
nsAutoCString uriSpec, jarSpec;
|
||||
Unused << aJarURI->GetSpec(uriSpec);
|
||||
|
@ -921,16 +902,16 @@ ExtensionProtocolHandler::SubstituteRemoteJarChannel(nsIURI* aURI,
|
|||
// Build a JAR URI for this jar:file:// URI and use it to extract the
|
||||
// inner file URI.
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_TRY(NS_NewURI(getter_AddRefs(uri), aResolvedSpec));
|
||||
MOZ_TRY(NS_NewURI(getter_AddRefs(uri), aResolvedSpec));
|
||||
|
||||
nsCOMPtr<nsIJARURI> jarURI = do_QueryInterface(uri, &rv);
|
||||
NS_TRY(rv);
|
||||
MOZ_TRY(rv);
|
||||
|
||||
nsCOMPtr<nsIJARChannel> jarChannel = do_QueryInterface(*aRetVal, &rv);
|
||||
NS_TRY(rv);
|
||||
MOZ_TRY(rv);
|
||||
|
||||
bool isCached = false;
|
||||
NS_TRY(jarChannel->EnsureCached(&isCached));
|
||||
MOZ_TRY(jarChannel->EnsureCached(&isCached));
|
||||
if (MOZ_LOG_TEST(gExtProtocolLog, LogLevel::Debug)) {
|
||||
Unused << LogCacheCheck(jarChannel, jarURI, isCached);
|
||||
}
|
||||
|
@ -941,13 +922,13 @@ ExtensionProtocolHandler::SubstituteRemoteJarChannel(nsIURI* aURI,
|
|||
streamGetter = new ExtensionStreamGetter(jarChannel.forget());
|
||||
} else {
|
||||
nsCOMPtr<nsIURI> innerFileURI;
|
||||
NS_TRY(jarURI->GetJARFile(getter_AddRefs(innerFileURI)));
|
||||
MOZ_TRY(jarURI->GetJARFile(getter_AddRefs(innerFileURI)));
|
||||
|
||||
nsCOMPtr<nsIFileURL> innerFileURL = do_QueryInterface(innerFileURI, &rv);
|
||||
NS_TRY(rv);
|
||||
MOZ_TRY(rv);
|
||||
|
||||
nsCOMPtr<nsIFile> jarFile;
|
||||
NS_TRY(innerFileURL->GetFile(getter_AddRefs(jarFile)));
|
||||
MOZ_TRY(innerFileURL->GetFile(getter_AddRefs(jarFile)));
|
||||
|
||||
streamGetter = new ExtensionStreamGetter(aURI,
|
||||
aLoadinfo,
|
||||
|
@ -959,7 +940,5 @@ ExtensionProtocolHandler::SubstituteRemoteJarChannel(nsIURI* aURI,
|
|||
return Ok();
|
||||
}
|
||||
|
||||
#undef NS_TRY
|
||||
|
||||
} // namespace net
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -74,7 +74,7 @@ TEST_F(BTSerializationTest, FailsDecodingInclusionProofUnexpectedData)
|
|||
Reader encodedProofReader(encodedProofInput);
|
||||
InclusionProofDataV2 ipr;
|
||||
|
||||
ASSERT_EQ(Result::ERROR_BAD_DER, DecodeInclusionProof(encodedProofReader, ipr));
|
||||
ASSERT_EQ(pkix::Result::ERROR_BAD_DER, DecodeInclusionProof(encodedProofReader, ipr));
|
||||
}
|
||||
|
||||
TEST_F(BTSerializationTest, FailsDecodingInvalidHashSize)
|
||||
|
@ -83,7 +83,7 @@ TEST_F(BTSerializationTest, FailsDecodingInvalidHashSize)
|
|||
Reader encodedProofReader(encodedProofInput);
|
||||
InclusionProofDataV2 ipr;
|
||||
|
||||
ASSERT_EQ(Result::ERROR_BAD_DER, DecodeInclusionProof(encodedProofReader, ipr));
|
||||
ASSERT_EQ(pkix::Result::ERROR_BAD_DER, DecodeInclusionProof(encodedProofReader, ipr));
|
||||
}
|
||||
|
||||
TEST_F(BTSerializationTest, FailsDecodingInvalidHash)
|
||||
|
@ -92,7 +92,7 @@ TEST_F(BTSerializationTest, FailsDecodingInvalidHash)
|
|||
Reader encodedProofReader(encodedProofInput);
|
||||
InclusionProofDataV2 ipr;
|
||||
|
||||
ASSERT_EQ(Result::ERROR_BAD_DER, DecodeInclusionProof(encodedProofReader, ipr));
|
||||
ASSERT_EQ(pkix::Result::ERROR_BAD_DER, DecodeInclusionProof(encodedProofReader, ipr));
|
||||
}
|
||||
|
||||
TEST_F(BTSerializationTest, FailsDecodingMissingLogId)
|
||||
|
@ -101,7 +101,7 @@ TEST_F(BTSerializationTest, FailsDecodingMissingLogId)
|
|||
Reader encodedProofReader(encodedProofInput);
|
||||
InclusionProofDataV2 ipr;
|
||||
|
||||
ASSERT_EQ(Result::ERROR_BAD_DER, DecodeInclusionProof(encodedProofReader, ipr));
|
||||
ASSERT_EQ(pkix::Result::ERROR_BAD_DER, DecodeInclusionProof(encodedProofReader, ipr));
|
||||
}
|
||||
|
||||
TEST_F(BTSerializationTest, FailsDecodingNullPathLength)
|
||||
|
@ -110,7 +110,7 @@ TEST_F(BTSerializationTest, FailsDecodingNullPathLength)
|
|||
Reader encodedProofReader(encodedProofInput);
|
||||
InclusionProofDataV2 ipr;
|
||||
|
||||
ASSERT_EQ(Result::ERROR_BAD_DER, DecodeInclusionProof(encodedProofReader, ipr));
|
||||
ASSERT_EQ(pkix::Result::ERROR_BAD_DER, DecodeInclusionProof(encodedProofReader, ipr));
|
||||
}
|
||||
|
||||
TEST_F(BTSerializationTest, FailsDecodingPathLengthTooSmall)
|
||||
|
@ -119,7 +119,7 @@ TEST_F(BTSerializationTest, FailsDecodingPathLengthTooSmall)
|
|||
Reader encodedProofReader(encodedProofInput);
|
||||
InclusionProofDataV2 ipr;
|
||||
|
||||
ASSERT_EQ(Result::ERROR_BAD_DER, DecodeInclusionProof(encodedProofReader, ipr));
|
||||
ASSERT_EQ(pkix::Result::ERROR_BAD_DER, DecodeInclusionProof(encodedProofReader, ipr));
|
||||
}
|
||||
|
||||
TEST_F(BTSerializationTest, FailsDecodingPathLengthTooLarge)
|
||||
|
@ -128,7 +128,7 @@ TEST_F(BTSerializationTest, FailsDecodingPathLengthTooLarge)
|
|||
Reader encodedProofReader(encodedProofInput);
|
||||
InclusionProofDataV2 ipr;
|
||||
|
||||
ASSERT_EQ(Result::ERROR_BAD_DER, DecodeInclusionProof(encodedProofReader, ipr));
|
||||
ASSERT_EQ(pkix::Result::ERROR_BAD_DER, DecodeInclusionProof(encodedProofReader, ipr));
|
||||
}
|
||||
|
||||
TEST_F(BTSerializationTest, FailsDecodingNullTreeSize)
|
||||
|
@ -137,7 +137,7 @@ TEST_F(BTSerializationTest, FailsDecodingNullTreeSize)
|
|||
Reader encodedProofReader(encodedProofInput);
|
||||
InclusionProofDataV2 ipr;
|
||||
|
||||
ASSERT_EQ(Result::ERROR_BAD_DER, DecodeInclusionProof(encodedProofReader, ipr));
|
||||
ASSERT_EQ(pkix::Result::ERROR_BAD_DER, DecodeInclusionProof(encodedProofReader, ipr));
|
||||
}
|
||||
|
||||
TEST_F(BTSerializationTest, FailsDecodingLeafIndexOutOfBounds)
|
||||
|
@ -146,7 +146,7 @@ TEST_F(BTSerializationTest, FailsDecodingLeafIndexOutOfBounds)
|
|||
Reader encodedProofReader(encodedProofInput);
|
||||
InclusionProofDataV2 ipr;
|
||||
|
||||
ASSERT_EQ(Result::ERROR_BAD_DER, DecodeInclusionProof(encodedProofReader, ipr));
|
||||
ASSERT_EQ(pkix::Result::ERROR_BAD_DER, DecodeInclusionProof(encodedProofReader, ipr));
|
||||
}
|
||||
|
||||
TEST_F(BTSerializationTest, FailsDecodingExtraData)
|
||||
|
@ -155,6 +155,6 @@ TEST_F(BTSerializationTest, FailsDecodingExtraData)
|
|||
Reader encodedProofReader(encodedProofInput);
|
||||
InclusionProofDataV2 ipr;
|
||||
|
||||
ASSERT_EQ(Result::ERROR_BAD_DER, DecodeInclusionProof(encodedProofReader, ipr));
|
||||
ASSERT_EQ(pkix::Result::ERROR_BAD_DER, DecodeInclusionProof(encodedProofReader, ipr));
|
||||
}
|
||||
} } // namespace mozilla::ct
|
||||
|
|
|
@ -229,14 +229,14 @@ TEST_F(CTSerializationTest, FailsDecodingInvalidSignedCertificateTimestamp)
|
|||
const uint8_t INVALID_VERSION_BYTES[] = { 0x02, 0x00 };
|
||||
Input invalidVersionSctInput(INVALID_VERSION_BYTES);
|
||||
Reader invalidVersionSctReader(invalidVersionSctInput);
|
||||
EXPECT_EQ(Result::ERROR_BAD_DER,
|
||||
EXPECT_EQ(pkix::Result::ERROR_BAD_DER,
|
||||
DecodeSignedCertificateTimestamp(invalidVersionSctReader, sct));
|
||||
|
||||
// Valid version, invalid length (missing data)
|
||||
const uint8_t INVALID_LENGTH_BYTES[] = { 0x00, 0x0a, 0x0b, 0x0c };
|
||||
Input invalidLengthSctInput(INVALID_LENGTH_BYTES);
|
||||
Reader invalidLengthSctReader(invalidLengthSctInput);
|
||||
EXPECT_EQ(Result::ERROR_BAD_DER,
|
||||
EXPECT_EQ(pkix::Result::ERROR_BAD_DER,
|
||||
DecodeSignedCertificateTimestamp(invalidLengthSctReader, sct));
|
||||
}
|
||||
|
||||
|
|
|
@ -754,83 +754,83 @@ ExtractEmbeddedSCTList(const Buffer& cert, Buffer& result)
|
|||
class OCSPExtensionTrustDomain : public TrustDomain
|
||||
{
|
||||
public:
|
||||
Result GetCertTrust(EndEntityOrCA, const CertPolicyId&,
|
||||
Input, TrustLevel&) override
|
||||
pkix::Result GetCertTrust(EndEntityOrCA, const CertPolicyId&,
|
||||
Input, TrustLevel&) override
|
||||
{
|
||||
ADD_FAILURE();
|
||||
return Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
return pkix::Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
}
|
||||
|
||||
Result FindIssuer(Input, IssuerChecker&, Time) override
|
||||
pkix::Result FindIssuer(Input, IssuerChecker&, Time) override
|
||||
{
|
||||
ADD_FAILURE();
|
||||
return Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
return pkix::Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
}
|
||||
|
||||
Result CheckRevocation(EndEntityOrCA, const CertID&, Time, Duration,
|
||||
const Input*, const Input*) override
|
||||
pkix::Result CheckRevocation(EndEntityOrCA, const CertID&, Time, Duration,
|
||||
const Input*, const Input*) override
|
||||
{
|
||||
ADD_FAILURE();
|
||||
return Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
return pkix::Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
}
|
||||
|
||||
Result IsChainValid(const DERArray&, Time, const CertPolicyId&) override
|
||||
pkix::Result IsChainValid(const DERArray&, Time, const CertPolicyId&) override
|
||||
{
|
||||
ADD_FAILURE();
|
||||
return Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
return pkix::Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
}
|
||||
|
||||
Result DigestBuf(Input item, DigestAlgorithm digestAlg,
|
||||
/*out*/ uint8_t* digestBuf, size_t digestBufLen) override
|
||||
pkix::Result DigestBuf(Input item, DigestAlgorithm digestAlg,
|
||||
/*out*/ uint8_t* digestBuf, size_t digestBufLen) override
|
||||
{
|
||||
return DigestBufNSS(item, digestAlg, digestBuf, digestBufLen);
|
||||
}
|
||||
|
||||
Result CheckSignatureDigestAlgorithm(DigestAlgorithm, EndEntityOrCA, Time)
|
||||
pkix::Result CheckSignatureDigestAlgorithm(DigestAlgorithm, EndEntityOrCA, Time)
|
||||
override
|
||||
{
|
||||
ADD_FAILURE();
|
||||
return Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
return pkix::Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
}
|
||||
|
||||
Result CheckECDSACurveIsAcceptable(EndEntityOrCA, NamedCurve) override
|
||||
pkix::Result CheckECDSACurveIsAcceptable(EndEntityOrCA, NamedCurve) override
|
||||
{
|
||||
ADD_FAILURE();
|
||||
return Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
return pkix::Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
}
|
||||
|
||||
Result VerifyECDSASignedDigest(const SignedDigest& signedDigest,
|
||||
Input subjectPublicKeyInfo) override
|
||||
pkix::Result VerifyECDSASignedDigest(const SignedDigest& signedDigest,
|
||||
Input subjectPublicKeyInfo) override
|
||||
{
|
||||
return VerifyECDSASignedDigestNSS(signedDigest, subjectPublicKeyInfo,
|
||||
nullptr);
|
||||
}
|
||||
|
||||
Result CheckRSAPublicKeyModulusSizeInBits(EndEntityOrCA, unsigned int)
|
||||
pkix::Result CheckRSAPublicKeyModulusSizeInBits(EndEntityOrCA, unsigned int)
|
||||
override
|
||||
{
|
||||
ADD_FAILURE();
|
||||
return Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
return pkix::Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
}
|
||||
|
||||
Result VerifyRSAPKCS1SignedDigest(const SignedDigest& signedDigest,
|
||||
Input subjectPublicKeyInfo) override
|
||||
pkix::Result VerifyRSAPKCS1SignedDigest(const SignedDigest& signedDigest,
|
||||
Input subjectPublicKeyInfo) override
|
||||
{
|
||||
return VerifyRSAPKCS1SignedDigestNSS(signedDigest, subjectPublicKeyInfo,
|
||||
nullptr);
|
||||
}
|
||||
|
||||
Result CheckValidityIsAcceptable(Time, Time, EndEntityOrCA, KeyPurposeId)
|
||||
pkix::Result CheckValidityIsAcceptable(Time, Time, EndEntityOrCA, KeyPurposeId)
|
||||
override
|
||||
{
|
||||
ADD_FAILURE();
|
||||
return Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
return pkix::Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
}
|
||||
|
||||
Result NetscapeStepUpMatchesServerAuth(Time, bool&) override
|
||||
pkix::Result NetscapeStepUpMatchesServerAuth(Time, bool&) override
|
||||
{
|
||||
ADD_FAILURE();
|
||||
return Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
return pkix::Result::FATAL_ERROR_LIBRARY_FAILURE;
|
||||
}
|
||||
|
||||
void NoteAuxiliaryExtension(AuxiliaryExtension extension, Input data) override
|
||||
|
@ -864,10 +864,10 @@ ExtractSCTListFromOCSPResponse(Input cert,
|
|||
|
||||
bool expired;
|
||||
OCSPExtensionTrustDomain trustDomain;
|
||||
Result rv = VerifyEncodedOCSPResponse(trustDomain, certID,
|
||||
time, /*time*/
|
||||
1000, /*maxLifetimeInDays*/
|
||||
encodedResponse, expired);
|
||||
pkix::Result rv = VerifyEncodedOCSPResponse(trustDomain, certID,
|
||||
time, /*time*/
|
||||
1000, /*maxLifetimeInDays*/
|
||||
encodedResponse, expired);
|
||||
ASSERT_EQ(Success, rv);
|
||||
|
||||
result = Move(trustDomain.signedCertificateTimestamps);
|
||||
|
|
|
@ -19,26 +19,6 @@ namespace extensions {
|
|||
|
||||
using namespace dom;
|
||||
|
||||
static inline Result<Ok, nsresult>
|
||||
WrapNSResult(PRStatus aRv)
|
||||
{
|
||||
if (aRv != PR_SUCCESS) {
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
static inline Result<Ok, nsresult>
|
||||
WrapNSResult(nsresult aRv)
|
||||
{
|
||||
if (NS_FAILED(aRv)) {
|
||||
return Err(aRv);
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
#define NS_TRY(expr) MOZ_TRY(WrapNSResult(expr))
|
||||
|
||||
static const char kProto[] = "moz-extension";
|
||||
|
||||
static const char kBackgroundPageHTMLStart[] = "<!DOCTYPE html>\n\
|
||||
|
@ -225,9 +205,9 @@ WebExtensionPolicy::GetURL(const nsAString& aPath) const
|
|||
nsPrintfCString spec("%s://%s/", kProto, mHostname.get());
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_TRY(NS_NewURI(getter_AddRefs(uri), spec));
|
||||
MOZ_TRY(NS_NewURI(getter_AddRefs(uri), spec));
|
||||
|
||||
NS_TRY(uri->Resolve(NS_ConvertUTF16toUTF8(aPath), spec));
|
||||
MOZ_TRY(uri->Resolve(NS_ConvertUTF16toUTF8(aPath), spec));
|
||||
|
||||
return NS_ConvertUTF8toUTF16(spec);
|
||||
}
|
||||
|
|
|
@ -43,27 +43,6 @@
|
|||
|
||||
namespace mozilla {
|
||||
|
||||
static inline Result<Ok, nsresult>
|
||||
WrapNSResult(PRStatus aRv)
|
||||
{
|
||||
if (aRv != PR_SUCCESS) {
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
static inline Result<Ok, nsresult>
|
||||
WrapNSResult(nsresult aRv)
|
||||
{
|
||||
if (NS_FAILED(aRv)) {
|
||||
return Err(aRv);
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
#define NS_TRY(expr) MOZ_TRY(WrapNSResult(expr))
|
||||
|
||||
|
||||
using Compression::LZ4;
|
||||
using dom::ipc::StructuredCloneData;
|
||||
|
||||
|
@ -131,7 +110,7 @@ ReadFile(nsIFile* file)
|
|||
nsCString result;
|
||||
|
||||
AutoFDClose fd;
|
||||
NS_TRY(file->OpenNSPRFileDesc(PR_RDONLY, 0, &fd.rwget()));
|
||||
MOZ_TRY(file->OpenNSPRFileDesc(PR_RDONLY, 0, &fd.rwget()));
|
||||
|
||||
auto size = PR_Seek64(fd, 0, PR_SEEK_END);
|
||||
PR_Seek64(fd, 0, PR_SEEK_SET);
|
||||
|
@ -247,13 +226,13 @@ GetJarCache()
|
|||
NS_ENSURE_TRUE(ios, Err(NS_ERROR_FAILURE));
|
||||
|
||||
nsCOMPtr<nsIProtocolHandler> jarProto;
|
||||
NS_TRY(ios->GetProtocolHandler("jar", getter_AddRefs(jarProto)));
|
||||
MOZ_TRY(ios->GetProtocolHandler("jar", getter_AddRefs(jarProto)));
|
||||
|
||||
nsCOMPtr<nsIJARProtocolHandler> jar = do_QueryInterface(jarProto);
|
||||
MOZ_ASSERT(jar);
|
||||
|
||||
nsCOMPtr<nsIZipReaderCache> zipCache;
|
||||
NS_TRY(jar->GetJARCache(getter_AddRefs(zipCache)));
|
||||
MOZ_TRY(jar->GetJARCache(getter_AddRefs(zipCache)));
|
||||
|
||||
return Move(zipCache);
|
||||
}
|
||||
|
@ -266,22 +245,22 @@ GetFileLocation(nsIURI* uri)
|
|||
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(uri);
|
||||
nsCOMPtr<nsIFile> file;
|
||||
if (fileURL) {
|
||||
NS_TRY(fileURL->GetFile(getter_AddRefs(file)));
|
||||
MOZ_TRY(fileURL->GetFile(getter_AddRefs(file)));
|
||||
location.Init(file);
|
||||
} else {
|
||||
nsCOMPtr<nsIJARURI> jarURI = do_QueryInterface(uri);
|
||||
NS_ENSURE_TRUE(jarURI, Err(NS_ERROR_INVALID_ARG));
|
||||
|
||||
nsCOMPtr<nsIURI> fileURI;
|
||||
NS_TRY(jarURI->GetJARFile(getter_AddRefs(fileURI)));
|
||||
MOZ_TRY(jarURI->GetJARFile(getter_AddRefs(fileURI)));
|
||||
|
||||
fileURL = do_QueryInterface(fileURI);
|
||||
NS_ENSURE_TRUE(fileURL, Err(NS_ERROR_INVALID_ARG));
|
||||
|
||||
NS_TRY(fileURL->GetFile(getter_AddRefs(file)));
|
||||
MOZ_TRY(fileURL->GetFile(getter_AddRefs(file)));
|
||||
|
||||
nsCString entry;
|
||||
NS_TRY(jarURI->GetJAREntry(entry));
|
||||
MOZ_TRY(jarURI->GetJAREntry(entry));
|
||||
|
||||
location.Init(file, entry.get());
|
||||
}
|
||||
|
@ -485,9 +464,9 @@ Addon::FullPath()
|
|||
}
|
||||
|
||||
// If not an absolute path, fall back to a relative path from the location.
|
||||
NS_TRY(NS_NewLocalFile(mLocation.Path(), false, getter_AddRefs(file)));
|
||||
MOZ_TRY(NS_NewLocalFile(mLocation.Path(), false, getter_AddRefs(file)));
|
||||
|
||||
NS_TRY(file->AppendRelativePath(path));
|
||||
MOZ_TRY(file->AppendRelativePath(path));
|
||||
return Move(file);
|
||||
}
|
||||
|
||||
|
@ -580,7 +559,7 @@ AddonManagerStartup::AddInstallLocation(Addon& addon)
|
|||
MOZ_TRY_VAR(file, addon.FullPath());
|
||||
|
||||
nsString path;
|
||||
NS_TRY(file->GetPath(path));
|
||||
MOZ_TRY(file->GetPath(path));
|
||||
|
||||
auto type = addon.LocationType();
|
||||
|
||||
|
@ -699,7 +678,7 @@ AddonManagerStartup::EncodeBlob(JS::HandleValue value, JSContext* cx, JS::Mutabl
|
|||
MOZ_TRY_VAR(lz4, EncodeLZ4(scData, STRUCTURED_CLONE_MAGIC));
|
||||
|
||||
JS::RootedObject obj(cx);
|
||||
NS_TRY(nsContentUtils::CreateArrayBuffer(cx, lz4, &obj.get()));
|
||||
MOZ_TRY(nsContentUtils::CreateArrayBuffer(cx, lz4, &obj.get()));
|
||||
|
||||
result.set(JS::ObjectValue(*obj));
|
||||
return NS_OK;
|
||||
|
@ -749,16 +728,16 @@ AddonManagerStartup::EnumerateZipFile(nsIFile* file, const nsACString& pattern,
|
|||
MOZ_TRY_VAR(zipCache, GetJarCache());
|
||||
|
||||
nsCOMPtr<nsIZipReader> zip;
|
||||
NS_TRY(zipCache->GetZip(file, getter_AddRefs(zip)));
|
||||
MOZ_TRY(zipCache->GetZip(file, getter_AddRefs(zip)));
|
||||
|
||||
nsCOMPtr<nsIUTF8StringEnumerator> entries;
|
||||
NS_TRY(zip->FindEntries(pattern, getter_AddRefs(entries)));
|
||||
MOZ_TRY(zip->FindEntries(pattern, getter_AddRefs(entries)));
|
||||
|
||||
nsTArray<nsString> results;
|
||||
bool hasMore;
|
||||
while (NS_SUCCEEDED(entries->HasMore(&hasMore)) && hasMore) {
|
||||
nsAutoCString name;
|
||||
NS_TRY(entries->GetNext(name));
|
||||
MOZ_TRY(entries->GetNext(name));
|
||||
|
||||
results.AppendElement(NS_ConvertUTF8toUTF16(name));
|
||||
}
|
||||
|
|
|
@ -215,6 +215,12 @@ struct UnusedZero<nsresult>
|
|||
|
||||
template <typename T> class MOZ_MUST_USE_TYPE GenericErrorResult;
|
||||
template <> class MOZ_MUST_USE_TYPE GenericErrorResult<nsresult>;
|
||||
|
||||
struct Ok;
|
||||
template <typename V, typename E> class Result;
|
||||
|
||||
// Allow MOZ_TRY to handle `nsresult` values.
|
||||
inline Result<Ok, nsresult> ToResult(nsresult aValue);
|
||||
} // namespace mozilla
|
||||
|
||||
/*
|
||||
|
|
Загрузка…
Ссылка в новой задаче