DXR will be turned off on Tuesday, December 29th. It will redirect to Searchfox.
See the announcement on Discourse.

DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Header

Mercurial (d1ed7de67f5a)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
/* 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/. */

#include "mozilla/dom/DataStore.h"
#include "mozilla/dom/DataStoreCursor.h"
#include "mozilla/dom/DataStoreBinding.h"
#include "mozilla/dom/DataStoreImplBinding.h"
#include "mozilla/dom/Navigator.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/Preferences.h"
#include "AccessCheck.h"

namespace mozilla {
namespace dom {

NS_IMPL_ADDREF_INHERITED(DataStore, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(DataStore, DOMEventTargetHelper)

NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DataStore)
  NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)

NS_IMPL_CYCLE_COLLECTION_INHERITED(DataStore, DOMEventTargetHelper, mStore)

DataStore::DataStore(nsPIDOMWindow* aWindow)
  : DOMEventTargetHelper(aWindow)
{
}

DataStore::~DataStore()
{
}

already_AddRefed<DataStore>
DataStore::Constructor(GlobalObject& aGlobal, ErrorResult& aRv)
{
  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
  if (!window) {
    aRv.Throw(NS_ERROR_FAILURE);
    return nullptr;
  }

  nsRefPtr<DataStore> store = new DataStore(window);
  return store.forget();
}

JSObject*
DataStore::WrapObject(JSContext* aCx)
{
  return DataStoreBinding::Wrap(aCx, this);
}

/*static*/ bool
DataStore::EnabledForScope(JSContext* aCx, JS::Handle<JSObject*> aObj)
{
  // Only expose the interface when it is:
  // 1. enabled by the preference and
  // 2. accessed by the chrome codes in Gecko.
  return (Navigator::HasDataStoreSupport(aCx, aObj) &&
          nsContentUtils::ThreadsafeIsCallerChrome());
}

void
DataStore::GetName(nsAString& aName, ErrorResult& aRv)
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(mStore);

  nsAutoString name;
  mStore->GetName(name, aRv);
  aName.Assign(name);
}

void
DataStore::GetOwner(nsAString& aOwner, ErrorResult& aRv)
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(mStore);

  nsAutoString owner;
  mStore->GetOwner(owner, aRv);
  aOwner.Assign(owner);
}

bool
DataStore::GetReadOnly(ErrorResult& aRv)
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(mStore);

  return mStore->GetReadOnly(aRv);
}

already_AddRefed<Promise>
DataStore::Get(const Sequence<OwningStringOrUnsignedLong>& aId,
               ErrorResult& aRv)
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(mStore);

  return mStore->Get(aId, aRv);
}

already_AddRefed<Promise>
DataStore::Put(JSContext* aCx,
               JS::Handle<JS::Value> aObj,
               const StringOrUnsignedLong& aId,
               const nsAString& aRevisionId,
               ErrorResult& aRv)
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(mStore);

  return mStore->Put(aObj, aId, aRevisionId, aRv);
}

already_AddRefed<Promise>
DataStore::Add(JSContext* aCx,
               JS::Handle<JS::Value> aObj,
               const Optional<StringOrUnsignedLong>& aId,
               const nsAString& aRevisionId,
               ErrorResult& aRv)
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(mStore);

  return mStore->Add(aObj, aId, aRevisionId, aRv);
}

already_AddRefed<Promise>
DataStore::Remove(const StringOrUnsignedLong& aId,
                  const nsAString& aRevisionId,
                  ErrorResult& aRv)
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(mStore);

  return mStore->Remove(aId, aRevisionId, aRv);
}

already_AddRefed<Promise>
DataStore::Clear(const nsAString& aRevisionId, ErrorResult& aRv)
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(mStore);

  return mStore->Clear(aRevisionId, aRv);
}

void
DataStore::GetRevisionId(nsAString& aRevisionId, ErrorResult& aRv)
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(mStore);

  nsAutoString revisionId;
  mStore->GetRevisionId(revisionId, aRv);
  aRevisionId.Assign(revisionId);
}

already_AddRefed<Promise>
DataStore::GetLength(ErrorResult& aRv)
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(mStore);

  return mStore->GetLength(aRv);
}

already_AddRefed<DataStoreCursor>
DataStore::Sync(const nsAString& aRevisionId, ErrorResult& aRv)
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(mStore);

  return mStore->Sync(aRevisionId, aRv);
}

void
DataStore::SetDataStoreImpl(DataStoreImpl& aStore, ErrorResult& aRv)
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(!mStore);

  mStore = &aStore;
  mStore->SetEventTarget(*this, aRv);
}

} //namespace dom
} //namespace mozilla