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"
|
|
|
|
#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"
|
2012-07-14 15:24:20 +04:00
|
|
|
#include "mozilla/dom/TabChild.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"
|
2017-09-18 12:00:37 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2014-12-17 09:26:15 +03:00
|
|
|
#include "mozIThirdPartyUtil.h"
|
|
|
|
#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"
|
|
|
|
#include "nsIPrincipal.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 {
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const char kPrefIndexedDBEnabled[] = "dom.indexedDB.enabled";
|
|
|
|
|
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()
|
2014-09-27 03:21:57 +04:00
|
|
|
: mOwningObject(nullptr)
|
|
|
|
, mBackgroundActor(nullptr)
|
2014-11-14 05:20:38 +03:00
|
|
|
, mInnerWindowID(0)
|
2014-09-27 03:21:57 +04:00
|
|
|
, mBackgroundActorFailed(false)
|
|
|
|
, mPrivateBrowsingMode(false)
|
2011-04-30 03:46:20 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
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);
|
|
|
|
|
2014-11-05 11:44:26 +03:00
|
|
|
mOwningObject = nullptr;
|
|
|
|
mozilla::DropJSObjects(this);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
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
|
2012-06-01 21:21:12 +04:00
|
|
|
nsresult
|
2016-01-30 20:05:36 +03:00
|
|
|
IDBFactory::CreateForWindow(nsPIDOMWindowInner* aWindow,
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBFactory** aFactory)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
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;
|
|
|
|
nsresult rv = AllowedForWindowInternal(aWindow, getter_AddRefs(principal));
|
|
|
|
|
|
|
|
if (!(NS_SUCCEEDED(rv) && nsContentUtils::IsSystemPrincipal(principal)) &&
|
|
|
|
NS_WARN_IF(!Preferences::GetBool(kPrefIndexedDBEnabled, false))) {
|
2014-09-27 03:21:57 +04:00
|
|
|
*aFactory = nullptr;
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
2014-09-13 20:12:19 +04:00
|
|
|
}
|
2012-06-01 21:21:12 +04: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
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
nsAutoPtr<PrincipalInfo> principalInfo(new PrincipalInfo());
|
|
|
|
rv = PrincipalToPrincipalInfo(principal, principalInfo);
|
|
|
|
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);
|
|
|
|
|
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();
|
2014-09-27 03:21:57 +04:00
|
|
|
factory->mPrincipalInfo = Move(principalInfo);
|
|
|
|
factory->mWindow = aWindow;
|
|
|
|
factory->mTabChild = TabChild::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
|
2012-06-01 21:21:12 +04:00
|
|
|
nsresult
|
2015-07-02 23:30:15 +03:00
|
|
|
IDBFactory::CreateForMainThreadJS(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aOwningObject,
|
|
|
|
IDBFactory** aFactory)
|
2012-01-24 14:03:37 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2011-01-27 04:53:02 +03:00
|
|
|
|
2015-07-02 23:30:15 +03:00
|
|
|
nsAutoPtr<PrincipalInfo> principalInfo(new PrincipalInfo());
|
|
|
|
nsIPrincipal* principal = nsContentUtils::ObjectPrincipal(aOwningObject);
|
|
|
|
MOZ_ASSERT(principal);
|
|
|
|
bool isSystem;
|
|
|
|
if (!AllowedForPrincipal(principal, &isSystem)) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2015-07-02 23:30:15 +03:00
|
|
|
nsresult rv = PrincipalToPrincipalInfo(principal, principalInfo);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = CreateForMainThreadJSInternal(aCx, aOwningObject, 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
|
|
|
|
nsresult
|
2014-12-17 09:26:15 +03:00
|
|
|
IDBFactory::CreateForWorker(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aOwningObject,
|
|
|
|
const PrincipalInfo& aPrincipalInfo,
|
|
|
|
uint64_t aInnerWindowID,
|
|
|
|
IDBFactory** aFactory)
|
2012-07-14 15:24:20 +04:00
|
|
|
{
|
2014-12-17 09:26:15 +03:00
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aPrincipalInfo.type() != PrincipalInfo::T__None);
|
2012-07-14 15:24:20 +04:00
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
nsAutoPtr<PrincipalInfo> principalInfo(new PrincipalInfo(aPrincipalInfo));
|
|
|
|
|
|
|
|
nsresult rv =
|
|
|
|
CreateForJSInternal(aCx,
|
|
|
|
aOwningObject,
|
|
|
|
principalInfo,
|
|
|
|
aInnerWindowID,
|
|
|
|
aFactory);
|
|
|
|
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
|
|
|
MOZ_ASSERT(!principalInfo);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsresult
|
|
|
|
IDBFactory::CreateForMainThreadJSInternal(
|
|
|
|
JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aOwningObject,
|
|
|
|
nsAutoPtr<PrincipalInfo>& aPrincipalInfo,
|
|
|
|
IDBFactory** aFactory)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-06 02:08:12 +03:00
|
|
|
MOZ_ASSERT(aPrincipalInfo);
|
2014-12-17 09:26:15 +03:00
|
|
|
|
2015-01-06 02:08:12 +03:00
|
|
|
if (aPrincipalInfo->type() != PrincipalInfo::TSystemPrincipalInfo &&
|
|
|
|
NS_WARN_IF(!Preferences::GetBool(kPrefIndexedDBEnabled, false))) {
|
2014-09-27 03:21:57 +04:00
|
|
|
*aFactory = nullptr;
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
|
|
|
}
|
2014-09-18 03:36:01 +04: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
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
nsresult rv =
|
|
|
|
CreateForJSInternal(aCx,
|
|
|
|
aOwningObject,
|
|
|
|
aPrincipalInfo,
|
|
|
|
/* aInnerWindowID */ 0,
|
|
|
|
aFactory);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsresult
|
|
|
|
IDBFactory::CreateForJSInternal(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aOwningObject,
|
|
|
|
nsAutoPtr<PrincipalInfo>& aPrincipalInfo,
|
|
|
|
uint64_t aInnerWindowID,
|
|
|
|
IDBFactory** aFactory)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aCx);
|
|
|
|
MOZ_ASSERT(aOwningObject);
|
|
|
|
MOZ_ASSERT(aPrincipalInfo);
|
|
|
|
MOZ_ASSERT(aPrincipalInfo->type() != PrincipalInfo::T__None);
|
|
|
|
MOZ_ASSERT(aFactory);
|
|
|
|
MOZ_ASSERT(JS_GetGlobalForObject(aCx, aOwningObject) == aOwningObject,
|
|
|
|
"Not a global object!");
|
|
|
|
|
|
|
|
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();
|
2014-09-27 03:21:57 +04:00
|
|
|
factory->mPrincipalInfo = aPrincipalInfo.forget();
|
|
|
|
factory->mOwningObject = aOwningObject;
|
2013-08-17 00:10:17 +04:00
|
|
|
mozilla::HoldJSObjects(factory.get());
|
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
|
|
|
|
bool
|
2016-01-30 20:05:36 +03:00
|
|
|
IDBFactory::AllowedForWindow(nsPIDOMWindowInner* aWindow)
|
2014-12-17 09:26:15 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aWindow);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
nsresult rv = AllowedForWindowInternal(aWindow, getter_AddRefs(principal));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsresult
|
2016-01-30 20:05:36 +03:00
|
|
|
IDBFactory::AllowedForWindowInternal(nsPIDOMWindowInner* aWindow,
|
2014-12-17 09:26:15 +03:00
|
|
|
nsIPrincipal** aPrincipal)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aWindow);
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!IndexedDatabaseManager::GetOrCreate())) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
2015-07-16 00:01:02 +03:00
|
|
|
nsContentUtils::StorageAccess access =
|
|
|
|
nsContentUtils::StorageAllowedForWindow(aWindow);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
if (access == nsContentUtils::StorageAccess::eDeny) {
|
2014-12-17 09:26:15 +03:00
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(aWindow);
|
|
|
|
MOZ_ASSERT(sop);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = sop->GetPrincipal();
|
|
|
|
if (NS_WARN_IF(!principal)) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-16 00:01:02 +03:00
|
|
|
if (nsContentUtils::IsSystemPrincipal(principal)) {
|
2015-06-11 16:32:54 +03:00
|
|
|
principal.forget(aPrincipal);
|
|
|
|
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
|
|
|
nsCOMPtr<nsIURI> uri;
|
2016-03-28 20:28:15 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(principal->GetURI(getter_AddRefs(uri)));
|
2015-07-16 00:01:02 +03:00
|
|
|
MOZ_ASSERT(uri);
|
2014-12-17 09:26:15 +03:00
|
|
|
|
2015-07-16 00:01:02 +03:00
|
|
|
bool isAbout = false;
|
2016-03-28 20:28:15 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(uri->SchemeIs("about", &isAbout));
|
2014-12-17 09:26:15 +03:00
|
|
|
|
|
|
|
if (isAbout) {
|
|
|
|
nsCOMPtr<nsIAboutModule> module;
|
|
|
|
if (NS_SUCCEEDED(NS_GetAboutModule(uri, getter_AddRefs(module)))) {
|
|
|
|
uint32_t flags;
|
|
|
|
if (NS_SUCCEEDED(module->GetURIFlags(uri, &flags))) {
|
2015-07-16 00:01:02 +03:00
|
|
|
if (!(flags & nsIAboutModule::ENABLE_INDEXED_DB)) {
|
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
|
|
|
}
|
2014-12-17 09:26:15 +03:00
|
|
|
} else {
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
principal.forget(aPrincipal);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsContentUtils::IsSystemPrincipal(aPrincipal)) {
|
|
|
|
if (aIsSystemPrincipal) {
|
|
|
|
*aIsSystemPrincipal = true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else if (aIsSystemPrincipal) {
|
|
|
|
*aIsSystemPrincipal = false;
|
|
|
|
}
|
|
|
|
|
2016-08-12 08:19:29 +03:00
|
|
|
if (aPrincipal->GetIsNullPrincipal()) {
|
2015-06-11 16:32:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-16 14:06:36 +03:00
|
|
|
void
|
|
|
|
IDBFactory::UpdateActiveTransactionCount(int32_t aDelta)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
if (mWindow) {
|
|
|
|
mWindow->UpdateActiveIndexedDBTransactionCount(aDelta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IDBFactory::UpdateActiveDatabaseCount(int32_t aDelta)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
if (mWindow) {
|
|
|
|
mWindow->UpdateActiveIndexedDBDatabaseCount(aDelta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
2016-03-23 18:02:57 +03:00
|
|
|
IDBFactory::Open(JSContext* aCx,
|
|
|
|
const nsAString& aName,
|
2014-09-27 03:21:57 +04:00
|
|
|
uint64_t aVersion,
|
2017-02-01 23:43:37 +03:00
|
|
|
CallerType aCallerType,
|
2014-09-27 03:21:57 +04:00
|
|
|
ErrorResult& aRv)
|
2014-09-13 20:12:19 +04:00
|
|
|
{
|
2016-03-23 18:02:57 +03:00
|
|
|
return OpenInternal(aCx,
|
|
|
|
/* aPrincipal */ nullptr,
|
2014-09-27 03:21:57 +04:00
|
|
|
aName,
|
|
|
|
Optional<uint64_t>(aVersion),
|
|
|
|
Optional<StorageType>(),
|
|
|
|
/* aDeleting */ false,
|
2017-02-01 23:43:37 +03:00
|
|
|
aCallerType,
|
2014-09-27 03:21:57 +04:00
|
|
|
aRv);
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
2016-03-23 18:02:57 +03:00
|
|
|
IDBFactory::Open(JSContext* aCx,
|
|
|
|
const nsAString& aName,
|
2014-09-27 03:21:57 +04:00
|
|
|
const IDBOpenDBOptions& aOptions,
|
2017-02-01 23:43:37 +03:00
|
|
|
CallerType aCallerType,
|
2014-09-27 03:21:57 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2017-09-18 12:00:37 +03:00
|
|
|
if (!IsChrome() &&
|
|
|
|
aOptions.mStorage.WasPassed()) {
|
|
|
|
switch (aOptions.mStorage.Value()) {
|
|
|
|
case StorageType::Persistent: {
|
|
|
|
Telemetry::ScalarAdd(Telemetry::ScalarID::IDB_TYPE_PERSISTENT_COUNT, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case StorageType::Temporary: {
|
|
|
|
Telemetry::ScalarAdd(Telemetry::ScalarID::IDB_TYPE_TEMPORARY_COUNT, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case StorageType::Default:
|
|
|
|
case StorageType::EndGuard_:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Invalid storage type!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-23 18:02:57 +03:00
|
|
|
return OpenInternal(aCx,
|
|
|
|
/* aPrincipal */ nullptr,
|
2014-09-27 03:21:57 +04:00
|
|
|
aName,
|
|
|
|
aOptions.mVersion,
|
|
|
|
aOptions.mStorage,
|
|
|
|
/* aDeleting */ false,
|
2017-02-01 23:43:37 +03:00
|
|
|
aCallerType,
|
2014-09-27 03:21:57 +04:00
|
|
|
aRv);
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
2016-03-23 18:02:57 +03:00
|
|
|
IDBFactory::DeleteDatabase(JSContext* aCx,
|
|
|
|
const nsAString& aName,
|
2014-09-27 03:21:57 +04:00
|
|
|
const IDBOpenDBOptions& aOptions,
|
2017-02-01 23:43:37 +03:00
|
|
|
CallerType aCallerType,
|
2014-09-27 03:21:57 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2016-03-23 18:02:57 +03:00
|
|
|
return OpenInternal(aCx,
|
|
|
|
/* aPrincipal */ nullptr,
|
2014-09-27 03:21:57 +04:00
|
|
|
aName,
|
|
|
|
Optional<uint64_t>(),
|
|
|
|
aOptions.mStorage,
|
|
|
|
/* aDeleting */ true,
|
2017-02-01 23:43:37 +03:00
|
|
|
aCallerType,
|
2014-09-27 03:21:57 +04:00
|
|
|
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;
|
|
|
|
nsresult rv = first.SetFromJSVal(aCx, aFirst);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return 0;
|
|
|
|
}
|
2013-04-08 23:47:13 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
rv = second.SetFromJSVal(aCx, aSecond);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
2016-03-23 18:02:57 +03:00
|
|
|
IDBFactory::OpenForPrincipal(JSContext* aCx,
|
|
|
|
nsIPrincipal* aPrincipal,
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsAString& aName,
|
|
|
|
uint64_t aVersion,
|
2017-02-01 23:43:37 +03:00
|
|
|
SystemCallerGuarantee aGuarantee,
|
2014-09-27 03:21:57 +04:00
|
|
|
ErrorResult& aRv)
|
2011-12-20 14:59:07 +04:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2016-03-23 18:02:57 +03:00
|
|
|
return OpenInternal(aCx,
|
|
|
|
aPrincipal,
|
2014-09-27 03:21:57 +04:00
|
|
|
aName,
|
|
|
|
Optional<uint64_t>(aVersion),
|
|
|
|
Optional<StorageType>(),
|
|
|
|
/* aDeleting */ false,
|
2017-02-01 23:43:37 +03:00
|
|
|
aGuarantee,
|
2014-09-27 03:21:57 +04:00
|
|
|
aRv);
|
2011-12-20 14:59:07 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
2016-03-23 18:02:57 +03:00
|
|
|
IDBFactory::OpenForPrincipal(JSContext* aCx,
|
|
|
|
nsIPrincipal* aPrincipal,
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsAString& aName,
|
|
|
|
const IDBOpenDBOptions& aOptions,
|
2017-02-01 23:43:37 +03:00
|
|
|
SystemCallerGuarantee aGuarantee,
|
2014-09-27 03:21:57 +04:00
|
|
|
ErrorResult& aRv)
|
2010-10-19 21:58:52 +04:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2016-03-23 18:02:57 +03:00
|
|
|
return OpenInternal(aCx,
|
|
|
|
aPrincipal,
|
2014-09-27 03:21:57 +04:00
|
|
|
aName,
|
|
|
|
aOptions.mVersion,
|
|
|
|
aOptions.mStorage,
|
|
|
|
/* aDeleting */ false,
|
2017-02-01 23:43:37 +03:00
|
|
|
aGuarantee,
|
2014-09-27 03:21:57 +04:00
|
|
|
aRv);
|
2014-09-13 20:12:19 +04:00
|
|
|
}
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
2016-03-23 18:02:57 +03:00
|
|
|
IDBFactory::DeleteForPrincipal(JSContext* aCx,
|
|
|
|
nsIPrincipal* aPrincipal,
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsAString& aName,
|
|
|
|
const IDBOpenDBOptions& aOptions,
|
2017-02-01 23:43:37 +03:00
|
|
|
SystemCallerGuarantee aGuarantee,
|
2014-09-27 03:21:57 +04:00
|
|
|
ErrorResult& aRv)
|
2014-09-13 20:12:19 +04:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2016-03-23 18:02:57 +03:00
|
|
|
return OpenInternal(aCx,
|
|
|
|
aPrincipal,
|
2014-09-27 03:21:57 +04:00
|
|
|
aName,
|
|
|
|
Optional<uint64_t>(),
|
|
|
|
aOptions.mStorage,
|
|
|
|
/* aDeleting */ true,
|
2017-02-01 23:43:37 +03:00
|
|
|
aGuarantee,
|
2014-09-27 03:21:57 +04:00
|
|
|
aRv);
|
|
|
|
}
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
2016-03-23 18:02:57 +03:00
|
|
|
IDBFactory::OpenInternal(JSContext* aCx,
|
|
|
|
nsIPrincipal* aPrincipal,
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsAString& aName,
|
|
|
|
const Optional<uint64_t>& aVersion,
|
|
|
|
const Optional<StorageType>& aStorageType,
|
|
|
|
bool aDeleting,
|
2017-02-01 23:43:37 +03:00
|
|
|
CallerType aCallerType,
|
2014-09-27 03:21:57 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mWindow || mOwningObject);
|
|
|
|
MOZ_ASSERT_IF(!mWindow, !mPrivateBrowsingMode);
|
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;
|
|
|
|
}
|
|
|
|
} 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) {
|
2015-10-05 19:38:14 +03:00
|
|
|
aRv.ThrowTypeError<MSG_INVALID_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;
|
|
|
|
|
|
|
|
if (principalInfo.type() == PrincipalInfo::TSystemPrincipalInfo) {
|
|
|
|
// Chrome privilege always gets persistent storage.
|
|
|
|
persistenceType = PERSISTENCE_TYPE_PERSISTENT;
|
|
|
|
} else {
|
2014-11-04 23:44:56 +03:00
|
|
|
persistenceType = PersistenceTypeFromStorage(aStorageType);
|
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);
|
|
|
|
|
|
|
|
threadLocal->mIndexedDBThreadLocal = newIDBThreadLocal.forget();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
}
|
2011-12-20 14:59:07 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBOpenDBRequest> request;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (mWindow) {
|
2016-03-23 18:02:57 +03:00
|
|
|
JS::Rooted<JSObject*> scriptOwner(aCx,
|
2017-11-04 01:25:38 +03:00
|
|
|
nsGlobalWindowInner::Cast(mWindow.get())->FastGetGlobalJSObject());
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(scriptOwner);
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2016-03-23 18:02:57 +03:00
|
|
|
request = IDBOpenDBRequest::CreateForWindow(aCx, this, mWindow, scriptOwner);
|
2014-09-27 03:21:57 +04:00
|
|
|
} else {
|
2016-03-23 18:02:57 +03:00
|
|
|
JS::Rooted<JSObject*> scriptOwner(aCx, mOwningObject);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2016-03-23 18:02:57 +03:00
|
|
|
request = IDBOpenDBRequest::CreateForJS(aCx, this, scriptOwner);
|
2015-06-22 22:13:38 +03:00
|
|
|
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) {
|
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Request[%llu]: "
|
|
|
|
"indexedDB.deleteDatabase(\"%s\")",
|
|
|
|
"IndexedDB %s: C R[%llu]: IDBFactory.deleteDatabase()",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
request->LoggingSerialNumber(),
|
|
|
|
NS_ConvertUTF16toUTF8(aName).get());
|
|
|
|
} else {
|
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Request[%llu]: "
|
|
|
|
"indexedDB.open(\"%s\", %s)",
|
|
|
|
"IndexedDB %s: C R[%llu]: IDBFactory.open()",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
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
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return request.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
|
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
|
2014-11-05 11:44:26 +03:00
|
|
|
tmp->mOwningObject = nullptr;
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
|
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-06-11 03:44:50 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mOwningObject)
|
2012-01-24 14:03:37 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2013-03-31 12:18:30 +04:00
|
|
|
JSObject*
|
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
|
|
|
IDBFactory::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2011-11-08 04:15:45 +04:00
|
|
|
{
|
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
|
|
|
return IDBFactoryBinding::Wrap(aCx, this, aGivenProto);
|
2013-03-31 12:18:30 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|