コード例 #1
0
ファイル: CefView.cs プロジェクト: ydkgame/WebViewANE
 public void Load(UrlRequest url, string allowingReadAccessTo = null)
 {
     if (_isLoaded)
     {
         CurrentBrowser.Load(url.Url);
     }
     else
     {
         InitialUrl = url;
     }
 }
コード例 #2
0
ファイル: CefView.cs プロジェクト: ydkgame/WebViewANE
 public void LoadHtmlString(string html, UrlRequest url)
 {
     if (_isLoaded)
     {
         CurrentBrowser.LoadHtml(html, url.Url);
     }
     else
     {
         _initialHtml = html;
         InitialUrl   = url;
     }
 }
コード例 #3
0
ファイル: MainController.cs プロジェクト: ydkgame/WebViewANE
        private FREObject Load(FREContext ctx, uint argc, FREObject[] argv)
        {
            try {
                var request = new UrlRequest(argv[0], _useEdge);
                UrlRequestHeaderManager.GetInstance().Add(request);
                _view.Load(request, argc > 1 ? argv[1].AsString() : null);
            }
            catch (Exception e) {
                return(new FreException(e).RawValue);
            }

            return(FREObject.Zero);
        }
コード例 #4
0
ファイル: EdgeView.cs プロジェクト: slavikyad/WebViewANE
 public void Load(UrlRequest url, string allowingReadAccessTo = null)
 {
     if (allowingReadAccessTo != null)
     {
         LoadFile(url.Url, allowingReadAccessTo);
     }
     else
     {
         try {
             var headers = url.RequestHeaders;
             _currentBrowser.Navigate(new Uri(url.Url), HttpMethod.Get, null,
                                      headers.Count > 0 ? headers : null);
         }
         catch (Exception e) {
             Context.DispatchEvent("TRACE", e.Message);
         }
     }
 }
コード例 #5
0
        public void Add(UrlRequest urlRequest)
        {
            var uri = new Uri(urlRequest.Url);

            if (urlRequest.RequestHeaders.Count == 0)
            {
                Headers.Remove(uri.Host);
                return;
            }

            if (Headers.ContainsKey(uri.Host))
            {
                Headers[uri.Host] = urlRequest.RequestHeaders;
            }
            else
            {
                Headers.Add(uri.Host, urlRequest.RequestHeaders);
            }
        }
コード例 #6
0
ファイル: MainController.cs プロジェクト: ydkgame/WebViewANE
        private FREObject InitView(FREContext ctx, uint argc, FREObject[] argv)
        {
            FreSharpLogger.GetInstance().Context = Context;
            _airWindow = Process.GetCurrentProcess().MainWindowHandle;
            if (_airWindow == Hwnd.Zero)
            {
                return(new FreException(
                           "Cannot find AIR window to attach webView to. Ensure you init the ANE AFTER your main Sprite is initialized. " +
                           "Please see https://forum.starling-framework.org/topic/webviewane-for-osx/page/7?replies=201#post-105524 for more details")
                       .RawValue);
            }

            bool useTransparentBackground;

            try {
                dynamic settings = new FreObjectSharp(argv[2]);
                _useEdge = settings.engine == 1;

                UrlRequestHeaderManager.GetInstance().PersistRequestHeaders = settings.persistRequestHeaders;
                dynamic    cefSettings = new FreObjectSharp(settings.cef);
                var        freUrl      = argv[0];
                UrlRequest initialUrl  = null;
                if (FreObjectTypeSharp.Null != freUrl.Type())
                {
                    initialUrl = new UrlRequest(freUrl, _useEdge);
                    UrlRequestHeaderManager.GetInstance().Add(initialUrl);
                }

                var viewPort = argv[1].AsRect();

                useTransparentBackground = settings.useTransparentBackground;
                FREArray clArr = cefSettings.commandLineArgs;

                var argsDict = new Dictionary <string, string>();
                foreach (var argFre in clArr)
                {
                    var key = argFre.GetProp("key").AsString();
                    var val = argFre.GetProp("value").AsString();
                    if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(val))
                    {
                        continue;
                    }
                    argsDict.Add(key, val);
                }

                ArrayList whiteList = settings.urlWhiteList.AsArrayList();
                ArrayList blackList = settings.urlBlackList.AsArrayList();

                _backgroundColor = argv[4].AsColor();
                var backgroundMediaColor = new System.Windows.Media.Color {
                    A = _backgroundColor.A,
                    R = _backgroundColor.R,
                    G = _backgroundColor.G,
                    B = _backgroundColor.B
                };

                _useHiDpi = settings.useHiDPI;

                if (Environment.OSVersion.Version.Major > 7)
                {
                    _scaleFactor = _useHiDpi ? WinApi.GetScaleFactor(_airWindow) : 1.0;
                }
                else
                {
                    _scaleFactor = _useHiDpi ? WinApi.GetScaleFactor() : 1.0;
                }

                if (_useEdge)
                {
                    EdgeView.Context = Context;
                    _view            = new EdgeView {
                        Background = new SolidColorBrush(backgroundMediaColor)
                    };
                }
                else
                {
                    CefView.Context = Context;
                    dynamic contextMenu = new FreObjectSharp(settings.contextMenu);
                    dynamic popup       = new FreObjectSharp(settings.popup);
                    dynamic dimensions  = new FreObjectSharp(popup.dimensions);

                    _view = new CefView {
                        Background          = new SolidColorBrush(backgroundMediaColor),
                        RemoteDebuggingPort = cefSettings.remoteDebuggingPort,
                        EnablePrintPreview  = cefSettings.enablePrintPreview,
                        CachePath           = cefSettings.cachePath,
                        DownloadPath        = settings.downloadPath,
                        EnableDownloads     = settings.enableDownloads,
                        CacheEnabled        = settings.cacheEnabled,
                        LogLevel            = cefSettings.logSeverity,
                        AcceptLanguageList  = cefSettings.acceptLanguageList,
                        Locale             = cefSettings.locale,
                        ContextMenuEnabled = contextMenu.enabled,
                        UserAgent          = settings.userAgent,
                        UserDataPath       = cefSettings.userDataPath,
                        CommandLineArgs    = argsDict,
                        PopupBehaviour     = (PopupBehaviour)popup.behaviour,
                        PopupDimensions    = new Tuple <int, int>(dimensions.width, dimensions.height),
                        ScaleFactor        = _scaleFactor
                    };
                }

                _view.InitialUrl = initialUrl;
                _view.WhiteList  = whiteList;
                _view.BlackList  = blackList;
                _view.X          = Convert.ToInt32(viewPort.X * _scaleFactor);
                _view.Y          = Convert.ToInt32(viewPort.Y * _scaleFactor);
                _view.ViewWidth  = Convert.ToInt32(viewPort.Width * _scaleFactor);
                _view.ViewHeight = Convert.ToInt32(viewPort.Height * _scaleFactor);
                _view.Init();
            }
            catch (Exception e) {
                return(new FreException(e).RawValue);
            }

            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;

            if (useTransparentBackground && Environment.OSVersion.Version.Major > 7)
            {
                parameters.ExtendedWindowStyle      = (int)WindowExStyles.WS_EX_LAYERED;
                parameters.UsesPerPixelTransparency = true;
            }

            var source = _useEdge
                ? new HwndSource(parameters)
            {
                RootVisual = (EdgeView)_view
            }
                : new HwndSource(parameters)
            {
                RootVisual = (CefView)_view
            };

            if (useTransparentBackground && source.CompositionTarget != null)
            {
                source.CompositionTarget.BackgroundColor = Colors.Transparent;
            }

            _webViewWindow = source.Handle;

            MessageTouchDevice.RegisterTouchWindow(_webViewWindow);

            return(FREObject.Zero);
        }
コード例 #7
0
ファイル: EdgeView.cs プロジェクト: slavikyad/WebViewANE
 public void LoadHtmlString(string html, UrlRequest url)
 {
     _currentBrowser.NavigateToString(html);
 }