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); }
static GeckoPreferences() { // ensure we're initialized Xpcom.Initialize(); PrefService = Xpcom.GetService <nsIPrefService>("@mozilla.org/preferences-service;1"); }
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 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); }
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); }
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); }
public CookieManager() { var manager = Xpcom.GetService <nsICookieManager2>("@mozilla.org/cookiemanager;1"); _cookieManager = Xpcom.QueryInterface <nsICookieManager2>(manager); }
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); }