Esempio n. 1
0
        public virtual ChromelyConfiguration RegisterCustomrUrlScheme(string schemeName, string domainName)
        {
            UrlScheme scheme = new UrlScheme(schemeName, domainName, false);

            UrlSchemeProvider.RegisterScheme(scheme);
            return(this);
        }
Esempio n. 2
0
        public virtual ChromelyConfiguration RegisterExternaleUrlScheme(string schemeName, string domainName)
        {
            UrlScheme scheme = new UrlScheme(schemeName, domainName, true);

            UrlSchemeProvider.RegisterScheme(scheme);
            return(this);
        }
Esempio n. 3
0
 /// <summary>
 /// The init.
 /// </summary>
 private void Init()
 {
     UrlSchemeProvider.RegisterScheme(new UrlScheme("http", "chromely.com", false));
     UrlSchemeProvider.RegisterScheme(new UrlScheme("https", "test.com", false));
     UrlSchemeProvider.RegisterScheme(new UrlScheme("https://www.google.com", true));
     UrlSchemeProvider.RegisterScheme(new UrlScheme("http://www.test.com", true));
 }
Esempio n. 4
0
 /// <summary>
 /// The init.
 /// </summary>
 private void Init()
 {
     UrlSchemeProvider.RegisterScheme(new UrlScheme("http", "chromely.com", UrlSchemeType.Custom));
     UrlSchemeProvider.RegisterScheme(new UrlScheme("https", "test.com", UrlSchemeType.Custom));
     UrlSchemeProvider.RegisterScheme(new UrlScheme("https://www.google.com", UrlSchemeType.External));
     UrlSchemeProvider.RegisterScheme(new UrlScheme("http://www.test.com", UrlSchemeType.External));
 }
Esempio n. 5
0
        /// <summary>
        /// The on before popup.
        /// </summary>
        /// <param name="browser">
        /// The browser.
        /// </param>
        /// <param name="frame">
        /// The frame.
        /// </param>
        /// <param name="targetUrl">
        /// The target url.
        /// </param>
        /// <param name="targetFrameName">
        /// The target frame name.
        /// </param>
        /// <param name="targetDisposition">
        /// The target disposition.
        /// </param>
        /// <param name="userGesture">
        /// The user gesture.
        /// </param>
        /// <param name="popupFeatures">
        /// The popup features.
        /// </param>
        /// <param name="windowInfo">
        /// The window info.
        /// </param>
        /// <param name="client">
        /// The client.
        /// </param>
        /// <param name="settings">
        /// The settings.
        /// </param>
        /// <param name="noJavascriptAccess">
        /// The no javascript access.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
        {
            var isUrlExternal = UrlSchemeProvider.IsUrlRegisteredExternal(targetUrl);
            if (isUrlExternal)
            {
                RegisteredExternalUrl.Launch(targetUrl);
            }

            return true;
        }
Esempio n. 6
0
        public virtual ChromelyConfiguration RegisterSchemeHandler(ChromelySchemeHandler chromelySchemeHandler)
        {
            if (chromelySchemeHandler != null)
            {
                UrlScheme scheme = new UrlScheme(chromelySchemeHandler.SchemeName, chromelySchemeHandler.DomainName, false);
                UrlSchemeProvider.RegisterScheme(scheme);
                IoC.RegisterInstance(typeof(ChromelySchemeHandler), chromelySchemeHandler.Key, chromelySchemeHandler);
            }

            return(this);
        }
Esempio n. 7
0
        /// <summary>
        /// Registers scheme handler.
        /// </summary>
        /// <param name="schemeHandler">
        /// The chromely scheme handler.
        /// </param>
        /// <returns>
        /// The <see cref="ChromelyConfiguration"/> object.
        /// </returns>
        public virtual ChromelyConfiguration RegisterSchemeHandler(ChromelySchemeHandler schemeHandler)
        {
            if (schemeHandler != null)
            {
                var scheme = new UrlScheme(schemeHandler.SchemeName, schemeHandler.DomainName, UrlSchemeType.Custom);
                UrlSchemeProvider.RegisterScheme(scheme);
                IoC.RegisterInstance(typeof(ChromelySchemeHandler), schemeHandler.Key, schemeHandler);
            }

            return(this);
        }
Esempio n. 8
0
        /// <summary>
        /// Registers scheme handler.
        /// </summary>
        /// <param name="ePlugSchemeHandler">
        /// The blis scheme handler.
        /// </param>
        /// <returns>
        /// The <see cref="CefConfiguration"/> object.
        /// </returns>
        public virtual CefConfiguration RegisterSchemeHandler(SchemeHandler ePlugSchemeHandler)
        {
            if (ePlugSchemeHandler != null)
            {
                var scheme = new UrlScheme(ePlugSchemeHandler.SchemeName, ePlugSchemeHandler.DomainName, false);
                UrlSchemeProvider.RegisterScheme(scheme);
                IoC.RegisterInstance(typeof(SchemeHandler), ePlugSchemeHandler.Key, ePlugSchemeHandler);
            }

            return(this);
        }
Esempio n. 9
0
        /// <summary>
        /// The on before browse.
        /// </summary>
        /// <param name="browserControl">
        /// The browser control.
        /// </param>
        /// <param name="browser">
        /// The browser.
        /// </param>
        /// <param name="frame">
        /// The frame.
        /// </param>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <param name="isRedirect">
        /// The is redirect.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        bool IRequestHandler.OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, bool isRedirect)
        {
            bool isUrlExternal = UrlSchemeProvider.IsUrlRegisteredExternal(request.Url);

            if (isUrlExternal)
            {
                System.Diagnostics.Process.Start(request.Url);
                return(true);
            }

            return(false);
        }
Esempio n. 10
0
        protected override bool OnBeforeBrowse(CefBrowser browser, CefFrame frame, CefRequest request, bool isRedirect)
        {
            bool isUrlExternal = UrlSchemeProvider.IsUrlRegisteredExternal(request.Url);

            if (isUrlExternal)
            {
                System.Diagnostics.Process.Start(request.Url);
                return(true);
            }

            return(false);
        }
Esempio n. 11
0
        /// <summary>
        /// The on before browse.
        /// </summary>
        /// <param name="browser">
        /// The browser.
        /// </param>
        /// <param name="frame">
        /// The frame.
        /// </param>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <param name="userGesture">
        /// The user gesture.
        /// </param>
        /// <param name="isRedirect">
        /// The is redirect.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        protected override bool OnBeforeBrowse(CefBrowser browser, CefFrame frame, CefRequest request, bool userGesture, bool isRedirect)
        {
            var isUrlExternal = UrlSchemeProvider.IsUrlRegisteredExternal(request.Url);

            if (isUrlExternal)
            {
                // https://brockallen.com/2016/09/24/process-start-for-urls-on-net-core/
                try
                {
                    Process.Start(request.Url);
                }
                catch
                {
                    try
                    {
                        // hack because of this: https://github.com/dotnet/corefx/issues/10361
                        if (CefRuntime.Platform == CefRuntimePlatform.Windows)
                        {
                            var url = request.Url.Replace("&", "^&");
                            Process.Start(new ProcessStartInfo("cmd", $"/c start {url}")
                            {
                                CreateNoWindow = true
                            });
                        }
                        else if (CefRuntime.Platform == CefRuntimePlatform.Linux)
                        {
                            Process.Start("xdg-open", request.Url);
                        }
                        else if (CefRuntime.Platform == CefRuntimePlatform.MacOSX)
                        {
                            Process.Start("open", request.Url);
                        }
                    }
                    catch (Exception exception)
                    {
                        Log.Error(exception);
                    }
                }

                return(true);
            }

            var isUrlCommand = UrlSchemeProvider.IsUrlRegisteredCommand(request.Url);

            if (isUrlCommand)
            {
                CommandTaskRunner.RunAsync(request.Url);
                return(true);
            }

            return(false);
        }
Esempio n. 12
0
        /// <summary>
        /// The on before popup.
        /// </summary>
        /// <param name="browserControl">
        /// The browser control.
        /// </param>
        /// <param name="browser">
        /// The browser.
        /// </param>
        /// <param name="frame">
        /// The frame.
        /// </param>
        /// <param name="targetUrl">
        /// The target url.
        /// </param>
        /// <param name="targetFrameName">
        /// The target frame name.
        /// </param>
        /// <param name="targetDisposition">
        /// The target disposition.
        /// </param>
        /// <param name="userGesture">
        /// The user gesture.
        /// </param>
        /// <param name="popupFeatures">
        /// The popup features.
        /// </param>
        /// <param name="windowInfo">
        /// The window info.
        /// </param>
        /// <param name="browserSettings">
        /// The browser settings.
        /// </param>
        /// <param name="noJavascriptAccess">
        /// The no javascript access.
        /// </param>
        /// <param name="newBrowser">
        /// The new browser.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            newBrowser = null;

            var isUrlExternal = UrlSchemeProvider.IsUrlRegisteredExternal(targetUrl);

            if (isUrlExternal)
            {
                System.Diagnostics.Process.Start(targetUrl);
            }

            return(true);
        }
Esempio n. 13
0
        /// <summary>
        /// The run.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <returns>
        /// The <see cref="ChromelyResponse"/>.
        /// </returns>
        /// <exception cref="Exception">
        /// Generic exception - Route path not valid.
        /// </exception>
        public static ChromelyResponse Run(IRequest request)
        {
            bool isCustomScheme = UrlSchemeProvider.IsUrlOfRegisteredCustomScheme(request.Url);

            if (!isCustomScheme)
            {
                throw new Exception($"Url {request.Url} is not of a registered custom scheme.");
            }

            var    uri        = new Uri(request.Url);
            string routePath  = uri.LocalPath;
            var    parameters = GetParameters(request.Url);
            object postData   = GetPostData(request);

            return(Run(routePath, parameters, postData));
        }
Esempio n. 14
0
        /// <summary>
        /// The run.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <returns>
        /// The <see cref="ChromelyResponse"/>.
        /// </returns>
        /// <exception cref="Exception">
        /// Generic exception - Route path not valid.
        /// </exception>
        public static ChromelyResponse Run(IRequest request)
        {
            var isCustomScheme = UrlSchemeProvider.IsUrlOfRegisteredCustomScheme(request.Url);

            if (!isCustomScheme)
            {
                throw new Exception($"Url {request.Url} is not of a registered custom scheme.");
            }

            var uri        = new Uri(request.Url);
            var path       = uri.LocalPath;
            var parameters = request.Url.GetParameters();
            var postData   = GetPostData(request);

            var routePath = new RoutePath(request.Method, path);

            return(Run(string.Empty, routePath, parameters, postData));
        }
Esempio n. 15
0
        /// <summary>
        /// The process request async.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <param name="callback">
        /// The callback.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public override bool ProcessRequestAsync(IRequest request, ICallback callback)
        {
            bool isCustomScheme = UrlSchemeProvider.IsUrlOfRegisteredCustomScheme(request.Url);

            if (isCustomScheme)
            {
                Task.Run(() =>
                {
                    using (callback)
                    {
                        try
                        {
                            this.mChromelyResponse = RequestTaskRunner.Run(request);

                            string jsonData = this.mChromelyResponse.Data.EnsureResponseIsJsonFormat();
                            var content     = Encoding.UTF8.GetBytes(jsonData);
                            this.mStream.Write(content, 0, content.Length);
                            this.mMimeType = "application/json";
                        }
                        catch (Exception exception)
                        {
                            Log.Error(exception);

                            this.mChromelyResponse =
                                new ChromelyResponse
                            {
                                Status = (int)HttpStatusCode.BadRequest,
                                Data   = "An error occured."
                            };
                        }
                        finally
                        {
                            callback.Continue();
                        }
                    }
                });

                return(true);
            }

            Log.Error($"Url {request.Url} is not of a registered custom scheme.");
            callback.Dispose();
            return(false);
        }
Esempio n. 16
0
        /// <summary>
        /// The on before browse.
        /// </summary>
        /// <param name="browserControl">
        /// The browser control.
        /// </param>
        /// <param name="browser">
        /// The browser.
        /// </param>
        /// <param name="frame">
        /// The frame.
        /// </param>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <param name="userGesture">
        /// The user Gesture.
        /// </param>
        /// <param name="isRedirect">
        /// The is redirect.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        bool IRequestHandler.OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, bool userGesture, bool isRedirect)
        {
            bool isUrlExternal = UrlSchemeProvider.IsUrlRegisteredExternal(request.Url);

            if (isUrlExternal)
            {
                System.Diagnostics.Process.Start(request.Url);
                return(true);
            }

            var isUrlCommand = UrlSchemeProvider.IsUrlRegisteredCommand(request.Url);

            if (isUrlCommand)
            {
                CommandTaskRunner.RunAsync(request.Url);
                return(true);
            }

            return(false);
        }
Esempio n. 17
0
        /// <summary>
        /// The process request.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <param name="callback">
        /// The callback.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        protected override bool ProcessRequest(CefRequest request, CefCallback callback)
        {
            bool isCustomScheme = UrlSchemeProvider.IsUrlOfRegisteredCustomScheme(request.Url);

            if (isCustomScheme)
            {
                Task.Run(() =>
                {
                    using (callback)
                    {
                        try
                        {
                            mChromelyResponse = RequestTaskRunner.Run(request);
                            string jsonData   = mChromelyResponse.Data.EnsureResponseIsJsonFormat();
                            mResponseBytes    = Encoding.UTF8.GetBytes(jsonData);
                        }
                        catch (Exception exception)
                        {
                            Log.Error(exception);

                            mChromelyResponse =
                                new ChromelyResponse
                            {
                                Status = (int)HttpStatusCode.BadRequest,
                                Data   = "An error occured."
                            };
                        }
                        finally
                        {
                            callback.Continue();
                        }
                    }
                });

                return(true);
            }

            Log.Error($"Url {request.Url} is not of a registered custom scheme.");
            callback.Dispose();
            return(false);
        }
Esempio n. 18
0
        protected override bool ProcessRequest(CefRequest request, CefCallback callback)
        {
            bool isCustomScheme = UrlSchemeProvider.IsUrlOfRegisteredCustomScheme(request.Url);

            if (isCustomScheme)
            {
                Task.Factory.StartNew(() =>
                {
                    using (callback)
                    {
                        try
                        {
                            m_chromelyResponse = CefGlueRequestTaskRunner.Run(request);
                        }
                        catch (Exception exception)
                        {
                            Log.Error(exception);

                            m_chromelyResponse        = new ChromelyResponse();
                            m_chromelyResponse.Status = (int)HttpStatusCode.BadRequest;
                            m_chromelyResponse.Data   = "An error occured.";
                        }
                        finally
                        {
                            callback.Continue();
                        }
                    }
                });

                return(true);
            }

            Log.Error(string.Format("Url {0} is not of a registered custom scheme.", request.Url));
            callback.Dispose();
            return(false);
        }
Esempio n. 19
0
 /// <summary>
 /// The register url scheme.
 /// </summary>
 /// <param name="scheme">
 /// The scheme.
 /// </param>
 public void RegisterUrlScheme(UrlScheme scheme)
 {
     UrlSchemeProvider.RegisterScheme(scheme);
 }
Esempio n. 20
0
 public void RegisterExternalUrlScheme(UrlScheme scheme)
 {
     scheme.IsExternal = true;
     UrlSchemeProvider.RegisterScheme(scheme);
 }
Esempio n. 21
0
 public void IsCustomUrlTest()
 {
     Assert.True(UrlSchemeProvider.IsUrlOfRegisteredCustomScheme("http://chromely.com/getvaluefromme"));
     Assert.True(UrlSchemeProvider.IsUrlOfRegisteredCustomScheme("https://test.com/savevaluetome"));
 }
Esempio n. 22
0
 public void IsExternalUrlTest()
 {
     Assert.True(UrlSchemeProvider.IsUrlRegisteredExternal("https://www.google.com/getvaluefromme"));
     Assert.True(UrlSchemeProvider.IsUrlRegisteredExternal("http://www.test.com/savevaluetome"));
 }
Esempio n. 23
0
 /// <summary>
 /// Registers customr url scheme.
 /// </summary>
 /// <param name="urlScheme">
 /// The url scheme object.
 /// </param>
 /// <returns>
 /// The <see cref="ChromelyConfiguration"/> object.
 /// </returns>
 public virtual ChromelyConfiguration RegisterCustomrUrlScheme(UrlScheme urlScheme)
 {
     UrlSchemeProvider.RegisterScheme(urlScheme);
     return(this);
 }