/// <summary>
        /// Create a AutoJSContext using the SafeJSContext.
        /// If context is IntPtr.Zero use the SafeJSContext
        /// </summary>
        /// <param name="context"></param>
        public AutoJSContext(IntPtr context)
        {
            if (context == IntPtr.Zero)
            {
                _jsContextStack = Xpcom.GetService <nsIThreadJSContextStack>("@mozilla.org/js/xpc/ContextStack;1");
                context         = _jsContextStack.GetSafeJSContextAttribute();
            }

            _cx = context;

            // begin a new request
            JS_BeginRequest(_cx);

            // push the context onto the context stack
            _contextStack = Xpcom.GetService <nsIJSContextStack>("@mozilla.org/js/xpc/ContextStack;1");
            _contextStack.Push(_cx);

            // obtain the system principal (no security checks) (one could get a different principal by calling securityManager.GetObjectPrincipal())
            _securityManager = Xpcom.GetService <nsIScriptSecurityManager>("@mozilla.org/scriptsecuritymanager;1");

            _systemPrincipal = _securityManager.GetSystemPrincipal();
            _jsPrincipals    = _systemPrincipal.GetJSPrincipals(_cx);

            _securityManager.PushContextPrincipal(_cx, IntPtr.Zero, _systemPrincipal);
        }
Beispiel #2
0
        public AutoJSContext()
        {
            var jsContextStack = Xpcom.GetService <nsIThreadJSContextStack>("@mozilla.org/js/xpc/ContextStack;1");

            cx = jsContextStack.GetSafeJSContextAttribute();

            // begin a new request
            JS_BeginRequest(cx);

            // push the context onto the context stack
            nsIJSContextStack contextStack = Xpcom.GetService <nsIJSContextStack>("@mozilla.org/js/xpc/ContextStack;1");

            contextStack.Push(cx);

            // obtain the system principal (no security checks)
            nsIScriptSecurityManager securityManager = Xpcom.GetService <nsIScriptSecurityManager>("@mozilla.org/scriptsecuritymanager;1");
            nsIPrincipal             system          = securityManager.GetSystemPrincipal();
            IntPtr jsPrincipals = system.GetJSPrincipals(cx);

            securityManager.PushContextPrincipal(cx, IntPtr.Zero, system);
        }
        /// <summary>
        /// Create a AutoJSContext using the SafeJSContext.
        /// If context is IntPtr.Zero use the SafeJSContext
        /// </summary>
        /// <param name="context"></param>
        public AutoJSContext(IntPtr context)
        {
            if (context == IntPtr.Zero)
            {
                _jsContextStack = Xpcom.GetService<nsIThreadJSContextStack>("@mozilla.org/js/xpc/ContextStack;1");
                context = _jsContextStack.GetSafeJSContextAttribute();
            }

            _cx = context;

            // begin a new request
            SpiderMonkey.JS_BeginRequest(_cx);

            // push the context onto the context stack
            _contextStack = Xpcom.GetService<nsIJSContextStack>("@mozilla.org/js/xpc/ContextStack;1");
            _contextStack.Push(_cx);

            // obtain the system principal (no security checks) (one could get a different principal by calling securityManager.GetObjectPrincipal())
            _securityManager = Xpcom.GetService<nsIScriptSecurityManager>("@mozilla.org/scriptsecuritymanager;1");
            _systemPrincipal = _securityManager.GetSystemPrincipal();
            _securityManager.PushContextPrincipal(_cx, IntPtr.Zero, _systemPrincipal);
        }