NS_IMETHODIMP DOMStorageManager::CloneStorage(nsIDOMStorage* aStorage) { if (mType != SessionStorage) { // Cloning is supported only for sessionStorage return NS_ERROR_NOT_IMPLEMENTED; } nsCOMPtr<nsPIDOMStorage> pstorage = do_QueryInterface(aStorage); if (!pstorage) { return NS_ERROR_UNEXPECTED; } const DOMStorageCache* origCache = pstorage->GetCache(); DOMStorageCache* existingCache = GetCache(origCache->Scope()); if (existingCache) { // Do not replace an existing sessionStorage. return NS_ERROR_NOT_AVAILABLE; } // Since this manager is sessionStorage manager, PutCache hard references // the cache in our hashtable. nsRefPtr<DOMStorageCache> newCache = PutCache(origCache->Scope(), origCache->Principal()); newCache->CloneFrom(origCache); return NS_OK; }
NS_IMETHODIMP DOMStorageManager::CloneStorage(nsIDOMStorage* aStorage) { if (mType != SessionStorage) { // Cloning is supported only for sessionStorage return NS_ERROR_NOT_IMPLEMENTED; } RefPtr<DOMStorage> storage = static_cast<DOMStorage*>(aStorage); if (!storage) { return NS_ERROR_UNEXPECTED; } const DOMStorageCache* origCache = storage->GetCache(); DOMStorageCache* existingCache = GetCache(origCache->OriginSuffix(), origCache->OriginNoSuffix()); if (existingCache) { // Do not replace an existing sessionStorage. return NS_ERROR_NOT_AVAILABLE; } // Since this manager is sessionStorage manager, PutCache hard references // the cache in our hashtable. RefPtr<DOMStorageCache> newCache = PutCache(origCache->OriginSuffix(), origCache->OriginNoSuffix(), origCache->Principal()); newCache->CloneFrom(origCache); return NS_OK; }
nsresult DOMStorageManager::GetStorageInternal(bool aCreate, nsIDOMWindow* aWindow, nsIPrincipal* aPrincipal, const nsAString& aDocumentURI, bool aPrivate, nsIDOMStorage** aRetval) { nsresult rv; nsAutoCString scope; rv = CreateScopeKey(aPrincipal, scope); if (NS_FAILED(rv)) { return NS_ERROR_NOT_AVAILABLE; } RefPtr<DOMStorageCache> cache = GetCache(scope); // Get or create a cache for the given scope if (!cache) { if (!aCreate) { *aRetval = nullptr; return NS_OK; } if (!aRetval) { // This is demand to just preload the cache, if the scope has // no data stored, bypass creation and preload of the cache. DOMStorageDBBridge* db = DOMStorageCache::GetDatabase(); if (db) { if (!db->ShouldPreloadScope(scope)) { return NS_OK; } } else { if (scope.EqualsLiteral("knalb.:about")) { return NS_OK; } } } // There is always a single instance of a cache per scope // in a single instance of a DOM storage manager. cache = PutCache(scope, aPrincipal); } else if (mType == SessionStorage) { if (!cache->CheckPrincipal(aPrincipal)) { return NS_ERROR_DOM_SECURITY_ERR; } } if (aRetval) { nsCOMPtr<nsIDOMStorage> storage = new DOMStorage( aWindow, this, cache, aDocumentURI, aPrincipal, aPrivate); storage.forget(aRetval); } return NS_OK; }
nsresult DOMStorageManager::GetStorageInternal(bool aCreate, mozIDOMWindow* aWindow, nsIPrincipal* aPrincipal, const nsAString& aDocumentURI, bool aPrivate, nsIDOMStorage** aRetval) { nsresult rv; nsAutoCString originAttrSuffix; BasePrincipal::Cast(aPrincipal)->OriginAttributesRef().CreateSuffix(originAttrSuffix); nsAutoCString originKey; rv = AppendOriginNoSuffix(aPrincipal, originKey); if (NS_FAILED(rv)) { return NS_ERROR_NOT_AVAILABLE; } RefPtr<DOMStorageCache> cache = GetCache(originAttrSuffix, originKey); // Get or create a cache for the given scope if (!cache) { if (!aCreate) { *aRetval = nullptr; return NS_OK; } if (!aRetval) { // This is a demand to just preload the cache, if the scope has // no data stored, bypass creation and preload of the cache. DOMStorageDBBridge* db = DOMStorageCache::GetDatabase(); if (db) { if (!db->ShouldPreloadOrigin(DOMStorageManager::CreateOrigin(originAttrSuffix, originKey))) { return NS_OK; } } else { if (originKey.EqualsLiteral("knalb.:about")) { return NS_OK; } } } // There is always a single instance of a cache per scope // in a single instance of a DOM storage manager. cache = PutCache(originAttrSuffix, originKey, aPrincipal); } else if (mType == SessionStorage) { if (!cache->CheckPrincipal(aPrincipal)) { return NS_ERROR_DOM_SECURITY_ERR; } } if (aRetval) { nsCOMPtr<nsPIDOMWindowInner> inner = nsPIDOMWindowInner::From(aWindow); nsCOMPtr<nsIDOMStorage> storage = new DOMStorage( inner, this, cache, aDocumentURI, aPrincipal, aPrivate); storage.forget(aRetval); } return NS_OK; }