Skybound.Gecko.AutoJSContext.AutoJSContext C# (CSharp) Method

AutoJSContext() public method

public AutoJSContext ( ) : System
return System
        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);
        }