Bug 777072 - 5/7 - Update IPC::Permission to use appId/isInBrowserElement. r=sicking

This commit is contained in:
Mounir Lamouri 2012-08-23 11:38:01 -07:00
Родитель a2e5fe652d
Коммит 0eb75e0f22
4 изменённых файлов: 54 добавлений и 10 удалений

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

@ -858,7 +858,9 @@ ContentChild::RecvAddPermission(const IPC::Permission& permission)
MOZ_ASSERT(secMan);
nsCOMPtr<nsIPrincipal> principal;
nsresult rv = secMan->GetNoAppCodebasePrincipal(uri, getter_AddRefs(principal));
nsresult rv = secMan->GetAppCodebasePrincipal(uri, permission.appId,
permission.isInBrowserElement,
getter_AddRefs(principal));
NS_ENSURE_SUCCESS(rv, true);
permissionManager->AddInternal(principal,

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

@ -784,6 +784,10 @@ ContentParent::RecvReadPermissions(InfallibleTArray<IPC::Permission>* aPermissio
nsCString host;
perm->GetHost(host);
uint32_t appId;
perm->GetAppId(&appId);
bool isInBrowserElement;
perm->GetIsInBrowserElement(&isInBrowserElement);
nsCString type;
perm->GetType(type);
uint32_t capability;
@ -793,8 +797,10 @@ ContentParent::RecvReadPermissions(InfallibleTArray<IPC::Permission>* aPermissio
int64_t expireTime;
perm->GetExpireTime(&expireTime);
aPermissions->AppendElement(IPC::Permission(host, type, capability,
expireType, expireTime));
aPermissions->AppendElement(IPC::Permission(host, appId,
isInBrowserElement, type,
capability, expireType,
expireTime));
}
// Ask for future changes

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

@ -294,7 +294,13 @@ nsPermissionManager::Init()
const IPC::Permission &perm = perms[i];
nsCOMPtr<nsIPrincipal> principal;
nsresult rv = GetPrincipalForHost(perm.host, getter_AddRefs(principal));
nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
MOZ_ASSERT(secMan, "No security manager!?");
nsCOMPtr<nsIURI> uri;
NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING("http://") + perm.host);
rv = secMan->GetAppCodebasePrincipal(uri, perm.appId, perm.isInBrowserElement, getter_AddRefs(principal));
NS_ENSURE_SUCCESS(rv, rv);
AddInternal(principal, perm.type, perm.capability, 0, perm.expireType,
@ -553,8 +559,15 @@ nsPermissionManager::AddInternal(nsIPrincipal* aPrincipal,
NS_ENSURE_SUCCESS(rv, rv);
if (!IsChildProcess()) {
IPC::Permission permission((host),
(aType),
uint32_t appId;
rv = aPrincipal->GetAppId(&appId);
NS_ENSURE_SUCCESS(rv, rv);
bool isInBrowserElement;
rv = aPrincipal->GetIsInBrowserElement(&isInBrowserElement);
NS_ENSURE_SUCCESS(rv, rv);
IPC::Permission permission(host, appId, isInBrowserElement, aType,
aPermission, aExpireType, aExpireTime);
nsTArray<ContentParent*> cplist;

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

@ -20,9 +20,13 @@ struct Permission
nsCString host, type;
uint32_t capability, expireType;
int64_t expireTime;
uint32_t appId;
bool isInBrowserElement;
Permission() { }
Permission(const nsCString& aHost,
const uint32_t aAppId,
const bool aIsInBrowserElement,
const nsCString& aType,
const uint32_t aCapability,
const uint32_t aExpireType,
@ -30,7 +34,10 @@ struct Permission
type(aType),
capability(aCapability),
expireType(aExpireType),
expireTime(aExpireTime) { }
expireTime(aExpireTime),
appId(aAppId),
isInBrowserElement(aIsInBrowserElement)
{}
};
template<>
@ -43,6 +50,8 @@ struct ParamTraits<Permission>
WriteParam(aMsg, aParam.capability);
WriteParam(aMsg, aParam.expireType);
WriteParam(aMsg, aParam.expireTime);
WriteParam(aMsg, aParam.appId);
WriteParam(aMsg, aParam.isInBrowserElement);
}
static bool Read(const Message* aMsg, void** aIter, Permission* aResult)
@ -51,12 +60,26 @@ struct ParamTraits<Permission>
ReadParam(aMsg, aIter, &aResult->type) &&
ReadParam(aMsg, aIter, &aResult->capability) &&
ReadParam(aMsg, aIter, &aResult->expireType) &&
ReadParam(aMsg, aIter, &aResult->expireTime);
ReadParam(aMsg, aIter, &aResult->expireTime) &&
ReadParam(aMsg, aIter, &aResult->appId) &&
ReadParam(aMsg, aIter, &aResult->isInBrowserElement);
}
static void Log(const Permission& aParam, std::wstring* aLog)
static void Log(const Permission& p, std::wstring* l)
{
aLog->append(StringPrintf(L"[%s]", aParam.host.get()));
l->append(L"(");
LogParam(p.host, l);
l->append(L", ");
LogParam(p.appId, l);
l->append(L", ");
LogParam(p.isInBrowserElement, l);
l->append(L", ");
LogParam(p.capability, l);
l->append(L", ");
LogParam(p.expireTime, l);
l->append(L", ");
LogParam(p.expireType, l);
l->append(L")");
}
};