public nsISupports GetCurrentDescriptorAttribute()
            {
                const string          ComponentManagerCID = "91775d60-d5dc-11d2-92fb-00e09805570f";
                nsIComponentRegistrar mgr = (nsIComponentRegistrar)Xpcom.GetObjectForIUnknown((IntPtr)Xpcom.GetService(new Guid(ComponentManagerCID)));

                return((nsISupports)mgr);
            }
        public void GetAppShell_CleanXpComInstance_ReturnsValidInstance()
        {
            System.IntPtr ptr      = (IntPtr)Xpcom.GetService(new Guid("2d96b3df-c051-11d1-a827-0040959a28c9"));
            var           instance = (nsIAppShell)Xpcom.GetObjectForIUnknown(ptr);

            Assert.IsNotNull(instance);
        }
        internal static T GetElementAs <T>(this nsIArray array, int index)
        {
            Guid uid = typeof(T).GUID;
            var  ptr = array.QueryElementAt((uint)index, ref uid);
            var  obj = ( T )Xpcom.GetObjectForIUnknown(ptr);

            return(obj);
        }
Exemple #4
0
        public void BeforeEachTestSetup()
        {
            Xpcom.Initialize(XpComTests.XulRunnerLocation);
            // defined in nsIXPConent.idl
            // CB6593E0-F9B2-11d2-BDD6-000064657374
            var ptr = (IntPtr)Xpcom.GetService(new Guid("CB6593E0-F9B2-11d2-BDD6-000064657374"));

            Assert.IsNotNull(ptr);
            m_instance = (nsIXPConnect)Xpcom.GetObjectForIUnknown(ptr);
            Assert.IsNotNull(m_instance);
        }
        public void JavaScriptToCSharpCallBack()
        {
            // Note: Firefox 17 removed enablePrivilege #546848 - refactored test so that javascript to create "@mozillazine.org/example/priority;1" is now executated by AutoJsContext

            // Register a C# COM Object

            const string          ComponentManagerCID = "91775d60-d5dc-11d2-92fb-00e09805570f";
            nsIComponentRegistrar mgr = (nsIComponentRegistrar)Xpcom.GetObjectForIUnknown((IntPtr)Xpcom.GetService(new Guid(ComponentManagerCID)));
            Guid aClass = new Guid("a7139c0e-962c-44b6-bec3-aaaaaaaaaaab");

            mgr.RegisterFactory(ref aClass, "Example C sharp com component", "@geckofx/mysharpclass;1", new MyCSharpComClassFactory());

            // In order to use Components.classes etc we need to enable certan privileges.
            GeckoPreferences.User["capability.principal.codebase.p0.granted"]     = "UniversalXPConnect";
            GeckoPreferences.User["capability.principal.codebase.p0.id"]          = "file://";
            GeckoPreferences.User["capability.principal.codebase.p0.subjectName"] = "";
            GeckoPreferences.User["security.fileuri.strict_origin_policy"]        = false;

#if PORT
            browser.JavascriptError += (x, w) => Console.WriteLine(w.Message);
#endif

            string inithtml = "<html><body></body></html>";

            string initialjavascript =
                "var myClassInstance = Components.classes['@geckofx/mysharpclass;1'].createInstance(Components.interfaces.nsICommandHandler); myClassInstance.exec('hello', 'world');";

            // Create temp file to load
            var tempfilename = Path.GetTempFileName();
            tempfilename += ".html";
            using (TextWriter tw = new StreamWriter(tempfilename))
            {
                tw.WriteLine(inithtml);
                tw.Close();
            }

            browser.Navigate(tempfilename);
            browser.NavigateFinishedNotifier.BlockUntilNavigationFinished();
            File.Delete(tempfilename);

            using (var context = new AutoJSContext(GlobalJSContextHolder.BackstageJSContext))
            {
                string result  = String.Empty;
                bool   success = context.EvaluateScript(initialjavascript, out result);
                Console.WriteLine("success = {1} result = {0}", result, success);
            }

            // Test the results
            Assert.AreEqual(MyCSharpComClass._execCount, 1);
            Assert.AreEqual(MyCSharpComClass._aCommand, "hello");
            Assert.AreEqual(MyCSharpComClass._aParameters, "world");
        }
        public static PluginTag[] GetPluginTags()
        {
            PluginTag[] tags;
            IntPtr      pluginTagsArrayPtr = IntPtr.Zero;

            try
            {
                uint aCount = 0;
                pluginTagsArrayPtr = _pluginHost.Instance.GetPluginTags(ref aCount);
                int      count   = (int)aCount;
                IntPtr[] tagPtrs = new IntPtr[count];
                tags = new PluginTag[count];
                Marshal.Copy(pluginTagsArrayPtr, tagPtrs, 0, tagPtrs.Length);

                for (int i = 0; i < count; i++)
                {
                    object tag = null;
                    try
                    {
                        tag     = Xpcom.GetObjectForIUnknown(tagPtrs[i]);
                        tags[i] = new PluginTag(Xpcom.QueryInterface <nsIPluginTag>(tag));
                    }
                    finally
                    {
                        if (tag != null)
                        {
                            Marshal.ReleaseComObject(tag);
                        }
                    }
                }
            }
            finally
            {
                if (pluginTagsArrayPtr != IntPtr.Zero)
                {
                    Xpcom.Free(pluginTagsArrayPtr);
                }
            }
            return(tags);
        }