Esempio n. 1
0
        /// <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)
            {
                context = GlobalJSContextHolder.SafeJSContext;
            }

            _cx = context;

            // TODO: calling BeginRequest may not be neccessary anymore.
            // begin a new request
            SpiderMonkey.JS_BeginRequest(_cx);

            // TODO: pushing the context onto the context stack may not be neccessary anymore.
            // push the context onto the context stack
            _contextStack = Xpcom.GetService <nsIJSContextStack>("@mozilla.org/js/xpc/ContextStack;1");
            _contextStack.Push(_cx);
        }
Esempio n. 2
0
        /// <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);
        }