2010-06-23 19:46:08 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=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
|
|
|
|
2010-06-28 16:44:30 +00:00
|
|
|
#ifndef mozilla_dom_indexeddb_idbfactory_h__
|
|
|
|
#define mozilla_dom_indexeddb_idbfactory_h__
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-11 04:18:36 +00:00
|
|
|
#include "mozilla/dom/StorageTypeBinding.h"
|
2014-09-26 23:21:57 +00:00
|
|
|
#include "nsAutoPtr.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
|
|
|
|
2013-09-06 06:43:23 +00:00
|
|
|
class nsIPrincipal;
|
2012-01-24 10:03:37 +00:00
|
|
|
class nsPIDOMWindow;
|
2014-09-26 23:21:57 +00:00
|
|
|
struct PRThread;
|
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;
|
2014-12-17 06:26:15 +00:00
|
|
|
template <typename> class Optional;
|
2014-09-26 23:21:57 +00:00
|
|
|
class TabChild;
|
2012-08-02 06:02:29 +00:00
|
|
|
|
2013-09-06 06:43:23 +00:00
|
|
|
namespace indexedDB {
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
class BackgroundFactoryChild;
|
|
|
|
class FactoryRequestParams;
|
2012-06-01 17:21:12 +00:00
|
|
|
class IDBOpenDBRequest;
|
2014-10-16 04:56:52 +00:00
|
|
|
class LoggingInfo;
|
2012-06-01 17:21:12 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
class IDBFactory MOZ_FINAL
|
|
|
|
: public nsISupports
|
|
|
|
, public nsWrapperCache
|
2014-09-17 23:36:01 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
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
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
nsAutoPtr<PrincipalInfo> mPrincipalInfo;
|
|
|
|
|
|
|
|
// If this factory lives on a window then mWindow must be non-null. Otherwise
|
|
|
|
// mOwningObject must be non-null.
|
|
|
|
nsCOMPtr<nsPIDOMWindow> mWindow;
|
|
|
|
JS::Heap<JSObject*> mOwningObject;
|
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.
|
2014-09-26 23:21:57 +00:00
|
|
|
nsRefPtr<TabChild> mTabChild;
|
2013-04-08 19:47:13 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
nsTArray<nsAutoPtr<PendingRequestInfo>> mPendingRequests;
|
2010-10-19 17:58:52 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
BackgroundFactoryChild* mBackgroundActor;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRThread* mOwningThread;
|
|
|
|
#endif
|
|
|
|
|
2014-11-14 02:20:38 +00:00
|
|
|
uint64_t mInnerWindowID;
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
bool mBackgroundActorFailed;
|
|
|
|
bool mPrivateBrowsingMode;
|
|
|
|
|
|
|
|
public:
|
2010-10-19 17:58:52 +00:00
|
|
|
static nsresult
|
2014-09-26 23:21:57 +00:00
|
|
|
CreateForWindow(nsPIDOMWindow* aWindow,
|
|
|
|
IDBFactory** aFactory);
|
2010-10-19 17:58:52 +00:00
|
|
|
|
2014-09-13 16:12:19 +00:00
|
|
|
static nsresult
|
2014-09-26 23:21:57 +00:00
|
|
|
CreateForChromeJS(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aOwningObject,
|
|
|
|
IDBFactory** aFactory);
|
2012-06-01 17:21:12 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
static nsresult
|
|
|
|
CreateForDatastore(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aOwningObject,
|
|
|
|
IDBFactory** aFactory);
|
2012-10-30 06:11:58 +00:00
|
|
|
|
2014-12-17 06:26:15 +00:00
|
|
|
static nsresult
|
|
|
|
CreateForWorker(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aOwningObject,
|
|
|
|
const PrincipalInfo& aPrincipalInfo,
|
|
|
|
uint64_t aInnerWindowID,
|
|
|
|
IDBFactory** aFactory);
|
|
|
|
|
|
|
|
static bool
|
|
|
|
AllowedForWindow(nsPIDOMWindow* aWindow);
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
AssertIsOnOwningThread() const
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{ }
|
|
|
|
#endif
|
2012-06-01 17:21:12 +00:00
|
|
|
|
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
SetBackgroundActor(BackgroundFactoryChild* aBackgroundActor);
|
2012-06-01 17:21:12 +00:00
|
|
|
|
2014-09-17 23:36:01 +00:00
|
|
|
void
|
2014-09-26 23:21:57 +00:00
|
|
|
ClearBackgroundActor()
|
2012-07-14 11:24:20 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
mBackgroundActor = nullptr;
|
2012-07-14 11:24:20 +00:00
|
|
|
}
|
|
|
|
|
2014-10-16 04:56:52 +00:00
|
|
|
void
|
|
|
|
IncrementParentLoggingRequestSerialNumber();
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
nsPIDOMWindow*
|
|
|
|
GetParentObject() const
|
2013-11-04 12:57:53 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
return mWindow;
|
2013-11-04 12:57:53 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
TabChild*
|
|
|
|
GetTabChild() const
|
2013-03-31 08:18:30 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
return mTabChild;
|
2014-09-17 23:36:01 +00:00
|
|
|
}
|
2014-09-13 16:12:19 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
PrincipalInfo*
|
|
|
|
GetPrincipalInfo() const
|
2014-09-17 23:36:01 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return mPrincipalInfo;
|
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;
|
|
|
|
|
2013-07-31 22:28:15 +00:00
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
2014-09-26 23:21:57 +00:00
|
|
|
Open(const nsAString& aName,
|
|
|
|
uint64_t aVersion,
|
|
|
|
ErrorResult& aRv);
|
2013-03-31 08:18:30 +00:00
|
|
|
|
2013-07-31 22:28:15 +00:00
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
2014-09-26 23:21:57 +00:00
|
|
|
Open(const nsAString& aName,
|
|
|
|
const IDBOpenDBOptions& aOptions,
|
2013-09-11 04:18:36 +00:00
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
2014-09-26 23:21:57 +00:00
|
|
|
DeleteDatabase(const nsAString& aName,
|
|
|
|
const IDBOpenDBOptions& aOptions,
|
2013-09-11 04:18:36 +00:00
|
|
|
ErrorResult& aRv);
|
2013-03-31 08:18:30 +00:00
|
|
|
|
|
|
|
int16_t
|
2014-09-26 23:21:57 +00:00
|
|
|
Cmp(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aFirst,
|
|
|
|
JS::Handle<JS::Value> aSecond,
|
|
|
|
ErrorResult& aRv);
|
2013-03-31 08:18:30 +00:00
|
|
|
|
2013-07-31 22:28:15 +00:00
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
2014-09-26 23:21:57 +00:00
|
|
|
OpenForPrincipal(nsIPrincipal* aPrincipal,
|
|
|
|
const nsAString& aName,
|
|
|
|
uint64_t aVersion,
|
|
|
|
ErrorResult& aRv);
|
2013-09-11 04:18:36 +00:00
|
|
|
|
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
2014-09-26 23:21:57 +00:00
|
|
|
OpenForPrincipal(nsIPrincipal* aPrincipal,
|
|
|
|
const nsAString& aName,
|
|
|
|
const IDBOpenDBOptions& aOptions,
|
|
|
|
ErrorResult& aRv);
|
2013-03-31 08:18:30 +00:00
|
|
|
|
2013-07-31 22:28:15 +00:00
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
2014-09-26 23:21:57 +00:00
|
|
|
DeleteForPrincipal(nsIPrincipal* aPrincipal,
|
|
|
|
const nsAString& aName,
|
|
|
|
const IDBOpenDBOptions& aOptions,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBFactory)
|
|
|
|
|
|
|
|
// nsWrapperCache
|
|
|
|
virtual JSObject*
|
|
|
|
WrapObject(JSContext* aCx) MOZ_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(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aOwningObject,
|
|
|
|
nsAutoPtr<PrincipalInfo>& aPrincipalInfo,
|
|
|
|
IDBFactory** aFactory);
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
static nsresult
|
|
|
|
CreateForJSInternal(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aOwningObject,
|
|
|
|
nsAutoPtr<PrincipalInfo>& aPrincipalInfo,
|
2014-12-17 06:26:15 +00:00
|
|
|
uint64_t aInnerWindowID,
|
2014-09-26 23:21:57 +00:00
|
|
|
IDBFactory** aFactory);
|
2012-07-14 11:24:20 +00:00
|
|
|
|
2014-12-17 06:26:15 +00:00
|
|
|
static nsresult
|
|
|
|
AllowedForWindowInternal(nsPIDOMWindow* aWindow,
|
|
|
|
nsIPrincipal** aPrincipal);
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
|
|
|
OpenInternal(nsIPrincipal* aPrincipal,
|
|
|
|
const nsAString& aName,
|
|
|
|
const Optional<uint64_t>& aVersion,
|
|
|
|
const Optional<StorageType>& aStorageType,
|
|
|
|
bool aDeleting,
|
|
|
|
ErrorResult& aRv);
|
2012-08-02 06:02:29 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
nsresult
|
2014-10-16 04:56:52 +00:00
|
|
|
BackgroundActorCreated(PBackgroundChild* aBackgroundActor,
|
|
|
|
const LoggingInfo& aLoggingInfo);
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
void
|
|
|
|
BackgroundActorFailed();
|
2014-09-17 23:36:01 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
nsresult
|
|
|
|
InitiateRequest(IDBOpenDBRequest* aRequest,
|
|
|
|
const FactoryRequestParams& aParams);
|
2010-06-23 19:46:08 +00:00
|
|
|
};
|
|
|
|
|
2013-09-06 06:43:23 +00:00
|
|
|
} // namespace indexedDB
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2010-06-28 16:44:30 +00:00
|
|
|
#endif // mozilla_dom_indexeddb_idbfactory_h__
|