2010-06-23 23:46:08 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-06-28 20:44:30 +04:00
|
|
|
#include "IDBFactory.h"
|
2013-03-16 10:58:50 +04:00
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
#include "BackgroundChildImpl.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "IDBRequest.h"
|
|
|
|
#include "IndexedDatabaseManager.h"
|
2019-12-05 07:44:32 +03:00
|
|
|
#include "mozilla/BasePrincipal.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2017-01-13 11:40:58 +03:00
|
|
|
#include "mozilla/SystemGroup.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2013-03-31 12:18:30 +04:00
|
|
|
#include "mozilla/dom/IDBFactoryBinding.h"
|
2018-03-15 12:35:05 +03:00
|
|
|
#include "mozilla/dom/quota/QuotaManager.h"
|
2019-04-10 01:39:01 +03:00
|
|
|
#include "mozilla/dom/BrowserChild.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/ipc/BackgroundChild.h"
|
|
|
|
#include "mozilla/ipc/BackgroundUtils.h"
|
|
|
|
#include "mozilla/ipc/PBackground.h"
|
|
|
|
#include "mozilla/ipc/PBackgroundChild.h"
|
2019-07-26 04:10:23 +03:00
|
|
|
#include "mozilla/StaticPrefs_dom.h"
|
2019-05-25 04:25:41 +03:00
|
|
|
#include "mozilla/StorageAccess.h"
|
2017-09-18 12:00:37 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2014-12-17 09:26:15 +03:00
|
|
|
#include "nsAboutProtocolUtils.h"
|
|
|
|
#include "nsContentUtils.h"
|
2012-07-06 21:28:51 +04:00
|
|
|
#include "nsGlobalWindow.h"
|
2014-12-17 09:26:15 +03:00
|
|
|
#include "nsIAboutModule.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "nsILoadContext.h"
|
2014-12-17 09:26:15 +03:00
|
|
|
#include "nsIURI.h"
|
2014-10-16 08:56:52 +04:00
|
|
|
#include "nsIUUIDGenerator.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "nsIWebNavigation.h"
|
2014-12-17 09:26:15 +03:00
|
|
|
#include "nsSandboxFlags.h"
|
2014-10-16 08:56:52 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2013-03-16 10:58:50 +04:00
|
|
|
#include "ProfilerHelpers.h"
|
2014-01-28 04:37:05 +04:00
|
|
|
#include "ReportInternalError.h"
|
2011-05-29 03:42:57 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// Include this last to avoid path problems on Windows.
|
|
|
|
#include "ActorsChild.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
#ifdef DEBUG
|
2014-11-14 05:20:38 +03:00
|
|
|
# include "nsContentUtils.h" // For assertions.
|
2014-09-27 03:21:57 +04:00
|
|
|
#endif
|
2013-09-13 15:19:25 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2017-06-07 13:36:20 +03:00
|
|
|
using namespace mozilla::dom::indexedDB;
|
2014-09-27 03:21:57 +04:00
|
|
|
using namespace mozilla::dom::quota;
|
|
|
|
using namespace mozilla::ipc;
|
2012-07-14 15:24:20 +04:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
namespace {
|
|
|
|
|
2019-08-19 17:22:09 +03:00
|
|
|
Telemetry::LABELS_IDB_CUSTOM_OPEN_WITH_OPTIONS_COUNT IdentifyPrincipalType(
|
|
|
|
const mozilla::ipc::PrincipalInfo& aPrincipalInfo) {
|
|
|
|
switch (aPrincipalInfo.type()) {
|
|
|
|
case PrincipalInfo::TSystemPrincipalInfo:
|
|
|
|
return Telemetry::LABELS_IDB_CUSTOM_OPEN_WITH_OPTIONS_COUNT::system;
|
|
|
|
case PrincipalInfo::TContentPrincipalInfo: {
|
|
|
|
const ContentPrincipalInfo& info =
|
|
|
|
aPrincipalInfo.get_ContentPrincipalInfo();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(NS_NewURI(getter_AddRefs(uri), info.spec())))) {
|
|
|
|
// This could be discriminated as an extra error value, but this is
|
|
|
|
// extremely unlikely to fail, so we just misuse ContentOther
|
|
|
|
return Telemetry::LABELS_IDB_CUSTOM_OPEN_WITH_OPTIONS_COUNT::
|
|
|
|
content_other;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO Are there constants defined for the schemes somewhere?
|
|
|
|
if (uri->SchemeIs("file")) {
|
|
|
|
return Telemetry::LABELS_IDB_CUSTOM_OPEN_WITH_OPTIONS_COUNT::
|
|
|
|
content_file;
|
|
|
|
}
|
|
|
|
if (uri->SchemeIs("http") || uri->SchemeIs("https")) {
|
|
|
|
return Telemetry::LABELS_IDB_CUSTOM_OPEN_WITH_OPTIONS_COUNT::
|
|
|
|
content_http_https;
|
|
|
|
}
|
|
|
|
if (uri->SchemeIs("moz-extension")) {
|
|
|
|
return Telemetry::LABELS_IDB_CUSTOM_OPEN_WITH_OPTIONS_COUNT::
|
|
|
|
content_moz_ext;
|
|
|
|
}
|
|
|
|
if (uri->SchemeIs("about")) {
|
|
|
|
return Telemetry::LABELS_IDB_CUSTOM_OPEN_WITH_OPTIONS_COUNT::
|
|
|
|
content_about;
|
|
|
|
}
|
|
|
|
return Telemetry::LABELS_IDB_CUSTOM_OPEN_WITH_OPTIONS_COUNT::
|
|
|
|
content_other;
|
|
|
|
}
|
|
|
|
case PrincipalInfo::TExpandedPrincipalInfo:
|
|
|
|
return Telemetry::LABELS_IDB_CUSTOM_OPEN_WITH_OPTIONS_COUNT::expanded;
|
|
|
|
default:
|
|
|
|
return Telemetry::LABELS_IDB_CUSTOM_OPEN_WITH_OPTIONS_COUNT::other;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
struct IDBFactory::PendingRequestInfo {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBOpenDBRequest> mRequest;
|
2014-09-27 03:21:57 +04:00
|
|
|
FactoryRequestParams mParams;
|
|
|
|
|
|
|
|
PendingRequestInfo(IDBOpenDBRequest* aRequest,
|
|
|
|
const FactoryRequestParams& aParams)
|
|
|
|
: mRequest(aRequest), mParams(aParams) {
|
|
|
|
MOZ_ASSERT(aRequest);
|
|
|
|
MOZ_ASSERT(aParams.type() != FactoryRequestParams::T__None);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-04-30 03:46:20 +04:00
|
|
|
IDBFactory::IDBFactory()
|
2019-03-29 21:05:11 +03:00
|
|
|
: mBackgroundActor(nullptr),
|
2014-11-14 05:20:38 +03:00
|
|
|
mInnerWindowID(0),
|
2018-04-16 16:08:52 +03:00
|
|
|
mActiveTransactionCount(0),
|
|
|
|
mActiveDatabaseCount(0),
|
2014-09-27 03:21:57 +04:00
|
|
|
mBackgroundActorFailed(false),
|
|
|
|
mPrivateBrowsingMode(false) {
|
|
|
|
AssertIsOnOwningThread();
|
2011-04-30 03:46:20 +04:00
|
|
|
}
|
|
|
|
|
2012-01-24 14:03:37 +04:00
|
|
|
IDBFactory::~IDBFactory() {
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT_IF(mBackgroundActorFailed, !mBackgroundActor);
|
|
|
|
|
|
|
|
if (mBackgroundActor) {
|
|
|
|
mBackgroundActor->SendDeleteMeInternal();
|
|
|
|
MOZ_ASSERT(!mBackgroundActor, "SendDeleteMeInternal should have cleared!");
|
|
|
|
}
|
2012-01-24 14:03:37 +04:00
|
|
|
}
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
// static
|
2016-01-30 20:05:36 +03:00
|
|
|
nsresult IDBFactory::CreateForWindow(nsPIDOMWindowInner* aWindow,
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBFactory** aFactory) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aWindow);
|
|
|
|
MOZ_ASSERT(aFactory);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2015-01-06 02:08:12 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
2019-12-19 12:56:12 +03:00
|
|
|
nsresult rv = AllowedForWindowInternal(aWindow, &principal);
|
2015-01-06 02:08:12 +03:00
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
if (rv == NS_ERROR_DOM_NOT_SUPPORTED_ERR) {
|
|
|
|
NS_WARNING("IndexedDB is not permitted in a third-party window.");
|
|
|
|
*aFactory = nullptr;
|
|
|
|
return NS_OK;
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
if (rv == NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR) {
|
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
}
|
|
|
|
return rv;
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
MOZ_ASSERT(principal);
|
2011-01-27 04:53:02 +03:00
|
|
|
|
2019-12-19 12:57:42 +03:00
|
|
|
auto principalInfo = MakeUnique<PrincipalInfo>();
|
|
|
|
rv = PrincipalToPrincipalInfo(principal, principalInfo.get());
|
2014-12-17 09:26:15 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2014-09-27 03:21:57 +04:00
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
MOZ_ASSERT(principalInfo->type() == PrincipalInfo::TContentPrincipalInfo ||
|
|
|
|
principalInfo->type() == PrincipalInfo::TSystemPrincipalInfo);
|
|
|
|
|
2019-02-23 19:03:40 +03:00
|
|
|
if (NS_WARN_IF(!QuotaManager::IsPrincipalInfoValid(*principalInfo))) {
|
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(aWindow);
|
|
|
|
nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(webNav);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBFactory> factory = new IDBFactory();
|
2018-05-30 22:15:35 +03:00
|
|
|
factory->mPrincipalInfo = std::move(principalInfo);
|
2019-03-29 21:05:11 +03:00
|
|
|
|
|
|
|
factory->mGlobal = do_QueryInterface(aWindow);
|
|
|
|
MOZ_ASSERT(factory->mGlobal);
|
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
factory->mBrowserChild = BrowserChild::GetFrom(aWindow);
|
2017-06-21 06:01:52 +03:00
|
|
|
factory->mEventTarget =
|
2017-11-04 01:25:38 +03:00
|
|
|
nsGlobalWindowInner::Cast(aWindow)->EventTargetFor(TaskCategory::Other);
|
2014-11-14 05:20:38 +03:00
|
|
|
factory->mInnerWindowID = aWindow->WindowID();
|
2014-12-17 09:26:15 +03:00
|
|
|
factory->mPrivateBrowsingMode =
|
|
|
|
loadContext && loadContext->UsePrivateBrowsing();
|
2012-06-01 21:21:12 +04:00
|
|
|
|
|
|
|
factory.forget(aFactory);
|
|
|
|
return NS_OK;
|
2012-01-24 14:03:37 +04:00
|
|
|
}
|
2011-01-27 04:53:02 +03:00
|
|
|
|
2012-01-24 14:03:37 +04:00
|
|
|
// static
|
2019-03-29 21:05:11 +03:00
|
|
|
nsresult IDBFactory::CreateForMainThreadJS(nsIGlobalObject* aGlobal,
|
2015-07-02 23:30:15 +03:00
|
|
|
IDBFactory** aFactory) {
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2019-03-29 21:05:11 +03:00
|
|
|
MOZ_ASSERT(aGlobal);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(aGlobal);
|
|
|
|
if (NS_WARN_IF(!sop)) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
2011-01-27 04:53:02 +03:00
|
|
|
|
2019-12-19 12:57:42 +03:00
|
|
|
auto principalInfo = MakeUnique<PrincipalInfo>();
|
2019-05-31 22:31:04 +03:00
|
|
|
nsIPrincipal* principal = sop->GetEffectiveStoragePrincipal();
|
2015-07-02 23:30:15 +03:00
|
|
|
MOZ_ASSERT(principal);
|
|
|
|
bool isSystem;
|
|
|
|
if (!AllowedForPrincipal(principal, &isSystem)) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2019-12-19 12:57:42 +03:00
|
|
|
nsresult rv = PrincipalToPrincipalInfo(principal, principalInfo.get());
|
2015-07-02 23:30:15 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2019-02-23 19:03:40 +03:00
|
|
|
if (NS_WARN_IF(!QuotaManager::IsPrincipalInfoValid(*principalInfo))) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
2019-12-19 12:57:42 +03:00
|
|
|
rv = CreateForMainThreadJSInternal(aGlobal, std::move(principalInfo),
|
|
|
|
aFactory);
|
2014-09-27 03:21:57 +04:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2014-01-12 06:45:15 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(!principalInfo);
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-14 15:24:20 +04:00
|
|
|
// static
|
2019-03-29 21:05:11 +03:00
|
|
|
nsresult IDBFactory::CreateForWorker(nsIGlobalObject* aGlobal,
|
2014-12-17 09:26:15 +03:00
|
|
|
const PrincipalInfo& aPrincipalInfo,
|
|
|
|
uint64_t aInnerWindowID,
|
|
|
|
IDBFactory** aFactory) {
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
2019-03-29 21:05:11 +03:00
|
|
|
MOZ_ASSERT(aGlobal);
|
2014-12-17 09:26:15 +03:00
|
|
|
MOZ_ASSERT(aPrincipalInfo.type() != PrincipalInfo::T__None);
|
2012-07-14 15:24:20 +04:00
|
|
|
|
2019-12-19 12:57:42 +03:00
|
|
|
nsresult rv =
|
|
|
|
CreateInternal(aGlobal, MakeUnique<PrincipalInfo>(aPrincipalInfo),
|
|
|
|
aInnerWindowID, aFactory);
|
2014-12-17 09:26:15 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsresult IDBFactory::CreateForMainThreadJSInternal(
|
2019-12-19 12:57:42 +03:00
|
|
|
nsIGlobalObject* aGlobal, UniquePtr<PrincipalInfo> aPrincipalInfo,
|
2019-03-29 21:05:11 +03:00
|
|
|
IDBFactory** aFactory) {
|
2014-12-17 09:26:15 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2019-03-29 21:05:11 +03:00
|
|
|
MOZ_ASSERT(aGlobal);
|
2015-01-06 02:08:12 +03:00
|
|
|
MOZ_ASSERT(aPrincipalInfo);
|
2014-12-17 09:26:15 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
IndexedDatabaseManager* mgr = IndexedDatabaseManager::GetOrCreate();
|
|
|
|
if (NS_WARN_IF(!mgr)) {
|
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
2012-07-14 15:24:20 +04:00
|
|
|
|
2019-12-19 12:56:12 +03:00
|
|
|
nsresult rv = CreateInternal(aGlobal, std::move(aPrincipalInfo),
|
|
|
|
/* aInnerWindowID */ 0, aFactory);
|
2014-12-17 09:26:15 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2019-03-29 21:05:11 +03:00
|
|
|
nsresult IDBFactory::CreateInternal(nsIGlobalObject* aGlobal,
|
2019-12-19 12:57:42 +03:00
|
|
|
UniquePtr<PrincipalInfo> aPrincipalInfo,
|
2019-03-29 21:05:11 +03:00
|
|
|
uint64_t aInnerWindowID,
|
|
|
|
IDBFactory** aFactory) {
|
|
|
|
MOZ_ASSERT(aGlobal);
|
2014-12-17 09:26:15 +03:00
|
|
|
MOZ_ASSERT(aPrincipalInfo);
|
|
|
|
MOZ_ASSERT(aPrincipalInfo->type() != PrincipalInfo::T__None);
|
|
|
|
MOZ_ASSERT(aFactory);
|
|
|
|
|
|
|
|
if (aPrincipalInfo->type() != PrincipalInfo::TContentPrincipalInfo &&
|
|
|
|
aPrincipalInfo->type() != PrincipalInfo::TSystemPrincipalInfo) {
|
|
|
|
NS_WARNING("IndexedDB not allowed for this principal!");
|
2015-04-09 01:21:26 +03:00
|
|
|
aPrincipalInfo = nullptr;
|
2014-12-17 09:26:15 +03:00
|
|
|
*aFactory = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBFactory> factory = new IDBFactory();
|
2019-12-19 12:56:12 +03:00
|
|
|
factory->mPrincipalInfo = std::move(aPrincipalInfo);
|
2019-03-29 21:05:11 +03:00
|
|
|
factory->mGlobal = aGlobal;
|
2017-11-06 06:58:13 +03:00
|
|
|
factory->mEventTarget = GetCurrentThreadEventTarget();
|
2014-12-17 09:26:15 +03:00
|
|
|
factory->mInnerWindowID = aInnerWindowID;
|
2012-07-14 15:24:20 +04:00
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
factory.forget(aFactory);
|
|
|
|
return NS_OK;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
// static
|
2016-01-30 20:05:36 +03:00
|
|
|
bool IDBFactory::AllowedForWindow(nsPIDOMWindowInner* aWindow) {
|
2014-12-17 09:26:15 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aWindow);
|
|
|
|
|
2019-11-08 16:22:28 +03:00
|
|
|
return !NS_WARN_IF(NS_FAILED(AllowedForWindowInternal(aWindow, nullptr)));
|
2014-12-17 09:26:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2019-12-19 12:56:12 +03:00
|
|
|
nsresult IDBFactory::AllowedForWindowInternal(
|
|
|
|
nsPIDOMWindowInner* aWindow, nsCOMPtr<nsIPrincipal>* aPrincipal) {
|
2014-12-17 09:26:15 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aWindow);
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!IndexedDatabaseManager::GetOrCreate())) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
2019-05-27 17:06:49 +03:00
|
|
|
StorageAccess access = StorageAllowedForWindow(aWindow);
|
2015-07-16 00:01:02 +03:00
|
|
|
|
|
|
|
// the factory callsite records whether the browser is in private browsing.
|
|
|
|
// and thus we don't have to respect that setting here. IndexedDB has no
|
|
|
|
// concept of session-local storage, and thus ignores it.
|
2019-05-27 17:06:49 +03:00
|
|
|
if (access == StorageAccess::eDeny) {
|
2019-04-12 08:31:13 +03:00
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
}
|
|
|
|
|
2019-05-25 04:25:41 +03:00
|
|
|
if (ShouldPartitionStorage(access) &&
|
|
|
|
!StoragePartitioningEnabled(access,
|
|
|
|
aWindow->GetExtantDoc()->CookieSettings())) {
|
2014-12-17 09:26:15 +03:00
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(aWindow);
|
|
|
|
MOZ_ASSERT(sop);
|
|
|
|
|
2019-04-12 08:31:13 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> principal = sop->GetEffectiveStoragePrincipal();
|
2014-12-17 09:26:15 +03:00
|
|
|
if (NS_WARN_IF(!principal)) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
2019-12-05 07:44:32 +03:00
|
|
|
if (principal->IsSystemPrincipal()) {
|
2019-12-19 12:56:12 +03:00
|
|
|
*aPrincipal = std::move(principal);
|
2015-06-11 16:32:54 +03:00
|
|
|
return NS_OK;
|
2014-12-17 09:26:15 +03:00
|
|
|
}
|
|
|
|
|
2015-07-16 00:01:02 +03:00
|
|
|
// About URIs shouldn't be able to access IndexedDB unless they have the
|
|
|
|
// nsIAboutModule::ENABLE_INDEXED_DB flag set on them.
|
2014-12-17 09:26:15 +03:00
|
|
|
|
2019-09-26 13:47:16 +03:00
|
|
|
if (principal->SchemeIs("about")) {
|
2019-10-17 16:54:41 +03:00
|
|
|
uint32_t flags;
|
|
|
|
if (NS_SUCCEEDED(principal->GetAboutModuleFlags(&flags))) {
|
|
|
|
if (!(flags & nsIAboutModule::ENABLE_INDEXED_DB)) {
|
2015-07-16 00:01:02 +03:00
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
2014-12-17 09:26:15 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 16:22:28 +03:00
|
|
|
if (aPrincipal) {
|
2019-12-19 12:56:12 +03:00
|
|
|
*aPrincipal = std::move(principal);
|
2019-11-08 16:22:28 +03:00
|
|
|
}
|
2014-12-17 09:26:15 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-06-11 16:32:54 +03:00
|
|
|
// static
|
|
|
|
bool IDBFactory::AllowedForPrincipal(nsIPrincipal* aPrincipal,
|
|
|
|
bool* aIsSystemPrincipal) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aPrincipal);
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!IndexedDatabaseManager::GetOrCreate())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-12-05 07:44:32 +03:00
|
|
|
if (aPrincipal->IsSystemPrincipal()) {
|
2015-06-11 16:32:54 +03:00
|
|
|
if (aIsSystemPrincipal) {
|
|
|
|
*aIsSystemPrincipal = true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-11-08 16:22:28 +03:00
|
|
|
if (aIsSystemPrincipal) {
|
|
|
|
*aIsSystemPrincipal = false;
|
2015-06-11 16:32:54 +03:00
|
|
|
}
|
|
|
|
|
2019-11-08 16:22:28 +03:00
|
|
|
return !aPrincipal->GetIsNullPrincipal();
|
2015-06-11 16:32:54 +03:00
|
|
|
}
|
|
|
|
|
2017-06-16 14:06:36 +03:00
|
|
|
void IDBFactory::UpdateActiveTransactionCount(int32_t aDelta) {
|
|
|
|
AssertIsOnOwningThread();
|
2018-04-16 16:08:52 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aDelta > 0 || (mActiveTransactionCount + aDelta) <
|
|
|
|
mActiveTransactionCount);
|
|
|
|
mActiveTransactionCount += aDelta;
|
2017-06-16 14:06:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void IDBFactory::UpdateActiveDatabaseCount(int32_t aDelta) {
|
|
|
|
AssertIsOnOwningThread();
|
2018-04-16 16:08:52 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aDelta > 0 ||
|
|
|
|
(mActiveDatabaseCount + aDelta) < mActiveDatabaseCount);
|
|
|
|
mActiveDatabaseCount += aDelta;
|
2019-03-29 21:05:11 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(mGlobal);
|
|
|
|
if (window) {
|
|
|
|
window->UpdateActiveIndexedDBDatabaseCount(aDelta);
|
2017-06-16 14:06:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-14 05:20:38 +03:00
|
|
|
bool IDBFactory::IsChrome() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mPrincipalInfo);
|
|
|
|
|
|
|
|
return mPrincipalInfo->type() == PrincipalInfo::TSystemPrincipalInfo;
|
|
|
|
}
|
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
void IDBFactory::IncrementParentLoggingRequestSerialNumber() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mBackgroundActor);
|
|
|
|
|
|
|
|
mBackgroundActor->SendIncrementLoggingRequestSerialNumber();
|
|
|
|
}
|
|
|
|
|
2019-12-19 12:23:55 +03:00
|
|
|
RefPtr<IDBOpenDBRequest> IDBFactory::Open(JSContext* aCx,
|
|
|
|
const nsAString& aName,
|
|
|
|
uint64_t aVersion,
|
|
|
|
CallerType aCallerType,
|
|
|
|
ErrorResult& aRv) {
|
2016-03-23 18:02:57 +03:00
|
|
|
return OpenInternal(aCx,
|
|
|
|
/* aPrincipal */ nullptr, aName,
|
2014-09-27 03:21:57 +04:00
|
|
|
Optional<uint64_t>(aVersion), Optional<StorageType>(),
|
|
|
|
/* aDeleting */ false, aCallerType, aRv);
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2019-12-19 12:23:55 +03:00
|
|
|
RefPtr<IDBOpenDBRequest> IDBFactory::Open(JSContext* aCx,
|
|
|
|
const nsAString& aName,
|
|
|
|
const IDBOpenDBOptions& aOptions,
|
|
|
|
CallerType aCallerType,
|
|
|
|
ErrorResult& aRv) {
|
2017-09-18 12:00:37 +03:00
|
|
|
if (!IsChrome() && aOptions.mStorage.WasPassed()) {
|
2019-03-29 21:05:11 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(mGlobal);
|
|
|
|
if (window && window->GetExtantDoc()) {
|
|
|
|
window->GetExtantDoc()->WarnOnceAbout(
|
2019-01-02 16:05:23 +03:00
|
|
|
Document::eIDBOpenDBOptions_StorageType);
|
2018-03-05 22:01:00 +03:00
|
|
|
} else if (!NS_IsMainThread()) {
|
|
|
|
// The method below reports on the main thread too, so we need to make
|
|
|
|
// sure we're on a worker. Workers don't have a WarnOnceAbout mechanism,
|
|
|
|
// so this will be reported every time.
|
|
|
|
WorkerPrivate::ReportErrorToConsole("IDBOpenDBOptions_StorageType");
|
|
|
|
}
|
2017-09-18 12:00:37 +03:00
|
|
|
}
|
|
|
|
|
2019-09-13 19:55:13 +03:00
|
|
|
// Ignore calls with empty options for telemetry of usage count.
|
|
|
|
// Unfortunately, we cannot distinguish between the use of the method with
|
|
|
|
// only a single argument (which actually is a standard overload we don't want
|
|
|
|
// to count) an empty dictionary passed explicitly (which is the custom
|
|
|
|
// overload we would like to count). However, we assume that the latter is so
|
|
|
|
// rare that it can be neglected.
|
|
|
|
if (aOptions.IsAnyMemberPresent()) {
|
|
|
|
Telemetry::AccumulateCategorical(IdentifyPrincipalType(*mPrincipalInfo));
|
|
|
|
}
|
2019-08-19 17:22:09 +03:00
|
|
|
|
2016-03-23 18:02:57 +03:00
|
|
|
return OpenInternal(aCx,
|
|
|
|
/* aPrincipal */ nullptr, aName, aOptions.mVersion,
|
2014-09-27 03:21:57 +04:00
|
|
|
aOptions.mStorage,
|
|
|
|
/* aDeleting */ false, aCallerType, aRv);
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2019-12-19 12:23:55 +03:00
|
|
|
RefPtr<IDBOpenDBRequest> IDBFactory::DeleteDatabase(
|
2014-09-27 03:21:57 +04:00
|
|
|
JSContext* aCx, const nsAString& aName, const IDBOpenDBOptions& aOptions,
|
2017-02-01 23:43:37 +03:00
|
|
|
CallerType aCallerType, ErrorResult& aRv) {
|
2016-03-23 18:02:57 +03:00
|
|
|
return OpenInternal(aCx,
|
|
|
|
/* aPrincipal */ nullptr, aName, Optional<uint64_t>(),
|
2014-09-27 03:21:57 +04:00
|
|
|
aOptions.mStorage,
|
|
|
|
/* aDeleting */ true, aCallerType, aRv);
|
|
|
|
}
|
2013-04-08 23:47:13 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
int16_t IDBFactory::Cmp(JSContext* aCx, JS::Handle<JS::Value> aFirst,
|
|
|
|
JS::Handle<JS::Value> aSecond, ErrorResult& aRv) {
|
|
|
|
Key first, second;
|
2019-07-29 12:05:44 +03:00
|
|
|
auto result = first.SetFromJSVal(aCx, aFirst, aRv);
|
|
|
|
if (!result.Is(Ok, aRv)) {
|
|
|
|
if (result.Is(Invalid, aRv)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2013-04-08 23:47:13 +04:00
|
|
|
|
2019-07-29 12:05:44 +03:00
|
|
|
result = second.SetFromJSVal(aCx, aSecond, aRv);
|
|
|
|
if (!result.Is(Ok, aRv)) {
|
|
|
|
if (result.Is(Invalid, aRv)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (first.IsUnset() || second.IsUnset()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
|
|
|
|
return 0;
|
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return Key::CompareKeys(first, second);
|
2013-04-08 23:47:13 +04:00
|
|
|
}
|
|
|
|
|
2019-12-19 12:23:55 +03:00
|
|
|
RefPtr<IDBOpenDBRequest> IDBFactory::OpenForPrincipal(
|
2016-03-23 18:02:57 +03:00
|
|
|
JSContext* aCx, nsIPrincipal* aPrincipal, const nsAString& aName,
|
2017-02-01 23:43:37 +03:00
|
|
|
uint64_t aVersion, SystemCallerGuarantee aGuarantee, ErrorResult& aRv) {
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aPrincipal);
|
|
|
|
if (!NS_IsMainThread()) {
|
2017-02-01 23:43:37 +03:00
|
|
|
MOZ_CRASH(
|
|
|
|
"Figure out security checks for workers! What's this aPrincipal "
|
|
|
|
"we have on a worker thread?");
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return OpenInternal(aCx, aPrincipal, aName, Optional<uint64_t>(aVersion),
|
|
|
|
Optional<StorageType>(),
|
|
|
|
/* aDeleting */ false, aGuarantee, aRv);
|
2011-12-20 14:59:07 +04:00
|
|
|
}
|
|
|
|
|
2019-12-19 12:23:55 +03:00
|
|
|
RefPtr<IDBOpenDBRequest> IDBFactory::OpenForPrincipal(
|
2016-03-23 18:02:57 +03:00
|
|
|
JSContext* aCx, nsIPrincipal* aPrincipal, const nsAString& aName,
|
2017-02-01 23:43:37 +03:00
|
|
|
const IDBOpenDBOptions& aOptions, SystemCallerGuarantee aGuarantee,
|
2014-09-27 03:21:57 +04:00
|
|
|
ErrorResult& aRv) {
|
|
|
|
MOZ_ASSERT(aPrincipal);
|
|
|
|
if (!NS_IsMainThread()) {
|
2017-02-01 23:43:37 +03:00
|
|
|
MOZ_CRASH(
|
|
|
|
"Figure out security checks for workers! What's this aPrincipal "
|
|
|
|
"we have on a worker thread?");
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
2016-03-23 18:02:57 +03:00
|
|
|
return OpenInternal(aCx, aPrincipal, aName, aOptions.mVersion,
|
2014-09-27 03:21:57 +04:00
|
|
|
aOptions.mStorage,
|
|
|
|
/* aDeleting */ false, aGuarantee, aRv);
|
2014-09-13 20:12:19 +04:00
|
|
|
}
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2019-12-19 12:23:55 +03:00
|
|
|
RefPtr<IDBOpenDBRequest> IDBFactory::DeleteForPrincipal(
|
2016-03-23 18:02:57 +03:00
|
|
|
JSContext* aCx, nsIPrincipal* aPrincipal, const nsAString& aName,
|
2017-02-01 23:43:37 +03:00
|
|
|
const IDBOpenDBOptions& aOptions, SystemCallerGuarantee aGuarantee,
|
2014-09-27 03:21:57 +04:00
|
|
|
ErrorResult& aRv) {
|
|
|
|
MOZ_ASSERT(aPrincipal);
|
|
|
|
if (!NS_IsMainThread()) {
|
2017-02-01 23:43:37 +03:00
|
|
|
MOZ_CRASH(
|
|
|
|
"Figure out security checks for workers! What's this aPrincipal "
|
|
|
|
"we have on a worker thread?");
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
2016-03-23 18:02:57 +03:00
|
|
|
return OpenInternal(aCx, aPrincipal, aName, Optional<uint64_t>(),
|
2014-09-27 03:21:57 +04:00
|
|
|
aOptions.mStorage,
|
|
|
|
/* aDeleting */ true, aGuarantee, aRv);
|
|
|
|
}
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2019-12-19 12:23:55 +03:00
|
|
|
RefPtr<IDBOpenDBRequest> IDBFactory::OpenInternal(
|
2016-03-23 18:02:57 +03:00
|
|
|
JSContext* aCx, nsIPrincipal* aPrincipal, const nsAString& aName,
|
2014-09-27 03:21:57 +04:00
|
|
|
const Optional<uint64_t>& aVersion,
|
|
|
|
const Optional<StorageType>& aStorageType, bool aDeleting,
|
2017-02-01 23:43:37 +03:00
|
|
|
CallerType aCallerType, ErrorResult& aRv) {
|
2020-01-23 12:27:47 +03:00
|
|
|
if (NS_WARN_IF(!mGlobal)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
CommonFactoryRequestParams commonParams;
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
PrincipalInfo& principalInfo = commonParams.principalInfo();
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (aPrincipal) {
|
|
|
|
if (!NS_IsMainThread()) {
|
2017-02-01 23:43:37 +03:00
|
|
|
MOZ_CRASH(
|
|
|
|
"Figure out security checks for workers! What's this "
|
|
|
|
"aPrincipal we have on a worker thread?");
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
2017-02-01 23:43:37 +03:00
|
|
|
MOZ_ASSERT(aCallerType == CallerType::System);
|
2016-11-17 14:14:00 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mPrivateBrowsingMode ==
|
|
|
|
(aPrincipal->GetPrivateBrowsingId() > 0));
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
if (NS_WARN_IF(
|
|
|
|
NS_FAILED(PrincipalToPrincipalInfo(aPrincipal, &principalInfo)))) {
|
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (principalInfo.type() != PrincipalInfo::TContentPrincipalInfo &&
|
|
|
|
principalInfo.type() != PrincipalInfo::TSystemPrincipalInfo) {
|
2014-09-27 03:21:57 +04:00
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-02-23 19:03:40 +03:00
|
|
|
|
|
|
|
if (NS_WARN_IF(!QuotaManager::IsPrincipalInfoValid(principalInfo))) {
|
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
} else {
|
|
|
|
principalInfo = *mPrincipalInfo;
|
|
|
|
}
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
uint64_t version = 0;
|
|
|
|
if (!aDeleting && aVersion.WasPassed()) {
|
|
|
|
if (aVersion.Value() < 1) {
|
2019-09-20 05:19:18 +03:00
|
|
|
aRv.ThrowTypeError(u"0 (Zero) is not a valid database version.");
|
2014-09-27 03:21:57 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
version = aVersion.Value();
|
|
|
|
}
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// Nothing can be done here if we have previously failed to create a
|
|
|
|
// background actor.
|
|
|
|
if (mBackgroundActorFailed) {
|
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-06-22 02:27:13 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
PersistenceType persistenceType;
|
|
|
|
|
2018-03-15 12:35:05 +03:00
|
|
|
bool isInternal = principalInfo.type() == PrincipalInfo::TSystemPrincipalInfo;
|
|
|
|
if (!isInternal &&
|
|
|
|
principalInfo.type() == PrincipalInfo::TContentPrincipalInfo) {
|
|
|
|
nsCString origin =
|
|
|
|
principalInfo.get_ContentPrincipalInfo().originNoSuffix();
|
|
|
|
isInternal = QuotaManager::IsOriginInternal(origin);
|
|
|
|
}
|
|
|
|
|
2018-04-11 00:00:30 +03:00
|
|
|
// Allow storage attributes for add-ons independent of the pref.
|
|
|
|
// This works in the main thread only, workers don't have the principal.
|
|
|
|
bool isAddon = false;
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
// aPrincipal is passed inconsistently, so even when we are already on
|
|
|
|
// the main thread, we may have been passed a null aPrincipal.
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = PrincipalInfoToPrincipal(principalInfo);
|
|
|
|
if (principal) {
|
|
|
|
nsAutoString addonId;
|
|
|
|
Unused << NS_WARN_IF(NS_FAILED(principal->GetAddonId(addonId)));
|
|
|
|
isAddon = !addonId.IsEmpty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-15 12:35:05 +03:00
|
|
|
if (isInternal) {
|
|
|
|
// Chrome privilege and internal origins always get persistent storage.
|
2014-09-27 03:21:57 +04:00
|
|
|
persistenceType = PERSISTENCE_TYPE_PERSISTENT;
|
2018-09-10 21:36:17 +03:00
|
|
|
} else if (isAddon || StaticPrefs::dom_indexedDB_storageOption_enabled()) {
|
2014-11-04 23:44:56 +03:00
|
|
|
persistenceType = PersistenceTypeFromStorage(aStorageType);
|
2018-04-11 00:00:30 +03:00
|
|
|
} else {
|
|
|
|
persistenceType = PERSISTENCE_TYPE_DEFAULT;
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DatabaseMetadata& metadata = commonParams.metadata();
|
|
|
|
metadata.name() = aName;
|
|
|
|
metadata.persistenceType() = persistenceType;
|
|
|
|
|
|
|
|
FactoryRequestParams params;
|
|
|
|
if (aDeleting) {
|
|
|
|
metadata.version() = 0;
|
|
|
|
params = DeleteDatabaseRequestParams(commonParams);
|
|
|
|
} else {
|
|
|
|
metadata.version() = version;
|
|
|
|
params = OpenDatabaseRequestParams(commonParams);
|
|
|
|
}
|
|
|
|
|
2017-10-24 13:02:41 +03:00
|
|
|
if (!mBackgroundActor) {
|
2014-10-16 08:56:52 +04:00
|
|
|
BackgroundChildImpl::ThreadLocal* threadLocal =
|
|
|
|
BackgroundChildImpl::GetThreadLocalForCurrentThread();
|
|
|
|
|
|
|
|
nsAutoPtr<ThreadLocal> newIDBThreadLocal;
|
|
|
|
ThreadLocal* idbThreadLocal;
|
|
|
|
|
|
|
|
if (threadLocal && threadLocal->mIndexedDBThreadLocal) {
|
|
|
|
idbThreadLocal = threadLocal->mIndexedDBThreadLocal;
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIUUIDGenerator> uuidGen =
|
|
|
|
do_GetService("@mozilla.org/uuid-generator;1");
|
|
|
|
MOZ_ASSERT(uuidGen);
|
|
|
|
|
|
|
|
nsID id;
|
2016-03-28 20:28:15 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(uuidGen->GenerateUUIDInPlace(&id));
|
2014-10-16 08:56:52 +04:00
|
|
|
|
|
|
|
newIDBThreadLocal = idbThreadLocal = new ThreadLocal(id);
|
|
|
|
}
|
|
|
|
|
2017-10-24 13:02:41 +03:00
|
|
|
PBackgroundChild* backgroundActor =
|
|
|
|
BackgroundChild::GetOrCreateForCurrentThread();
|
|
|
|
if (NS_WARN_IF(!backgroundActor)) {
|
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
BackgroundFactoryChild* actor = new BackgroundFactoryChild(this);
|
|
|
|
|
|
|
|
// Set EventTarget for the top-level actor.
|
|
|
|
// All child actors created later inherit the same event target.
|
|
|
|
backgroundActor->SetEventTargetForActor(actor, EventTarget());
|
|
|
|
MOZ_ASSERT(actor->GetActorEventTarget());
|
|
|
|
mBackgroundActor = static_cast<BackgroundFactoryChild*>(
|
|
|
|
backgroundActor->SendPBackgroundIDBFactoryConstructor(
|
|
|
|
actor, idbThreadLocal->GetLoggingInfo()));
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!mBackgroundActor)) {
|
|
|
|
mBackgroundActorFailed = true;
|
2015-11-25 05:57:07 +03:00
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-10-16 08:56:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (newIDBThreadLocal) {
|
|
|
|
if (!threadLocal) {
|
|
|
|
threadLocal = BackgroundChildImpl::GetThreadLocalForCurrentThread();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
2014-10-16 08:56:52 +04:00
|
|
|
MOZ_ASSERT(threadLocal);
|
|
|
|
MOZ_ASSERT(!threadLocal->mIndexedDBThreadLocal);
|
|
|
|
|
2019-12-19 12:56:25 +03:00
|
|
|
threadLocal->mIndexedDBThreadLocal = std::move(newIDBThreadLocal);
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
}
|
2011-12-20 14:59:07 +04:00
|
|
|
|
2019-03-29 21:05:11 +03:00
|
|
|
RefPtr<IDBOpenDBRequest> request =
|
|
|
|
IDBOpenDBRequest::Create(aCx, this, mGlobal);
|
|
|
|
if (!request) {
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
aRv.ThrowUncatchableException();
|
|
|
|
return nullptr;
|
2010-10-19 21:58:52 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(request);
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
if (aDeleting) {
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_REQUEST(
|
|
|
|
"indexedDB.deleteDatabase(\"%s\")", "IDBFactory.deleteDatabase()",
|
|
|
|
request->LoggingSerialNumber(), NS_ConvertUTF16toUTF8(aName).get());
|
2014-10-16 08:56:52 +04:00
|
|
|
} else {
|
2019-09-27 13:11:45 +03:00
|
|
|
IDB_LOG_MARK_CHILD_REQUEST(
|
|
|
|
"indexedDB.open(\"%s\", %s)", "IDBFactory.open()",
|
2014-10-16 08:56:52 +04:00
|
|
|
request->LoggingSerialNumber(), NS_ConvertUTF16toUTF8(aName).get(),
|
|
|
|
IDB_LOG_STRINGIFY(aVersion));
|
|
|
|
}
|
|
|
|
|
2017-10-24 13:02:41 +03:00
|
|
|
nsresult rv = InitiateRequest(request, params);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2019-12-19 12:23:55 +03:00
|
|
|
return request;
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult IDBFactory::InitiateRequest(IDBOpenDBRequest* aRequest,
|
|
|
|
const FactoryRequestParams& aParams) {
|
|
|
|
MOZ_ASSERT(aRequest);
|
|
|
|
MOZ_ASSERT(mBackgroundActor);
|
|
|
|
MOZ_ASSERT(!mBackgroundActorFailed);
|
|
|
|
|
|
|
|
bool deleting;
|
|
|
|
uint64_t requestedVersion;
|
|
|
|
|
|
|
|
switch (aParams.type()) {
|
|
|
|
case FactoryRequestParams::TDeleteDatabaseRequestParams: {
|
|
|
|
const DatabaseMetadata& metadata =
|
|
|
|
aParams.get_DeleteDatabaseRequestParams().commonParams().metadata();
|
|
|
|
deleting = true;
|
|
|
|
requestedVersion = metadata.version();
|
|
|
|
break;
|
|
|
|
}
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
case FactoryRequestParams::TOpenDatabaseRequestParams: {
|
|
|
|
const DatabaseMetadata& metadata =
|
|
|
|
aParams.get_OpenDatabaseRequestParams().commonParams().metadata();
|
|
|
|
deleting = false;
|
|
|
|
requestedVersion = metadata.version();
|
|
|
|
break;
|
2010-10-19 21:58:52 +04:00
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Should never get here!");
|
|
|
|
}
|
|
|
|
|
|
|
|
auto actor = new BackgroundFactoryRequestChild(this, aRequest, deleting,
|
|
|
|
requestedVersion);
|
|
|
|
|
|
|
|
if (!mBackgroundActor->SendPBackgroundIDBFactoryRequestConstructor(actor,
|
|
|
|
aParams)) {
|
|
|
|
aRequest->DispatchNonTransactionError(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
2010-10-19 21:58:52 +04:00
|
|
|
}
|
|
|
|
|
2017-02-10 10:13:45 +03:00
|
|
|
MOZ_ASSERT(actor->GetActorEventTarget(),
|
|
|
|
"The event target shall be inherited from its manager actor.");
|
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-03-29 21:05:11 +03:00
|
|
|
void IDBFactory::DisconnectFromGlobal(nsIGlobalObject* aOldGlobal) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aOldGlobal);
|
|
|
|
// If CC unlinks us first, then mGlobal might be nullptr
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mGlobal || mGlobal == aOldGlobal);
|
2018-04-16 16:08:53 +03:00
|
|
|
|
2019-03-29 21:05:11 +03:00
|
|
|
mGlobal = nullptr;
|
2018-04-16 16:08:53 +03:00
|
|
|
}
|
|
|
|
|
2012-01-24 14:03:37 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(IDBFactory)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(IDBFactory)
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-01-24 14:03:37 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IDBFactory)
|
2013-03-31 12:18:30 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2010-09-10 02:15:38 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2010-06-23 23:46:08 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBFactory)
|
|
|
|
|
2012-01-24 14:03:37 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(IDBFactory)
|
2019-03-29 21:05:11 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobal)
|
2019-04-10 01:39:01 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBrowserChild)
|
2018-11-15 16:46:18 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEventTarget)
|
2012-01-24 14:03:37 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBFactory)
|
2013-03-31 12:18:30 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
2019-03-29 21:05:11 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGlobal)
|
2019-04-10 01:39:01 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mBrowserChild)
|
2018-11-15 16:46:18 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mEventTarget)
|
2012-01-24 14:03:37 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBFactory)
|
2013-03-31 12:18:30 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
2012-01-24 14:03:37 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
JSObject* IDBFactory::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return IDBFactory_Binding::Wrap(aCx, this, aGivenProto);
|
2013-03-31 12:18:30 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|