Beispiel #1
0
        private FREObject Capture(FREContext ctx, uint argc, FREObject[] argv)
        {
            var rect = new WinApi.Rect();

            WinApi.GetWindowRect(_cefWindow, ref rect);
            try {
                var freX = argv[0].AsInt();
                var freY = argv[1].AsInt();
                var freW = argv[2].AsInt();
                var freH = argv[3].AsInt();

                var width  = freW > 0 ? freW : rect.right - rect.left;
                var height = freH > 0 ? freH : rect.bottom - rect.top;

                var bmp      = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                var graphics = Graphics.FromImage(bmp);
                graphics.CopyFromScreen(rect.left + freX, rect.top + freY, 0, 0, new Size(width, height),
                                        CopyPixelOperation.SourceCopy);
                return(bmp.ToFREObject());
            }
            catch (Exception e) {
                return(new FreException(e).RawValue);
            }
        }
Beispiel #2
0
        public FREObject SetViewPort(FREContext ctx, uint argc, FREObject[] argv)
        {
            System.Windows.Rect viewPort;
            try {
                viewPort = argv[0].AsRect();
            }
            catch (Exception e) {
                return(new FreException(e).RawValue);
            }

            var tmpX      = Convert.ToInt32(viewPort.X * _scaleFactor);
            var tmpY      = Convert.ToInt32(viewPort.Y * _scaleFactor);
            var tmpWidth  = Convert.ToInt32(viewPort.Width * _scaleFactor);
            var tmpHeight = Convert.ToInt32(viewPort.Height * _scaleFactor);

            var updateWidth  = false;
            var updateHeight = false;
            var updateX      = false;
            var updateY      = false;

            if (tmpWidth != _view.ViewWidth)
            {
                _view.ViewWidth = tmpWidth;
                updateWidth     = true;
            }

            if (tmpHeight != _view.ViewHeight)
            {
                _view.ViewHeight = tmpHeight;
                updateHeight     = true;
            }

            if (tmpX != _view.X)
            {
                _view.X = tmpX;
                updateX = true;
            }

            if (tmpY != _view.Y)
            {
                _view.Y = tmpY;
                updateY = true;
            }

            if (!updateX && !updateY && !updateWidth && !updateHeight)
            {
                return(FREObject.Zero);
            }
            var flgs = (WindowPositionFlags)0;

            if (!updateWidth && !updateHeight)
            {
                flgs |= WindowPositionFlags.SWP_NOSIZE;
            }
            if (!updateX && !updateY)
            {
                flgs |= WindowPositionFlags.SWP_NOMOVE;
            }
            WinApi.SetWindowPos(_cefWindow, new Hwnd(0), _view.X, _view.Y, _view.ViewWidth, _view.ViewHeight, flgs);
            WinApi.UpdateWindow(_cefWindow);
            return(FREObject.Zero);
        }
Beispiel #3
0
        public FREObject InitView(FREContext ctx, uint argc, FREObject[] argv)
        {
            _airWindow = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
            if (_airWindow == Hwnd.Zero)
            {
                var e = new Exception(
                    "Cannot find AIR window to attach webView to. Ensure you init the ANE AFTER your main Sprite is initialised. " +
                    "Please see https://forum.starling-framework.org/topic/webviewane-for-osx/page/7?replies=201#post-105524 for more details");
                return(new FreException(e).RawValue);
            }

            try {
                var viewPort       = argv[1].AsRect(); //viewPort
                var inFre2         = argv[2];          //settings
                var inFre4         = argv[4];          //backgroundColor
                var cefSettingsFre = inFre2.GetProp("cef");
                var useHiDpi       = argv[5].AsBool();

                var clArr    = new FREArray(cefSettingsFre.GetProp("commandLineArgs"));
                var argsDict = new Dictionary <string, string>();

                uint i;
                for (i = 0; i < clArr.Length; ++i)
                {
                    var argFre = clArr.At(i);
                    var key    = argFre.GetProp("key").AsString();
                    var val    = argFre.GetProp("value").AsString();
                    if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(val))
                    {
                        continue;
                    }
                    argsDict.Add(key, val);
                }

                var whiteList = inFre2.GetProp("urlWhiteList").ToArrayList();
                var blackList = inFre2.GetProp("urlBlackList").ToArrayList();
                _backgroundColor = inFre4.AsColor(true);
                _scaleFactor     = useHiDpi ? WinApi.GetScaleFactor() : 1.0;

                CefView.Context = Context;
                _view           = new CefView {
                    InitialUrl            = argv[0].AsString(),
                    Background            = new SolidColorBrush(_backgroundColor),
                    X                     = Convert.ToInt32(viewPort.X * _scaleFactor),
                    Y                     = Convert.ToInt32(viewPort.Y * _scaleFactor),
                    ViewWidth             = Convert.ToInt32(viewPort.Width * _scaleFactor),
                    ViewHeight            = Convert.ToInt32(viewPort.Height * _scaleFactor),
                    RemoteDebuggingPort   = cefSettingsFre.GetProp("remoteDebuggingPort").AsInt(),
                    CachePath             = cefSettingsFre.GetProp("cachePath").AsString(),
                    CacheEnabled          = inFre2.GetProp("cacheEnabled").AsBool(),
                    LogLevel              = cefSettingsFre.GetProp("logSeverity").AsInt(),
                    BrowserSubprocessPath = cefSettingsFre.GetProp("browserSubprocessPath").AsString(),
                    ContextMenuEnabled    = cefSettingsFre.GetProp("contextMenu").GetProp("enabled").AsBool(),
                    EnableDownloads       = cefSettingsFre.GetProp("enableDownloads").AsBool(),
                    UserAgent             = inFre2.GetProp("userAgent").AsString(),
                    CommandLineArgs       = argsDict,
                    WhiteList             = whiteList,
                    BlackList             = blackList,
                    PopupBehaviour        = (PopupBehaviour)inFre2.GetProp("popup").GetProp("behaviour").AsInt(),
                    PopupDimensions       = new Tuple <int, int>(
                        inFre2.GetProp("popup").GetProp("dimensions").GetProp("width").AsInt(),
                        inFre2.GetProp("popup").GetProp("dimensions").GetProp("height").AsInt()
                        )
                };
                _view.Init();
            }
            catch (Exception e) {
                return(new FreException(e).RawValue); //return as3 error and throw in swc
            }

            var parameters = new HwndSourceParameters();

            parameters.SetPosition(_view.X, _view.Y);
            parameters.SetSize(_view.ViewWidth, _view.ViewHeight);
            parameters.ParentWindow = _airWindow;
            parameters.WindowName   = "Cef Window";
            parameters.WindowStyle  = (int)WindowStyles.WS_CHILD;
            parameters.AcquireHwndFocusInMenuMode = true;
            var source = new HwndSource(parameters)
            {
                RootVisual = _view
            };

            _cefWindow = source.Handle;

            WinApi.RegisterTouchWindow(_cefWindow, TouchWindowFlags.TWF_WANTPALM);

            return(FREObject.Zero);
        }
Beispiel #4
0
 public FREObject RemoveFromStage(FREContext ctx, uint argc, FREObject[] argv)
 {
     WinApi.ShowWindow(_cefWindow, ShowWindowCommands.SW_HIDE);
     WinApi.UpdateWindow(_cefWindow);
     return(FREObject.Zero);
 }
Beispiel #5
0
 public FREObject AddToStage(FREContext ctx, uint argc, FREObject[] argv)
 {
     WinApi.ShowWindow(_cefWindow, ShowWindowCommands.SW_SHOWNORMAL);
     WinApi.UpdateWindow(_cefWindow);
     return(FREObject.Zero);
 }
Beispiel #6
0
        public FREObject InitView(FREContext ctx, uint argc, FREObject[] argv)
        {
            _airWindow = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
            var inFre5         = new FreObjectSharp(argv[5]); //settings
            var cefSettingsFre = inFre5.GetProperty("cef");

            //Trace("initing view and here is a trace");

            var googleApiKeyFre              = cefSettingsFre.GetProperty("GOOGLE_API_KEY");
            var googleDefaultClientIdFre     = cefSettingsFre.GetProperty("GOOGLE_DEFAULT_CLIENT_ID");
            var googleDefaultClientSecretFre = cefSettingsFre.GetProperty("GOOGLE_DEFAULT_CLIENT_SECRET");


            if (FreObjectTypeSharp.String == googleApiKeyFre.GetType())
            {
                Environment.SetEnvironmentVariable("GOOGLE_API_KEY", Convert.ToString(googleApiKeyFre.Value));
            }
            if (FreObjectTypeSharp.String == googleDefaultClientIdFre.GetType())
            {
                Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_ID", Convert.ToString(googleDefaultClientIdFre.Value));
            }
            if (FreObjectTypeSharp.String == googleDefaultClientSecretFre.GetType())
            {
                Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_SECRET", Convert.ToString(googleDefaultClientSecretFre.Value));
            }

            var clArr    = new FreArraySharp(cefSettingsFre.GetProperty("commandLineArgs").RawValue);
            var argsDict = new Dictionary <string, string>();

            uint i;

            for (i = 0; i < clArr.Length; ++i)
            {
                var argFre = clArr.GetObjectAt(i);
                var key    = Convert.ToString(argFre.GetProperty("key").Value);
                var val    = Convert.ToString(argFre.GetProperty("value").Value);
                if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(val))
                {
                    continue;
                }
                argsDict.Add(key, val);
            }

            var whiteList = new FreArraySharp(inFre5.GetProperty("urlWhiteList").RawValue).GetAsArrayList();

            _view = new CefView {
                InitialUrl            = Convert.ToString(new FreObjectSharp(argv[0]).Value),
                Background            = _backgroundColorBrush,
                X                     = Convert.ToInt32(new FreObjectSharp(argv[1]).Value),
                Y                     = Convert.ToInt32(new FreObjectSharp(argv[2]).Value),
                ViewWidth             = Convert.ToInt32(new FreObjectSharp(argv[3]).Value),
                ViewHeight            = Convert.ToInt32(new FreObjectSharp(argv[4]).Value),
                RemoteDebuggingPort   = Convert.ToInt32(cefSettingsFre.GetProperty("remoteDebuggingPort").Value),
                CachePath             = Convert.ToString(cefSettingsFre.GetProperty("cachePath").Value),
                LogLevel              = Convert.ToInt32(cefSettingsFre.GetProperty("logSeverity").Value),
                BrowserSubprocessPath = Convert.ToString(cefSettingsFre.GetProperty("browserSubprocessPath").Value),
                EnableDownloads       = Convert.ToBoolean(cefSettingsFre.GetProperty("enableDownloads").Value),
                UserAgent             = Convert.ToString(inFre5.GetProperty("userAgent").Value),
                CommandLineArgs       = argsDict,
                WhiteList             = whiteList,
                PopupBehaviour        = (PopupBehaviour)inFre5.GetProperty("popup").GetProperty("behaviour").Value,
                PopupDimensions       = new Tuple <int, int>(
                    Convert.ToInt32(inFre5.GetProperty("popup").GetProperty("dimensions").GetProperty("width").Value),
                    Convert.ToInt32(inFre5.GetProperty("popup").GetProperty("dimensions").GetProperty("height").Value)
                    )
            };



            _view.Init();

            var parameters = new HwndSourceParameters();

            parameters.SetPosition(_view.X, _view.Y);
            parameters.SetSize(_view.ViewWidth, _view.ViewHeight);
            parameters.ParentWindow = _airWindow;
            parameters.WindowName   = "Cef Window";
            parameters.WindowStyle  = (int)WindowStyles.WS_CHILD;
            parameters.AcquireHwndFocusInMenuMode = true;
            var source = new HwndSource(parameters)
            {
                RootVisual = _view
            };

            _cefWindow = source.Handle;

            WinApi.RegisterTouchWindow(_cefWindow, TouchWindowFlags.TWF_WANTPALM);

            return(FREObject.Zero);
        }
Beispiel #7
0
        public FREObject InitView(FREContext ctx, uint argc, FREObject[] argv)
        {
            _airWindow = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
            if (_airWindow == Hwnd.Zero)
            {
                var e = new Exception(
                    "Cannot find AIR window to attach webView to. Ensure you init the ANE AFTER your main Sprite is initialised. " +
                    "Please see https://forum.starling-framework.org/topic/webviewane-for-osx/page/7?replies=201#post-105524 for more details");
                return(new FreException(e).RawValue);
            }

            try {
                var inFre1         = new FreRectangleSharp(argv[1]); //viewport
                var inFre2         = new FreObjectSharp(argv[2]);    //settings
                var inFre4         = new FreObjectSharp(argv[4]);    //backgroundColor
                var cefSettingsFre = inFre2.GetProperty("cef");

                var googleApiKeyFre              = cefSettingsFre.GetProperty("GOOGLE_API_KEY");
                var googleDefaultClientIdFre     = cefSettingsFre.GetProperty("GOOGLE_DEFAULT_CLIENT_ID");
                var googleDefaultClientSecretFre = cefSettingsFre.GetProperty("GOOGLE_DEFAULT_CLIENT_SECRET");

                if (FreObjectTypeSharp.String == googleApiKeyFre.GetType())
                {
                    Environment.SetEnvironmentVariable("GOOGLE_API_KEY", Convert.ToString(googleApiKeyFre.Value));
                }
                if (FreObjectTypeSharp.String == googleDefaultClientIdFre.GetType())
                {
                    Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_ID",
                                                       Convert.ToString(googleDefaultClientIdFre.Value));
                }
                if (FreObjectTypeSharp.String == googleDefaultClientSecretFre.GetType())
                {
                    Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_SECRET",
                                                       Convert.ToString(googleDefaultClientSecretFre.Value));
                }

                var clArr    = new FreArraySharp(cefSettingsFre.GetProperty("commandLineArgs").RawValue);
                var argsDict = new Dictionary <string, string>();

                uint i;
                for (i = 0; i < clArr.Length; ++i)
                {
                    var argFre = clArr.GetObjectAt(i);
                    var key    = Convert.ToString(argFre.GetProperty("key").Value);
                    var val    = Convert.ToString(argFre.GetProperty("value").Value);
                    if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(val))
                    {
                        continue;
                    }
                    argsDict.Add(key, val);
                }

                var whiteList = new FreArraySharp(inFre2.GetProperty("urlWhiteList").RawValue).GetAsArrayList();
                var blackList = new FreArraySharp(inFre2.GetProperty("urlBlackList").RawValue).GetAsArrayList();

                var rgb = FreSharpHelper.GetAsUInt(inFre4.RawValue);
                _backgroundColor = Color.FromRgb(
                    Convert.ToByte((rgb >> 16) & 0xff),
                    Convert.ToByte((rgb >> 8) & 0xff),
                    Convert.ToByte((rgb >> 0) & 0xff));

                var viewPort = inFre1.Value;
                _view = new CefView {
                    InitialUrl            = Convert.ToString(new FreObjectSharp(argv[0]).Value),
                    Background            = new SolidColorBrush(_backgroundColor),
                    X                     = Convert.ToInt32(viewPort.X),
                    Y                     = Convert.ToInt32(viewPort.Y),
                    ViewWidth             = Convert.ToInt32(viewPort.Width),
                    ViewHeight            = Convert.ToInt32(viewPort.Height),
                    RemoteDebuggingPort   = Convert.ToInt32(cefSettingsFre.GetProperty("remoteDebuggingPort").Value),
                    CachePath             = Convert.ToString(cefSettingsFre.GetProperty("cachePath").Value),
                    CacheEnabled          = Convert.ToBoolean(inFre2.GetProperty("cacheEnabled").Value),
                    LogLevel              = Convert.ToInt32(cefSettingsFre.GetProperty("logSeverity").Value),
                    BrowserSubprocessPath = Convert.ToString(cefSettingsFre.GetProperty("browserSubprocessPath").Value),
                    ContextMenuEnabled    = Convert.ToBoolean(cefSettingsFre.GetProperty("contextMenu")
                                                              .GetProperty("enabled")
                                                              .Value),
                    EnableDownloads = Convert.ToBoolean(cefSettingsFre.GetProperty("enableDownloads").Value),
                    UserAgent       = Convert.ToString(inFre2.GetProperty("userAgent").Value),
                    CommandLineArgs = argsDict,
                    WhiteList       = whiteList,
                    BlackList       = blackList,
                    PopupBehaviour  = (PopupBehaviour)inFre2.GetProperty("popup").GetProperty("behaviour").Value,
                    PopupDimensions = new Tuple <int, int>(
                        Convert.ToInt32(
                            inFre2.GetProperty("popup").GetProperty("dimensions").GetProperty("width").Value),
                        Convert.ToInt32(inFre2.GetProperty("popup").GetProperty("dimensions").GetProperty("height")
                                        .Value)
                        )
                };

                _view.Init();
            }
            catch (Exception e) {
                return(new FreException(e).RawValue); //return as3 error and throw in swc
            }

            var parameters = new HwndSourceParameters();

            parameters.SetPosition(_view.X, _view.Y);
            parameters.SetSize(_view.ViewWidth, _view.ViewHeight);
            parameters.ParentWindow = _airWindow;
            parameters.WindowName   = "Cef Window";
            parameters.WindowStyle  = (int)WindowStyles.WS_CHILD;
            parameters.AcquireHwndFocusInMenuMode = true;
            var source = new HwndSource(parameters)
            {
                RootVisual = _view
            };

            _cefWindow = source.Handle;

            WinApi.RegisterTouchWindow(_cefWindow, TouchWindowFlags.TWF_WANTPALM);

            return(FREObject.Zero);
        }