Bug 958667 part 3. Add helper methods for testing whether things should be exposed in privilegd or certified apps. r=peterv

This commit is contained in:
Boris Zbarsky 2014-02-05 13:38:17 -05:00
Родитель aca1375a89
Коммит f9ba8ad57a
2 изменённых файлов: 42 добавлений и 0 удалений

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

@ -18,7 +18,9 @@
#include "AccessCheck.h"
#include "jsfriendapi.h"
#include "js/OldDebugAPI.h"
#include "nsContentUtils.h"
#include "nsIDOMGlobalPropertyInitializer.h"
#include "nsIPrincipal.h"
#include "nsIXPConnect.h"
#include "WrapperFactory.h"
#include "xpcprivate.h"
@ -2148,6 +2150,32 @@ ThreadsafeCheckIsChrome(JSContext* aCx, JSObject* aObj)
GetWorkerPrivateFromContext(aCx)->UsesSystemPrincipal();
}
bool
IsInPrivilegedApp(JSContext* aCx, JSObject* aObj)
{
using mozilla::dom::workers::GetWorkerPrivateFromContext;
if (!NS_IsMainThread()) {
return GetWorkerPrivateFromContext(aCx)->IsInPrivilegedApp();
}
nsIPrincipal* principal = nsContentUtils::GetObjectPrincipal(aObj);
uint16_t appStatus = principal->GetAppStatus();
return (appStatus == nsIPrincipal::APP_STATUS_CERTIFIED ||
appStatus == nsIPrincipal::APP_STATUS_PRIVILEGED);
}
bool
IsInCertifiedApp(JSContext* aCx, JSObject* aObj)
{
using mozilla::dom::workers::GetWorkerPrivateFromContext;
if (!NS_IsMainThread()) {
return GetWorkerPrivateFromContext(aCx)->IsInCertifiedApp();
}
nsIPrincipal* principal = nsContentUtils::GetObjectPrincipal(aObj);
return principal->GetAppStatus() == nsIPrincipal::APP_STATUS_CERTIFIED;
}
void
TraceGlobal(JSTracer* aTrc, JSObject* aObj)
{

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

@ -2354,6 +2354,20 @@ public:
bool
ThreadsafeCheckIsChrome(JSContext* aCx, JSObject* aObj);
/*
* Helper function for testing whether the given object comes from a
* privileged app.
*/
bool
IsInPrivilegedApp(JSContext* aCx, JSObject* aObj);
/*
* Helper function for testing whether the given object comes from a
* certified app.
*/
bool
IsInCertifiedApp(JSContext* aCx, JSObject* aObj);
void
TraceGlobal(JSTracer* aTrc, JSObject* aObj);