Ejemplo n.º 1
0
		public static nsIServiceManager GetProxy (Mono.WebBrowser.IWebBrowser control, nsIServiceManager obj)
		{
			object o = Base.GetProxyForObject (control, typeof(nsIServiceManager).GUID, obj);
			return o as nsIServiceManager;
		}
Ejemplo n.º 2
0
 static extern int NS_InitXPCOM2([MarshalAs(UnmanagedType.Interface)] out nsIServiceManager serviceManager, [MarshalAs(UnmanagedType.IUnknown)] object binDirectory, nsIDirectoryServiceProvider appFileLocationProvider);
Ejemplo n.º 3
0
 static extern int NS_ShutdownXPCOM([MarshalAs(UnmanagedType.Interface)] nsIServiceManager serviceManager);
Ejemplo n.º 4
0
		public static extern nsResult NS_GetServiceManager(out nsIServiceManager result);
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes XPCOM using the specified directory.
        /// </summary>
        /// <param name="binDirectory">The directory which contains xul.dll.</param>
        public static void Initialize(string binDirectory)
        {
            if (_IsInitialized)
            {
                return;
            }

            if (BeforeInitalization != null)
            {
                BeforeInitalization();
            }

            Interlocked.Exchange(ref _XpcomThreadId, Thread.CurrentThread.ManagedThreadId);

            if (IsWindows)
            {
                Kernel32.SetDllDirectory(binDirectory);
            }

            string folder    = binDirectory ?? Environment.CurrentDirectory;
            string xpcomPath = Path.Combine(folder, IsLinux ? "libxul.so" : "xul.dll");

            try
            {
                // works on windows
                // but some classes can be not exist on mono (may be)
                // so make it in another function(stack allocation is making on function start)
                ReadXulrunnerVersion(xpcomPath);
            }
            catch (Exception)
            {
            }


            if (binDirectory != null)
            {
                Environment.SetEnvironmentVariable("PATH",
                                                   Environment.GetEnvironmentVariable("PATH") + ";" + binDirectory, EnvironmentVariableTarget.Process);
            }

            object mreAppDir = null;

            if (binDirectory != null)
            {
                using (nsAString str = new nsAString(Path.GetFullPath(binDirectory)))
                    if (NS_NewLocalFile(str, true, out mreAppDir) != 0)
                    {
                        throw new Exception("Failed on NS_NewLocalFile");
                    }
            }

            // temporarily change the current directory so NS_InitEmbedding can find all the DLLs it needs
            String oldCurrent = Environment.CurrentDirectory;

            Environment.CurrentDirectory = folder;

            nsIServiceManager serviceManager;
            //int res = NS_InitXPCOM2(out serviceManagerPtr, mreAppDir, new DirectoryServiceProvider());


            //Note: the error box that this can generate can't be prevented with try/catch, and res is 0 even if it fails
            //REVIEW: how else can we determine what happened and give a more useful answer, to help new GeckoFX users,
            //Telling them that probably the version of firefox or xulrunner didn't match this library version?

            // calling NS_InitXPCOM2 invokes AddRef to the returned nsIServerManager, but as this gets assigned to the __ComObject serviceManager
            // Release will be called by the when the GC runs __ComObject finaliser.
            int res = NS_InitXPCOM2(out serviceManager, mreAppDir, null);

            // change back
            Environment.CurrentDirectory = oldCurrent;

            if (res != 0)
            {
                throw new Exception("Failed on NS_InitXPCOM2");
            }

            ServiceManager = (nsIServiceManager)serviceManager;

            // get some global objects we will need later
            NS_GetComponentManager(out ComponentManager);
            NS_GetComponentRegistrar(out ComponentRegistrar);

            if (IsMono)
            {
                _comGC = new COMGC();
            }



            // RegisterProvider is necessary to get link styles etc.
            nsIDirectoryService directoryService = GetService <nsIDirectoryService>("@mozilla.org/file/directory_service;1");

            if (directoryService != null)
            {
                directoryService.RegisterProvider(new ProfileProvider());
            }

            _IsInitialized = true;
            GlobalJSContextHolder.Initialize();

            // On Linux calling CreateWindowlessBrowser too early crashes with passing null to gdk_window_enable_synchronized_configure()
            // the gdkwidgets window is null.
            if (!Xpcom.IsLinux)
            {
                InitChromeContext();
            }

            PromptFactoryFactory.Init();

            if (AfterInitalization != null)
            {
                AfterInitalization();
            }
        }
Ejemplo n.º 6
0
		public static extern nsResult NS_ShutdownXPCOM(nsIServiceManager servMgr);
Ejemplo n.º 7
0
		public static extern nsResult NS_InitXPCOM2(out nsIServiceManager result, nsIFile binDirectory, nsIDirectoryServiceProvider appFileLocationProvider);
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes XPCOM using the specified directory.
        /// </summary>
        /// <param name="binDirectory">The directory which contains xul.dll.</param>
        public static void Initialize(string binDirectory)
        {
            if (_IsInitialized)
            {
                return;
            }

            Debug.WriteLineIf(Thread.CurrentThread.GetApartmentState() != ApartmentState.STA,
                              "Warning: Main Entry point missing [STAThread] attribute.");
            Debug.Assert(Thread.CurrentThread.GetApartmentState() == ApartmentState.STA,
                         "Main Entry point missing [STAThread] attribute.");

            if (BeforeInitalization != null)
            {
                BeforeInitalization();
            }

            Interlocked.Exchange(ref _XpcomThreadId, Thread.CurrentThread.ManagedThreadId);

            if (IsWindows)
            {
                Kernel32.SetDllDirectory(binDirectory);
            }

            string folder    = binDirectory ?? Environment.CurrentDirectory;
            string xpcomPath = Path.Combine(folder, IsLinux ? "libxul.so" : "xul.dll");

            try
            {
                // works on windows
                // but some classes can be not exist on mono (may be)
                // so make it in another function(stack allocation is making on function start)
                ReadXulrunnerVersion(xpcomPath);
            }
            catch (Exception)
            {
            }


            if (binDirectory != null)
            {
                Environment.SetEnvironmentVariable("PATH", string.Format("{0}{1}{2}",
                                                                         Environment.GetEnvironmentVariable("PATH"), Path.PathSeparator, binDirectory),
                                                   EnvironmentVariableTarget.Process);
            }

            object mreAppDir = null;

            if (binDirectory != null)
            {
                using (nsAString str = new nsAString(Path.GetFullPath(binDirectory)))
                    if (NS_NewLocalFile(str, true, out mreAppDir) != 0)
                    {
                        throw new Exception("Failed on NS_NewLocalFile");
                    }
            }

            // temporarily change the current directory so NS_InitEmbedding can find all the DLLs it needs
            String oldCurrent = Environment.CurrentDirectory;

            Environment.CurrentDirectory = folder;

            nsIServiceManager serviceManager;
            //int res = NS_InitXPCOM2(out serviceManagerPtr, mreAppDir, new DirectoryServiceProvider());


            //Note: the error box that this can generate can't be prevented with try/catch, and res is 0 even if it fails
            //REVIEW: how else can we determine what happened and give a more useful answer, to help new GeckoFX users,
            //Telling them that probably the version of firefox or xulrunner didn't match this library version?

            // calling NS_InitXPCOM2 invokes AddRef to the returned nsIServerManager, but as this gets assigned to the __ComObject serviceManager
            // Release will be called by the when the GC runs __ComObject finaliser.
            int res = NS_InitXPCOM2(out serviceManager, mreAppDir, null);

            // change back
            Environment.CurrentDirectory = oldCurrent;

            if (res != 0)
            {
                throw new Exception("Failed on NS_InitXPCOM2");
            }

            ServiceManager = (nsIServiceManager)serviceManager;

            // get some global objects we will need later
            NS_GetComponentManager(out ComponentManager);
            NS_GetComponentRegistrar(out ComponentRegistrar);

            if (IsMono)
            {
                _comGC = new COMGC();
            }

            // RegisterProvider is necessary to get link styles etc.
            nsIDirectoryService directoryService =
                GetService <nsIDirectoryService>("@mozilla.org/file/directory_service;1");

            if (directoryService != null)
            {
                directoryService.RegisterProvider(new DirectoryServiceProvider());
            }

            _IsInitialized = true;

            // On Linux calling CreateWindowlessBrowser too early crashes with passing null to gdk_window_enable_synchronized_configure()
            // the gdkwidgets window is null.
            if (!Xpcom.IsLinux)
            {
                InitChromeContext();
            }

            XULAppInfoFactory.Init();
            OnProfileStartup();
            PromptFactoryFactory.Init();

            if (AfterInitalization != null)
            {
                AfterInitalization();
            }

            if (Xpcom.IsLinux)
            {
                // Firefox enable offmainthreadcomposition on Linux around May 2015.
                // (see https://mozillagfx.wordpress.com/2015/05/19/off-main-thread-compositing-on-linux/ )
                // However with geckofx on Linux we end up with two Compositors.
                // So we end up with a ClientLayerManager with an uninitalzied mTransactionIdAllocator
                // which causes segfault on Paint.
                GeckoPreferences.User["layers.offmainthreadcomposition.enabled"] = false;
            }
        }
Ejemplo n.º 9
0
        public static nsIServiceManager GetProxy(Mono.WebBrowser.IWebBrowser control, nsIServiceManager obj)
        {
            object o = Base.GetProxyForObject(control, typeof(nsIServiceManager).GUID, obj);

            return(o as nsIServiceManager);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes XPCOM using the specified directory.
        /// </summary>
        /// <param name="binDirectory">The directory which contains xpcom.dll.</param>
        public static void Initialize(string binDirectory)
        {
            if (_IsInitialized)
            {
                return;
            }

            Interlocked.Exchange(ref _XpcomThreadId, Thread.CurrentThread.ManagedThreadId);

            if (IsWindows)
            {
                Kernel32.SetDllDirectory(binDirectory);
            }

            string folder    = binDirectory ?? Environment.CurrentDirectory;
            string xpcomPath = Path.Combine(folder, IsLinux ? "libxpcom.so" : "xpcom.dll");

            if (Debugger.IsAttached)
            {
                // make sure this DLL is there
                if (!File.Exists(xpcomPath))
                {
                    if (MessageBox.Show("Couldn't find XULRunner in '" + folder + "'.  Call Xpcom.Initialize() in your application startup code and specify the directory where XULRunner is installed.\r\n\r\n" +
                                        "If you do not have XULRunner installed, click Yes to open the download page.  Otherwise, click No, and update your application startup code.",
                                        "XULRunner Not Found", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                    {
                        Process.Start("http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/1.9.1.2/runtimes/xulrunner-1.9.1.2.en-US.win32.zip");
                    }

                    Environment.Exit(0);
                }
            }

            if (binDirectory != null)
            {
                Environment.SetEnvironmentVariable("path",
                                                   Environment.GetEnvironmentVariable("path") + ";" + binDirectory, EnvironmentVariableTarget.Process);
            }

            object mreAppDir = null;

            if (binDirectory != null)
            {
                using (nsACString str = new nsACString(Path.GetFullPath(binDirectory)))
                    if (NS_NewNativeLocalFile(str, true, out mreAppDir) != 0)
                    {
                        throw new Exception("Failed on NS_NewNativeLocalFile");
                    }
            }

            // temporarily change the current directory so NS_InitEmbedding can find all the DLLs it needs
            String oldCurrent = Environment.CurrentDirectory;

            Environment.CurrentDirectory = folder;

            nsIServiceManager serviceManagerPtr;
            //int res = NS_InitXPCOM2(out serviceManagerPtr, mreAppDir, new DirectoryServiceProvider());
            int res = NS_InitXPCOM2(out serviceManagerPtr, mreAppDir, null);

            // change back
            Environment.CurrentDirectory = oldCurrent;

            if (res != 0)
            {
                throw new Exception("Failed on NS_InitXPCOM2");
            }

            ServiceManager = (nsIServiceManager)serviceManagerPtr;

            // get some global objects we will need later
            NS_GetComponentManager(out ComponentManager);
            NS_GetComponentRegistrar(out ComponentRegistrar);

            // RegisterProvider is neccessary to get link styles etc.
            nsIDirectoryService directoryService = GetService <nsIDirectoryService>("@mozilla.org/file/directory_service;1");

            if (directoryService != null)
            {
                directoryService.RegisterProvider(new ProfileProvider());
            }

            if (UseCustomPrompt)
            {
                PromptFactoryFactory.Register();
            }

            _IsInitialized = true;
        }