Bug 915629 - Chrome doesn't need to check the indexedDB permission. r=bent

This commit is contained in:
Jan Varga 2013-09-13 13:19:25 +02:00
parent 9109fb60ff
commit 561b789fb3
3 changed files with 37 additions and 28 deletions

View File

@ -19,13 +19,11 @@
#include "nsContentUtils.h"
#include "nsNetUtil.h"
#include "nsThreadUtils.h"
#include "mozilla/Preferences.h"
#include "mozilla/Services.h"
#include "IndexedDatabaseManager.h"
#define PERMISSION_INDEXEDDB "indexedDB"
#define PREF_INDEXEDDB_ENABLED "dom.indexedDB.enabled"
#define TOPIC_PERMISSIONS_PROMPT "indexedDB-permissions-prompt"
#define TOPIC_PERMISSIONS_RESPONSE "indexedDB-permissions-response"
@ -40,7 +38,6 @@
USING_INDEXEDDB_NAMESPACE
using namespace mozilla::services;
using mozilla::dom::quota::CheckQuotaHelper;
using mozilla::Preferences;
namespace {
@ -50,21 +47,13 @@ GetIndexedDBPermissions(nsIDOMWindow* aWindow)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
if (!Preferences::GetBool(PREF_INDEXEDDB_ENABLED)) {
return PERMISSION_DENIED;
}
// No window here means chrome access.
if (!aWindow) {
return PERMISSION_ALLOWED;
}
NS_ASSERTION(aWindow, "Chrome shouldn't check the permission!");
nsCOMPtr<nsIScriptObjectPrincipal> sop(do_QueryInterface(aWindow));
NS_ENSURE_TRUE(sop, nsIPermissionManager::DENY_ACTION);
if (nsContentUtils::IsSystemPrincipal(sop->GetPrincipal())) {
return PERMISSION_ALLOWED;
}
NS_ASSERTION(!nsContentUtils::IsSystemPrincipal(sop->GetPrincipal()),
"Chrome windows shouldn't check the permission!");
nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(aWindow);
nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(webNav);

View File

@ -21,6 +21,7 @@
#include "mozilla/dom/quota/OriginOrPatternString.h"
#include "mozilla/dom/quota/QuotaManager.h"
#include "mozilla/dom/TabChild.h"
#include "mozilla/Preferences.h"
#include "mozilla/storage.h"
#include "nsComponentManagerUtils.h"
#include "nsCharSeparatedTokenizer.h"
@ -46,6 +47,8 @@
#include "ipc/IndexedDBChild.h"
#define PREF_INDEXEDDB_ENABLED "dom.indexedDB.enabled"
USING_INDEXEDDB_NAMESPACE
USING_QUOTA_NAMESPACE
@ -56,6 +59,7 @@ using mozilla::dom::NonNull;
using mozilla::dom::Optional;
using mozilla::dom::TabChild;
using mozilla::ErrorResult;
using mozilla::Preferences;
namespace {
@ -602,22 +606,33 @@ IDBFactory::OpenInternal(const nsAString& aName,
rv = openHelper->Init();
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
if (aPersistenceType == PERSISTENCE_TYPE_PERSISTENT) {
nsRefPtr<CheckPermissionsHelper> permissionHelper =
new CheckPermissionsHelper(openHelper, window);
QuotaManager* quotaManager = QuotaManager::Get();
NS_ASSERTION(quotaManager, "This should never be null!");
rv = quotaManager->
WaitForOpenAllowed(OriginOrPatternString::FromOrigin(aASCIIOrigin),
Nullable<PersistenceType>(aPersistenceType),
openHelper->Id(), permissionHelper);
if (!Preferences::GetBool(PREF_INDEXEDDB_ENABLED)) {
openHelper->SetError(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
rv = openHelper->WaitForOpenAllowed();
}
else {
NS_ASSERTION(aPersistenceType == PERSISTENCE_TYPE_TEMPORARY, "Huh?");
StoragePrivilege openerPrivilege;
rv = QuotaManager::GetInfoFromWindow(window, nullptr, nullptr,
&openerPrivilege, nullptr);
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
rv = openHelper->WaitForOpenAllowed();
if (openerPrivilege != Chrome &&
aPersistenceType == PERSISTENCE_TYPE_PERSISTENT) {
nsRefPtr<CheckPermissionsHelper> permissionHelper =
new CheckPermissionsHelper(openHelper, window);
QuotaManager* quotaManager = QuotaManager::Get();
NS_ASSERTION(quotaManager, "This should never be null!");
rv = quotaManager->
WaitForOpenAllowed(OriginOrPatternString::FromOrigin(aASCIIOrigin),
Nullable<PersistenceType>(aPersistenceType),
openHelper->Id(), permissionHelper);
}
else {
// Chrome and temporary storage doesn't need to check the permission.
rv = openHelper->WaitForOpenAllowed();
}
}
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
}

View File

@ -1737,7 +1737,8 @@ OpenDatabaseHelper::DispatchToIOThread()
nsresult
OpenDatabaseHelper::RunImmediately()
{
NS_ASSERTION(mState == eCreated, "We've already been dispatched?");
NS_ASSERTION(mState == eCreated || mState == eOpenPending,
"We've already been dispatched?");
NS_ASSERTION(NS_FAILED(mResultCode),
"Should only be short-circuiting if we failed!");
NS_ASSERTION(NS_IsMainThread(), "All hell is about to break lose!");
@ -2168,6 +2169,10 @@ OpenDatabaseHelper::Run()
PROFILER_MAIN_THREAD_LABEL("IndexedDB", "OpenDatabaseHelper::Run");
if (mState == eOpenPending) {
if (NS_FAILED(mResultCode)) {
return RunImmediately();
}
return DispatchToIOThread();
}