/// <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 void Dispose()
        {
            nsIScriptSecurityManager securityManager = Xpcom.GetService <nsIScriptSecurityManager>("@mozilla.org/scriptsecuritymanager;1");

            securityManager.PopContextPrincipal(cx);

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

            contextStack.Pop();
            JS_EndRequest(cx);
        }
        public FullTrustSecMan(nsIXPConnect xpConnect, IntPtr context)
        {
            _xpConnect = xpConnect;

            _originalSecurityManager = null;
            _originalFlags = 0;

            if (context != IntPtr.Zero)
            {
                _context = context;
                xpConnect.GetSecurityManagerForJSContext(context, ref _originalSecurityManager, ref _originalFlags);
                _ssm = (nsIScriptSecurityManager)_originalSecurityManager;
                xpConnect.SetSecurityManagerForJSContext(context, this, 0xFFFF);
            }
            else
            {
                xpConnect.GetDefaultSecurityManager(ref _originalSecurityManager, ref _originalFlags);
                _ssm = (nsIScriptSecurityManager)_originalSecurityManager;
                xpConnect.SetDefaultSecurityManager(this, 0xFFFF);
            }
        }
Beispiel #4
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);
        }
        /// <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");
                // Due to GetSafeJSContext (being changed from an attribute to a virtual method in FF 15) we can no longer call
                // it safely from C#. // TODO: find a better solution for this.
                context = _jsContextStack.GetSafeJSContext();
            }

            _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>( Contracts.JsContextStack );
            _contextStack.Push(_cx);

            // PushContextPrinciple was removed in firefox 16.
            // TODO: It would be nice to get elevated security when running javascript from geckofx.
            #if false
            // obtain the system principal (no security checks) (one could get a different principal by calling securityManager.GetObjectPrincipal())
            if (_securityManager == null)
            {
                _securityManager = Xpcom.GetService<nsIScriptSecurityManager>("@mozilla.org/scriptsecuritymanager;1");
            }

            _systemPrincipal = _securityManager.GetSystemPrincipal();

            _securityManager.PushContextPrincipal(_cx, IntPtr.Zero, _systemPrincipal);
            #endif
        }