コード例 #1
0
        private static IntPtr GetContextByName(string contextName)
        {
            Xpcom.AssertCorrectThread();

            IntPtr rt    = Runtime;
            IntPtr iterp = IntPtr.Zero;
            IntPtr cx;

            while ((cx = SpiderMonkey.JS_ContextIterator(rt, ref iterp)) != IntPtr.Zero)
            {
                IntPtr global = SpiderMonkey.JS_GetGlobalObject(cx);
                if (global != IntPtr.Zero)
                {
                    IntPtr classp = SpiderMonkey.JS_GetClass(global);
                    // get class name
                    if (classp != IntPtr.Zero)
                    {
                        string className = Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(classp));
                        if (className == contextName)
                        {
                            return(cx);
                        }
                    }
                }
            }
            return(IntPtr.Zero);
        }
コード例 #2
0
		/// <summary>
		/// Add hooks to listen for new JSContext creation and store the context for later use.
		/// </summary>
		internal static void Initialize()
		{
			Xpcom.AssertCorrectThread();

			if (!_isInitialized)
				_isInitialized = true;			
		}
コード例 #3
0
ファイル: Xpcom.cs プロジェクト: Arsslensoft/ALFX
        ///	<summary>
        /// Helper method for WeakReference
        ///	</summary>
        internal static IntPtr QueryReferent(object obj, ref Guid uuid)
        {
            Xpcom.AssertCorrectThread();

            IntPtr ppv, pUnk = Marshal.GetIUnknownForObject(obj);

            Marshal.QueryInterface(pUnk, ref uuid, out ppv);

            Marshal.Release(pUnk);

            return(ppv);
        }
コード例 #4
0
        /// <summary>
        /// Add hooks to listen for new JSContext creation and store the context for later use.
        /// </summary>
        internal static void Initialize()
        {
            Xpcom.AssertCorrectThread();

            if (!_isInitialized)
            {
                _isInitialized = true;

                using (var runtimeService = new Gecko.Interop.ServiceWrapper <nsIJSRuntimeService>("@mozilla.org/js/xpc/RuntimeService;1"))
                {
                    _originalContextCallback = SpiderMonkey.JS_SetContextCallback(Runtime, _globalContextCallback);
                }
            }
        }
コード例 #5
0
        internal byte[] DrawWindow(nsIDOMWindow window, uint x, uint y, uint w, uint h)
        {
            Xpcom.AssertCorrectThread();
            Init();

            SetValue("x", x);
            SetValue("y", y);
            SetValue("w", w);
            SetValue("h", h);

            using (var data = Xpcom.CreateInstance2 <nsIWritableVariant>("@mozilla.org/variant;1"))
            {
                data.Instance.SetAsISupports((nsISupports)window);
                using (var key = new nsAString("window"))
                {
                    object comObj = command.Instance.SetUserData(key, data.Instance, null);
                    Xpcom.FreeComObject(ref comObj);
                    command.Instance.DoCommand();
                    comObj = command.Instance.SetUserData(key, null, null);
                    Xpcom.FreeComObject(ref comObj);
                }
            }
            string base64Image = null;

            using (var key = new nsAString("drawResult"))
            {
                using (var drawResult = command.Instance.SetUserData(key, null, null).AsComPtr())
                {
                    if (drawResult != null)
                    {
                        base64Image = drawResult.Instance.GetAsWString();
                    }
                }
            }

            if (base64Image == null)
            {
                throw new InvalidOperationException();
            }
            if (!base64Image.StartsWith("data:image/png;base64,"))
            {
                throw new InvalidOperationException(base64Image);
            }

            byte[] bytes = Convert.FromBase64String(base64Image.Substring("data:image/png;base64,".Length));
            return(bytes);
        }
コード例 #6
0
        internal byte[] DrawWindow(mozIDOMWindowProxy window, uint x, uint y, uint w, uint h)
        {
            Xpcom.AssertCorrectThread();
            Init();

            var proxy = (mozIDOMWindowProxy)Xpcom.QueryInterface(_webNav.Instance, typeof(mozIDOMWindowProxy).GUID);

            SetValue(proxy, "x", x);
            SetValue(proxy, "y", y);
            SetValue(proxy, "w", w);
            SetValue(proxy, "h", h);

            new HTMLElement(proxy, (nsISupports)_command.Instance).SetProperty("sourceWin", window);
            var element = new HTMLElement(proxy, (nsISupports)_command.Instance);

            element.Click();
            string base64Image = null;
            var    dataSet     = new DOMStringMap(proxy, new HTMLElement(proxy, (nsISupports)_command.Instance).Dataset);
            var    drawResult  = dataSet.GetProperty <string>("drawResult");

            if (drawResult != null)
            {
                base64Image = drawResult;
            }

            if (base64Image == null)
            {
                throw new InvalidOperationException();
            }
            if (!base64Image.StartsWith("data:image/png;base64,"))
            {
                throw new InvalidOperationException(base64Image);
            }

            byte[] bytes = Convert.FromBase64String(base64Image.Substring("data:image/png;base64,".Length));
            return(bytes);
        }