2019-01-19 01:52:06 +03:00
|
|
|
/* -*- 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 "QuotaCommon.h"
|
|
|
|
|
2020-04-01 10:26:27 +03:00
|
|
|
#include "mozilla/Logging.h" // LazyLogModule
|
|
|
|
#include "nsIFile.h"
|
2020-04-06 12:28:35 +03:00
|
|
|
#include "nsXPCOM.h"
|
|
|
|
#include "nsXULAppAPI.h"
|
2020-04-01 10:26:27 +03:00
|
|
|
#ifdef XP_WIN
|
2020-04-06 12:28:35 +03:00
|
|
|
# include "mozilla/ipc/BackgroundParent.h"
|
|
|
|
# include "mozilla/StaticPrefs_dom.h"
|
2020-04-01 10:26:27 +03:00
|
|
|
# include "nsILocalFileWin.h"
|
|
|
|
#endif
|
|
|
|
#include "nsXPCOM.h"
|
|
|
|
|
2019-03-21 23:08:00 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace quota {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2020-04-06 12:28:35 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
Atomic<int32_t> gUseDOSDevicePathSyntax(-1);
|
|
|
|
#endif
|
|
|
|
|
2019-03-21 23:08:00 +03:00
|
|
|
LazyLogModule gLogger("QuotaManager");
|
|
|
|
|
2019-10-02 07:28:23 +03:00
|
|
|
void AnonymizeCString(nsACString& aCString, uint32_t aStart) {
|
|
|
|
MOZ_ASSERT(!aCString.IsEmpty());
|
|
|
|
MOZ_ASSERT(aStart < aCString.Length());
|
2019-01-19 01:52:06 +03:00
|
|
|
|
2019-10-02 07:28:23 +03:00
|
|
|
char* iter = aCString.BeginWriting() + aStart;
|
|
|
|
char* end = aCString.EndWriting();
|
2019-06-09 22:46:34 +03:00
|
|
|
|
|
|
|
while (iter != end) {
|
|
|
|
char c = *iter;
|
|
|
|
|
|
|
|
if (IsAsciiAlpha(c)) {
|
|
|
|
*iter = 'a';
|
|
|
|
} else if (IsAsciiDigit(c)) {
|
|
|
|
*iter = 'D';
|
|
|
|
}
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-02 07:28:23 +03:00
|
|
|
} // namespace
|
2019-06-09 22:46:34 +03:00
|
|
|
|
2019-10-02 07:28:23 +03:00
|
|
|
const char kQuotaGenericDelimiter = '|';
|
2019-06-09 22:46:34 +03:00
|
|
|
|
2019-10-02 07:28:23 +03:00
|
|
|
#ifdef NIGHTLY_BUILD
|
|
|
|
NS_NAMED_LITERAL_CSTRING(kQuotaInternalError, "internal");
|
|
|
|
NS_NAMED_LITERAL_CSTRING(kQuotaExternalError, "external");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
LogModule* GetQuotaManagerLogger() { return gLogger; }
|
|
|
|
|
|
|
|
void AnonymizeCString(nsACString& aCString) {
|
|
|
|
if (aCString.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AnonymizeCString(aCString, /* aStart */ 0);
|
|
|
|
}
|
2019-06-09 22:46:34 +03:00
|
|
|
|
2019-10-02 07:28:23 +03:00
|
|
|
void AnonymizeOriginString(nsACString& aOriginString) {
|
|
|
|
if (aOriginString.IsEmpty()) {
|
|
|
|
return;
|
2019-06-09 22:46:34 +03:00
|
|
|
}
|
2019-10-02 07:28:23 +03:00
|
|
|
|
|
|
|
int32_t start = aOriginString.FindChar(':');
|
|
|
|
if (start < 0) {
|
|
|
|
start = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
AnonymizeCString(aOriginString, start);
|
2019-06-09 22:46:34 +03:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:28:35 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
void CacheUseDOSDevicePathSyntaxPrefValue() {
|
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
|
|
AssertIsOnBackgroundThread();
|
|
|
|
|
|
|
|
if (gUseDOSDevicePathSyntax == -1) {
|
|
|
|
bool useDOSDevicePathSyntax =
|
|
|
|
StaticPrefs::dom_quotaManager_useDOSDevicePathSyntax_DoNotUseDirectly();
|
|
|
|
gUseDOSDevicePathSyntax = useDOSDevicePathSyntax ? 1 : 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-04-01 10:26:27 +03:00
|
|
|
Result<nsCOMPtr<nsIFile>, nsresult> QM_NewLocalFile(const nsAString& aPath) {
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
nsresult rv =
|
|
|
|
NS_NewLocalFile(aPath, /* aFollowLinks */ false, getter_AddRefs(file));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2020-04-27 11:38:55 +03:00
|
|
|
QM_WARNING("Failed to construct a file for path (%s)",
|
|
|
|
NS_ConvertUTF16toUTF8(aPath).get());
|
2020-04-01 10:26:27 +03:00
|
|
|
return Err(rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
2020-04-06 12:28:35 +03:00
|
|
|
MOZ_ASSERT(gUseDOSDevicePathSyntax != -1);
|
2020-04-01 10:26:27 +03:00
|
|
|
|
2020-04-06 12:28:35 +03:00
|
|
|
if (gUseDOSDevicePathSyntax) {
|
|
|
|
nsCOMPtr<nsILocalFileWin> winFile = do_QueryInterface(file, &rv);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return Err(rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(winFile);
|
|
|
|
winFile->SetUseDOSDevicePathSyntax(true);
|
|
|
|
}
|
2020-04-01 10:26:27 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2019-03-21 23:08:00 +03:00
|
|
|
} // namespace quota
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|