NS_IMETHODIMP DOMStorageManager::CheckStorage(nsIPrincipal* aPrincipal, nsIDOMStorage* aStorage, bool* aRetval) { RefPtr<DOMStorage> storage = static_cast<DOMStorage*>(aStorage); if (!storage) { return NS_ERROR_UNEXPECTED; } *aRetval = false; if (!aPrincipal) { return NS_ERROR_NOT_AVAILABLE; } nsAutoCString scope; nsresult rv = CreateScopeKey(aPrincipal, scope); if (NS_FAILED(rv)) { return rv; } DOMStorageCache* cache = GetCache(scope); if (cache != storage->GetCache()) { return NS_OK; } if (!storage->PrincipalEquals(aPrincipal)) { return NS_OK; } *aRetval = true; return NS_OK; }
NS_IMETHODIMP DOMStorageManager::CheckStorage(nsIPrincipal* aPrincipal, nsIDOMStorage* aStorage, bool* aRetval) { nsCOMPtr<nsPIDOMStorage> pstorage = do_QueryInterface(aStorage); if (!pstorage) { return NS_ERROR_UNEXPECTED; } *aRetval = false; if (!aPrincipal) { return NS_ERROR_NOT_AVAILABLE; } nsAutoCString scope; nsresult rv = CreateScopeKey(aPrincipal, scope); NS_ENSURE_SUCCESS(rv, rv); DOMStorageCache* cache = GetCache(scope); if (cache != pstorage->GetCache()) { return NS_OK; } if (!pstorage->PrincipalEquals(aPrincipal)) { return NS_OK; } *aRetval = true; 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; }