2010-06-23 19:46:08 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 19:32:37 +00:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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 19:46:08 +00:00
|
|
|
|
2016-02-16 21:46:08 +00:00
|
|
|
#ifndef mozilla_dom_idbfactory_h__
|
|
|
|
#define mozilla_dom_idbfactory_h__
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2017-02-01 20:43:37 +00:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2013-09-11 04:18:36 +00:00
|
|
|
#include "mozilla/dom/StorageTypeBinding.h"
|
2019-12-19 09:57:42 +00:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2013-09-06 06:43:23 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2012-01-24 10:03:37 +00:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2014-09-26 23:21:57 +00:00
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTArray.h"
|
2013-03-31 08:18:30 +00:00
|
|
|
#include "nsWrapperCache.h"
|
2011-01-27 01:53:02 +00:00
|
|
|
|
2019-03-29 18:05:11 +00:00
|
|
|
class nsIGlobalObject;
|
2017-01-13 08:40:58 +00:00
|
|
|
class nsIEventTarget;
|
2013-09-06 06:43:23 +00:00
|
|
|
class nsIPrincipal;
|
2016-01-30 17:05:36 +00:00
|
|
|
class nsPIDOMWindowInner;
|
2011-01-27 01:53:02 +00:00
|
|
|
|
2012-08-02 06:02:29 +00:00
|
|
|
namespace mozilla {
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2013-09-06 06:43:23 +00:00
|
|
|
class ErrorResult;
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
namespace ipc {
|
|
|
|
|
|
|
|
class PBackgroundChild;
|
|
|
|
class PrincipalInfo;
|
|
|
|
|
|
|
|
} // namespace ipc
|
|
|
|
|
2012-08-02 06:02:29 +00:00
|
|
|
namespace dom {
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2014-06-19 00:57:51 +00:00
|
|
|
struct IDBOpenDBOptions;
|
2016-02-16 21:46:08 +00:00
|
|
|
class IDBOpenDBRequest;
|
2014-12-17 06:26:15 +00:00
|
|
|
template <typename>
|
|
|
|
class Optional;
|
2019-04-09 22:39:01 +00:00
|
|
|
class BrowserChild;
|
2017-02-01 20:43:37 +00:00
|
|
|
enum class CallerType : uint32_t;
|
2012-08-02 06:02:29 +00:00
|
|
|
|
2013-09-06 06:43:23 +00:00
|
|
|
namespace indexedDB {
|
2014-09-26 23:21:57 +00:00
|
|
|
class BackgroundFactoryChild;
|
|
|
|
class FactoryRequestParams;
|
2014-10-16 04:56:52 +00:00
|
|
|
class LoggingInfo;
|
2016-02-16 21:46:08 +00:00
|
|
|
} // namespace indexedDB
|
2012-06-01 17:21:12 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
class IDBFactory final : public nsISupports, public nsWrapperCache {
|
|
|
|
typedef mozilla::dom::StorageType StorageType;
|
|
|
|
typedef mozilla::ipc::PBackgroundChild PBackgroundChild;
|
|
|
|
typedef mozilla::ipc::PrincipalInfo PrincipalInfo;
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
class BackgroundCreateCallback;
|
|
|
|
struct PendingRequestInfo;
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2019-12-19 09:57:42 +00:00
|
|
|
UniquePtr<PrincipalInfo> mPrincipalInfo;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2019-03-29 18:05:11 +00:00
|
|
|
nsCOMPtr<nsIGlobalObject> mGlobal;
|
2012-06-01 17:21:12 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
// This will only be set if the factory belongs to a window in a child
|
2012-07-14 11:24:20 +00:00
|
|
|
// process.
|
2019-04-09 22:39:01 +00:00
|
|
|
RefPtr<BrowserChild> mBrowserChild;
|
2013-04-08 19:47:13 +00:00
|
|
|
|
2016-02-16 21:46:08 +00:00
|
|
|
indexedDB::BackgroundFactoryChild* mBackgroundActor;
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2017-11-06 03:58:13 +00:00
|
|
|
// It is either set to a DocGroup-specific EventTarget if created by
|
|
|
|
// CreateForWindow() or set to GetCurrentThreadEventTarget() otherwise.
|
2017-01-13 08:40:58 +00:00
|
|
|
nsCOMPtr<nsIEventTarget> mEventTarget;
|
|
|
|
|
2014-11-14 02:20:38 +00:00
|
|
|
uint64_t mInnerWindowID;
|
2018-04-16 13:08:52 +00:00
|
|
|
uint32_t mActiveTransactionCount;
|
|
|
|
uint32_t mActiveDatabaseCount;
|
2014-11-14 02:20:38 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
bool mBackgroundActorFailed;
|
|
|
|
bool mPrivateBrowsingMode;
|
|
|
|
|
|
|
|
public:
|
2016-01-30 17:05:36 +00:00
|
|
|
static nsresult CreateForWindow(nsPIDOMWindowInner* aWindow,
|
2014-09-26 23:21:57 +00:00
|
|
|
IDBFactory** aFactory);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2019-03-29 18:05:11 +00:00
|
|
|
static nsresult CreateForMainThreadJS(nsIGlobalObject* aGlobal,
|
2015-07-02 20:30:15 +00:00
|
|
|
IDBFactory** aFactory);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2019-03-29 18:05:11 +00:00
|
|
|
static nsresult CreateForWorker(nsIGlobalObject* aGlobal,
|
2014-12-17 06:26:15 +00:00
|
|
|
const PrincipalInfo& aPrincipalInfo,
|
|
|
|
uint64_t aInnerWindowID,
|
|
|
|
IDBFactory** aFactory);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
static bool AllowedForWindow(nsPIDOMWindowInner* aWindow);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-06-11 13:32:54 +00:00
|
|
|
static bool AllowedForPrincipal(nsIPrincipal* aPrincipal,
|
|
|
|
bool* aIsSystemPrincipal = nullptr);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2017-06-07 05:55:00 +00:00
|
|
|
void AssertIsOnOwningThread() const { NS_ASSERT_OWNINGTHREAD(IDBFactory); }
|
2012-06-01 17:21:12 +00:00
|
|
|
|
2017-01-13 08:40:58 +00:00
|
|
|
nsIEventTarget* EventTarget() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_RELEASE_ASSERT(mEventTarget);
|
|
|
|
return mEventTarget;
|
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void ClearBackgroundActor() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
mBackgroundActor = nullptr;
|
2012-07-14 11:24:20 +00:00
|
|
|
}
|
|
|
|
|
2017-06-16 11:06:36 +00:00
|
|
|
// Increase/Decrease the number of active transactions for the decision
|
|
|
|
// making of preemption and throttling.
|
|
|
|
// Note: If the state of its actor is not committed or aborted, it could block
|
|
|
|
// IDB operations in other window.
|
|
|
|
void UpdateActiveTransactionCount(int32_t aDelta);
|
|
|
|
|
|
|
|
// Increase/Decrease the number of active databases and IDBOpenRequests for
|
|
|
|
// the decision making of preemption and throttling.
|
|
|
|
// Note: A non-closed database or a pending IDBOpenRequest could block
|
|
|
|
// IDB operations in other window.
|
|
|
|
void UpdateActiveDatabaseCount(int32_t aDelta);
|
|
|
|
|
2014-10-16 04:56:52 +00:00
|
|
|
void IncrementParentLoggingRequestSerialNumber();
|
|
|
|
|
2019-03-29 18:05:11 +00:00
|
|
|
nsIGlobalObject* GetParentObject() const { return mGlobal; }
|
2013-11-04 12:57:53 +00:00
|
|
|
|
2019-04-09 22:39:01 +00:00
|
|
|
BrowserChild* GetBrowserChild() const { return mBrowserChild; }
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
PrincipalInfo* GetPrincipalInfo() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2019-12-19 09:57:42 +00:00
|
|
|
return mPrincipalInfo.get();
|
2013-03-31 08:18:30 +00:00
|
|
|
}
|
|
|
|
|
2014-11-14 02:20:38 +00:00
|
|
|
uint64_t InnerWindowID() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return mInnerWindowID;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsChrome() const;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2019-12-19 09:23:55 +00:00
|
|
|
MOZ_MUST_USE RefPtr<IDBOpenDBRequest> Open(JSContext* aCx,
|
|
|
|
const nsAString& aName,
|
|
|
|
uint64_t aVersion,
|
|
|
|
CallerType aCallerType,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
MOZ_MUST_USE RefPtr<IDBOpenDBRequest> Open(JSContext* aCx,
|
|
|
|
const nsAString& aName,
|
|
|
|
const IDBOpenDBOptions& aOptions,
|
|
|
|
CallerType aCallerType,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
MOZ_MUST_USE RefPtr<IDBOpenDBRequest> DeleteDatabase(
|
2016-03-23 15:02:57 +00:00
|
|
|
JSContext* aCx, const nsAString& aName, const IDBOpenDBOptions& aOptions,
|
2017-02-01 20:43:37 +00:00
|
|
|
CallerType aCallerType, ErrorResult& aRv);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
int16_t Cmp(JSContext* aCx, JS::Handle<JS::Value> aFirst,
|
2014-09-26 23:21:57 +00:00
|
|
|
JS::Handle<JS::Value> aSecond, ErrorResult& aRv);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2019-12-19 09:23:55 +00:00
|
|
|
MOZ_MUST_USE RefPtr<IDBOpenDBRequest> OpenForPrincipal(
|
2016-03-23 15:02:57 +00:00
|
|
|
JSContext* aCx, nsIPrincipal* aPrincipal, const nsAString& aName,
|
2017-02-01 20:43:37 +00:00
|
|
|
uint64_t aVersion, SystemCallerGuarantee, ErrorResult& aRv);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2019-12-19 09:23:55 +00:00
|
|
|
MOZ_MUST_USE RefPtr<IDBOpenDBRequest> OpenForPrincipal(
|
2016-03-23 15:02:57 +00:00
|
|
|
JSContext* aCx, nsIPrincipal* aPrincipal, const nsAString& aName,
|
2014-09-26 23:21:57 +00:00
|
|
|
const IDBOpenDBOptions& aOptions, SystemCallerGuarantee,
|
2013-09-11 04:18:36 +00:00
|
|
|
ErrorResult& aRv);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2019-12-19 09:23:55 +00:00
|
|
|
MOZ_MUST_USE RefPtr<IDBOpenDBRequest> DeleteForPrincipal(
|
2016-03-23 15:02:57 +00:00
|
|
|
JSContext* aCx, nsIPrincipal* aPrincipal, const nsAString& aName,
|
2014-09-26 23:21:57 +00:00
|
|
|
const IDBOpenDBOptions& aOptions, SystemCallerGuarantee,
|
|
|
|
ErrorResult& aRv);
|
2013-03-31 08:18:30 +00:00
|
|
|
|
2019-03-29 18:05:11 +00:00
|
|
|
void DisconnectFromGlobal(nsIGlobalObject* aOldGlobal);
|
2018-04-16 13:08:53 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBFactory)
|
|
|
|
|
|
|
|
// nsWrapperCache
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2013-03-31 08:18:30 +00:00
|
|
|
|
2012-06-01 17:21:12 +00:00
|
|
|
private:
|
|
|
|
IDBFactory();
|
|
|
|
~IDBFactory();
|
|
|
|
|
2014-12-17 06:26:15 +00:00
|
|
|
static nsresult CreateForMainThreadJSInternal(
|
2019-12-19 09:57:42 +00:00
|
|
|
nsIGlobalObject* aGlobal, UniquePtr<PrincipalInfo> aPrincipalInfo,
|
2019-03-29 18:05:11 +00:00
|
|
|
IDBFactory** aFactory);
|
|
|
|
|
|
|
|
static nsresult CreateInternal(nsIGlobalObject* aGlobal,
|
2019-12-19 09:57:42 +00:00
|
|
|
UniquePtr<PrincipalInfo> aPrincipalInfo,
|
2019-03-29 18:05:11 +00:00
|
|
|
uint64_t aInnerWindowID,
|
|
|
|
IDBFactory** aFactory);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
static nsresult AllowedForWindowInternal(nsPIDOMWindowInner* aWindow,
|
2019-12-19 09:56:12 +00:00
|
|
|
nsCOMPtr<nsIPrincipal>* aPrincipal);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2019-12-19 09:23:55 +00:00
|
|
|
MOZ_MUST_USE RefPtr<IDBOpenDBRequest> OpenInternal(
|
2016-03-23 15:02:57 +00:00
|
|
|
JSContext* aCx, nsIPrincipal* aPrincipal, const nsAString& aName,
|
2014-09-26 23:21:57 +00:00
|
|
|
const Optional<uint64_t>& aVersion,
|
|
|
|
const Optional<StorageType>& aStorageType, bool aDeleting,
|
2017-02-01 20:43:37 +00:00
|
|
|
CallerType aCallerType, ErrorResult& aRv);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
nsresult InitiateRequest(IDBOpenDBRequest* aRequest,
|
2016-02-16 21:46:08 +00:00
|
|
|
const indexedDB::FactoryRequestParams& aParams);
|
2010-06-23 19:46:08 +00:00
|
|
|
};
|
|
|
|
|
2013-09-06 06:43:23 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2016-02-16 21:46:08 +00:00
|
|
|
#endif // mozilla_dom_idbfactory_h__
|