Bug 813995 - Check device storage permissions in parent process. r=bent a=blocking-basecamp

This commit is contained in:
Doug Turner 2012-11-29 21:41:40 -08:00
Родитель f03931dfaf
Коммит b8cbbff7b0
4 изменённых файлов: 116 добавлений и 12 удалений

Просмотреть файл

@ -46,8 +46,8 @@ private:
nsresult EnumerateInternal(const JS::Value & aName,
const JS::Value & aOptions,
JSContext* aCx,
uint8_t aArgc,
bool aEditable,
uint8_t aArgc,
bool aEditable,
nsIDOMDeviceStorageCursor** aRetval);
nsString mStorageType;

Просмотреть файл

@ -11,21 +11,28 @@
#include "mozilla/dom/ipc/Blob.h"
#include "ContentParent.h"
#include "nsProxyRelease.h"
#include "AppProcessPermissions.h"
#include "mozilla/Preferences.h"
namespace mozilla {
namespace dom {
namespace devicestorage {
DeviceStorageRequestParent::DeviceStorageRequestParent(const DeviceStorageParams& aParams)
: mMutex("DeviceStorageRequestParent::mMutex")
: mParams(aParams)
, mMutex("DeviceStorageRequestParent::mMutex")
, mActorDestoryed(false)
{
MOZ_COUNT_CTOR(DeviceStorageRequestParent);
}
switch (aParams.type()) {
void
DeviceStorageRequestParent::Dispatch()
{
switch (mParams.type()) {
case DeviceStorageParams::TDeviceStorageAddParams:
{
DeviceStorageAddParams p = aParams;
DeviceStorageAddParams p = mParams;
nsCOMPtr<nsIFile> f;
NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f));
@ -48,7 +55,7 @@ DeviceStorageRequestParent::DeviceStorageRequestParent(const DeviceStorageParams
case DeviceStorageParams::TDeviceStorageGetParams:
{
DeviceStorageGetParams p = aParams;
DeviceStorageGetParams p = mParams;
nsCOMPtr<nsIFile> f;
NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f));
@ -65,7 +72,7 @@ DeviceStorageRequestParent::DeviceStorageRequestParent(const DeviceStorageParams
case DeviceStorageParams::TDeviceStorageDeleteParams:
{
DeviceStorageDeleteParams p = aParams;
DeviceStorageDeleteParams p = mParams;
nsCOMPtr<nsIFile> f;
NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f));
@ -81,7 +88,7 @@ DeviceStorageRequestParent::DeviceStorageRequestParent(const DeviceStorageParams
case DeviceStorageParams::TDeviceStorageStatParams:
{
DeviceStorageStatParams p = aParams;
DeviceStorageStatParams p = mParams;
nsCOMPtr<nsIFile> f;
NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f));
@ -97,7 +104,7 @@ DeviceStorageRequestParent::DeviceStorageRequestParent(const DeviceStorageParams
case DeviceStorageParams::TDeviceStorageEnumerationParams:
{
DeviceStorageEnumerationParams p = aParams;
DeviceStorageEnumerationParams p = mParams;
nsCOMPtr<nsIFile> f;
NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f));
@ -118,6 +125,94 @@ DeviceStorageRequestParent::DeviceStorageRequestParent(const DeviceStorageParams
}
}
bool
DeviceStorageRequestParent::EnsureRequiredPermissions(mozilla::dom::ContentParent* aParent)
{
if (mozilla::Preferences::GetBool("device.storage.testing", false)) {
return true;
}
nsString type;
DeviceStorageRequestType requestType;
switch (mParams.type())
{
case DeviceStorageParams::TDeviceStorageAddParams:
{
DeviceStorageAddParams p = mParams;
type = p.type();
requestType = DEVICE_STORAGE_REQUEST_CREATE;
break;
}
case DeviceStorageParams::TDeviceStorageGetParams:
{
DeviceStorageGetParams p = mParams;
type = p.type();
requestType = DEVICE_STORAGE_REQUEST_READ;
break;
}
case DeviceStorageParams::TDeviceStorageDeleteParams:
{
DeviceStorageDeleteParams p = mParams;
type = p.type();
requestType = DEVICE_STORAGE_REQUEST_DELETE;
break;
}
case DeviceStorageParams::TDeviceStorageStatParams:
{
DeviceStorageStatParams p = mParams;
type = p.type();
requestType = DEVICE_STORAGE_REQUEST_STAT;
break;
}
case DeviceStorageParams::TDeviceStorageEnumerationParams:
{
DeviceStorageEnumerationParams p = mParams;
type = p.type();
requestType = DEVICE_STORAGE_REQUEST_READ;
break;
}
default:
{
return false;
}
}
// The 'apps' type is special. We only want this exposed
// if the caller has the "webapps-manage" permission.
if (type.EqualsLiteral("apps")) {
if (!AssertAppProcessPermission(aParent, "webapps-manage")) {
return false;
}
}
nsAutoCString permissionName;
nsresult rv = DeviceStorageTypeChecker::GetPermissionForType(type, permissionName);
if (NS_FAILED(rv)) {
return false;
}
nsCString access;
rv = DeviceStorageTypeChecker::GetAccessForRequest(requestType, access);
if (NS_FAILED(rv)) {
return false;
}
permissionName.AppendLiteral("-");
permissionName.Append(access);
if (!AssertAppProcessPermission(aParent, permissionName.get())) {
return false;
}
return true;
}
DeviceStorageRequestParent::~DeviceStorageRequestParent()
{
MOZ_COUNT_DTOR(DeviceStorageRequestParent);

Просмотреть файл

@ -8,6 +8,7 @@
#include "mozilla/dom/devicestorage/PDeviceStorageRequestParent.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/ContentParent.h"
#include "nsThreadUtils.h"
#include "nsDeviceStorage.h"
@ -24,6 +25,10 @@ public:
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
bool EnsureRequiredPermissions(mozilla::dom::ContentParent* aParent);
void Dispatch();
virtual void ActorDestroy(ActorDestroyReason);
protected:
@ -31,6 +36,7 @@ protected:
private:
nsAutoRefCnt mRefCnt;
DeviceStorageParams mParams;
class CancelableRunnable : public nsRunnable
{

Просмотреть файл

@ -1198,9 +1198,12 @@ ContentParent::DeallocPBrowser(PBrowserParent* frame)
PDeviceStorageRequestParent*
ContentParent::AllocPDeviceStorageRequest(const DeviceStorageParams& aParams)
{
DeviceStorageRequestParent* result = new DeviceStorageRequestParent(aParams);
NS_ADDREF(result);
return result;
nsRefPtr<DeviceStorageRequestParent> result = new DeviceStorageRequestParent(aParams);
if (!result->EnsureRequiredPermissions(this)) {
return nullptr;
}
result->Dispatch();
return result.forget().get();
}
bool