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); }
/// <summary> /// Remove a override for the given hostname:port. /// </summary> /// <param name="url"></param> public void ClearValidityOverride(Uri url) { if (url == null) { throw new ArgumentNullException("url"); } var mapping = new System.Globalization.IdnMapping(); using (var aHostName = new nsACString(url.Scheme != "all" ? mapping.GetAscii(url.Host) : url.OriginalString)) { Instance.ClearValidityOverride(aHostName, url.Port); } }
/// <param name="flags">see nsICertOverrideServiceConsts</param> public static void RememberValidityOverride(Uri url, ComPtr <nsIX509Cert> cert, int flags) { if (url == null) { throw new ArgumentNullException("url"); } using (var aHostName = new nsACString(url.Host)) { using (var svc = GetService()) { svc.Instance.RememberValidityOverride(aHostName, url.Port, cert.Instance, (uint)flags, true); } } }
public static void ClearValidityOverride(Uri url) { if (url == null) { throw new ArgumentNullException("url"); } using (var aHostName = new nsACString(url.Host)) { using (var svc = GetService()) { svc.Instance.ClearValidityOverride(aHostName, url.Port); } } }
public bool HasMatchingOverride(Uri url, Certificate cert) { if (url == null) { throw new ArgumentNullException("url"); } var mapping = new System.Globalization.IdnMapping(); using (var aHostName = new nsACString(mapping.GetAscii(url.Host))) { uint flags = 0; bool isTemp = false; return(Instance.HasMatchingOverride(aHostName, url.Port, cert._cert.Instance, ref flags, ref isTemp)); } }
public static bool HasMatchingOverride(Uri url, ComPtr <nsIX509Cert> cert) { if (url == null) { throw new ArgumentNullException("url"); } using (var aHostName = new nsACString(url.Host)) { uint flags = 0; bool isTemp = false; using (var overrideSvc = GetService()) { return(overrideSvc.Instance.HasMatchingOverride(aHostName, url.Port, cert.Instance, ref flags, ref isTemp)); } } }
/// <summary> /// The given cert should always be accepted for the given hostname:port, /// regardless of errors verifying the cert. /// Host:Port is a primary key, only one entry per host:port can exist. /// </summary> /// <param name="url"></param> /// <param name="cert">The cert that should always be accepted</param> /// <param name="flags">The errors we want to be overriden.</param> public void RememberValidityOverride(Uri url, Certificate cert, CertOverride flags, bool temporary) { if (url == null) { throw new ArgumentNullException("url"); } if (cert == null) { throw new ArgumentNullException("cert"); } var mapping = new System.Globalization.IdnMapping(); using (var aHostName = new nsACString(mapping.GetAscii(url.Host))) { Instance.RememberValidityOverride(aHostName, url.Port, cert._cert.Instance, (uint)flags, temporary); } }
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; } 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 ? "libxpcom.so" : "xpcom.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 (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()); //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? 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()); } _IsInitialized = true; GlobalJSContextHolder.Initialize(); if (AfterInitalization != null) { AfterInitalization(); } }
/// <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; }