Exemplo n.º 1
0
        public AutoJSContext()
        {
            nsIJSRuntimeService runtimeService = (nsIJSRuntimeService)Xpcom.GetService("@mozilla.org/js/xpc/RuntimeService;1");
            IntPtr jsRuntime = runtimeService.GetRuntime();

            IntPtr cx = JS_NewContext(jsRuntime, 8192);

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

            contextStack.Push(cx);

            nsIPrincipal system       = Xpcom.GetService <nsIScriptSecurityManager>("@mozilla.org/scriptsecuritymanager;1").GetSystemPrincipal();
            IntPtr       jsPrincipals = system.GetJSPrincipals(cx);

            JSStackFrame frame = new JSStackFrame();

            frame.script = JS_CompileScriptForPrincipals(cx, JS_GetGlobalObject(cx), jsPrincipals, "", 0, "", 1);

            //NOTE: this code is based on the definition of JSContext from mozilla 1.8 and will not work for other versions
            IntPtr old = Marshal.ReadIntPtr(cx, 0x34);

            frame.down = old;

            IntPtr framePtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(JSStackFrame)));

            Marshal.StructureToPtr(frame, framePtr, true);

            // cx->fp = framePtr;
            Marshal.WriteIntPtr(cx, 0x34, framePtr);
        }
Exemplo n.º 2
0
        static GeckoPreferences()
        {
            // ensure we're initialized
            Xpcom.Initialize();

            PrefService = Xpcom.GetService <nsIPrefService>("@mozilla.org/preferences-service;1");
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
		public void Dispose()
		{
			nsIJSContextStack contextStack = Xpcom.GetService<nsIJSContextStack>("@mozilla.org/js/xpc/ContextStack;1");
			contextStack.Pop();
			
			// free the memory allocated for the fake stack frame
			Marshal.FreeHGlobal(Marshal.ReadIntPtr(cx, OfsetOfFP));
			
			// end the request, destroy the context
			JS_EndRequest(cx);
			JS_DestroyContextNoGC(cx);
		}
        public void UnregisterStyleSheet(string sheetURI, uint type)
        {
            nsIIOService ios = Xpcom.GetService <nsIIOService>("@mozilla.org/network/io-service;1");

            ios = Xpcom.QueryInterface <nsIIOService>(ios);
            nsIURI ssURI = ios.NewURI(new nsAUTF8String(sheetURI), null, null);

            if (StyleSheetService.sheetRegistered(ssURI, type))
            {
                StyleSheetService.unregisterSheet(ssURI, type);
            }
        }
        public bool IsStyleSheetRegistered(string sheetURI, uint type)
        {
            nsIIOService ios = Xpcom.GetService <nsIIOService>("@mozilla.org/network/io-service;1");

            ios = Xpcom.QueryInterface <nsIIOService>(ios);
            nsIURI ssURI = ios.NewURI(new nsAUTF8String(sheetURI), null, null);

            if (!StyleSheetService.sheetRegistered(ssURI, type))
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        public AutoJSContext()
        {
            // obtain the JS runtime used by gecko
            nsIJSRuntimeService runtimeService = (nsIJSRuntimeService)Xpcom.GetService("@mozilla.org/js/xpc/RuntimeService;1");
            IntPtr jsRuntime = runtimeService.GetRuntimeAttribute();

            // create a new JSContext
            cx = JS_NewContext(jsRuntime, 8192);

            // 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) which we will use when compiling the empty script below
            nsIPrincipal system       = Xpcom.GetService <nsIScriptSecurityManager>("@mozilla.org/scriptsecuritymanager;1").GetSystemPrincipal();
            IntPtr       jsPrincipals = system.GetJSPrincipals(cx);

            // create a fake stack frame
            JSStackFrame frame = new JSStackFrame();

            frame.script = JS_CompileScriptForPrincipals(cx, JS_GetGlobalObject(cx), jsPrincipals, "", 0, "", 1);

            // put a pointer to the fake stack frame on the JSContext

            // frame.down = cx->fp
            IntPtr old = Marshal.ReadIntPtr(cx, OfsetOfFP);

            frame.down = old;

            IntPtr framePtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(JSStackFrame)));

            Marshal.StructureToPtr(frame, framePtr, true);

            // cx->fp = framePtr;
            Marshal.WriteIntPtr(cx, OfsetOfFP, framePtr);
        }
Exemplo n.º 9
0
        public CookieManager()
        {
            var manager = Xpcom.GetService <nsICookieManager2>("@mozilla.org/cookiemanager;1");

            _cookieManager = Xpcom.QueryInterface <nsICookieManager2>(manager);
        }
Exemplo n.º 10
0
        public void Dispose()
        {
            nsIJSContextStack contextStack = Xpcom.GetService <nsIJSContextStack>("@mozilla.org/js/xpc/ContextStack;1");

            contextStack.Pop();
        }
 public GeckoStyleSheetService()
 {
     StyleSheetService = Xpcom.GetService <nsIStyleSheetService>("@mozilla.org/content/style-sheet-service;1");
     StyleSheetService = Xpcom.QueryInterface <nsIStyleSheetService>(StyleSheetService);
 }