コード例 #1
0
ファイル: nsString.cs プロジェクト: niravpatel/PopcornStudios
		public static string Get(StringAttributeAnsi getter)
		{
			using (nsACString str = new nsACString())
			{
				getter(str);
				return str.ToString();
			}
		}
コード例 #2
0
ファイル: nsString.cs プロジェクト: niravpatel/PopcornStudios
		public static void Set(StringAttributeAnsi setter, string value)
		{
			using (nsACString str = new nsACString())
			{
				if (!string.IsNullOrEmpty(value))
					str.SetData(value);
				
				setter(str);
			}
		}
コード例 #3
0
ファイル: Xpcom.cs プロジェクト: LoveChiba/jg.editor
        public static object NewNativeLocalFile(string filename)
        {
            object result;

            using (nsACString str = new nsACString(filename))
                if (NS_NewNativeLocalFile(str, true, out result) == 0)
                {
                    return(result);
                }

            return(null);
        }
コード例 #4
0
        public static void Set(StringAttributeAnsi setter, string value)
        {
            using (nsACString str = new nsACString())
            {
                if (!string.IsNullOrEmpty(value))
                {
                    str.SetData(value);
                }

                setter(str);
            }
        }
コード例 #5
0
 static extern int NS_CStringContainerFinish(nsACString container);
コード例 #6
0
 internal static extern int NS_CStringGetData(nsACString str, out IntPtr data, IntPtr nullTerm);
コード例 #7
0
 static extern int NS_CStringContainerFinish(nsACString container);
コード例 #8
0
 internal static extern int NS_CStringGetData(nsACString str, out IntPtr data, IntPtr nullTerm);
コード例 #9
0
 static extern int NS_CStringSetData(nsACString str, string data, int length);
コード例 #10
0
 static extern int NS_CStringContainerInit(nsACString container);
コード例 #11
0
 private static extern int NS_NewNativeLocalFile(nsACString path, bool followLinks, [MarshalAs(UnmanagedType.IUnknown)] out object result);
コード例 #12
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;
            }

            string folder    = binDirectory ?? Environment.CurrentDirectory;
            string xpcomPath = Path.Combine(folder, "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.8.1.3/contrib/win32");
                    }

                    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;

            IntPtr 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)Marshal.GetObjectForIUnknown(serviceManagerPtr);

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

            _IsInitialized = true;
        }
コード例 #13
0
ファイル: Xpcom.cs プロジェクト: LoveChiba/jg.editor
        /// <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;
            }

            string folder    = binDirectory ?? Environment.CurrentDirectory;
            string xpcomPath = Path.Combine(folder, "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)
                    {
                                                #if GECKO_1_9_1
                        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");
                                                #elif GECKO_1_9
                        Process.Start("http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/1.9.0.13/runtimes/xulrunner-1.9.0.13.en-US.win32.zip");
                                                #elif GECKO_1_8
                        Process.Start("http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/1.8.1.3/contrib/win32");
                                                #endif
                    }

                    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;

            IntPtr 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)Marshal.GetObjectForIUnknown(serviceManagerPtr);

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

            // a bug in Mozilla 1.8 (https://bugzilla.mozilla.org/show_bug.cgi?id=309877) causes the PSM to
            // crash when loading a site over HTTPS.  in order to work around this bug, we must register an nsIDirectoryServiceProvider
            // which will provide the location of a profile
            nsIDirectoryService directoryService = GetService <nsIDirectoryService>("@mozilla.org/file/directory_service;1");
            directoryService.RegisterProvider(new ProfileProvider());

            _IsInitialized = true;
        }
コード例 #14
0
 static extern int NS_CStringContainerInit(nsACString container);
コード例 #15
0
 private static extern int NS_NewNativeLocalFile(nsACString path, bool followLinks, [MarshalAs(UnmanagedType.IUnknown)] out object result);
コード例 #16
0
 static extern int NS_CStringSetData(nsACString str, string data, int length);
コード例 #17
0
        /// <summary>
        /// Initializes XPCOM using the specified GeckoAppInfo.
        /// </summary>
        public static void Initialize(GeckoAppInfo geckoInfo)
        {
            if (_IsInitialized)
            {
                return;
            }

            string folder       = geckoInfo.GeckoPath;
            string binDirectory = (folder != Application.StartupPath) ? folder : null;
            string xpcomPath    = Path.Combine(folder, "xpcom.dll");

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

                    Environment.Exit(0);
                }
            }

            if (binDirectory != null)
            {
                Environment.SetEnvironmentVariable("path",
                                                   String.Format("{0};{1}", 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;

            IntPtr 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");
            }

            // ok, we initialized xpcom, most like we will work, so we need gecko version from now on
            geckoAppInfo = geckoInfo;

            ServiceManager = (nsIServiceManager)Marshal.GetObjectForIUnknown(serviceManagerPtr);

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

            // a bug in Mozilla 1.8 (https://bugzilla.mozilla.org/show_bug.cgi?id=309877) causes the PSM to
            // crash when loading a site over HTTPS.  in order to work around this bug, we must register an nsIDirectoryServiceProvider
            // which will provide the location of a profile
            nsIDirectoryService directoryService = GetService <nsIDirectoryService>("@mozilla.org/file/directory_service;1");

            directoryService.RegisterProvider(new ProfileProvider());

            XULAppInfo.Initialize();

            _IsInitialized = true;
        }