dom/indexedDB/OpenDatabaseHelper.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef mozilla_dom_indexeddb_opendatabasehelper_h__
michael@0 6 #define mozilla_dom_indexeddb_opendatabasehelper_h__
michael@0 7
michael@0 8 #include "AsyncConnectionHelper.h"
michael@0 9
michael@0 10 #include "nsIRunnable.h"
michael@0 11
michael@0 12 #include "mozilla/dom/quota/StoragePrivilege.h"
michael@0 13
michael@0 14 #include "DatabaseInfo.h"
michael@0 15 #include "IDBDatabase.h"
michael@0 16 #include "IDBRequest.h"
michael@0 17
michael@0 18 class mozIStorageConnection;
michael@0 19
michael@0 20 namespace mozilla {
michael@0 21 namespace dom {
michael@0 22 class ContentParent;
michael@0 23 }
michael@0 24 }
michael@0 25
michael@0 26 BEGIN_INDEXEDDB_NAMESPACE
michael@0 27
michael@0 28 class CheckPermissionsHelper;
michael@0 29
michael@0 30 class OpenDatabaseHelper : public HelperBase
michael@0 31 {
michael@0 32 friend class CheckPermissionsHelper;
michael@0 33
michael@0 34 typedef mozilla::dom::quota::PersistenceType PersistenceType;
michael@0 35 typedef mozilla::dom::quota::StoragePrivilege StoragePrivilege;
michael@0 36
michael@0 37 public:
michael@0 38 OpenDatabaseHelper(IDBOpenDBRequest* aRequest,
michael@0 39 const nsAString& aName,
michael@0 40 const nsACString& aGroup,
michael@0 41 const nsACString& aASCIIOrigin,
michael@0 42 uint64_t aRequestedVersion,
michael@0 43 PersistenceType aPersistenceType,
michael@0 44 bool aForDeletion,
michael@0 45 mozilla::dom::ContentParent* aContentParent,
michael@0 46 StoragePrivilege aPrivilege)
michael@0 47 : HelperBase(aRequest), mOpenDBRequest(aRequest), mName(aName),
michael@0 48 mGroup(aGroup), mASCIIOrigin(aASCIIOrigin),
michael@0 49 mRequestedVersion(aRequestedVersion), mPersistenceType(aPersistenceType),
michael@0 50 mForDeletion(aForDeletion), mPrivilege(aPrivilege),
michael@0 51 mContentParent(aContentParent), mCurrentVersion(0), mLastObjectStoreId(0),
michael@0 52 mLastIndexId(0), mState(eCreated), mResultCode(NS_OK),
michael@0 53 mLoadDBMetadata(false),
michael@0 54 mTrackingQuota(aPrivilege != mozilla::dom::quota::Chrome)
michael@0 55 {
michael@0 56 NS_ASSERTION(!aForDeletion || !aRequestedVersion,
michael@0 57 "Can't be for deletion and request a version!");
michael@0 58 }
michael@0 59
michael@0 60 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 61 NS_DECL_NSIRUNNABLE
michael@0 62
michael@0 63 nsresult Init();
michael@0 64
michael@0 65 nsresult WaitForOpenAllowed();
michael@0 66 nsresult Dispatch(nsIEventTarget* aDatabaseThread);
michael@0 67 nsresult DispatchToIOThread();
michael@0 68 nsresult RunImmediately();
michael@0 69
michael@0 70 void SetError(nsresult rv)
michael@0 71 {
michael@0 72 NS_ASSERTION(NS_FAILED(rv), "Why are you telling me?");
michael@0 73 mResultCode = rv;
michael@0 74 }
michael@0 75
michael@0 76 virtual nsresult GetResultCode() MOZ_OVERRIDE
michael@0 77 {
michael@0 78 return mResultCode;
michael@0 79 }
michael@0 80
michael@0 81 nsresult NotifySetVersionFinished();
michael@0 82 nsresult NotifyDeleteFinished();
michael@0 83 void BlockDatabase();
michael@0 84
michael@0 85 const nsACString& Id() const
michael@0 86 {
michael@0 87 return mDatabaseId;
michael@0 88 }
michael@0 89
michael@0 90 IDBDatabase* Database() const
michael@0 91 {
michael@0 92 NS_ASSERTION(mDatabase, "Calling at the wrong time!");
michael@0 93 return mDatabase;
michael@0 94 }
michael@0 95
michael@0 96 const StoragePrivilege& Privilege() const
michael@0 97 {
michael@0 98 return mPrivilege;
michael@0 99 }
michael@0 100
michael@0 101 static
michael@0 102 nsresult CreateDatabaseConnection(nsIFile* aDBFile,
michael@0 103 nsIFile* aFMDirectory,
michael@0 104 const nsAString& aName,
michael@0 105 PersistenceType aPersistenceType,
michael@0 106 const nsACString& aGroup,
michael@0 107 const nsACString& aOrigin,
michael@0 108 mozIStorageConnection** aConnection);
michael@0 109
michael@0 110 protected:
michael@0 111 // Methods only called on the main thread
michael@0 112 nsresult EnsureSuccessResult();
michael@0 113 nsresult StartSetVersion();
michael@0 114 nsresult StartDelete();
michael@0 115 virtual nsresult GetSuccessResult(JSContext* aCx,
michael@0 116 JS::MutableHandle<JS::Value> aVal) MOZ_OVERRIDE;
michael@0 117 void DispatchSuccessEvent();
michael@0 118 void DispatchErrorEvent();
michael@0 119 virtual void ReleaseMainThreadObjects() MOZ_OVERRIDE;
michael@0 120
michael@0 121 // Called by CheckPermissionsHelper on the main thread before dispatch.
michael@0 122 void SetUnlimitedQuotaAllowed()
michael@0 123 {
michael@0 124 mTrackingQuota = false;
michael@0 125 }
michael@0 126
michael@0 127 // Methods only called on the DB thread
michael@0 128 nsresult DoDatabaseWork();
michael@0 129
michael@0 130 // In-params.
michael@0 131 nsRefPtr<IDBOpenDBRequest> mOpenDBRequest;
michael@0 132 nsString mName;
michael@0 133 nsCString mGroup;
michael@0 134 nsCString mASCIIOrigin;
michael@0 135 uint64_t mRequestedVersion;
michael@0 136 PersistenceType mPersistenceType;
michael@0 137 bool mForDeletion;
michael@0 138 StoragePrivilege mPrivilege;
michael@0 139 nsCString mDatabaseId;
michael@0 140 mozilla::dom::ContentParent* mContentParent;
michael@0 141
michael@0 142 // Out-params.
michael@0 143 nsTArray<nsRefPtr<ObjectStoreInfo> > mObjectStores;
michael@0 144 uint64_t mCurrentVersion;
michael@0 145 nsString mDatabaseFilePath;
michael@0 146 int64_t mLastObjectStoreId;
michael@0 147 int64_t mLastIndexId;
michael@0 148 nsRefPtr<IDBDatabase> mDatabase;
michael@0 149
michael@0 150 // State variables
michael@0 151 enum OpenDatabaseState {
michael@0 152 eCreated = 0, // Not yet dispatched to the DB thread
michael@0 153 eOpenPending, // Waiting for open allowed/open allowed
michael@0 154 eDBWork, // Waiting to do/doing work on the DB thread
michael@0 155 eFiringEvents, // Waiting to fire/firing events on the main thread
michael@0 156 eSetVersionPending, // Waiting on a SetVersionHelper
michael@0 157 eSetVersionCompleted, // SetVersionHelper is done
michael@0 158 eDeletePending, // Waiting on a DeleteDatabaseHelper
michael@0 159 eDeleteCompleted, // DeleteDatabaseHelper is done
michael@0 160 };
michael@0 161 OpenDatabaseState mState;
michael@0 162 nsresult mResultCode;
michael@0 163
michael@0 164 nsRefPtr<FileManager> mFileManager;
michael@0 165
michael@0 166 nsRefPtr<DatabaseInfo> mDBInfo;
michael@0 167 bool mLoadDBMetadata;
michael@0 168 bool mTrackingQuota;
michael@0 169 };
michael@0 170
michael@0 171 END_INDEXEDDB_NAMESPACE
michael@0 172
michael@0 173 #endif // mozilla_dom_indexeddb_opendatabasehelper_h__

mercurial