Backed out changeset 3a242f8d8298 (bug 856032) for mochitest-2 failures.

This commit is contained in:
Ryan VanderMeulen 2013-03-30 16:15:06 -04:00
parent 662f70cf41
commit a3899ec9ca
10 changed files with 48 additions and 124 deletions

View File

@ -15,7 +15,6 @@
#include "nsIScriptObjectPrincipal.h"
#include "nsIURI.h"
#include "CheckQuotaHelper.h"
#include "nsContentUtils.h"
#include "nsDOMStorage.h"
#include "nsNetUtil.h"
@ -39,10 +38,9 @@
#define PERMISSION_DENIED nsIPermissionManager::DENY_ACTION
#define PERMISSION_PROMPT nsIPermissionManager::ALLOW_ACTION
using namespace mozilla;
USING_INDEXEDDB_NAMESPACE
using namespace mozilla::services;
using mozilla::dom::quota::CheckQuotaHelper;
using mozilla::Preferences;
namespace {
@ -113,19 +111,14 @@ CheckPermissionsHelper::Run()
// we cannot set the permission from the child).
if (permission != PERMISSION_PROMPT &&
IndexedDatabaseManager::IsMainProcess()) {
NS_ASSERTION(mWindow, "Null window!");
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(mWindow);
NS_ASSERTION(sop, "Window didn't QI to nsIScriptObjectPrincipal!");
nsIPrincipal* windowPrincipal = sop->GetPrincipal();
NS_ASSERTION(windowPrincipal, "Null principal!");
nsCOMPtr<nsIPermissionManager> permissionManager =
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
NS_ENSURE_STATE(permissionManager);
rv = permissionManager->AddFromPrincipal(windowPrincipal,
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(mWindow);
NS_ENSURE_TRUE(sop, NS_ERROR_FAILURE);
rv = permissionManager->AddFromPrincipal(sop->GetPrincipal(),
PERMISSION_INDEXEDDB, permission,
nsIPermissionManager::EXPIRE_NEVER,
0);
@ -148,24 +141,6 @@ CheckPermissionsHelper::Run()
window.swap(mWindow);
if (permission == PERMISSION_ALLOWED) {
// If we're running from a window then we should check the quota permission
// as well. If we don't have a window then we're opening a chrome database
// and the quota will be unlimited already.
if (window) {
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(window);
NS_ASSERTION(sop, "Window didn't QI to nsIScriptObjectPrincipal!");
nsIPrincipal* windowPrincipal = sop->GetPrincipal();
NS_ASSERTION(windowPrincipal, "Null principal!");
uint32_t quotaPermission =
CheckQuotaHelper::GetQuotaPermission(windowPrincipal);
if (quotaPermission == nsIPermissionManager::ALLOW_ACTION) {
helper->SetUnlimitedQuotaAllowed();
}
}
quota::QuotaManager* quotaManager = quota::QuotaManager::Get();
NS_ASSERTION(quotaManager, "This should never be null!");

View File

@ -2691,25 +2691,22 @@ CopyData(nsIInputStream* aInputStream, nsIOutputStream* aOutputStream)
char copyBuffer[FILE_COPY_BUFFER_SIZE];
uint32_t numRead;
rv = aInputStream->Read(copyBuffer, sizeof(copyBuffer), &numRead);
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
rv = aInputStream->Read(copyBuffer, FILE_COPY_BUFFER_SIZE, &numRead);
NS_ENSURE_SUCCESS(rv, rv);
if (!numRead) {
if (numRead <= 0) {
break;
}
uint32_t numWrite;
rv = aOutputStream->Write(copyBuffer, numRead, &numWrite);
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
NS_ENSURE_SUCCESS(rv, rv);
if (numWrite < numRead) {
// Must have hit the quota limit.
return NS_ERROR_DOM_INDEXEDDB_QUOTA_ERR;
}
NS_ENSURE_TRUE(numWrite == numRead, NS_ERROR_FAILURE);
} while (true);
rv = aOutputStream->Flush();
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
@ -2917,7 +2914,7 @@ AddHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
NS_ENSURE_TRUE(outputStream, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
rv = CopyData(inputStream, outputStream);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
cloneFile.mFile->AddFileInfo(fileInfo);
}

View File

@ -72,7 +72,6 @@ LOCAL_INCLUDES = \
-I$(topsrcdir)/db/sqlite3/src \
-I$(topsrcdir)/dom/base \
-I$(topsrcdir)/dom/src/storage \
-I$(topsrcdir)/dom/quota \
-I$(topsrcdir)/xpcom/build \
$(NULL)

View File

@ -1651,7 +1651,7 @@ OpenDatabaseHelper::DoDatabaseWork()
nsresult rv =
quotaManager->EnsureOriginIsInitialized(mASCIIOrigin,
mTrackingQuota,
mPrivilege,
getter_AddRefs(dbDirectory));
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);

View File

@ -6,15 +6,12 @@
#define mozilla_dom_indexeddb_opendatabasehelper_h__
#include "AsyncConnectionHelper.h"
#include "nsIRunnable.h"
#include "mozilla/dom/quota/StoragePrivilege.h"
#include "DatabaseInfo.h"
#include "IDBDatabase.h"
#include "IDBRequest.h"
#include "nsIRunnable.h"
class mozIStorageConnection;
namespace mozilla {
@ -25,12 +22,8 @@ class ContentParent;
BEGIN_INDEXEDDB_NAMESPACE
class CheckPermissionsHelper;
class OpenDatabaseHelper : public HelperBase
{
friend class CheckPermissionsHelper;
typedef mozilla::dom::quota::StoragePrivilege StoragePrivilege;
public:
@ -46,8 +39,7 @@ public:
mForDeletion(aForDeletion), mPrivilege(aPrivilege), mDatabaseId(nullptr),
mContentParent(aContentParent), mCurrentVersion(0), mLastObjectStoreId(0),
mLastIndexId(0), mState(eCreated), mResultCode(NS_OK),
mLoadDBMetadata(false),
mTrackingQuota(aPrivilege != mozilla::dom::quota::Chrome)
mLoadDBMetadata(false)
{
NS_ASSERTION(!aForDeletion || !aRequestedVersion,
"Can't be for deletion and request a version!");
@ -110,12 +102,6 @@ protected:
void DispatchErrorEvent();
virtual void ReleaseMainThreadObjects() MOZ_OVERRIDE;
// Called by CheckPermissionsHelper on the main thread before dispatch.
void SetUnlimitedQuotaAllowed()
{
mTrackingQuota = false;
}
// Methods only called on the DB thread
nsresult DoDatabaseWork();
@ -154,7 +140,6 @@ protected:
nsRefPtr<DatabaseInfo> mDBInfo;
bool mLoadDBMetadata;
bool mTrackingQuota;
};
END_INDEXEDDB_NAMESPACE

View File

@ -35,14 +35,29 @@ namespace {
inline
uint32_t
GetQuotaPermissionFromWindow(nsIDOMWindow* aWindow)
GetQuotaPermissions(nsIDOMWindow* aWindow)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
nsCOMPtr<nsIScriptObjectPrincipal> sop(do_QueryInterface(aWindow));
NS_ENSURE_TRUE(sop, nsIPermissionManager::DENY_ACTION);
return CheckQuotaHelper::GetQuotaPermission(sop->GetPrincipal());
if (nsContentUtils::IsSystemPrincipal(sop->GetPrincipal())) {
return nsIPermissionManager::ALLOW_ACTION;
}
nsCOMPtr<nsIPermissionManager> permissionManager =
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
NS_ENSURE_TRUE(permissionManager, nsIPermissionManager::DENY_ACTION);
uint32_t permission;
nsresult rv =
permissionManager->TestPermissionFromPrincipal(sop->GetPrincipal(),
PERMISSION_INDEXEDDB_UNLIMITED,
&permission);
NS_ENSURE_SUCCESS(rv, nsIPermissionManager::DENY_ACTION);
return permission;
}
} // anonymous namespace
@ -113,30 +128,6 @@ CheckQuotaHelper::Cancel()
}
}
// static
uint32_t
CheckQuotaHelper::GetQuotaPermission(nsIPrincipal* aPrincipal)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
NS_ASSERTION(aPrincipal, "Null principal!");
if (nsContentUtils::IsSystemPrincipal(aPrincipal)) {
return nsIPermissionManager::ALLOW_ACTION;
}
nsCOMPtr<nsIPermissionManager> pm =
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
NS_ENSURE_TRUE(pm, nsIPermissionManager::DENY_ACTION);
uint32_t permission;
nsresult rv = pm->TestPermissionFromPrincipal(aPrincipal,
PERMISSION_INDEXEDDB_UNLIMITED,
&permission);
NS_ENSURE_SUCCESS(rv, nsIPermissionManager::DENY_ACTION);
return permission;
}
NS_IMPL_THREADSAFE_ISUPPORTS3(CheckQuotaHelper, nsIRunnable,
nsIInterfaceRequestor,
nsIObserver)
@ -150,7 +141,7 @@ CheckQuotaHelper::Run()
if (NS_SUCCEEDED(rv)) {
if (!mHasPrompted) {
mPromptResult = GetQuotaPermissionFromWindow(mWindow);
mPromptResult = GetQuotaPermissions(mWindow);
}
if (mHasPrompted) {

View File

@ -16,7 +16,6 @@
#include "mozilla/Mutex.h"
#include "mozilla/CondVar.h"
class nsIPrincipal;
class nsPIDOMWindow;
BEGIN_QUOTA_NAMESPACE
@ -38,8 +37,6 @@ public:
void Cancel();
static uint32_t GetQuotaPermission(nsIPrincipal* aPrincipal);
private:
nsPIDOMWindow* mWindow;

View File

@ -76,10 +76,7 @@ FileQuotaStreamWithWrite<FileStreamBase>::Write(const char* aBuf,
if (!FileQuotaStreamWithWrite::
mQuotaObject->MaybeAllocateMoreSpace(offset, aCount)) {
// A quota failure shouldn't be confused with a write failure. We don't
// attempt the write and inform the caller.
*_retval = 0;
return NS_OK;
return NS_ERROR_FAILURE;
}
}

View File

@ -481,14 +481,10 @@ QuotaManager::Init()
void
QuotaManager::InitQuotaForOrigin(const nsACString& aOrigin,
int64_t aLimitBytes,
int64_t aUsageBytes)
int64_t aLimit,
int64_t aUsage)
{
MOZ_ASSERT(aUsageBytes >= 0);
MOZ_ASSERT(aLimitBytes > 0);
MOZ_ASSERT(aUsageBytes <= aLimitBytes);
OriginInfo* info = new OriginInfo(aOrigin, aLimitBytes, aUsageBytes);
OriginInfo* info = new OriginInfo(aOrigin, aLimit * 1024 * 1024, aUsage);
MutexAutoLock lock(mQuotaMutex);
@ -822,7 +818,7 @@ QuotaManager::GetDirectoryForOrigin(const nsACString& aASCIIOrigin,
nsresult
QuotaManager::EnsureOriginIsInitialized(const nsACString& aOrigin,
bool aTrackQuota,
StoragePrivilege aPrivilege,
nsIFile** aDirectory)
{
#ifdef DEBUG
@ -874,7 +870,7 @@ QuotaManager::EnsureOriginIsInitialized(const nsACString& aOrigin,
// We need to initialize directories of all clients if they exists and also
// get the total usage to initialize the quota.
nsAutoPtr<UsageRunnable> runnable;
if (aTrackQuota) {
if (aPrivilege != Chrome) {
runnable = new UsageRunnable();
}
@ -919,25 +915,12 @@ QuotaManager::EnsureOriginIsInitialized(const nsACString& aOrigin,
NS_ENSURE_SUCCESS(rv, rv);
}
if (aTrackQuota) {
uint64_t quotaMaxBytes = GetStorageQuotaMB() * 1024 * 1024;
uint64_t totalUsageBytes = runnable->TotalUsage();
if (aPrivilege != Chrome) {
QuotaManager* quotaManager = QuotaManager::Get();
NS_ASSERTION(quotaManager, "Shouldn't be null!");
if (totalUsageBytes > quotaMaxBytes) {
NS_WARNING("Origin is already using more storage than allowed by quota!");
return NS_ERROR_UNEXPECTED;
}
// XXX This signed/unsigned mismatch must be fixed.
int64_t limit = quotaMaxBytes >= uint64_t(INT64_MAX) ?
INT64_MAX :
int64_t(quotaMaxBytes);
int64_t usage = totalUsageBytes >= uint64_t(INT64_MAX) ?
INT64_MAX :
int64_t(totalUsageBytes);
InitQuotaForOrigin(aOrigin, limit, usage);
quotaManager->InitQuotaForOrigin(aOrigin, GetStorageQuotaMB(),
runnable->TotalUsage());
}
mInitializedOrigins.AppendElement(aOrigin);

View File

@ -82,8 +82,8 @@ public:
void
InitQuotaForOrigin(const nsACString& aOrigin,
int64_t aLimitBytes,
int64_t aUsageBytes);
int64_t aLimit,
int64_t aUsage);
void
DecreaseUsageForOrigin(const nsACString& aOrigin,
@ -192,7 +192,7 @@ public:
nsresult
EnsureOriginIsInitialized(const nsACString& aOrigin,
bool aTrackQuota,
StoragePrivilege aPrivilege,
nsIFile** aDirectory);
void