/// <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);
        }
        static GeckoPreferences()
        {
            // ensure we're initialized
            Xpcom.Initialize();

            PrefService = Xpcom.GetService <nsIPrefService>("@mozilla.org/preferences-service;1");
        }
Example #3
0
        private static void OnProfileStartup()
        {
            if (!EnableProfileMonitoring)
            {
                return;
            }

            nsIObserver addonsIntegration = null;

            nsIObserverService obsSvc = Xpcom.GetService <nsIObserverService>(Contracts.ObserverService);

            obsSvc.NotifyObservers(null, "profile-do-change", "startup");
            try
            {
                addonsIntegration = Xpcom.GetService <nsIObserver>("@mozilla.org/addons/integration;1");
                if (addonsIntegration != null)
                {
                    addonsIntegration.Observe(null, "addons-startup", null);
                }

                obsSvc.NotifyObservers(null, "load-extension-defaults", null);
            }
            finally
            {
                Xpcom.FreeComObject(ref addonsIntegration);

                obsSvc.NotifyObservers(null, "profile-after-change", "startup");
                NS_CreateServicesFromCategory("profile-after-change", null, "profile-after-change");
                obsSvc.NotifyObservers(null, "profile-initial-state", null);
                Xpcom.FreeComObject(ref obsSvc);
            }
        }
Example #4
0
        /// <summary>
        /// Create service wrapped into ComPtr'T
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="contractID"></param>
        /// <returns></returns>
        public static ComPtr <T> GetService2 <T>(string contractID)
            where T : class
        {
            if (!Xpcom.IsInitialized)
            {
                throw new GeckoException("Xpcom.Initialize must be called before using of any xulrunner/gecko-fx services");
            }
            var service = Xpcom.GetService <T>(contractID);
            var ret     = new ComPtr <T>(service);

            return(ret);
        }
        public static CertOverrideService GetService()
        {
            var svc     = Xpcom.GetService <nsICertOverrideService>(Contracts.CertOverride);
            var certSvc = svc as CertOverrideService;

            if (certSvc != null)
            {
                Marshal.Release(certSvc._pUnknown);
                return(certSvc);
            }
            return(Gecko.Interop.ExtensionMethods.Wrap(svc, CertOverrideService.Create));
        }
Example #6
0
        public static CertOverrideService GetService()
        {
            var svc     = Xpcom.GetService <nsICertOverrideService>(Contracts.CertOverride);
            var certSvc = svc as CertOverrideService;

            if (certSvc != null)
            {
                Marshal.Release(certSvc._pUnknown);
                return(certSvc);
            }
            return(svc.Wrap(CertOverrideService.Create));
        }
Example #7
0
        public static void MinimizeHeap(bool immeadiate)
        {
            var memoryService = Xpcom.GetService <nsIMemory>("@mozilla.org/xpcom/memory-service;1");

            try
            {
                memoryService.HeapMinimize(immeadiate);
            }
            catch (Exception)
            {
                //Ignore
            }
            finally
            {
                Marshal.ReleaseComObject(memoryService);
            }
        }
Example #8
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);
        }
Example #9
0
 public static void Init()
 {
     backXulRuntime = Xpcom.GetService <nsIXULRuntime>(Contracts.XulRuntime);
 }
Example #10
0
 internal static void Init()
 {
     factory = Xpcom.GetService <nsIPromptFactory>("@mozilla.org/prompter;1");
 }
        protected override void OnHandleCreated(EventArgs e)
        {
#if GTK
            if (Xpcom.IsMono)
            {
                base.OnHandleCreated(e);
                m_wrapper.Init();
            }
#endif
            if (!this.DesignMode)
            {
                Xpcom.Initialize();
                WindowCreator.Register();
#if !GTK
                LauncherDialogFactory.Register();
#endif

                WebBrowser      = Xpcom.CreateInstance <nsIWebBrowser>("@mozilla.org/embedding/browser/nsWebBrowser;1");
                WebBrowserFocus = (nsIWebBrowserFocus)WebBrowser;
                BaseWindow      = (nsIBaseWindow)WebBrowser;

                WebNav = (nsIWebNavigation)WebBrowser;

                WebBrowser.SetContainerWindowAttribute(this);
#if GTK
                if (Xpcom.IsMono)
                {
                    BaseWindow.InitWindow(m_wrapper.BrowserWindow.Handle, IntPtr.Zero, 0, 0, this.Width, this.Height);
                }
                else
#endif
                BaseWindow.InitWindow(this.Handle, IntPtr.Zero, 0, 0, this.Width, this.Height);


                RecordNewJsContext();
                BaseWindow.Create();

                Guid nsIWebProgressListenerGUID = typeof(nsIWebProgressListener).GUID;
                WebBrowser.AddWebBrowserListener(this.GetWeakReference(), ref nsIWebProgressListenerGUID);

                if (UseHttpActivityObserver)
                {
                    ObserverService.AddObserver(this, ObserverNotifications.HttpRequests.HttpOnModifyRequest, false);

                    nsIHttpActivityDistributor activityDistributor = Xpcom.GetService <nsIHttpActivityDistributor>("@mozilla.org/network/http-activity-distributor;1");
                    activityDistributor = Xpcom.QueryInterface <nsIHttpActivityDistributor>(activityDistributor);
                    activityDistributor.AddObserver(this);
                }

                // var domEventListener = new GeckoDOMEventListener(this);

                _target = Xpcom.QueryInterface <nsIDOMWindow>(WebBrowser.GetContentDOMWindowAttribute()).GetWindowRootAttribute();

                _target.AddEventListener(new nsAString("submit"), this, true, true, 2);
                _target.AddEventListener(new nsAString("keydown"), this, true, true, 2);
                _target.AddEventListener(new nsAString("keyup"), this, true, true, 2);
                _target.AddEventListener(new nsAString("keypress"), this, true, true, 2);
                _target.AddEventListener(new nsAString("mousemove"), this, true, true, 2);
                _target.AddEventListener(new nsAString("mouseover"), this, true, true, 2);
                _target.AddEventListener(new nsAString("mouseout"), this, true, true, 2);
                _target.AddEventListener(new nsAString("mousedown"), this, true, true, 2);
                _target.AddEventListener(new nsAString("mouseup"), this, true, true, 2);
                _target.AddEventListener(new nsAString("click"), this, true, true, 2);
                _target.AddEventListener(new nsAString("dblclick"), this, true, true, 2);
                _target.AddEventListener(new nsAString("compositionstart"), this, true, true, 2);
                _target.AddEventListener(new nsAString("compositionend"), this, true, true, 2);
                _target.AddEventListener(new nsAString("contextmenu"), this, true, true, 2);
                _target.AddEventListener(new nsAString("DOMMouseScroll"), this, true, true, 2);
                _target.AddEventListener(new nsAString("focus"), this, true, true, 2);
                _target.AddEventListener(new nsAString("blur"), this, true, true, 2);
                // Load event added here rather than DOMDocument as DOMDocument recreated when navigating
                // ths losing attached listener.
                _target.AddEventListener(new nsAString("load"), this, true, true, 2);
                _target.AddEventListener(new nsAString("change"), this, true, true, 2);

                // history
                {
                    var sessionHistory = WebNav.GetSessionHistoryAttribute();
                    if (sessionHistory != null)
                    {
                        sessionHistory.AddSHistoryListener(this);
                    }
                }

                BaseWindow.SetVisibilityAttribute(true);

                // this fix prevents the browser from crashing if the first page loaded is invalid (missing file, invalid URL, etc)
                if (Document != null)
                {
                    // only for html documents
                    Document.Cookie = "";
                }
            }

            base.OnHandleCreated(e);
        }
Example #12
0
        private static void NS_CreateServicesFromCategory(string category, nsISupports origin, string observerTopic)
        {
            nsICategoryManager      catMan      = null;
            nsISimpleEnumerator     enumerator  = null;
            nsIUTF8StringEnumerator senumerator = null;

            try
            {
                catMan = Xpcom.GetService <nsICategoryManager>(Contracts.CategoryManager);
                if (catMan == null)
                {
                    return;
                }

                enumerator = catMan.EnumerateCategory(category);
                if (enumerator == null)
                {
                    return;
                }

                senumerator = Xpcom.QueryInterface <nsIUTF8StringEnumerator>(enumerator);
                if (senumerator == null)
                {
                    return;
                }

                while (senumerator.HasMore())
                {
                    nsISupports serviceInstance = null;
                    nsIObserver observer        = null;
                    try
                    {
                        string entryString = nsString.Get(senumerator.GetNext);
                        string contractID  = catMan.GetCategoryEntry(category, entryString);
                        serviceInstance = Xpcom.GetService <nsISupports>(contractID);
                        if (serviceInstance == null || observerTopic == null)
                        {
                            continue;
                        }

                        observer = Xpcom.QueryInterface <nsIObserver>(serviceInstance);
                        if (observer == null)
                        {
                            continue;
                        }

                        observer.Observe(origin, observerTopic, "");
                    }
                    catch (NotImplementedException) { }
                    catch (OutOfMemoryException) { }
                    catch (COMException) { }
                    finally
                    {
                        Xpcom.FreeComObject(ref serviceInstance);
                        Xpcom.FreeComObject(ref observer);
                    }
                }
            }
            finally
            {
                Xpcom.FreeComObject(ref catMan);
                Xpcom.FreeComObject(ref enumerator);
                Xpcom.FreeComObject(ref senumerator);
            }
        }