Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1165214 - Use OriginAttributes in DOM Storage. r=smaug, r=bholley
Browse files Browse the repository at this point in the history
  • Loading branch information
mayhemer committed Jan 5, 2016
1 parent 77898dd commit 048d75d
Show file tree
Hide file tree
Showing 16 changed files with 1,114 additions and 471 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ add_task(function* test() {
// check each item in the title and validate it meets expectatations
for (let part of title) {
let [storageMethodName, value] = part.split("=");
let is_f = storageMethodName == "cookie" ? is : todo_is;
is_f(value, expectedContext,
is(value, expectedContext,
"the title reflects the expected contextual identity of " +
expectedContext + " for method " + storageMethodName + ": " + value);
}
Expand Down
1 change: 1 addition & 0 deletions caps/BasePrincipal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ OriginAttributes::CreateSuffix(nsACString& aStr) const
}

if (!mSignedPkg.IsEmpty()) {
MOZ_RELEASE_ASSERT(mSignedPkg.FindCharInSet(dom::quota::QuotaManager::kReplaceChars) == kNotFound);
params->Set(NS_LITERAL_STRING("signedPkg"), mSignedPkg);
}

Expand Down
31 changes: 24 additions & 7 deletions dom/storage/DOMStorageCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ NS_IMETHODIMP_(void) DOMStorageCacheBridge::Release(void)

// DOMStorageCache

DOMStorageCache::DOMStorageCache(const nsACString* aScope)
: mScope(*aScope)
DOMStorageCache::DOMStorageCache(const nsACString* aOriginNoSuffix)
: mOriginNoSuffix(*aOriginNoSuffix)
, mMonitor("DOMStorageCache")
, mLoaded(false)
, mLoadResult(NS_OK)
Expand Down Expand Up @@ -124,23 +124,34 @@ void
DOMStorageCache::Init(DOMStorageManager* aManager,
bool aPersistent,
nsIPrincipal* aPrincipal,
const nsACString& aQuotaScope)
const nsACString& aQuotaOriginScope)
{
if (mInitialized) {
return;
}

mInitialized = true;
mPrincipal = aPrincipal;
BasePrincipal::Cast(aPrincipal)->OriginAttributesRef().CreateSuffix(mOriginSuffix);
mPersistent = aPersistent;
mQuotaScope = aQuotaScope.IsEmpty() ? mScope : aQuotaScope;
if (aQuotaOriginScope.IsEmpty()) {
mQuotaOriginScope = Origin();
} else {
mQuotaOriginScope = aQuotaOriginScope;
}

if (mPersistent) {
mManager = aManager;
Preload();
}

mUsage = aManager->GetScopeUsage(mQuotaScope);
// Check the quota string has (or has not) the identical origin suffix as
// this storage cache is bound to.
MOZ_ASSERT(StringBeginsWith(mQuotaOriginScope, mOriginSuffix));
MOZ_ASSERT(mOriginSuffix.IsEmpty() != StringBeginsWith(mQuotaOriginScope,
NS_LITERAL_CSTRING("^")));

mUsage = aManager->GetOriginUsage(mQuotaOriginScope);
}

inline bool
Expand All @@ -151,6 +162,12 @@ DOMStorageCache::Persist(const DOMStorage* aStorage) const
!aStorage->IsPrivate();
}

const nsCString
DOMStorageCache::Origin() const
{
return DOMStorageManager::CreateOrigin(mOriginSuffix, mOriginNoSuffix);
}

DOMStorageCache::Data&
DOMStorageCache::DataSet(const DOMStorage* aStorage)
{
Expand Down Expand Up @@ -658,8 +675,8 @@ DOMStorageCache::LoadWait()

// DOMStorageUsage

DOMStorageUsage::DOMStorageUsage(const nsACString& aScope)
: mScope(aScope)
DOMStorageUsage::DOMStorageUsage(const nsACString& aOriginScope)
: mOriginScope(aOriginScope)
{
mUsage[kDefaultSet] = mUsage[kPrivateSet] = mUsage[kSessionSet] = 0LL;
}
Expand Down
43 changes: 30 additions & 13 deletions dom/storage/DOMStorageCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,16 @@ class DOMStorageCacheBridge
NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
NS_IMETHOD_(void) Release(void);

// The scope (origin) in the database usage format (reversed)
virtual const nsCString& Scope() const = 0;
// The origin of the cache, result is concatenation of OriginNoSuffix() and OriginSuffix(),
// see below.
virtual const nsCString Origin() const = 0;

// The origin attributes suffix alone, this is usually passed as an |aOriginSuffix|
// argument to various methods
virtual const nsCString& OriginSuffix() const = 0;

// The origin in the database usage format (reversed) and without the suffix
virtual const nsCString& OriginNoSuffix() const = 0;

// Whether the cache is already fully loaded
virtual bool Loaded() = 0;
Expand Down Expand Up @@ -70,14 +78,17 @@ class DOMStorageCache : public DOMStorageCacheBridge
public:
NS_IMETHOD_(void) Release(void);

explicit DOMStorageCache(const nsACString* aScope);
// Note: We pass aOriginNoSuffix through the ctor here, because
// DOMStorageCacheHashKey's ctor is creating this class and
// accepts reversed-origin-no-suffix as an argument - the hashing key.
explicit DOMStorageCache(const nsACString* aOriginNoSuffix);

protected:
virtual ~DOMStorageCache();

public:
void Init(DOMStorageManager* aManager, bool aPersistent, nsIPrincipal* aPrincipal,
const nsACString& aQuotaScope);
const nsACString& aQuotaOriginScope);

// Copies all data from the other storage.
void CloneFrom(const DOMStorageCache* aThat);
Expand Down Expand Up @@ -114,7 +125,9 @@ class DOMStorageCache : public DOMStorageCacheBridge

// DOMStorageCacheBridge

virtual const nsCString& Scope() const { return mScope; }
virtual const nsCString Origin() const;
virtual const nsCString& OriginNoSuffix() const { return mOriginNoSuffix; }
virtual const nsCString& OriginSuffix() const { return mOriginSuffix; }
virtual bool Loaded() { return mLoaded; }
virtual uint32_t LoadedCount();
virtual bool LoadItem(const nsAString& aKey, const nsString& aValue);
Expand Down Expand Up @@ -188,11 +201,15 @@ class DOMStorageCache : public DOMStorageCacheBridge
// origin only.
nsCOMPtr<nsIPrincipal> mPrincipal;

// The scope this cache belongs to in the "DB format", i.e. reversed
nsCString mScope;
// The origin this cache belongs to in the "DB format", i.e. reversed
nsCString mOriginNoSuffix;

// The origin attributes suffix
nsCString mOriginSuffix;

// The eTLD+1 scope used to count quota usage.
nsCString mQuotaScope;
// The eTLD+1 scope used to count quota usage. It is in the reversed format
// and contains the origin attributes suffix.
nsCString mQuotaOriginScope;

// Non-private Browsing, Private Browsing and Session Only sets.
Data mData[kDataSetCount];
Expand Down Expand Up @@ -241,7 +258,7 @@ class DOMStorageUsageBridge
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DOMStorageUsageBridge)

virtual const nsCString& Scope() = 0;
virtual const nsCString& OriginScope() = 0;
virtual void LoadUsage(const int64_t aUsage) = 0;

protected:
Expand All @@ -252,15 +269,15 @@ class DOMStorageUsageBridge
class DOMStorageUsage : public DOMStorageUsageBridge
{
public:
explicit DOMStorageUsage(const nsACString& aScope);
explicit DOMStorageUsage(const nsACString& aOriginScope);

bool CheckAndSetETLD1UsageDelta(uint32_t aDataSetIndex, int64_t aUsageDelta);

private:
virtual const nsCString& Scope() { return mScope; }
virtual const nsCString& OriginScope() { return mOriginScope; }
virtual void LoadUsage(const int64_t aUsage);

nsCString mScope;
nsCString mOriginScope;
int64_t mUsage[DOMStorageCache::kDataSetCount];
};

Expand Down
Loading

0 comments on commit 048d75d

Please sign in to comment.