2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-04-15 16:38:48 +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/. */
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
#include "Storage.h"
|
|
|
|
#include "StorageCache.h"
|
|
|
|
#include "StorageManager.h"
|
2013-04-15 16:38:48 +04:00
|
|
|
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsIPermissionManager.h"
|
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsICookiePermission.h"
|
|
|
|
|
2017-02-20 06:16:48 +03:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
|
|
|
#include "mozilla/dom/ContentParent.h"
|
|
|
|
#include "mozilla/dom/PermissionMessageUtils.h"
|
2014-07-23 09:07:12 +04:00
|
|
|
#include "mozilla/dom/StorageBinding.h"
|
|
|
|
#include "mozilla/dom/StorageEvent.h"
|
|
|
|
#include "mozilla/dom/StorageEventBinding.h"
|
2013-04-15 16:38:48 +04:00
|
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2015-07-15 23:44:42 +03:00
|
|
|
#include "mozilla/EnumSet.h"
|
2013-04-15 16:38:48 +04:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
2017-02-20 06:16:48 +03:00
|
|
|
|
|
|
|
using namespace ipc;
|
|
|
|
|
2013-04-15 16:38:48 +04:00
|
|
|
namespace dom {
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Storage, mManager, mPrincipal, mWindow)
|
2014-07-23 09:07:12 +04:00
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Storage)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Storage)
|
2013-04-15 16:38:48 +04:00
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Storage)
|
2014-07-23 09:07:12 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2013-04-15 16:38:48 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMStorage)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMStorage)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
Storage::Storage(nsPIDOMWindowInner* aWindow,
|
|
|
|
StorageManagerBase* aManager,
|
|
|
|
StorageCache* aCache,
|
|
|
|
const nsAString& aDocumentURI,
|
2016-12-21 01:37:21 +03:00
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
bool aIsPrivate)
|
2017-01-04 16:53:01 +03:00
|
|
|
: mWindow(aWindow)
|
|
|
|
, mManager(aManager)
|
|
|
|
, mCache(aCache)
|
|
|
|
, mDocumentURI(aDocumentURI)
|
|
|
|
, mPrincipal(aPrincipal)
|
2016-12-21 01:37:21 +03:00
|
|
|
, mIsPrivate(aIsPrivate)
|
2017-01-04 16:53:01 +03:00
|
|
|
, mIsSessionOnly(false)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
mCache->Preload();
|
|
|
|
}
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
Storage::~Storage()
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-23 09:07:12 +04:00
|
|
|
/* virtual */ JSObject*
|
2017-01-04 16:53:01 +03:00
|
|
|
Storage::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2014-07-23 09:07:12 +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 StorageBinding::Wrap(aCx, this, aGivenProto);
|
2014-07-23 09:07:12 +04:00
|
|
|
}
|
2013-04-15 16:38:48 +04:00
|
|
|
|
2014-07-23 09:07:12 +04:00
|
|
|
uint32_t
|
2017-01-04 16:53:01 +03:00
|
|
|
Storage::GetLength(nsIPrincipal& aSubjectPrincipal,
|
|
|
|
ErrorResult& aRv)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2016-10-11 04:07:48 +03:00
|
|
|
if (!CanUseStorage(aSubjectPrincipal)) {
|
2014-07-23 09:07:12 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return 0;
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2014-07-23 09:07:12 +04:00
|
|
|
uint32_t length;
|
|
|
|
aRv = mCache->GetLength(this, &length);
|
|
|
|
return length;
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2014-07-23 09:07:12 +04:00
|
|
|
void
|
2017-01-04 16:53:01 +03:00
|
|
|
Storage::Key(uint32_t aIndex, nsAString& aResult,
|
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
|
|
|
ErrorResult& aRv)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2016-10-11 04:07:48 +03:00
|
|
|
if (!CanUseStorage(aSubjectPrincipal)) {
|
2014-07-23 09:07:12 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return;
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2014-07-23 09:07:12 +04:00
|
|
|
aRv = mCache->GetKey(this, aIndex, aResult);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2014-07-23 09:07:12 +04:00
|
|
|
void
|
2017-01-04 16:53:01 +03:00
|
|
|
Storage::GetItem(const nsAString& aKey, nsAString& aResult,
|
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
|
|
|
ErrorResult& aRv)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2016-10-11 04:07:48 +03:00
|
|
|
if (!CanUseStorage(aSubjectPrincipal)) {
|
2014-07-23 09:07:12 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return;
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2014-07-23 09:07:12 +04:00
|
|
|
aRv = mCache->GetItem(this, aKey, aResult);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2014-07-23 09:07:12 +04:00
|
|
|
void
|
2017-01-04 16:53:01 +03:00
|
|
|
Storage::SetItem(const nsAString& aKey, const nsAString& aData,
|
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
|
|
|
ErrorResult& aRv)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2016-10-11 04:07:48 +03:00
|
|
|
if (!CanUseStorage(aSubjectPrincipal)) {
|
2014-07-23 09:07:12 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return;
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2014-06-29 07:12:48 +04:00
|
|
|
nsString data;
|
2015-01-28 12:00:40 +03:00
|
|
|
bool ok = data.Assign(aData, fallible);
|
2014-07-23 09:07:12 +04:00
|
|
|
if (!ok) {
|
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return;
|
|
|
|
}
|
2014-06-29 07:12:48 +04:00
|
|
|
|
2013-04-15 16:38:48 +04:00
|
|
|
nsString old;
|
2014-07-23 09:07:12 +04:00
|
|
|
aRv = mCache->SetItem(this, aKey, data, old);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2015-04-27 16:18:52 +03:00
|
|
|
if (!aRv.ErrorCodeIs(NS_SUCCESS_DOM_NO_OPERATION)) {
|
2013-04-15 16:38:48 +04:00
|
|
|
BroadcastChangeNotification(aKey, old, aData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-23 09:07:12 +04:00
|
|
|
void
|
2017-01-04 16:53:01 +03:00
|
|
|
Storage::RemoveItem(const nsAString& aKey, nsIPrincipal& aSubjectPrincipal,
|
|
|
|
ErrorResult& aRv)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2016-10-11 04:07:48 +03:00
|
|
|
if (!CanUseStorage(aSubjectPrincipal)) {
|
2014-07-23 09:07:12 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return;
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString old;
|
2014-07-23 09:07:12 +04:00
|
|
|
aRv = mCache->RemoveItem(this, aKey, old);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2015-04-27 16:18:52 +03:00
|
|
|
if (!aRv.ErrorCodeIs(NS_SUCCESS_DOM_NO_OPERATION)) {
|
2013-04-15 16:38:48 +04:00
|
|
|
BroadcastChangeNotification(aKey, old, NullString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-23 09:07:12 +04:00
|
|
|
void
|
2017-01-04 16:53:01 +03:00
|
|
|
Storage::Clear(nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2016-10-11 04:07:48 +03:00
|
|
|
if (!CanUseStorage(aSubjectPrincipal)) {
|
2014-07-23 09:07:12 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
return;
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2014-07-23 09:07:12 +04:00
|
|
|
aRv = mCache->Clear(this);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return;
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2015-04-27 16:18:52 +03:00
|
|
|
if (!aRv.ErrorCodeIs(NS_SUCCESS_DOM_NO_OPERATION)) {
|
2013-04-15 16:38:48 +04:00
|
|
|
BroadcastChangeNotification(NullString(), NullString(), NullString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class StorageNotifierRunnable : public Runnable
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-11-29 09:19:08 +03:00
|
|
|
StorageNotifierRunnable(nsISupports* aSubject, const char16_t* aType,
|
|
|
|
bool aPrivateBrowsing)
|
2017-02-11 09:11:48 +03:00
|
|
|
: Runnable("StorageNotifierRunnable")
|
|
|
|
, mSubject(aSubject)
|
|
|
|
, mType(aType)
|
|
|
|
, mPrivateBrowsing(aPrivateBrowsing)
|
2013-04-15 16:38:48 +04:00
|
|
|
{ }
|
|
|
|
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsISupports> mSubject;
|
2014-02-12 14:14:21 +04:00
|
|
|
const char16_t* mType;
|
2016-11-29 09:19:08 +03:00
|
|
|
const bool mPrivateBrowsing;
|
2013-04-15 16:38:48 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
StorageNotifierRunnable::Run()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (observerService) {
|
2016-11-29 09:19:08 +03:00
|
|
|
observerService->NotifyObservers(mSubject,
|
|
|
|
mPrivateBrowsing
|
|
|
|
? "dom-private-storage2-changed"
|
|
|
|
: "dom-storage2-changed",
|
|
|
|
mType);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2013-04-15 16:38:48 +04:00
|
|
|
|
|
|
|
void
|
2017-01-04 16:53:01 +03:00
|
|
|
Storage::BroadcastChangeNotification(const nsSubstring& aKey,
|
|
|
|
const nsSubstring& aOldValue,
|
|
|
|
const nsSubstring& aNewValue)
|
2017-02-20 06:16:48 +03:00
|
|
|
{
|
|
|
|
if (!XRE_IsParentProcess() && GetType() == LocalStorage && mPrincipal) {
|
|
|
|
// If we are in a child process, we want to send a message to the parent in
|
|
|
|
// order to broadcast the StorageEvent correctly to any child process.
|
|
|
|
dom::ContentChild* cc = dom::ContentChild::GetSingleton();
|
|
|
|
Unused << NS_WARN_IF(!cc->SendBroadcastLocalStorageChange(
|
|
|
|
mDocumentURI, nsString(aKey), nsString(aOldValue), nsString(aNewValue),
|
|
|
|
IPC::Principal(mPrincipal), mIsPrivate));
|
|
|
|
}
|
|
|
|
|
|
|
|
DispatchStorageEvent(GetType(), mDocumentURI, aKey, aOldValue, aNewValue,
|
|
|
|
mPrincipal, mIsPrivate, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
Storage::DispatchStorageEvent(StorageType aStorageType,
|
|
|
|
const nsAString& aDocumentURI,
|
|
|
|
const nsAString& aKey,
|
|
|
|
const nsAString& aOldValue,
|
|
|
|
const nsAString& aNewValue,
|
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
bool aIsPrivate,
|
|
|
|
Storage* aStorage)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2014-05-23 11:33:24 +04:00
|
|
|
StorageEventInit dict;
|
|
|
|
dict.mBubbles = false;
|
|
|
|
dict.mCancelable = false;
|
|
|
|
dict.mKey = aKey;
|
|
|
|
dict.mNewValue = aNewValue;
|
|
|
|
dict.mOldValue = aOldValue;
|
2017-02-20 06:16:48 +03:00
|
|
|
dict.mStorageArea = aStorage;
|
|
|
|
dict.mUrl = aDocumentURI;
|
2014-05-23 11:33:24 +04:00
|
|
|
|
2013-04-15 16:38:48 +04:00
|
|
|
// Note, this DOM event should never reach JS. It is cloned later in
|
|
|
|
// nsGlobalWindow.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<StorageEvent> event =
|
2014-05-23 11:33:24 +04:00
|
|
|
StorageEvent::Constructor(nullptr, NS_LITERAL_STRING("storage"), dict);
|
2013-04-15 16:38:48 +04:00
|
|
|
|
2017-02-20 06:16:48 +03:00
|
|
|
event->SetPrincipal(aPrincipal);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<StorageNotifierRunnable> r =
|
2014-02-12 14:14:21 +04:00
|
|
|
new StorageNotifierRunnable(event,
|
2017-02-20 06:16:48 +03:00
|
|
|
aStorageType == LocalStorage
|
2016-07-21 08:03:25 +03:00
|
|
|
? u"localStorage"
|
2016-11-29 09:19:08 +03:00
|
|
|
: u"sessionStorage",
|
2017-02-20 06:16:48 +03:00
|
|
|
aIsPrivate);
|
2017-02-03 09:02:24 +03:00
|
|
|
NS_DispatchToMainThread(r);
|
2017-02-20 06:16:48 +03:00
|
|
|
|
|
|
|
// If we are in the parent process and we have the principal, we want to
|
|
|
|
// broadcast this event to every other process.
|
|
|
|
if (aStorageType == LocalStorage && XRE_IsParentProcess() && aPrincipal) {
|
|
|
|
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
|
|
|
|
Unused << cp->SendDispatchLocalStorageChange(
|
|
|
|
nsString(aDocumentURI), nsString(aKey), nsString(aOldValue),
|
|
|
|
nsString(aNewValue), IPC::Principal(aPrincipal), aIsPrivate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Storage::ApplyEvent(StorageEvent* aStorageEvent)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aStorageEvent);
|
|
|
|
|
|
|
|
nsAutoString key;
|
|
|
|
nsAutoString old;
|
|
|
|
nsAutoString value;
|
|
|
|
|
|
|
|
aStorageEvent->GetKey(key);
|
|
|
|
aStorageEvent->GetNewValue(value);
|
|
|
|
|
|
|
|
// No key means clearing the full storage.
|
|
|
|
if (key.IsVoid()) {
|
|
|
|
MOZ_ASSERT(value.IsVoid());
|
2017-01-24 14:45:11 +03:00
|
|
|
mCache->Clear(this, StorageCache::E10sPropagated);
|
2017-02-20 06:16:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No new value means removing the key.
|
|
|
|
if (value.IsVoid()) {
|
2017-01-24 14:45:11 +03:00
|
|
|
mCache->RemoveItem(this, key, old, StorageCache::E10sPropagated);
|
2017-02-20 06:16:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we set the new value.
|
2017-01-24 14:45:11 +03:00
|
|
|
mCache->SetItem(this, key, value, old, StorageCache::E10sPropagated);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char kPermissionType[] = "cookie";
|
|
|
|
static const char kStorageEnabled[] = "dom.storage.enabled";
|
|
|
|
|
|
|
|
bool
|
2017-01-04 16:53:01 +03:00
|
|
|
Storage::CanUseStorage(nsIPrincipal& aSubjectPrincipal)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
// This method is responsible for correct setting of mIsSessionOnly.
|
2016-12-21 01:37:21 +03:00
|
|
|
// It doesn't work with mIsPrivate flag at all, since it is checked
|
|
|
|
// regardless mIsSessionOnly flag in DOMStorageCache code.
|
2013-04-15 16:38:48 +04:00
|
|
|
|
|
|
|
if (!mozilla::Preferences::GetBool(kStorageEnabled)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-11 04:07:48 +03:00
|
|
|
nsContentUtils::StorageAccess access =
|
|
|
|
nsContentUtils::StorageAllowedForPrincipal(mPrincipal);
|
2013-04-15 16:38:48 +04:00
|
|
|
|
2015-07-15 23:44:42 +03:00
|
|
|
if (access == nsContentUtils::StorageAccess::eDeny) {
|
2013-04-15 16:38:48 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-11 04:07:48 +03:00
|
|
|
mIsSessionOnly = access <= nsContentUtils::StorageAccess::eSessionScoped;
|
|
|
|
return CanAccess(&aSubjectPrincipal);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
Storage::StorageType
|
|
|
|
Storage::GetType() const
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
return mManager->Type();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPrincipal*
|
2017-01-04 16:53:01 +03:00
|
|
|
Storage::GetPrincipal()
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
return mPrincipal;
|
|
|
|
}
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
// Defined in StorageManager.cpp
|
2013-04-15 16:38:48 +04:00
|
|
|
extern bool
|
2017-01-04 16:53:01 +03:00
|
|
|
PrincipalsEqual(nsIPrincipal* aObjectPrincipal,
|
|
|
|
nsIPrincipal* aSubjectPrincipal);
|
2013-04-15 16:38:48 +04:00
|
|
|
|
|
|
|
bool
|
2017-01-04 16:53:01 +03:00
|
|
|
Storage::PrincipalEquals(nsIPrincipal* aPrincipal)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
return PrincipalsEqual(mPrincipal, aPrincipal);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-01-04 16:53:01 +03:00
|
|
|
Storage::CanAccess(nsIPrincipal* aPrincipal)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2014-02-14 06:57:36 +04:00
|
|
|
return !aPrincipal || aPrincipal->Subsumes(mPrincipal);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2014-07-23 09:07:12 +04:00
|
|
|
void
|
2017-01-04 16:53:01 +03:00
|
|
|
Storage::GetSupportedNames(nsTArray<nsString>& aKeys)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2016-10-11 04:07:48 +03:00
|
|
|
if (!CanUseStorage(*nsContentUtils::SubjectPrincipal())) {
|
2014-07-23 09:07:12 +04:00
|
|
|
// return just an empty array
|
|
|
|
aKeys.Clear();
|
|
|
|
return;
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2014-07-23 09:07:12 +04:00
|
|
|
mCache->GetKeys(this, aKeys);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|