public static string Get(StringAttributeAnsi getter) { using (nsACString str = new nsACString()) { getter(str); return str.ToString(); } }
public static void Set(StringAttributeAnsi setter, string value) { using (nsACString str = new nsACString()) { if (!string.IsNullOrEmpty(value)) str.SetData(value); setter(str); } }
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); }
public static void Set(StringAttributeAnsi setter, string value) { using (nsACString str = new nsACString()) { if (!string.IsNullOrEmpty(value)) { str.SetData(value); } setter(str); } }
static extern int NS_CStringContainerFinish(nsACString container);
internal static extern int NS_CStringGetData(nsACString str, out IntPtr data, IntPtr nullTerm);
static extern int NS_CStringSetData(nsACString str, string data, int length);
static extern int NS_CStringContainerInit(nsACString container);
private static extern int NS_NewNativeLocalFile(nsACString path, bool followLinks, [MarshalAs(UnmanagedType.IUnknown)] out object result);
/// <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; }
/// <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; }
/// <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; }