Files
palemoon27/dom/filesystem/FileSystemTaskBase.cpp
T
roytam1 baacd3ba62 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1254108 - Remove incorrect assertion about heap size r=terrence (a98d1df06b)
- Bug 1244412 - Make ZoneCellIter work correctly whether called under GC or not r=terrence (cec67ebbd3)
- Bug 1244412 - Remove ZoneCellIterUnderGC now it's no longer needed and refactor r=terrence (3b98615a8b)
- Bug 1244412 - Fix suprious GC hazard r=me (bfbdee71b0)
- Bug 1253461 - Fix race condition in Shape::fixupDictionaryShapeAfterMovingGC r=terrence (3f15dd893c)
- Bug 1224038 - Part 1: Add infallible versions of uid and hashcode getters; r=sfink (c8a7bac9b5)
- Bug 1252329 - Fix interaction between AutoClearTypeInferenceStateOnOOM and compacting GC r=terrence (3f35df9bad)
- Bug 1224038 - Part 2: Use stable hashing for NewTable; r=sfink (1046b72221)
- Bug 1224050 - Use stable hashing for the IntialShapesTable; r=jonco (08aa726019)
- Bug 1227035 - Tighten the check in ObjectGroup::useSingletonForClone a bit more. r=bhackett (c817b1a595)
- Bug 1257903 - Compact arenas containing shapes r=terrence (bc7f90586b)
- Bug 1235572 - Enforce SRI if content signature is enforced r=francois (1f0723fccf)
- Bug 1254856 - Use a better window for 3rd-party checks. r=sicking, r=billm (9160d94db5)
- Bug 1253575 - Annotate the crash report on failure in opening the process handle for plugin or content process. r=billm (8940f5247c)
- No bug. Make it easier to work on specific functions in the XDB files (01cd0735cc)
- Bug 1251703 - Always resolve virtual calls to known callees, r=mccr8 (b042b74487)
- Bug 1250709 - Implement shell-only hazard analysis job, r=garndt (a11947ad0d)
- Bug 1253466 - Don't pass --enable-threadsafe to js/src/configure. r=mshal (ed2fd1554b)
- Bug 1246804 - Switch to using in-source annotations. Use C++ inheritance information when describing GC types. Add a test suite., r=terrence (f5fddd8dad)
- Bug 1257979 - Use a GCHashSet for a hash in the JSON stringifying algorithm. r=sfink (e6baa61177)
- Bug 1242810. r=jandem (fca11d1b92)
- Bug 1253099. r=arai, r=efaust (9972e18152)
- Address review comments from bug 1246804 (f36a5d29df)
- Bug 1226928 - dochsell changes for content-signing on remote about:newtab, r=bz,mconley (da3ecffcd4)
- Bug 1226928 - content-signature verification tests for about:newtab, r=mconley (8f77c22596)
- Bug 1257730 - Fix ping when no URI is available. r=sicking (67d3a9541d)
- Bug 518805 - Don't do meta refreshes when backgrounded r=bz (609b2c0a2c)
- Bug 513129 - Dont reuse connections after security prefs change r=hurley (379e74d1f1)
- Bug 1256248 - allow disabling content-signatures for about:newtab on certain channels, r=mayhemer (35fadec30f)
- Bug 1234896 - refptrs for httphandler.cpp r=valentin.gosu (7aff77f88e)
- Bug 1242926 - Increase the max retry attempt number. r=mcmanus (9085644f4e)
- Bug 1144040 - Coverity detected uninitialized nsHttpHandler members, r=mcmanus (8ec1e49577)
- Bug 1231416 - fix Mulet UA string generation rule. r=fabrice. (d952dd06e2)
- Bug 1220061 - Android UA is not correct when MOZ_UA_OS_AGNOSTIC is set r=gerv (e007b6f1a3)
- Bug 962358 - Provide an observer event to close persistent connections. r=arthuredelstein (903d2fa203)
- Bug 1226526 - NS_ENSURE_ARG_POINTER on result to remove warning added by scan-build.  r=mcmanus (7d87d1502b)
- Bug 1248452: Rewrite NS_IsHSTSUpgradeRedirect to use HttpBaseChannel::GetSecureUpgradedURI. r=jduell (f806456238)
- Bug 1249450 part 1: Move GetSecureUpgradedURI from HttpBaseChannel to nsNetUtil. r=mcmanus (70b023486b)
- Bug 1249450 part 2: Convert some nsIURI SetScheme("https") calls to use NS_GetSecureUpgradedURI instead. r=mcmanus (6dea15dd6b)
- Bug 451081 - Introduce ORIGIN_IS_FULL_SPEC protocol handler flag, r=bz+standard8 IGNORE IDL (e7d651c6b7)
- Bug 991016 - Check return value of a setDelegate call. r=efaust. (4bf66d532f)
- Bug 1240414 - Fix ThrowUninitializedThis to do the right thing for eval and arrow function frames. r=efaust (a04625b047)
- Bug 1254349 - Remove unused error messages. r=mrrrgn (58fd90f345)
- Bug 1256464 - Use LPSTR instead of LPVOID to avoid C4477 on VS2015; r=froydnj (ec57a4894e)
- bug 1250486 - make some xpconnect wrapper ctors constexpr to get rid of static constructors r=bz (7681e3102f)
- Bug 1250192 - Do not synthesize a var binding for Annex B.3.5 if there is an arg binding of the same name. (r=jorendorff) (601ac2528c)
- Bug 1237588 - One of the File::Create methods is not used, r=smaug (ac6f036ceb)
- Bug 1173317 - Change the string argument for Directory::GetName from nsString to nsAString. r=sicking (1e670db10d)
- Bug 1244782 - Removed non-used variables in Directory.cpp, r=smaug (0f01c9747a)
- Bug 1234192 - part 1 - FileSystemBase should not be thread-safe, r=smaug (1d24a83a75)
- Bug 1234192 - part 2 - Directory should unlink/traverse the OSFileSystem in order to unlink/traverse the window, r=smaug (acea1d57d6)
- Bug 1251723 - remove ScopedDeletePtr; r=Waldo (eb6af862a5)
- Bug 1252153 - use UniquePtr instead of ScopedDeletePtr in HeapCopyOfStackArray; r=jrmuizel (1ffb6c113f)
- Bug 1251715 - use UniquePtr instead of ScopedDeletePtr in dom/media/; r=gerald (910c698731)
- Bug 1239870 - Part 1: Remove declaration of test_utils from header. r=bwc (d295b3a379)
- Bug 1239870 - Part 2: Split out NrIceCtx initialization. r=bwc (a399a76d59)
- Bug 1239870 - Part 3: Add a base mtransport gtest. r=bwc (5d0a79a54d)
- Bug 1239870 - Part 4: Disable broken proxy tunnel tests. r=bwc (8c24c01723)
- Bug 1239870 - Part 5: Switch over mtransport tests to mozilla gtests. r=bwc (0e00f9e97d)
- Bug 1251714 - use UniquePtr instead of ScopedDeletePtr in media/; r=jesup (a274b4172e)
- Bug 1251718 - use UniquePtr instead of ScopedDeletePtr in WebGLElementArrayCache; r=baku (39ebd0f02f)
- Bug 1251716 - use UniquePtr instead of ScopedDeletePtr in DrawTargetCairo; r=jrmuizel (fe889eaff3)
2024-02-26 23:06:55 +08:00

268 lines
6.7 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 "mozilla/dom/FileSystemTaskBase.h"
#include "nsNetCID.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/FileSystemBase.h"
#include "mozilla/dom/FileSystemRequestParent.h"
#include "mozilla/dom/FileSystemUtils.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/PContent.h"
#include "mozilla/dom/ipc/BlobParent.h"
#include "mozilla/unused.h"
#include "nsProxyRelease.h"
namespace mozilla {
namespace dom {
namespace {
class FileSystemReleaseRunnable : public nsRunnable
{
public:
explicit FileSystemReleaseRunnable(RefPtr<FileSystemBase>& aDoomed)
: mDoomed(nullptr)
{
aDoomed.swap(mDoomed);
}
NS_IMETHOD Run()
{
mDoomed->Release();
return NS_OK;
}
private:
FileSystemBase* MOZ_OWNING_REF mDoomed;
};
} // anonymous namespace
FileSystemTaskBase::FileSystemTaskBase(FileSystemBase* aFileSystem)
: mErrorValue(NS_OK)
, mFileSystem(aFileSystem)
{
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
MOZ_ASSERT(aFileSystem, "aFileSystem should not be null.");
}
FileSystemTaskBase::FileSystemTaskBase(FileSystemBase* aFileSystem,
const FileSystemParams& aParam,
FileSystemRequestParent* aParent)
: mErrorValue(NS_OK)
, mFileSystem(aFileSystem)
, mRequestParent(aParent)
{
MOZ_ASSERT(XRE_IsParentProcess(),
"Only call from parent process!");
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
MOZ_ASSERT(aFileSystem, "aFileSystem should not be null.");
}
FileSystemTaskBase::~FileSystemTaskBase()
{
if (!NS_IsMainThread()) {
RefPtr<FileSystemReleaseRunnable> runnable =
new FileSystemReleaseRunnable(mFileSystem);
MOZ_ASSERT(!mFileSystem);
NS_DispatchToMainThread(runnable);
}
}
FileSystemBase*
FileSystemTaskBase::GetFileSystem() const
{
return mFileSystem.get();
}
void
FileSystemTaskBase::Start()
{
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
if (HasError()) {
NS_DispatchToMainThread(this);
return;
}
if (XRE_IsParentProcess()) {
// Run in parent process.
// Start worker thread.
nsCOMPtr<nsIEventTarget> target
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
NS_ASSERTION(target, "Must have stream transport service.");
target->Dispatch(this, NS_DISPATCH_NORMAL);
return;
}
// Run in child process.
if (mFileSystem->IsShutdown()) {
return;
}
// Retain a reference so the task object isn't deleted without IPDL's
// knowledge. The reference will be released by
// mozilla::dom::ContentChild::DeallocPFileSystemRequestChild.
NS_ADDREF_THIS();
ContentChild::GetSingleton()->SendPFileSystemRequestConstructor(this,
GetRequestParams(mFileSystem->ToString()));
}
NS_IMETHODIMP
FileSystemTaskBase::Run()
{
if (!NS_IsMainThread()) {
// Run worker thread tasks
nsresult rv = Work();
if (NS_FAILED(rv)) {
SetError(rv);
}
// Dispatch itself to main thread
NS_DispatchToMainThread(this);
return NS_OK;
}
// Run main thread tasks
HandleResult();
return NS_OK;
}
void
FileSystemTaskBase::HandleResult()
{
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
if (mFileSystem->IsShutdown()) {
return;
}
if (mRequestParent && mRequestParent->IsRunning()) {
Unused << mRequestParent->Send__delete__(mRequestParent,
GetRequestResult());
} else {
HandlerCallback();
}
}
FileSystemResponseValue
FileSystemTaskBase::GetRequestResult() const
{
MOZ_ASSERT(XRE_IsParentProcess(),
"Only call from parent process!");
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
if (HasError()) {
return FileSystemErrorResponse(mErrorValue);
} else {
return GetSuccessRequestResult();
}
}
void
FileSystemTaskBase::SetRequestResult(const FileSystemResponseValue& aValue)
{
MOZ_ASSERT(!XRE_IsParentProcess(),
"Only call from child process!");
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
if (aValue.type() == FileSystemResponseValue::TFileSystemErrorResponse) {
FileSystemErrorResponse r = aValue;
mErrorValue = r.error();
} else {
SetSuccessRequestResult(aValue);
}
}
bool
FileSystemTaskBase::Recv__delete__(const FileSystemResponseValue& aValue)
{
SetRequestResult(aValue);
HandlerCallback();
return true;
}
BlobParent*
FileSystemTaskBase::GetBlobParent(BlobImpl* aFile) const
{
MOZ_ASSERT(XRE_IsParentProcess(),
"Only call from parent process!");
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
MOZ_ASSERT(aFile);
// Load the lazy dom file data from the parent before sending to the child.
nsString mimeType;
aFile->GetType(mimeType);
// We call GetSize and GetLastModified to prepopulate the value in the
// BlobImpl.
{
ErrorResult rv;
aFile->GetSize(rv);
rv.SuppressException();
}
{
ErrorResult rv;
aFile->GetLastModified(rv);
rv.SuppressException();
}
ContentParent* cp = static_cast<ContentParent*>(mRequestParent->Manager());
return cp->GetOrCreateActorForBlobImpl(aFile);
}
void
FileSystemTaskBase::SetError(const nsresult& aErrorValue)
{
uint16_t module = NS_ERROR_GET_MODULE(aErrorValue);
if (module == NS_ERROR_MODULE_DOM_FILESYSTEM ||
module == NS_ERROR_MODULE_DOM_FILE ||
module == NS_ERROR_MODULE_DOM) {
mErrorValue = aErrorValue;
return;
}
switch (aErrorValue) {
case NS_OK:
mErrorValue = NS_OK;
return;
case NS_ERROR_FILE_INVALID_PATH:
case NS_ERROR_FILE_UNRECOGNIZED_PATH:
mErrorValue = NS_ERROR_DOM_FILESYSTEM_INVALID_PATH_ERR;
return;
case NS_ERROR_FILE_DESTINATION_NOT_DIR:
mErrorValue = NS_ERROR_DOM_FILESYSTEM_INVALID_MODIFICATION_ERR;
return;
case NS_ERROR_FILE_ACCESS_DENIED:
case NS_ERROR_FILE_DIR_NOT_EMPTY:
mErrorValue = NS_ERROR_DOM_FILESYSTEM_NO_MODIFICATION_ALLOWED_ERR;
return;
case NS_ERROR_FILE_TARGET_DOES_NOT_EXIST:
case NS_ERROR_NOT_AVAILABLE:
mErrorValue = NS_ERROR_DOM_FILE_NOT_FOUND_ERR;
return;
case NS_ERROR_FILE_ALREADY_EXISTS:
mErrorValue = NS_ERROR_DOM_FILESYSTEM_PATH_EXISTS_ERR;
return;
case NS_ERROR_FILE_NOT_DIRECTORY:
mErrorValue = NS_ERROR_DOM_FILESYSTEM_TYPE_MISMATCH_ERR;
return;
case NS_ERROR_UNEXPECTED:
default:
mErrorValue = NS_ERROR_DOM_FILESYSTEM_UNKNOWN_ERR;
return;
}
}
} // namespace dom
} // namespace mozilla