2014-03-07 23:50:41 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
/* JSPrincipals and related interfaces. */
|
|
|
|
|
|
|
|
#ifndef js_Principals_h
|
|
|
|
#define js_Principals_h
|
|
|
|
|
|
|
|
#include "mozilla/Atomics.h"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "jspubtd.h"
|
|
|
|
|
2015-03-31 13:40:52 +03:00
|
|
|
namespace js {
|
|
|
|
struct PerformanceGroup;
|
|
|
|
}
|
|
|
|
|
2014-03-07 23:50:41 +04:00
|
|
|
struct JSPrincipals {
|
|
|
|
/* Don't call "destroy"; use reference counting macros below. */
|
|
|
|
mozilla::Atomic<int32_t> refcount;
|
|
|
|
|
|
|
|
#ifdef JS_DEBUG
|
|
|
|
/* A helper to facilitate principals debugging. */
|
|
|
|
uint32_t debugToken;
|
|
|
|
#endif
|
|
|
|
|
2014-09-15 19:49:11 +04:00
|
|
|
JSPrincipals() : refcount(0) {}
|
|
|
|
|
2014-03-07 23:50:41 +04:00
|
|
|
void setDebugToken(uint32_t token) {
|
|
|
|
# ifdef JS_DEBUG
|
|
|
|
debugToken = token;
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is not defined by the JS engine but should be provided by the
|
|
|
|
* embedding.
|
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(void) dump();
|
|
|
|
};
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
2015-03-29 01:22:11 +03:00
|
|
|
JS_HoldPrincipals(JSPrincipals* principals);
|
2014-03-07 23:50:41 +04:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
2015-03-29 01:22:11 +03:00
|
|
|
JS_DropPrincipals(JSRuntime* rt, JSPrincipals* principals);
|
2014-03-07 23:50:41 +04:00
|
|
|
|
|
|
|
// Return whether the first principal subsumes the second. The exact meaning of
|
|
|
|
// 'subsumes' is left up to the browser. Subsumption is checked inside the JS
|
|
|
|
// engine when determining, e.g., which stack frames to display in a backtrace.
|
|
|
|
typedef bool
|
2015-03-29 01:22:11 +03:00
|
|
|
(* JSSubsumesOp)(JSPrincipals* first, JSPrincipals* second);
|
2014-03-07 23:50:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Used to check if a CSP instance wants to disable eval() and friends.
|
|
|
|
* See js_CheckCSPPermitsJSAction() in jsobj.
|
|
|
|
*/
|
|
|
|
typedef bool
|
2015-03-29 01:22:11 +03:00
|
|
|
(* JSCSPEvalChecker)(JSContext* cx);
|
2014-03-07 23:50:41 +04:00
|
|
|
|
|
|
|
struct JSSecurityCallbacks {
|
|
|
|
JSCSPEvalChecker contentSecurityPolicyAllows;
|
|
|
|
JSSubsumesOp subsumes;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
2015-03-29 01:22:11 +03:00
|
|
|
JS_SetSecurityCallbacks(JSRuntime* rt, const JSSecurityCallbacks* callbacks);
|
2014-03-07 23:50:41 +04:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
extern JS_PUBLIC_API(const JSSecurityCallbacks*)
|
|
|
|
JS_GetSecurityCallbacks(JSRuntime* rt);
|
2014-03-07 23:50:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Code running with "trusted" principals will be given a deeper stack
|
|
|
|
* allocation than ordinary scripts. This allows trusted script to run after
|
|
|
|
* untrusted script has exhausted the stack. This function sets the
|
|
|
|
* runtime-wide trusted principal.
|
|
|
|
*
|
|
|
|
* This principals is not held (via JS_HoldPrincipals/JS_DropPrincipals) since
|
|
|
|
* there is no available JSContext. Instead, the caller must ensure that the
|
|
|
|
* given principals stays valid for as long as 'rt' may point to it. If the
|
|
|
|
* principals would be destroyed before 'rt', JS_SetTrustedPrincipals must be
|
|
|
|
* called again, passing nullptr for 'prin'.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
2015-03-29 01:22:11 +03:00
|
|
|
JS_SetTrustedPrincipals(JSRuntime* rt, const JSPrincipals* prin);
|
2014-03-07 23:50:41 +04:00
|
|
|
|
|
|
|
typedef void
|
2015-03-29 01:22:11 +03:00
|
|
|
(* JSDestroyPrincipalsOp)(JSPrincipals* principals);
|
2014-03-07 23:50:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the callback that is called to destroy JSPrincipals instance
|
|
|
|
* when its reference counter drops to zero. The initialization can be done
|
|
|
|
* only once per JS runtime.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
2015-03-29 01:22:11 +03:00
|
|
|
JS_InitDestroyPrincipalsCallback(JSRuntime* rt, JSDestroyPrincipalsOp destroyPrincipals);
|
2014-03-07 23:50:41 +04:00
|
|
|
|
|
|
|
#endif /* js_Principals_h */
|